-
Notifications
You must be signed in to change notification settings - Fork 0
/
calibration2.c
228 lines (207 loc) · 5.97 KB
/
calibration2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "defines.h"
unsigned char calibration(void)
{
floor=1;
Write_7Seg(3,'L');
Write_7Seg(2,'A');
Write_7Seg(1,'C');
Write_7Seg(4, 0 );
blink_en=0;
read_inputs();
if(CA1 && CF1)
{return 1;} //retun OK! to Main Program
//The car had been in lowest floor
//read_inputs_relay();
if(FEEDBU || FEEDBD)
{contce=1;
while(contce);
return 0;}
if(FEEDBF || FEEDBS)
{contce=1;
while(contce);
return 0;}
//To test contactors for being free
// after triggering
if((CA1 && (!CF1))||Calfs)
{ //Slow Calibratoin is selected or
CONTD=1; //car is between CA1 and 1CF
set_outputs_relay();
ptimer=0;
do
{
if(ptimer>10)
{contnca=1;
while(contnca);
return 0;}
//read_inputs_relay();
}while(!FEEDBD); //Check D feedback
CONTS=1; //Go down slowly to show 1CF
set_outputs_relay();
ptimer=0;
do
{
if(ptimer>10)
{contnca=1;
while(contnca);
return 0;}
//read_inputs_relay();
}while(!FEEDBS); //Check S feedback
ptimer=0;
/*
do
{
if(ptimer>10)
{feedb4bse=1;
while(feedb4bse);
return 0;}
read_inputs();
}while(FEEDB4BS); //Check Break feedback
*/
read_inputs();
ptimer = 0;
while(!(CA1 && CF1))
{
if(opmode!='n')return 0;
//read_inputs_relay();
/*
if(!FEEDB4BS)
{feedb4bse=1;
while(feedb4bse);
return 0;}
*/
if((ptimer>(Cf1mt+5)) && (!Calfs))
{time1cf=1;
while(time1cf);
return 0;}
//in fast calibration mode
if((ptimer>(Calmt*4+5)) && Calfs)
{time1cf=1;
while(time1cf);
return 0;}
//in slow calibration mode
//read_inputs();
if(CAn)
{motordi=1;
while(motordi);
return 0;} //Motor direction Error cause
//CA1 is expected but CAn has been sensed
} //end of while
delay_ms(Contofftd*100); //Delay as "Contactor off time delay"
CONTD=0;
CONTS=0;
set_outputs_relay(); //Stop!
ptimer=0;
do
{
if(ptimer>10)
{contcea=1;
while(contcea);
return 0;} //Wait one second for sense feedbacks
// read_inputs();
}while(FEEDBD || FEEDBS);
if(opmode!='n')return 0;
floor=1;
return 1;
}; //end of slow calibration mode
if((!CA1) && (!Calfs)) //Fast calibration is selected and
{ // Car has not been sensed CA1
CONTD=1;
set_outputs_relay(); //Triggering D cont.
ptimer=0;
do
{
if(ptimer>10)
{contnca=1; //wait 1 second for closing D cont.
while(contnca);
return 0;}
//read_inputs_relay();
}while(!FEEDBD);
CONTF=1;
set_outputs_relay(); //Triggering F cont.
ptimer=0;
do
{
if(ptimer>10)
{contnca=1; //wait 1 second for closing F cont.
while(contnca);
return 0;}
//read_inputs_relay();
}while(!FEEDBF);
ptimer=0;
/*do
{
if(ptimer>10)
{feedb4bse=1;
while(feedb4bse);
return 0;}
//read_inputs_relay();
}while(FEEDB4BS); //wait 1 second for opening Break
*/
ptimer=0; //Now Car goes down Fast
read_inputs();
while(!CA1)
{ //Go fast down till sense CA1
// read_inputs();
//read_inputs_relay();
if(opmode!='n')return 0;
/*
if(!FEEDB4BS)
{feedb4bse=1;
while(feedb4bse);
return 0;}
*/
if(CAn)
{motordi=1;
while(motordi);
return 0;} //CA1 is expected but CAn has been sensed
if(ptimer>Calmt)
{calmto=1; //calmt = Calibration Maximum Time
while(calmto);
return 0;} //calmto = Calibration maximum
} //time is over(ERROR)
CONTS=1;
set_outputs_relay(); //Turn off Fast contactor
delay_ms(Cont_overlap); //Delay for overlap 2 conts.
CONTF=0; //Turn on Slow contactor
set_outputs_relay();
ptimer=0;
/*
do
{
//read_inputs_relays();
if(ptimer>10)
{if(!FEEDBS)contnca=1;
if(FEEDBF)contcea=1;
while(contnca||contcea);
return 0;}
}while((!FEEDBS)||FEEDBF); //Check F cont.'s feedback for opening
*/ //and S cont.'s feedback for closing
ptimer=0;
do
{
if(opmode!='n')return 0;
if(ptimer>(Cf1mt+5))
{time1cf=1;
while(time1cf);
return 0;} //Wait to sense 1CF after CA1 (cf1mt + 5)
//read_inputs();
}while(!(CA1 && CF1)); //Go slowly down till sensing CA1 and
//1CF simultaneously
delay_ms(Contofftd*100); //Delay as "Contactors off time delay"
CONTD = 0;
CONTS = 0;
set_outputs_relay(); //Stop!
ptimer = 0;
do{
if(ptimer>10)
{contcea=1;
while(contcea);
return 0;}
//read_inputs_relay();
}while(FEEDBD || FEEDBS);
if(opmode!='n')return 0;
floor=1; //Find first floor
return 1; //Return OK!
}
return 0;
}