Changeset 925 for trunk/MagicSoft/Cosy
- Timestamp:
- 09/07/01 12:44:16 (23 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r924 r925 1 1 -*-*- END -*-*- 2 2001/09/07 - Thomas Bretz: 3 4 * aposs/Magic.m: 5 - implemented timeout if cosy crashes 6 7 * candrv/nodedrv.[h,cc]: 8 - Changed ms in WaitForSDO to signed 9 10 * devdrv/macs.[h,cc]: 11 - added 'case 0x4000' 12 - added SetTimeout 13 - added ReqTimeout 14 - added EnableTimeout 15 - added disabling Timeout to Init 16 - changed all upper case 'strings' to lower case 17 - added HandleTimer 18 19 * main/MCosy.cc: 20 - added enableing timeout for Mac1, Mac2 21 22 23 2 24 2001/09/06 - Thomas Bretz: 3 25 -
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 /*-------------------------------------------------------------------------*/ -
trunk/MagicSoft/Cosy/base/MTimeout.h
r910 r925 6 6 class MTimeout : public TTimer 7 7 { 8 Bool_t Notify( )8 Bool_t Notify(TTimer *t) 9 9 { 10 10 TurnOff(); // remove from system list -
trunk/MagicSoft/Cosy/candrv/nodedrv.cc
r920 r925 47 47 void NodeDrv::HandleSDOError(LWORD_t data) 48 48 { 49 lout << " Err:0x";50 lout << hex << setfill('0') << setw(4) << data ;51 lout << endl; ;49 lout << "Nodedrv: SDO Error: Entry not found in deictionary (data=0x"; 50 lout << hex << setfill('0') << setw(4) << data << ")"; 51 lout << endl; 52 52 } 53 53 … … 125 125 } 126 126 127 void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORD _t timeout)127 void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout) 128 128 { 129 129 fNetwork->WaitForSdo(fId, idx, subidx, timeout); -
trunk/MagicSoft/Cosy/candrv/nodedrv.h
r920 r925 65 65 66 66 // void WaitForSdos(); 67 void WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORD _t timeout=500);67 void WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORDS_t timeout=500); 68 68 69 69 void EnableCanMsg(BYTE_t fcode); -
trunk/MagicSoft/Cosy/devdrv/macs.cc
r920 r925 12 12 fPosActive(0), fRpmActive(0) 13 13 { 14 fTimeout = new TTimer(this, 100, kFALSE); // 100ms 14 15 } 15 16 16 17 Macs::~Macs() 17 18 { 19 fTimerOn = kFALSE; 20 delete fTimeout; 18 21 } 19 22 … … 30 33 fVel = val; 31 34 return; 35 36 case 0x4000: 37 switch (subidx) 38 { 39 case 1: 40 cout << "Timeout timer is " << (val?"en":"dis") << "abled." << endl; 41 return; 42 case 2: 43 cout << "Actual timeout time: " << dec << val << "ms" << endl; 44 return; 45 } 46 break; 32 47 33 48 case 0x6004: … … 74 89 75 90 case 0x6002: 76 lout << "- Velocity resolution #" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;91 lout << "- Velocity resolution Node#" << (int)GetId() << ": " << dec << val << " ticks/min" << endl; 77 92 fVelRes = val; 78 93 return; … … 82 97 } 83 98 99 void Macs::SetTimeoutTime(LWORD_t ms) 100 { 101 fTimeoutTime = ms/2; 102 103 SendSDO(0x4000, 2, ms); 104 WaitForSdo(0x4000, 2); 105 } 106 107 void Macs::ReqTimeoutTime() 108 { 109 RequestSDO(0x4000, 2); 110 WaitForSdo(0x4000, 2); 111 } 112 113 void Macs::EnableTimeout(bool enable, LWORDS_t ms) 114 { 115 if (!enable) 116 { 117 SendSDO(0x4000, 1, string('o', 'f', 'f')); 118 WaitForSdo(0x4000, 1); 119 120 cout << "--> Turn Off. " << endl; 121 fTimerOn = kFALSE; 122 } 123 else 124 { 125 if (ms>0) 126 SetTimeoutTime(ms); 127 128 cout << "--> Turn On." << endl; 129 fTimerOn = kTRUE; 130 fTimeout->Start(fTimeoutTime, kTRUE); 131 132 SendSDO(0x4000, 1, string('o', 'n')); 133 WaitForSdo(0x4000, 1); 134 } 135 } 136 84 137 void Macs::ReqVelRes() 85 138 { 86 lout << "- Requesting velocity resolution (velres, 0x 3007) of " << (int)GetId() << endl;139 lout << "- Requesting velocity resolution (velres, 0x6002) of " << (int)GetId() << endl; 87 140 RequestSDO(0x6002); 88 141 WaitForSdo(0x6002); … … 116 169 WaitForSdo(0x2004); 117 170 */ 171 EnableTimeout(kFALSE); 118 172 119 173 lout << "- Requesting Mac Software Version of " << (int)GetId() << endl; … … 126 180 127 181 lout << "- Motor on of " << (int)GetId() << endl; 128 SendSDO(0x3000, string(' O', 'N'));182 SendSDO(0x3000, string('o', 'n')); 129 183 WaitForSdo(0x3000); 130 184 … … 147 201 // Stop the motor and switch off the position control unit 148 202 // 149 SendSDO(0x3000, string(' S','T','O','P'));203 SendSDO(0x3000, string('s','t','o','p')); 150 204 WaitForSdo(0x3000); 151 205 } … … 153 207 void Macs::StopDevice() 154 208 { 209 EnableTimeout(kFALSE); 210 155 211 SetNoWait(FALSE); 156 212 … … 164 220 165 221 lout << "- Motor off of " << (int)GetId() << endl; 166 SendSDO(0x3000, string(' O', 'F', 'F'));222 SendSDO(0x3000, string('o', 'f', 'f')); 167 223 WaitForSdo(0x3000); 168 224 … … 227 283 // SetRpmMode(FALSE) stop the motor, but lets the position control unit on 228 284 // 229 SendSDO(0x3006, 0, mode ? string(' S','T','R','T') : string('S','T','O','P'));285 SendSDO(0x3006, 0, mode ? string('s','t','r','t') : string('s','t','o','p')); 230 286 WaitForSdo(0x3006, 0); 231 287 } … … 250 306 { 251 307 lout << "- Setting NOWAIT " << (flag?"ON":"OFF") << " #" << (int)GetId() << endl; 252 SendSDO(0x3008, flag ? string(' O', 'N') : string('O', 'F', 'F'));308 SendSDO(0x3008, flag ? string('o', 'n') : string('o', 'f', 'f')); 253 309 WaitForSdo(0x3008); 254 310 } … … 261 317 // 262 318 lout << "- Setting Vel Sync Mode #" << (int)GetId() << endl; 263 SendSDO(0x3007, 0, string(' S', 'Y', 'N', 'C'));319 SendSDO(0x3007, 0, string('s', 'y', 'n', 'c')); 264 320 WaitForSdo(0x3007, 0); 265 321 } … … 272 328 // 273 329 lout << "- Setting Pos Sync Mode #" << (int)GetId() << endl; 274 SendSDO(0x3007, 1, string(' S', 'Y', 'N', 'C'));330 SendSDO(0x3007, 1, string('s', 'y', 'n', 'c')); 275 331 WaitForSdo(0x3007, 1); 276 332 } … … 403 459 switch (GetError()) 404 460 { 405 case 6: // home 406 case 8: // control dev 407 case 9: // zero idx 408 case 84: // ON TIME 461 case 6: // home 462 case 8: // control dev 463 case 9: // zero idx 464 case 84: // ON TIME 465 case 100: // timeout 409 466 // Stop program? 410 467 return; … … 457 514 WaitForSdo(0x2000, 3); 458 515 } 516 517 Bool_t Macs::HandleTimer(TTimer *t) 518 { 519 /* 520 Fons: 521 ----- 522 523 timers never trigger at the same time or when in a TTimer::Notify. 524 Little explanation: 525 526 - there are two types of timers synchronous and a-synchronous. 527 - synchronous timers are only handled via the ROOT eventloop 528 (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard 529 events then the synchronous timer queue is checked. So if the processing 530 of a mouse/keyboard event takes a long time synchronous timers are not 531 called for a while. To prevent this from happening one can call in long 532 procedures gSystem->ProcessEvents(). The system schedules only the 533 next timer in the queue when the current one's Notify() has finished. 534 - a-synchronous timers are triggered via SIGALARM, i.e. the program is 535 interupted and execution jumps to the Notify() function. When the 536 notify is finished the next a-sync timer is scheduled and the system 537 resumes from the place where it was initially interrupted. One of the 538 things to remember when using a-sync timers is don't make any graphics 539 calls in them. X11 is not re-entrant and it might be that the SIGALARM 540 signal interrupted the system while being in X11. A-sync timers are best 541 used to set flags that you can test at a convenient and controlled 542 time. 543 */ 544 SendSDO(0x4000); 545 WaitForSdo(0x4000, 0, kDontWait); 546 if (fTimerOn) 547 fTimeout->Start(fTimeoutTime, kTRUE); 548 return kTRUE; 549 } -
trunk/MagicSoft/Cosy/devdrv/macs.h
r920 r925 1 1 #ifndef MACS_H 2 2 #define MACS_H 3 4 #include <TObject.h> 3 5 4 6 #include "nodedrv.h" 5 7 #include "base/timer.h" 6 8 7 class Macs : public NodeDrv 9 class Macs : public NodeDrv, public TObject 8 10 { 9 11 private: … … 22 24 BYTE_t fRpmActive; 23 25 26 TTimer *fTimeout; 27 Bool_t fTimerOn; 28 LWORD_t fTimeoutTime; 29 24 30 LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0) 25 31 { 26 32 return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3); 27 33 } 34 35 Bool_t HandleTimer(TTimer *t); 28 36 29 37 public: … … 70 78 void StartAbsPos(LWORDS_t pos); 71 79 80 void SetTimeoutTime(LWORD_t ms); 81 void ReqTimeoutTime(); 82 83 void EnableTimeout(bool enable=true, LWORDS_t ms=-1); 84 72 85 void StopMotor(); 73 86 -
trunk/MagicSoft/Cosy/gui/Makefile
r924 r925 21 21 22 22 INCLUDES = -I. -I.. -I../base -I../slalib -I../candrv -I../incl \ 23 -I../catalog -I../videodev 23 -I../catalog -I../videodev -I../main 24 24 25 25 # @code -
trunk/MagicSoft/Cosy/main/MCosy.cc
r924 r925 676 676 fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("Zd_Max[Deg]", +1.0))); 677 677 cout << "done." << endl; 678 679 fMac1->EnableTimeout(kTRUE, 500); 680 fMac2->EnableTimeout(kTRUE, 500); 678 681 679 682 /* -
trunk/MagicSoft/Cosy/main/MStarguider.h
r924 r925 3 3 4 4 #include "Camera.h" 5 #include " Starguider.h"5 #include "MGStarguider.h" 6 6 7 7 class MStarguider : public Camera 8 8 { 9 9 private: 10 Starguider *fDisplay;10 MGStarguider *fDisplay; 11 11 12 12 public: 13 13 MStarguider() 14 14 { 15 fDisplay = new Starguider;15 fDisplay = new MGStarguider; 16 16 } 17 17
Note:
See TracChangeset
for help on using the changeset viewer.