Changeset 1727 for trunk/MagicSoft/Cosy/devdrv
- Timestamp:
- 01/23/03 13:32:58 (22 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r1703 r1727 33 33 fPosActive(0), fRpmActive(0) 34 34 { 35 fTimeout = new TTimer(this, 100, kFALSE); // 100ms, asynchronous35 // fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous 36 36 } 37 37 38 38 Macs::~Macs() 39 39 { 40 fTimerOn = kFALSE;41 delete fTimeout;40 //fTimerOn = kFALSE; 41 // delete fTimeout; 42 42 } 43 43 … … 60 60 fVel = val; 61 61 return; 62 63 case 0x4000:64 switch (subidx)65 {66 case 1:67 cout << GetNodeName() << ": Timeout timer is " << (val?"en":"dis") << "abled." << endl;68 return;69 case 2:70 cout << GetNodeName() << ": Actual timeout time: " << dec << val << "ms" << endl;71 return;72 }73 break;74 62 75 63 case 0x6004: … … 129 117 } 130 118 131 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx )119 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv) 132 120 { 133 121 switch (idx) … … 137 125 { 138 126 case 0: 139 lout << ddev(MLog::eGui);127 //lout << ddev(MLog::eGui); 140 128 lout << "- " << GetNodeName() << ": Velocity set." << endl; 141 lout << edev(MLog::eGui);129 //lout << edev(MLog::eGui); 142 130 return; 143 131 } 144 132 break; 133 145 134 case 0x2003: 146 135 switch (subidx) 147 136 { 148 137 case 0: 149 lout << ddev(MLog::eGui);138 //lout << ddev(MLog::eGui); 150 139 lout << "- " << GetNodeName() << ": Acceleration set." << endl; 151 lout << edev(MLog::eGui);140 //lout << edev(MLog::eGui); 152 141 return; 153 142 case 1: 154 lout << ddev(MLog::eGui);143 //lout << ddev(MLog::eGui); 155 144 lout << "- " << GetNodeName() << ": Decceleration set." << endl; 156 lout << edev(MLog::eGui);145 //lout << edev(MLog::eGui); 157 146 return; 158 147 } 159 148 break; 149 160 150 case 0x3006: 161 151 switch (subidx) 162 152 { 163 153 case 0: 164 lout << ddev(MLog::eGui);154 //lout << ddev(MLog::eGui); 165 155 lout << "- " << GetNodeName() << ": RPM mode switched." << endl; 166 lout << edev(MLog::eGui);156 //lout << edev(MLog::eGui); 167 157 return; 168 158 … … 176 166 } 177 167 break; 168 178 169 case 0x4000: 179 if (subidx==0 && fTimerOn) 180 { 181 ResetTimeout(); 182 return; 183 } 184 break; 170 HandleNodeguard(tv); 171 return; 172 185 173 case 0x6004: 186 174 switch (subidx) 187 175 { 188 176 case 0: 189 lout << ddev(MLog::eGui);177 //lout << ddev(MLog::eGui); 190 178 lout << "- " << GetNodeName() << ": Absolute positioning started." << endl; 191 lout << edev(MLog::eGui);179 //lout << edev(MLog::eGui); 192 180 return; 193 181 194 182 case 1: 195 lout << ddev(MLog::eGui);183 //lout << ddev(MLog::eGui); 196 184 lout << "- " << GetNodeName() << ": Relative positioning started." << endl; 197 lout << edev(MLog::eGui);185 //lout << edev(MLog::eGui); 198 186 return; 199 187 } … … 202 190 203 191 } 204 NodeDrv::HandleSDOOK(idx, subidx );192 NodeDrv::HandleSDOOK(idx, subidx, tv); 205 193 } 206 194 … … 231 219 RequestSDO(0x100b); 232 220 WaitForSdo(0x100b); 233 234 // FIXME! Not statically linked!235 // if (fSoftVersion<0x00000035)236 // fIsZombie = true;237 221 } 238 222 … … 240 224 void Macs::Init() 241 225 { 226 if (HasError()) 227 { 228 lout << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl; 229 SetZombie(); 230 } 231 232 StopHostGuarding(); 233 StopGuarding(); 234 235 usleep(2000.*GetGuardTime()); 236 242 237 lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl; 243 238 RequestSDO(0x100a); 244 239 WaitForSdo(0x100a); 245 240 246 if ( fIsZombie)241 if (IsZombieNode()) 247 242 { 248 243 lout << GetNodeName() << " - InitDevice failed!" << endl; … … 250 245 } 251 246 252 EnableTimeout(kFALSE); 247 // FIXME! Not statically linked! 248 if (fSoftVersion<0x00000042) // 00.66 249 { 250 lout << GetNodeName() << " - Software Version too old!" << endl; 251 SetZombie(); 252 return; 253 } 254 253 255 SetRpmMode(FALSE); 254 256 … … 270 272 271 273 SetNoWait(TRUE); 274 275 StartGuarding(100, 2); 276 StartHostGuarding(); 272 277 } 273 278 … … 283 288 void Macs::StopDevice() 284 289 { 285 EnableTimeout(kFALSE);290 //EnableTimeout(kFALSE); 286 291 287 292 SetNoWait(FALSE); … … 348 353 { 349 354 SendSDO(0x2002, vel); // velocity 350 WaitForSdo(0x2002 );355 WaitForSdo(0x2002, 0); 351 356 } 352 357 … … 466 471 { 467 472 lout << "- " << GetNodeName() << ": reports Error occursion." << endl; 473 lout << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl; 474 SetZombie(); 468 475 SetError(-1); 469 476 return; … … 537 544 538 545 case 100: 539 lout << "Connection timed out." << endl;540 EnableTimeout(false);546 //lout << "Connection timed out." << endl; 547 //EnableTimeout(false); 541 548 return; 542 549 … … 562 569 // FIXME: Timeout??? 563 570 // 564 565 571 // while (GetError()<0) 572 // usleep(1); 566 573 567 574 // … … 569 576 // we can go on working 'as usual' Eg. Initialize a Display Update 570 577 // 571 cout << GetNodeName() << " Handling Error #" << GetError() << endl;578 cout << GetNodeName() << " Handling Error #" << dec << GetError() << endl; 572 579 switch (GetError()) 573 580 { … … 576 583 case 9: // zero idx 577 584 case 84: // ON TIME 578 // Stop program?585 lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 579 586 return; 580 587 581 588 case 11: // software endswitch 582 589 case 25: // hardware endswitch 590 lout << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl; 591 return; 592 583 593 case 100: // timeout (movement has been stopped, so we can go on) 584 594 DelError(); 585 595 return; 586 596 /* 587 597 case 101: 588 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl;598 //lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl; 589 599 DelError(); 590 600 return; 601 */ 602 default: 603 lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 604 591 605 } 592 606 } … … 633 647 } 634 648 635 void Macs::ReqTimeoutTime() 636 { 637 RequestSDO(0x4000, 2); 638 WaitForSdo(0x4000, 2); 639 } 640 641 void Macs::EnableTimeout(bool enable, LWORDS_t ms) 642 { 643 lout << "- " << GetNodeName() << ": " << (enable?"En":"Dis") << "able timeout, " << dec << ms << "ms." << endl; 644 if (!enable) 645 { 646 SendSDO(0x4000, 1, string('o', 'f', 'f')); 647 WaitForSdo(0x4000, 1); 648 649 lout << "- " << GetNodeName() << ": Stopping handshake (PC)." << endl; 650 651 fTimeout->Stop(); //kTRUE); 652 653 fTimerOn = kFALSE; 654 } 655 else 656 { 657 if (ms>0) 658 SetTimeoutTime(ms); 659 660 ResetTimeout(); 661 662 fTimerOn = kTRUE; 663 fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); //kFALSE); //TRUE); 664 665 // 666 // Start with kFALSE would be a continous timer, but this 667 // timer seems to stop it's activity at some stage without 668 // any reason 669 // 670 lout << "- " << GetNodeName() << ": starting handshake." << endl; 671 SendSDO(0x4000, 1, string('o', 'n')); 672 WaitForSdo(0x4000, 1); 673 } 674 lout << "- " << GetNodeName() << ": Timeout timer turned " 675 << (enable?"on.":"off.") << endl; 676 } 677 678 Bool_t Macs::HandleTimer(TTimer *t) 679 { 680 /* 681 Fons: 682 ----- 683 684 timers never trigger at the same time or when in a TTimer::Notify. 685 Little explanation: 686 687 - there are two types of timers synchronous and a-synchronous. 688 - synchronous timers are only handled via the ROOT eventloop 689 (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard 690 events then the synchronous timer queue is checked. So if the processing 691 of a mouse/keyboard event takes a long time synchronous timers are not 692 called for a while. To prevent this from happening one can call in long 693 procedures gSystem->ProcessEvents(). The system schedules only the 694 next timer in the queue when the current one's Notify() has finished. 695 - a-synchronous timers are triggered via SIGALARM, i.e. the program is 696 interupted and execution jumps to the Notify() function. When the 697 notify is finished the next a-sync timer is scheduled and the system 698 resumes from the place where it was initially interrupted. One of the 699 things to remember when using a-sync timers is don't make any graphics 700 calls in them. X11 is not re-entrant and it might be that the SIGALARM 701 signal interrupted the system while being in X11. A-sync timers are best 702 used to set flags that you can test at a convenient and controlled 703 time. 704 */ 705 706 // 707 // FIXME! Use NMT! 708 // 709 // --- lout << ddev(MLog::eGui); 710 // --- lout << "Send 0x4000: " << GetNodeName() << endl; 711 649 void Macs::SendNodeguard() 650 { 712 651 SendSDO(0x4000, 0, (LWORD_t)0, false); 713 714 // --- lout << "Done 0x4000: " << GetNodeName() << endl; 715 716 Timer time; 717 718 // --- lout << "dT " << GetNodeName() << ": " << dec <<(int)((fTimeoutTime-time.Now())*1000) << endl; 719 // --- lout << edev(MLog::eGui); 720 721 if (time.Now() > fTimeoutTime) 722 { 723 lout << ddev(MLog::eGui); 724 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window." << endl; 725 lout << edev(MLog::eGui); 726 SetError(101); 727 } 728 729 //WaitForSdo(0x4000, 0, kDontWait); 730 // 731 // Would not be necessary if I would Start the timer with 732 // kFALSE. This would be a continous timer, but this 733 // timer seems to stop it's activity at some stage without 734 // any reason 735 // 736 if (fTimerOn) 737 fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); 738 739 return kTRUE; 740 } 741 742 void Macs::ResetTimeout() 743 { 744 Timer time; 745 746 // --- lout << ddev(MLog::eGui); 747 // --- lout << "Reset " << GetNodeName() << ": " << dec << (int)((fTimeoutTime-time.Now())*1000) << endl; 748 // --- lout << edev(MLog::eGui); 749 750 fTimeoutTime = time.Now() + 3.*fGuardTime/1000.; 751 } 752 753 void Macs::SetTimeoutTime(LWORD_t ms) 754 { 755 // FIXME: Is '/2' the best choose? 756 fGuardTime = ms/3; // how often do we send/request the handshake 757 758 SendSDO(0x4000, 2, ms*2); // How often do we check for the handshake 759 WaitForSdo(0x4000, 2); 760 } 761 652 } 653 654 // -------------------------------------------------------------------------- 655 // 656 // This starts the host guarding. The host guarding is only available 657 // if the node guarding is running. The host guarding works with the 658 // guardtime and the lifetimefactor from the nodeguarding. 659 // 660 void Macs::StartHostGuarding() 661 { 662 SendSDO(0x100c, 0, (LWORD_t)GetGuardTime()); 663 WaitForSdo(0x100c); 664 665 SendSDO(0x100d, 0, (LWORD_t)GetLifeTimeFactor()); 666 WaitForSdo(0x100d); 667 668 lout << "- " << GetNodeName() << ": Hostguarding started (" << dec; 669 lout << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl; 670 } 671 672 // -------------------------------------------------------------------------- 673 // 674 // Stop the host guarding. 675 // 676 void Macs::StopHostGuarding() 677 { 678 SendSDO(0x100c, 0, (LWORD_t)0); 679 WaitForSdo(0x100c); 680 681 SendSDO(0x100d, 0, (LWORD_t)0); 682 WaitForSdo(0x100d); 683 684 lout << "- " << GetNodeName() << ": Hostguarding stopped." << endl; 685 } 686 -
trunk/MagicSoft/Cosy/devdrv/macs.h
r1703 r1727 1 1 #ifndef MACS_H 2 2 #define MACS_H 3 4 #include <TObject.h>5 3 6 4 #include "nodedrv.h" 7 5 #include "base/timer.h" 8 6 9 class Macs : public NodeDrv , public TObject7 class Macs : public NodeDrv 10 8 { 11 9 private: … … 30 28 BYTE_t fStatus; 31 29 32 TTimer *fTimeout;33 Bool_t fTimerOn;34 LWORD_t fGuardTime;35 double fTimeoutTime;36 37 30 LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0) 38 31 { … … 40 33 } 41 34 42 void ResetTimeout();43 Bool_t HandleTimer(TTimer *t);44 45 35 void Init(); 46 //bool Reboot();47 48 //bool InitDevice(Network *);49 50 //void StartDevice();51 36 void StopDevice(); 52 37 53 38 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv); 54 void HandleSDOOK(WORD_t idx, BYTE_t subidx );55 void HandleSDOError(LWORD_t data){ NodeDrv::HandleSDOError(data); }39 void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv); 40 //void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); } 56 41 57 42 void HandlePDO1(BYTE_t *data, timeval_t *tv); 58 43 void HandlePDO2(BYTE_t *data, timeval_t *tv); 44 //void HandleNodeguard(timeval_t *tv); 45 46 void SendNodeguard(); 59 47 60 48 void CheckConnection(); … … 108 96 void StartAbsPos(LWORDS_t pos); 109 97 110 void SetTimeoutTime(LWORD_t ms);111 void ReqTimeoutTime();112 113 void EnableTimeout(bool enable=true, LWORDS_t ms=-1);114 115 98 void StopMotor(); 116 99 … … 131 114 LWORD_t GetRes() const { return fRes; } // Encoder resolution 132 115 116 void StartHostGuarding(); 117 void StopHostGuarding(); 118 133 119 void HandleError(); 134 120 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r1703 r1727 1 1 #include "shaftencoder.h" 2 2 3 #include " timer.h"3 #include "base/timer.h" 4 4 #include "network.h" 5 5 … … 17 17 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out) 18 18 : NodeDrv(nodeid, name, out), fLabel(NULL), fPosHasChanged(false) 19 {20 }21 22 ShaftEncoder::~ShaftEncoder()23 19 { 24 20 } … … 55 51 return; 56 52 53 case 0x100c: 54 lout << "- Guardtime: " << dec << val << "ms" << endl; 55 return; 56 57 case 0x100d: 58 lout << "- Lifetimefactor: " << dec << val << endl; 59 return; 60 61 case 0x100e: 62 lout << "- CobId for guarding: 0x" << hex << val << endl; 63 return; 64 57 65 case 0x6000: 58 66 case 0x6500: 59 lout << "- Counting: " << (val&1 67 lout << "- Counting: " << (val&1 ?"anti-clockwise":"clockwise") << " "; 60 68 lout << "HwTest: " << (val&2 ?"on":"off") << " "; 61 69 lout << "Scaling: " << (val&4 ?"on":"off") << " "; … … 95 103 void ShaftEncoder::DisplayVal() 96 104 { 97 if ( fIsZombie)105 if (IsZombieNode()) 98 106 { 99 107 fLabel[0]->SetText(new TGString("")); … … 162 170 } 163 171 172 //#include <fstream.h> 173 //ofstream fout("log/shaftencoder.log"); 174 164 175 void ShaftEncoder::HandlePDOType2(BYTE_t *data, timeval_t *tv) 165 176 { … … 188 199 fPos = pos; 189 200 fTurn = turn; 201 202 //fout << dec << (int)GetId() << " " << turn << " " << pos << endl; 203 190 204 fTime.SetTimer(tv); 191 205 fPosHasChanged=true; … … 208 222 //----------------------------------------------------------------------- 209 223 224 StopGuarding(); 225 210 226 // 211 227 // Requesting and checking (FIXME) type of encoder … … 215 231 WaitForSdo(0x1000); 216 232 217 if ( fIsZombie)233 if (IsZombieNode()) 218 234 { 219 235 lout << GetNodeName() << " - Init failed!" << endl; … … 274 290 lout << "- " << GetNodeName() << ": Start Node (NMT)." << endl; 275 291 SendNMT(kNMT_START); 292 293 StartGuarding(125, 2); 276 294 } 277 295 … … 282 300 WaitForSdo(0x100b); 283 301 } 284 /*285 bool ShaftEncoder::InitDevice(Network *net)286 {287 NodeDrv::InitDevice(net);288 289 Init();290 291 return !fIsZombie;292 }293 294 // --------------------------------------------------------------------------295 //296 // This should be called from a master or main thread to get a node out297 // of the Zombie-Status.298 //299 bool ShaftEncoder::Reboot()300 {301 fIsZombie = false;302 303 Init();304 305 return !fIsZombie;306 }307 */308 302 309 303 void ShaftEncoder::ReqPos() … … 321 315 lout << "- " << GetNodeName() << ": Setting Preset." << endl; 322 316 323 SendSDO(0x6003, (LWORD_t) fPos);317 SendSDO(0x6003, (LWORD_t)pre); 324 318 if (!WaitForSdo(0x6003)) 325 319 return; -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r1703 r1727 2 2 #define SHAFTENCODER_H 3 3 4 #include " timer.h"4 #include "base/timer.h" 5 5 #include "nodedrv.h" 6 6 … … 17 17 WORD_t fTurns; // Number of possible turns 18 18 19 TGLabel **fLabel; 20 LWORDS_t fUpdPos; // ticks21 WORDS_t fUpdVel; // ticks per 5ms22 WORDS_t fUpdAcc; // ticks per 25ms^219 TGLabel **fLabel; // 20 LWORDS_t fUpdPos; // ticks 21 WORDS_t fUpdVel; // ticks per 5ms 22 WORDS_t fUpdAcc; // ticks per 25ms^2 23 23 24 bool fPosHasChanged; 24 bool fPosHasChanged; //! 25 25 26 26 Timer fTime; … … 37 37 public: 38 38 ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog); 39 virtual ~ShaftEncoder();40 39 41 //bool InitDevice(Network *);42 //bool Reboot();43 44 //void StartDevice();45 40 void StopDevice(); 46 41 … … 48 43 49 44 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv); 50 void HandleSDOOK(WORD_t idx, BYTE_t subidx) { NodeDrv::HandleSDOOK(idx, subidx); } 51 void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); } 52 45 /* 46 void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv) { NodeDrv::HandleSDOOK(idx, subidx, tv); } 47 void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); } 48 */ 53 49 void HandlePDO1(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); } 54 50 void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); } 55 51 56 LWORDS_t GetPos() { return fIsZombie? 0 : fPos+fTurn*fTicks; } // FIXME? 0?52 LWORDS_t GetPos() { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0? 57 53 LWORD_t GetPhysRes() { return fTicks; } 58 54
Note:
See TracChangeset
for help on using the changeset viewer.