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