1 | /* ----------------------------------------------------------------------- */
|
---|
2 | /* */
|
---|
3 | /* Version: */
|
---|
4 | /* */
|
---|
5 | kVERSION = 0 /* */
|
---|
6 | kSUBVERSION = 6 /* */
|
---|
7 | /* */
|
---|
8 | /* HISTORY: */
|
---|
9 | /* */
|
---|
10 | /* * V0.6 */
|
---|
11 | /* - do not reset the velocity if set already */
|
---|
12 | /* - set acceleration to 20% */
|
---|
13 | /* */
|
---|
14 | /* * V0.5: */
|
---|
15 | /* - changes 'DKC Ready' signal to IN1 for all MACS */
|
---|
16 | /* - control brake only when cannr==3 */
|
---|
17 | /* */
|
---|
18 | /* * V0.4: */
|
---|
19 | /* - restart MACS with PRGPAR 1 when not in manual mode */
|
---|
20 | /* - replaced label reset by a subprg */
|
---|
21 | /* */
|
---|
22 | /* * V0.3: */
|
---|
23 | /* - added support for the elevation axis brake */
|
---|
24 | /* - enabled check for operation mode (remote control/pc) */
|
---|
25 | /* - added 'reset' label */
|
---|
26 | /* - moved syncv/cstart to setting rf */
|
---|
27 | /* */
|
---|
28 | /* * V0.2: */
|
---|
29 | /* - fixed a bug, shaking the telescope switching on again after an */
|
---|
30 | /* emergency stop */
|
---|
31 | /* */
|
---|
32 | /* * V0.1: */
|
---|
33 | /* - first implementation */
|
---|
34 | /* */
|
---|
35 | /* ----------------------------------------------------------------------- */
|
---|
36 |
|
---|
37 | PRINT "Magic Manc (Manual Control) V", kVERSION, ".", kSUBVERSION /* */
|
---|
38 |
|
---|
39 | /*
|
---|
40 | if (get cannr!=1) and (get cannr!=3) then
|
---|
41 | PRINT "Sorry, wrong MACS (CAN Id=", get cannr, ") only #1 and #3 allowed!"
|
---|
42 | exit
|
---|
43 | endif
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*-------------------------------------------------------------------------*/
|
---|
47 | /* section for global constants */
|
---|
48 | /*-------------------------------------------------------------------------*/
|
---|
49 | SET PRGPAR -1 /* Don't restart any Program on Exit */
|
---|
50 |
|
---|
51 | SET ENCODERTYPE 0 /* Incremental Encoder */
|
---|
52 | SET MENCODERTYPE 0 /* Incremental Encoder (Master) */
|
---|
53 |
|
---|
54 | SET ENDSWMOD 0 /* No End Switch */
|
---|
55 | SET ERRCOND 2 /* Motor Stop, position control, no break */
|
---|
56 | SET POSDRCT -1 /* rotation direction */
|
---|
57 | SET POSFACT_Z 1 /* 1 user unit (be) = POSFACT_Z/POSFACT_N qc */
|
---|
58 | SET POSFACT_N 1 /* */
|
---|
59 |
|
---|
60 | SET HOME_FORCE 0 /* Don't force Home positioning on mainloopup */
|
---|
61 | SET HOME_OFFSET 0 /* Offset between index and home position */
|
---|
62 | SET HOMETYPE 0 /* drive to home, reverse, go to next index */
|
---|
63 |
|
---|
64 | /*----------------*/
|
---|
65 | /* syncronisation */
|
---|
66 | /*----------------*/
|
---|
67 | SET SYNCFACTM 1 /* Master Sync Velocity factor */
|
---|
68 | SET SYNCFACTS 1 /* Slave Sync Velocity factor */
|
---|
69 | SET SYNCPOSOFFS 0 /* Sync Position offset between M/S */
|
---|
70 | SET SYNCACCURACY 50 /* When to set Accuracy Flag */
|
---|
71 | SET REVERS 0 /* How to handle reversation of vel */
|
---|
72 |
|
---|
73 | /*----------------*/
|
---|
74 | /* Inputs */
|
---|
75 | /*----------------*/
|
---|
76 | SET I_REFSWITCH 0 /* Reference Switch */
|
---|
77 | SET I_POSLIMITSW 0 /* Pos Limit Switch */
|
---|
78 | SET I_NEGLIMITSW 0 /* Neg Limit Switch */
|
---|
79 | SET I_BREAK 0 /* Input which brakes a running program */
|
---|
80 | SET I_CONTINUE 0 /* Input to continue a broken program */
|
---|
81 | SET I_ERRCLR 0 /* Input to clear error */
|
---|
82 |
|
---|
83 | /*----------------*/
|
---|
84 | /* Outputs */
|
---|
85 | /*----------------*/
|
---|
86 | SET O_AXMOVE 0 /* Motor control is working */
|
---|
87 | SET O_BRAKE 0 /* Brake */
|
---|
88 | SET O_ERROR 0 /* error occured */
|
---|
89 |
|
---|
90 | /*----------------*/
|
---|
91 | /* Unit param. */
|
---|
92 | /*----------------*/
|
---|
93 | SET RAMPTYPE 1 /* Ramp Type: 0=Trapez, 1=Sinus */
|
---|
94 | SET ENCODER 1500 /* Encoder has 1500 Ticks */
|
---|
95 | SET MENCODER 1500 /* Encoder has 500 Ticks (Master) */
|
---|
96 | SET VELMAX 3000 /* Motor: Maximum revolutions per minute */
|
---|
97 | SET POSERR 1500 /* Maximum tolarable Position error (qc) 0.1° */
|
---|
98 | SET RAMPMIN 10000 /* Shortest Ramp 10s */
|
---|
99 |
|
---|
100 | /*----------------*/
|
---|
101 | /* Dflt vel & acc */
|
---|
102 | /*----------------*/
|
---|
103 |
|
---|
104 | /* Prop=100, Div=300, Int=800 */
|
---|
105 | if (get cannr==1) then
|
---|
106 | SET KPROP 100
|
---|
107 | SET KDER 300
|
---|
108 | SET KINT 1000
|
---|
109 | elseif (get cannr==2) then
|
---|
110 | SET KPROP 100
|
---|
111 | SET KDER 200
|
---|
112 | SET KINT 150
|
---|
113 | else
|
---|
114 | SET KPROP 350
|
---|
115 | SET KDER 50
|
---|
116 | SET KINT 350
|
---|
117 | endif
|
---|
118 |
|
---|
119 | vres = (GET ENCODER)*(GET VELMAX) /* ticks/R * R/M = ticks/min */
|
---|
120 | SET VELRES vres /* Set velocity units */
|
---|
121 |
|
---|
122 | /*----------------*/
|
---|
123 | /* Manual control */
|
---|
124 | /*----------------*/
|
---|
125 | SET RAMPTYPE 1 /* Ramp: 0=linear, 1=sinus */
|
---|
126 | defacc = 10*vres%100
|
---|
127 |
|
---|
128 | SET DFLTACC defacc /* Default acceleratio: [%] */
|
---|
129 | ACC defacc
|
---|
130 | DEC defacc*2
|
---|
131 | /* Velocity which is reached in
|
---|
132 | a time given by RAMPMIN */
|
---|
133 | SET DFLTVEL (1*vres%100) /* Default velocity [%] */
|
---|
134 |
|
---|
135 | manvel = (4*vres%100) /* 150 U/min */ /* Max speed in man mode: [%] */
|
---|
136 |
|
---|
137 | print "Vel Res (vel max): ", GET VELRES, " Encoder Ticks/min"
|
---|
138 | print "V_man: ", manvel, " Encoder Ticks/min, Acc=", defacc
|
---|
139 |
|
---|
140 | /*----------------*/
|
---|
141 | /* Software range */
|
---|
142 | /*----------------*/
|
---|
143 | SET SWPOSLIMACT 0 /* positive software limit switch inactive */
|
---|
144 | SET SWNEGLIMACT 0 /* negative software limit switch inactive */
|
---|
145 | SET POSLIMIT 0 /* positive software limit (qc) */
|
---|
146 | SET NEGLIMIT 0 /* negative software limit (qc) */
|
---|
147 |
|
---|
148 | /*-------------------------------------------------------------------------*/
|
---|
149 | /* const section for constant velues */
|
---|
150 | /*-------------------------------------------------------------------------*/
|
---|
151 | kTRUE = 1
|
---|
152 | kFALSE = 0
|
---|
153 |
|
---|
154 | /*-------------------------------------------------------------------------*/
|
---|
155 | /* Error routine */
|
---|
156 | /*-------------------------------------------------------------------------*/
|
---|
157 | on error gosub suberror
|
---|
158 |
|
---|
159 | kIoModule = 4*256
|
---|
160 |
|
---|
161 | /*-------------------------------------------------------------------------*/
|
---|
162 | /* mainloop rotation mode but stand still */
|
---|
163 | /*-------------------------------------------------------------------------*/
|
---|
164 |
|
---|
165 | brake = 0
|
---|
166 | RF = 0
|
---|
167 | velo = 0
|
---|
168 |
|
---|
169 | gosub reset
|
---|
170 |
|
---|
171 | mainloop:
|
---|
172 | fuse = in (kIoModule+1)
|
---|
173 | emcy = in (kIoModule+2)
|
---|
174 | vltg = in (kIoModule+3)
|
---|
175 | mode = in (kIoModule+4)
|
---|
176 | /*
|
---|
177 | if (get cannr==1) or (get cannr==2) then
|
---|
178 | */
|
---|
179 | ready = in 1
|
---|
180 | /*
|
---|
181 | elseif (get cannr==3) then
|
---|
182 | ready = in (kIoModule+5)
|
---|
183 | endif
|
---|
184 | */
|
---|
185 |
|
---|
186 | if (ready==0) and (RF==1) then
|
---|
187 | print "DKC not ready, but RF set... setting RF=AH=0!"
|
---|
188 | gosub reset
|
---|
189 | goto mainloop
|
---|
190 | elseif mode==0 then
|
---|
191 | print "Control not in manual mode!"
|
---|
192 | gosub reset
|
---|
193 | SET PRGPAR 1
|
---|
194 | exit
|
---|
195 | elseif fuse==0 then
|
---|
196 | print "Motor-Power Fuse not OK!"
|
---|
197 | gosub reset
|
---|
198 | goto mainloop
|
---|
199 | elseif vltg==0 then
|
---|
200 | print "Overvoltage control broken!"
|
---|
201 | gosub reset
|
---|
202 | goto mainloop
|
---|
203 | elseif emcy==0 then
|
---|
204 | print "Please release Emergency Stop!"
|
---|
205 | gosub reset
|
---|
206 | goto mainloop
|
---|
207 | elseif (ready==1) and (RF==0) then
|
---|
208 | print "DKC powered, RF=0... setting RF=AH=1!"
|
---|
209 | /*
|
---|
210 | * After switching on power wait at least 300ms until
|
---|
211 | * control changed state 'bb' to 'ab'
|
---|
212 | */
|
---|
213 | cvel 0
|
---|
214 | waitt 300
|
---|
215 | out 1 0
|
---|
216 | out 2 0
|
---|
217 | motor off
|
---|
218 | waitt 100
|
---|
219 | out 1 1
|
---|
220 | out 2 1
|
---|
221 | RF = 1
|
---|
222 | waitt 100
|
---|
223 |
|
---|
224 | if (brake==0 and get cannr==3) then
|
---|
225 | out (kIoModule+1) 1
|
---|
226 | brake = 1
|
---|
227 | waitt 1000
|
---|
228 | endif
|
---|
229 |
|
---|
230 | motor on
|
---|
231 |
|
---|
232 | if (get cannr==2) then
|
---|
233 | syncv
|
---|
234 | print "Synchronizing speed..."
|
---|
235 | else
|
---|
236 | cstart
|
---|
237 | print "Starting revolution mode..."
|
---|
238 | waitt 500
|
---|
239 | endif
|
---|
240 | elseif (ready==0) or (RF==0) then
|
---|
241 | goto mainloop
|
---|
242 | endif
|
---|
243 | /*
|
---|
244 | if (get cannr==2) then
|
---|
245 | print apos, " ", mapos, " ", avel," ", mavel
|
---|
246 | waitt 500
|
---|
247 | goto mainloop
|
---|
248 | endif
|
---|
249 | */
|
---|
250 | forward = in 2
|
---|
251 | backward = in 3
|
---|
252 |
|
---|
253 | if (forward==1) and (backward==0) and (velo!=manvel) then
|
---|
254 | cvel manvel
|
---|
255 | velo = manvel
|
---|
256 | elseif (forward==0) and (backward==1) and (velo!=-manvel) then
|
---|
257 | cvel -manvel
|
---|
258 | velo = -manvel
|
---|
259 | elseif (forward==backward) and (velo!=0) then
|
---|
260 | cvel 0
|
---|
261 | velo = 0
|
---|
262 | endif
|
---|
263 | goto mainloop
|
---|
264 |
|
---|
265 | SUBMAINPROG
|
---|
266 | subprog reset
|
---|
267 | out 1 0
|
---|
268 | out 2 0
|
---|
269 | RF = 0
|
---|
270 | motor off
|
---|
271 | velo = 0
|
---|
272 | waitt 1000
|
---|
273 |
|
---|
274 | if (brake==1 and get cannr==3) then
|
---|
275 | waitt 3000 /* wait 3s for DKC to stop the motor */
|
---|
276 | out (kIoModule+1) 0 /* brake the brake */
|
---|
277 | waitt 1000
|
---|
278 | endif
|
---|
279 | return
|
---|
280 |
|
---|
281 | subprog suberror
|
---|
282 | out 1 0
|
---|
283 | out 2 0
|
---|
284 | RF = 0
|
---|
285 | waitt 100
|
---|
286 | velo = 0
|
---|
287 |
|
---|
288 | if (brake==1 and get cannr==3) then
|
---|
289 | waitt 5000
|
---|
290 | out (kIoModule+1) 0
|
---|
291 | waitt 500
|
---|
292 | endif
|
---|
293 |
|
---|
294 | print "Error #", errno
|
---|
295 |
|
---|
296 | if errno==3 then /* axis not existing: shoud never happen */
|
---|
297 | exit
|
---|
298 | elseif errno==5 then /* error remaining: tried moving while error not cleared */
|
---|
299 | /* !!! */
|
---|
300 | exit
|
---|
301 | elseif errno==6 then /* home not first command: shoud never happen */
|
---|
302 | exit
|
---|
303 | elseif errno==8 then /* control deviation too large */
|
---|
304 | /*
|
---|
305 | *
|
---|
306 | */
|
---|
307 | elseif errno==9 then /* index not found: shoud never happen */
|
---|
308 | exit
|
---|
309 | elseif errno==10 then /* unknown command: shoud never happen */
|
---|
310 | exit
|
---|
311 | elseif errno==11 then /* software endswitch reached */
|
---|
312 | /*
|
---|
313 | *
|
---|
314 | */
|
---|
315 | elseif errno==12 then /* wrong paremeter number: shoud never happen */
|
---|
316 | exit
|
---|
317 | elseif errno==14 then /* too many LOOP commands: shoud never happen */
|
---|
318 | exit
|
---|
319 | elseif errno==16 then /* parameter in EEPROM broken */
|
---|
320 | exit
|
---|
321 | elseif errno==17 then /* programs in EEPROM broken */
|
---|
322 | exit
|
---|
323 | elseif errno==18 then /* RESET by CPU: Reason could be power-problems */
|
---|
324 | exit
|
---|
325 | elseif errno==19 then /* User break */
|
---|
326 | exit
|
---|
327 | elseif errno==25 then /* hardware Endswitch reached */
|
---|
328 | /*
|
---|
329 | *
|
---|
330 | */
|
---|
331 | elseif errno==51 then /* too many gosub: shoud never happen */
|
---|
332 | exit
|
---|
333 | elseif errno==52 then /* too many return: shoud never happen */
|
---|
334 | exit
|
---|
335 | elseif errno==62 then /* error verifying EEPROM */
|
---|
336 | exit
|
---|
337 | elseif errno==70 then /* error in DIM statement: should never happen */
|
---|
338 | exit
|
---|
339 | elseif errno==72 then /* DIM limit reached: should never happen */
|
---|
340 | exit
|
---|
341 | elseif errno==79 then /* Timeout waiting for an index */
|
---|
342 | exit
|
---|
343 | elseif errno==84 then /* Too many ON TIME calls */
|
---|
344 | exit
|
---|
345 | elseif errno==87 then /* storage for variables exhausted */
|
---|
346 | exit
|
---|
347 | else
|
---|
348 | print "Unknown (internal) error #", errno
|
---|
349 | exit
|
---|
350 | endif
|
---|
351 |
|
---|
352 | exit
|
---|
353 | /*errclr*/ /* errclr includes 'motor on' which enables the motor controlling */
|
---|
354 |
|
---|
355 | return
|
---|
356 | ENDPROG
|
---|
357 |
|
---|
358 |
|
---|