Changeset 925 for trunk/MagicSoft/Cosy/aposs
- Timestamp:
- 09/07/01 12:44:16 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/aposs/Magic.m
r808 r925 10 10 /* */ 11 11 kVERSION = 0 /* */ 12 kSUBVERSION = 6 2/* */12 kSUBVERSION = 63 /* */ 13 13 /* */ 14 14 /* HISTORY: */ 15 /* */ 16 /* * V0.63: */ 17 /* - added movement handshake timeout (removed 0x400 WAITAX) */ 18 /* - added brackets around string SDOs */ 19 /* - changed SDO 0x3007 to support both sync modes 15 20 /* */ 16 21 /* * V0.62: */ … … 92 97 /* 0x3006 0 wo Velocity Mode 'strt', 'stop' */ 93 98 /* 1 wo VelMode Velocity */ 94 /* 0x3007 x wo Syncronisation 'sync' */ 99 /* 0x3007 0 wo Velocity Syncronisation 'sync' */ 100 /* 1 wo Position Syncronisation 'sync' */ 95 101 /* 0x3008 x wo Nowait 'on', 'off' */ 102 /* 0x4000 0 wo Reset timeout timer */ 103 /* 1 rw Enable timeout timer, 'on' (1), 'off'(0) */ 104 /* 2 rw Timeout timer time */ 96 105 /* 0x6000 x rw Rotation Direction */ 97 106 /* 0x6002 x rw Velocity Resolution */ … … 185 194 pdo1on = kFALSE 186 195 187 /*-------------------------------------------------------------------------*/ 188 /* Can Open Difinitions */ 196 timeout = 100 197 timeouton = kFALSE 198 timeouttime = TIME 199 200 /*-------------------------------------------------------------------------*/ 201 /* Can Open Definitions */ 202 /*-------------------------------------------------------------------------*/ 203 /* The CAN Object are static object. This is why they must be deleted. */ 204 /* The program should run in any of our nodes. */ 205 /* Therefor the standard CAN objects (SDO, PDO1, PDO2) for communication */ 206 /* are defined. The nodenumber is part of the object ID (this is somehow */ 207 /* similar to the TCP/IP ports) */ 189 208 /*-------------------------------------------------------------------------*/ 190 209 CANDEL -1 … … 195 214 sdotx = DEFCANOUT (0x580+nodenr) 8 196 215 sdorx = DEFCANIN (0x600+nodenr) 8 197 216 217 /* Close and reopen communication, enable buffering */ 198 218 err = REOPEN 0 0 199 219 200 220 /*-------------------------------------------------------------------------*/ 201 221 /* Init */ 222 /*-------------------------------------------------------------------------*/ 223 /* Before the motor control hardware is enabled (hi on output 1) */ 224 /* the commands make sure, that the motor will not start moving. */ 225 /* As default positioning commands doesn't stop the further execution */ 226 /* of the program. */ 202 227 /*-------------------------------------------------------------------------*/ 203 228 MOTOR STOP … … 209 234 /*-------------------------------------------------------------------------*/ 210 235 /* ON ... GOSUB ... definitions */ 236 /*-------------------------------------------------------------------------*/ 237 /* The errorlist one can retreive using the corresponding CAN object */ 238 /* should be emty when the node is initialized (arrays are static objects) */ 239 /* therefor it must be deleted. */ 240 /* Errors are handled in an interrupt procedure called PROC_ERROR */ 211 241 /*-------------------------------------------------------------------------*/ 212 242 /* ON CANMSG GOSUB PROC_CANMSG */ … … 221 251 /*-------------------------------------------------------------------------*/ 222 252 /* Program Main Loop */ 253 /*-------------------------------------------------------------------------*/ 254 /* The main loop is the core of the program which handles incoming */ 255 /* objects. In principal CANIN should wait until an object is received, */ 256 /* but it stops waiting when an interrupt occurs. This is the reason why */ 257 /* the validity of the message must be checked. */ 223 258 /*-------------------------------------------------------------------------*/ 224 259 MAIN: … … 261 296 i = i - 1 262 297 endwhile 263 elseif (idx == 0x1010 and sdoval == 's'<<24|'a'<<16|'v'<<8|'e') then298 elseif (idx == 0x1010 and sdoval == ('s'<<24|'a'<<16|'v'<<8|'e')) then 264 299 SAVEPROM 265 300 elseif (idx == 0x1800 and subidx == 1) then … … 293 328 endif 294 329 elseif (idx == 0x3000) then 295 if (sdoval == 'o'<<24|'n'<<16) then330 if (sdoval == ('o'<<24|'n'<<16)) then 296 331 MOTOR ON 297 elseif (sdoval == 'o'<<24|'f'<<16|'f'<<8) then332 elseif (sdoval == ('o'<<24|'f'<<16|'f'<<8)) then 298 333 MOTOR OFF 299 elseif (sdoval == 's'<<24|'t'<<16|'o'<<8|'p') then334 elseif (sdoval == ('s'<<24|'t'<<16|'o'<<8|'p')) then 300 335 MOTOR STOP 301 336 endif 302 337 elseif (idx == 0x3001) then 303 if (sdoval == 'h'<<24|'o'<<16|'m'<<8|'e') then338 if (sdoval == ('h'<<24|'o'<<16|'m'<<8|'e')) then 304 339 limitsw = GET I_POSLIMITSW 305 340 set I_POSLIMITSW 0 … … 313 348 SET I_POSLIMITSW limitsw 314 349 endif 315 elseif (idx == 0x3002 and sdoval == 'o'<<24|'p'<<16|'e'<<8|'n') then350 elseif (idx == 0x3002 and sdoval == ('o'<<24|'p'<<16|'e'<<8|'n')) then 316 351 sdoval=REOPEN 2 0 317 352 if (sdoval) then 318 353 PRINT "Error Reopen" 319 354 endif 320 elseif (idx == 0x3003 and sdoval == 'e'<<24|'x'<<16|'i'<<8|'t') then355 elseif (idx == 0x3003 and sdoval == ('e'<<24|'x'<<16|'i'<<8|'t')) then 321 356 CANOUT sdotx (canhi&0xffffff | 0x60000000) 0 322 357 EXIT 323 358 elseif (idx == 0x3006) then 324 359 if (subidx == 0) then 325 if (sdoval == 's'<<24|'t'<<16|'r'<<8|'t') then360 if (sdoval == ('s'<<24|'t'<<16|'r'<<8|'t')) then 326 361 CVEL 0 327 362 CSTART 328 elseif (sdoval == 's'<<24|'t'<<16|'o'<<8|'p') then363 elseif (sdoval == ('s'<<24|'t'<<16|'o'<<8|'p')) then 329 364 CSTOP 330 365 endif … … 332 367 CVEL sdoval 333 368 endif 334 elseif (idx == 0x3007 and sdoval == 's'<<24|'y'<<16|'n'<<8|'c') then 335 SYNCP 369 elseif (idx == 0x3007) then 370 if (subidx==0 and sdoval == ('s'<<24|'y'<<16|'n'<<8|'c')) then 371 SYNCV 372 elseif (subidx==1 and sdoval == ('s'<<24|'y'<<16|'n'<<8|'c')) then 373 SYNCP 374 endif 336 375 elseif (idx == 0x3008) then 337 if (sdoval == 'o'<<24|'n'<<16) then376 if (sdoval == ('o'<<24|'n'<<16)) then 338 377 NOWAIT ON 339 elseif (sdoval == 'o'<<24|'f'<<16|'f'<<8) then378 elseif (sdoval == ('o'<<24|'f'<<16|'f'<<8)) then 340 379 NOWAIT OFF 380 endif 381 elseif (idx == 0x4000) then 382 if (subidx == 0) then 383 timeouttime = TIME + timeout 384 elseif (subidx == 1) then 385 ON PERIOD 0 GOSUB PROC_Timeout 386 if (sdoval == ('o'<<24|'n'<<16)) then 387 timeouttime = TIME + timeout 388 ON PERIOD timeout GOSUB PROC_Timeout 389 timeouton = kTRUE 390 elseif (sdoval == ('o'<<24|'f'<<16|'f'<<8)) then 391 timeouton = kFALSE 392 endif 393 elseif (subidx == 2) then 394 timeout = sdoval 395 if (timeouton) then 396 ON PERIOD 0 GOSUB PROC_Timeout 397 timeouttime = TIME + timeout 398 ON PERIOD timeout GOSUB PROC_Timeout 399 endif 341 400 endif 342 401 /* elseif (idx == 0x4000 and … … 356 415 SET VELRES sdoval 357 416 elseif (idx == 0x6003) then 358 if (subidx == 0 and sdoval == 's'<<24|'e'<<16|'t'<<8) then417 if (subidx == 0 and sdoval == ('s'<<24|'e'<<16|'t'<<8)) then 359 418 DEF ORIGIN 360 419 elseif (subidx == 1) then … … 384 443 SET VELMAX sdoval 385 444 else 386 CANOUT sdotx (canhi&0xffffff | 0x80000000) 0 445 CANOUT sdotx (canhi&0xffffff | (1<<31)/*&0x80000000*/) 0 446 PRINT "Unknown SDO: idx=", idx, ", subidx=", subidx 387 447 goto ENDSDOSET 388 448 endif … … 464 524 sdoval = STAT 465 525 elseif (idx == 0x4000) then 466 WAITAX 526 if (subidx == 1) then 527 sdoval = timeouton 528 elseif (subidx == 2) then 529 sdoval = timeout 530 endif 467 531 elseif (idx == 0x6000) then 468 532 if (GET POSDRCT == 1) then … … 500 564 RETURN 501 565 502 /*----------------------------------*/ 566 /*----------------------------------------------------------------------*/ 567 /* PROC_SDORX */ 568 /*----------------------------------------------------------------------*/ 569 /* This procedure handles incoming objects, it is called from the main */ 570 /* loop. If the object ID (COB ID) identifies a SDO object, it is */ 571 /* whether it is a object to set data (write into the object */ 572 /* dictionary) or data is requested (read from object dictionary) */ 573 /* If it isn't a valid SDO a error message is send. */ 574 /* Remark: Only objects with the right node number are received by the */ 575 /* main loop. */ 576 /*----------------------------------------------------------------------*/ 503 577 504 578 SUBPROG PROC_SDORX … … 536 610 CANOUT pdo1 AXEND APOS 537 611 RETURN 612 613 /*-------------------------------------------------------------------------*/ 614 /* Timeout Interrupt */ 615 /*-------------------------------------------------------------------------*/ 616 SUBPROG PROC_Timeout 617 if (TIME > timeouttime) then 618 MOTOR STOP 619 620 /* Tell the bus that an error occured */ 621 CANOUT pdo2 0 0 622 623 i = errlist[1] + 1 /* Fill status of array */ 624 while (i>2) do /* shift errors by one */ 625 errlist[i] = errlist[i-1] 626 i = i - 1 627 endwhile /* set new errornumber */ 628 errlist[2] = 100 /* User Error #100 */ 629 if (errlist[1]<8) then /* write new size if enhanced */ 630 errlist[1] = errlist[1] + 1 631 endif 632 633 errinf = 0 634 635 /*if (firstcall)*/ 636 PRINT "User Timeout at uptime=", (TIME%1000), "s" 637 /*firstcall = kFALSE */ 638 639 /* tell the bus what exactly happened */ 640 CANOUT pdo2 errlist[2] errinf 641 /*elseif 642 firstcall = kTRUE*/ 643 endif 644 RETURN 538 645 539 646 /*-------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.