Changeset 926 for trunk/MagicSoft/Cosy/devdrv
- Timestamp:
- 09/10/01 14:32:27 (23 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r925 r926 6 6 #include "timer.h" 7 7 #include "network.h" 8 9 Macs::Macs(BYTE_t nodeid, MLog &out) 10 : NodeDrv(nodeid, out), fMacId(2*nodeid+1), 8 #include "MLogManip.h" 9 10 Macs::Macs(const BYTE_t nodeid, const char *name, MLog &out) 11 : NodeDrv(nodeid, name, out), fMacId(2*nodeid+1), 11 12 fPos(0), fPosTime(0.0), fPdoPos(0), fPdoTime(0.0), 12 13 fPosActive(0), fRpmActive(0) … … 26 27 { 27 28 case 0x100a: 28 lout << "- Mac using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;29 lout << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl; 29 30 return; 30 31 31 32 case 0x2002: 32 cout << "Actual velocity: " << dec << val << endl;33 cout << GetNodeName() << ": Actual velocity: " << dec << val << endl; 33 34 fVel = val; 34 35 return; … … 38 39 { 39 40 case 1: 40 cout << "Timeout timer is " << (val?"en":"dis") << "abled." << endl;41 cout << GetNodeName() << ": Timeout timer is " << (val?"en":"dis") << "abled." << endl; 41 42 return; 42 43 case 2: 43 cout << "Actual timeout time: " << dec << val << "ms" << endl;44 cout << GetNodeName() << ": Actual timeout time: " << dec << val << "ms" << endl; 44 45 return; 45 46 } … … 89 90 90 91 case 0x6002: 91 lout << "- Velocity resolution Node#" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;92 lout << "- Velocity resolution " << GetNodeName() << ": " << dec << val << " ticks/min" << endl; 92 93 fVelRes = val; 93 94 return; … … 97 98 } 98 99 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 } 100 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx) 101 { 102 if (idx==0x4000 && subidx==0 && fTimerOn) 103 { 104 ResetTimeout(); 105 return; 106 } 107 NodeDrv::HandleSDOOK(idx, subidx); 108 } 109 136 110 137 111 void Macs::ReqVelRes() 138 112 { 139 lout << "- Requesting velocity resolution (velres, 0x6002) of " << (int)GetId() << endl;113 lout << "- Requesting velocity resolution (velres, 0x6002) of " << GetNodeName() << endl; 140 114 RequestSDO(0x6002); 141 115 WaitForSdo(0x6002); … … 144 118 void Macs::SetPDO1On(BYTE_t flag) 145 119 { 146 lout << "- " << (flag?"Enable":"Disable") << " PDO1 of #" << (int)GetId() << endl;120 lout << "- " << (flag?"Enable":"Disable") << " PDO1 of " << GetNodeName() << endl; 147 121 SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31); 148 122 WaitForSdo(0x1800, 1); … … 171 145 EnableTimeout(kFALSE); 172 146 173 lout << "- Requesting Mac Software Version of " << (int)GetId() << endl;147 lout << "- Requesting Mac Software Version of " << GetNodeName() << endl; 174 148 RequestSDO(0x100a); 175 149 WaitForSdo(0x100a); … … 179 153 ReqVelRes(); // Init fVelRes 180 154 181 lout << "- Motor on of " << (int)GetId() << endl;155 lout << "- Motor on of " << GetNodeName() << endl; 182 156 SendSDO(0x3000, string('o', 'n')); 183 157 WaitForSdo(0x3000); … … 219 193 SetPDO1On(FALSE); 220 194 221 lout << "- Motor off of " << (int)GetId() << endl;195 lout << "- Motor off of " << GetNodeName() << endl; 222 196 SendSDO(0x3000, string('o', 'f', 'f')); 223 197 WaitForSdo(0x3000); … … 232 206 void Macs::ReqPos() 233 207 { 234 lout << "- Requesting Position of #" << (int)GetId() << endl;208 lout << "- Requesting Position of " << GetNodeName() << endl; 235 209 RequestSDO(0x6004); 236 210 WaitForSdo(0x6004); … … 239 213 void Macs::ReqVel() 240 214 { 241 lout << "- Requesting Velocity of #" << (int)GetId() << endl;215 lout << "- Requesting Velocity of " << GetNodeName() << endl; 242 216 RequestSDO(0x2002); 243 217 WaitForSdo(0x2002); … … 246 220 void Macs::SetHome(LWORDS_t pos, WORD_t maxtime) 247 221 { 248 lout << "- Driving #" << (int)GetId() << " to home position, Offset=" << dec << pos << endl;222 lout << "- Driving " << GetNodeName() << " to home position, Offset=" << dec << pos << endl; 249 223 SendSDO(0x6003, 2, (LWORD_t)pos); // home 250 224 WaitForSdo(0x6003, 2); … … 254 228 SendSDO(0x3001, string('h','o','m','e')); // home 255 229 WaitForSdo(0x3001, 0, maxtime*1000); 256 lout << "- Home position of #" << (int)GetId() << " reached. " << endl;230 lout << "- Home position of " << GetNodeName() << " reached. " << endl; 257 231 258 232 SendSDO(0x6003, 0, string('s','e','t')); // home … … 305 279 void Macs::SetNoWait(BYTE_t flag) 306 280 { 307 lout << "- Setting NOWAIT " << (flag?"ON ":"OFF") << " #" << (int)GetId() << endl;281 lout << "- Setting NOWAIT " << (flag?"ON ":"OFF ") << GetNodeName() << endl; 308 282 SendSDO(0x3008, flag ? string('o', 'n') : string('o', 'f', 'f')); 309 283 WaitForSdo(0x3008); … … 316 290 // or by a positioning command (POSA, ...) 317 291 // 318 lout << "- Setting Vel Sync Mode #" << (int)GetId() << endl;292 lout << "- Setting Vel Sync Mode of " << GetNodeName() << endl; 319 293 SendSDO(0x3007, 0, string('s', 'y', 'n', 'c')); 320 294 WaitForSdo(0x3007, 0); … … 327 301 // or by a positioning command (POSA, ...) 328 302 // 329 lout << "- Setting Pos Sync Mode #" << (int)GetId() << endl;303 lout << "- Setting Pos Sync Mode of " << GetNodeName() << endl; 330 304 SendSDO(0x3007, 1, string('s', 'y', 'n', 'c')); 331 305 WaitForSdo(0x3007, 1); … … 372 346 if (!errnum) 373 347 { 374 cout << "Mac #" << (int)GetId() << " reports Error occursion." << endl;348 cout << "Mac " << GetNodeName() << " reports Error occursion." << endl; 375 349 SetError(-1); 376 350 return; … … 382 356 // 383 357 if (GetError()>0) 384 cout << "Mac #" << (int)GetId() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;358 cout << "Mac " << GetNodeName() << " WARNING! Error #" << GetError() << " unhandled by software." << endl; 385 359 386 360 SetError(errnum); 387 361 388 cout << "Mac #" << (int)GetId() << " reports: ";362 cout << "Mac " << GetNodeName() << " reports: "; 389 363 switch (errnum) 390 364 { … … 429 403 return; 430 404 405 case 100: 406 cout << "Connection timed out." << endl; 407 return; 408 431 409 default: 432 410 cout << "Error Nr. " << errnum << ", " << errinf << endl; … … 456 434 // we can go on working 'as usual' Eg. Initialize a Display Update 457 435 // 458 cout << "Mac #" << (int)GetId() << " Handling Error #" << GetError() << endl;436 cout << "Mac " << GetNodeName() << " Handling Error #" << GetError() << endl; 459 437 switch (GetError()) 460 438 { … … 463 441 case 9: // zero idx 464 442 case 84: // ON TIME 465 case 100: // timeout466 443 // Stop program? 467 444 return; 468 445 469 case 11: // software endswitch 470 case 25: // hardware endswitch 446 case 11: // software endswitch 447 case 25: // hardware endswitch 448 case 100: // timeout (movement has been stopped, so we can go on) 449 DelError(); 450 return; 451 452 case 101: 453 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl; 471 454 DelError(); 472 455 return; … … 513 496 SendSDO(0x2000, 3, (LWORD_t)(neg|(pos<<1))); 514 497 WaitForSdo(0x2000, 3); 498 } 499 500 void Macs::ReqTimeoutTime() 501 { 502 RequestSDO(0x4000, 2); 503 WaitForSdo(0x4000, 2); 504 } 505 506 void Macs::EnableTimeout(bool enable, LWORDS_t ms) 507 { 508 if (!enable) 509 { 510 SendSDO(0x4000, 1, string('o', 'f', 'f')); 511 WaitForSdo(0x4000, 1); 512 513 fTimeout->Stop(); //kTRUE); 514 515 fTimerOn = kFALSE; 516 } 517 else 518 { 519 if (ms>0) 520 SetTimeoutTime(ms); 521 522 ResetTimeout(); 523 524 fTimerOn = kTRUE; 525 fTimeout->Start(fGuardTime, kFALSE); //kTRUE); 526 527 SendSDO(0x4000, 1, string('o', 'n')); 528 WaitForSdo(0x4000, 1); 529 } 530 lout << "- Timeout timer of " << GetNodeName() << " turned " 531 << (enable?"on.":"off.") << endl; 515 532 } 516 533 … … 542 559 time. 543 560 */ 544 SendSDO(0x4000); 545 WaitForSdo(0x4000, 0, kDontWait); 546 if (fTimerOn) 547 fTimeout->Start(fTimeoutTime, kTRUE); 561 562 // 563 // FIXME! Use NMT! 564 // 565 SendSDO(0x4000, 0, (LWORD_t)0, false); 566 567 Timer time; 568 if (time.Now() > fTimeoutTime) 569 { 570 lout << ddev(MLog::eGui); 571 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window." << endl; 572 lout << edev(MLog::eGui); 573 SetError(101); 574 } 575 576 577 //WaitForSdo(0x4000, 0, kDontWait); 578 // if (fTimerOn) 579 // fTimeout->Start(fGuardTime, kTRUE); 580 548 581 return kTRUE; 549 582 } 583 584 void Macs::ResetTimeout() 585 { 586 Timer time; 587 fTimeoutTime = time.Now() + 2.*fGuardTime/1000.; //[usec] 588 } 589 590 void Macs::SetTimeoutTime(LWORD_t ms) 591 { 592 fGuardTime = ms/2; // FIXME: Is '/2' the best choose? 593 594 SendSDO(0x4000, 2, ms); 595 WaitForSdo(0x4000, 2); 596 } 597 -
trunk/MagicSoft/Cosy/devdrv/macs.h
r925 r926 26 26 TTimer *fTimeout; 27 27 Bool_t fTimerOn; 28 LWORD_t fTimeoutTime; 28 LWORD_t fGuardTime; 29 double fTimeoutTime; 29 30 30 31 LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0) … … 33 34 } 34 35 36 void ResetTimeout(); 35 37 Bool_t HandleTimer(TTimer *t); 36 38 37 39 public: 38 Macs( BYTE_t nodeid, MLog &out=gLog);40 Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog); 39 41 virtual ~Macs(); 40 42 … … 45 47 46 48 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv); 47 void HandleSDOOK(WORD_t idx, BYTE_t subidx) { NodeDrv::HandleSDOOK(idx, subidx); }49 void HandleSDOOK(WORD_t idx, BYTE_t subidx); 48 50 void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); } 49 51 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r921 r926 13 13 #include <sys/resource.h> // PRIO_PROCESS 14 14 15 ShaftEncoder::ShaftEncoder(BYTE_t nodeid, MLog &out) : NodeDrv(nodeid, out), fLabel(NULL), fPosHasChanged(false) 15 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out) 16 : NodeDrv(nodeid, name, out), fLabel(NULL), fPosHasChanged(false) 16 17 { 17 18 } … … 195 196 // Requesting and checking (FIXME) type of encoder 196 197 // 197 lout << "- Requesting Hardware Type (SDO 0x1000) of " << (int)GetId() << endl;198 lout << "- Requesting Hardware Type (SDO 0x1000) of " << GetNodeName() << endl; 198 199 RequestSDO(0x1000); 199 200 WaitForSdo(0x1000); … … 202 203 // Read physical ticks per revolution 203 204 // 204 lout << "- Requesting physical ticks/revolution (SDO 0x6501) of " << (int)GetId() << endl;205 lout << "- Requesting physical ticks/revolution (SDO 0x6501) of " << GetNodeName() << endl; 205 206 RequestSDO(0x6501); 206 207 WaitForSdo(0x6501); … … 209 210 // Read number of possible ticks per revolution 210 211 // 211 lout << "- Requesting possible ticks/revolution (SDO 0x6502) of " << (int)GetId() << endl;212 lout << "- Requesting possible ticks/revolution (SDO 0x6502) of " << GetNodeName() << endl; 212 213 RequestSDO(0x6502); 213 214 WaitForSdo(0x6502); … … 216 217 // Set logic ticks/revolution = physical ticks/revolution => scale factor = 1 217 218 // 218 lout << "- Configuring SDO 0x6001 of " << (int)GetId() << endl;219 lout << "- Configuring SDO 0x6001 of " << GetNodeName() << endl; 219 220 SendSDO(0x6001, fTicks); 220 221 WaitForSdo(0x6001); … … 223 224 // Set maximum number of ticks (ticks * turns) 224 225 // 225 lout << "- Configuring SDO 0x6002 of " << (int)GetId() << endl;226 lout << "- Configuring SDO 0x6002 of " << GetNodeName() << endl; 226 227 SendSDO(0x6002, (LWORD_t)(fTicks*fTurns)); 227 228 WaitForSdo(0x6002); … … 230 231 // Configure PDOs 231 232 // 232 lout << "- Configuring SDO 0x1802 of " << (int)GetId() << endl;233 lout << "- Configuring SDO 0x1802 of " << GetNodeName() << endl; 233 234 SendSDO(0x1802, 1, (LWORD_t)0x281); 234 235 WaitForSdo(0x1802, 1); … … 237 238 // Delete preset Value 238 239 // 239 lout << "- Configuring SDO 0x6003 of " << (int)GetId() << endl;240 lout << "- Configuring SDO 0x6003 of " << GetNodeName() << endl; 240 241 SendSDO(0x6003, (LWORD_t)0xffffffff); 241 242 WaitForSdo(0x6003); … … 244 245 // Request Parameter 245 246 // 246 lout << "- Requesting SDO 0x6000 of " << (int)GetId() << endl;247 lout << "- Requesting SDO 0x6000 of " << GetNodeName() << endl; 247 248 RequestSDO(0x6000); 248 249 WaitForSdo(0x6000); … … 250 251 ReqPos(); 251 252 252 lout << "- Start Node " << (int)GetId() << endl;253 lout << "- Start Node " << GetNodeName() << endl; 253 254 SendNMT(kNMT_START); 254 255 } … … 259 260 // Request Position 260 261 // 261 lout << "- Requesting Position of #" << (int)GetId() << endl;262 lout << "- Requesting Position of " << GetNodeName() << endl; 262 263 RequestSDO(0x6004); 263 264 WaitForSdo(0x6004); … … 269 270 fTurn = pre/16384; 270 271 271 lout << " - Setting Preset #" << (int)GetId() << endl;272 lout << " - Setting Preset " << GetNodeName() << endl; 272 273 SendSDO(0x6003, (LWORD_t)fPos); 273 274 WaitForSdo(0x6003); … … 276 277 void ShaftEncoder::StopDevice() 277 278 { 278 lout << "- Start Node " << (int)GetId() << endl;279 lout << "- Start Node " << GetNodeName() << endl; 279 280 SendNMT(kNMT_STOP); 280 281 } -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r924 r926 33 33 34 34 public: 35 ShaftEncoder( BYTE_t nodeid, MLog &out=gLog);35 ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog); 36 36 virtual ~ShaftEncoder(); 37 37
Note:
See TracChangeset
for help on using the changeset viewer.