Changeset 9431 for trunk/MagicSoft
- Timestamp:
- 04/22/09 10:36:03 (16 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/dkc.cc
r9132 r9431 20 20 : NodeDrv(nodeid, name), fMacId(2*nodeid+1), 21 21 fPdoPos1(0), fPdoPos2(0), fPosActive(0), fRpmActive(0), 22 fStatus DKC(0), fStatusPdo3(0xff), fArmed(false),23 fReport(NULL),fLabel(NULL) 22 fStatus(0), fStatusDKC(0), fStatusPdo3(0xff), fArmed(false), 23 fReport(NULL),fLabel(NULL),fUpdPos(0) 24 24 { 25 25 } … … 79 79 case 0xe252: return "Bleeder overtemp warning"; 80 80 case 0xe257: return "Continous current limit active"; 81 case 0xe259: return "Command velocity limit active"; 81 82 case 0xe264: return "Target position out of numerical range"; 82 83 case 0xe829: return "Positive position limit exceeded"; -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r8869 r9431 15 15 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name) 16 16 : NodeDrv(nodeid, name), 17 fPos(0), fVel(0), fAcc(0), fTurn(0), fTicks(0), fTurns(0), 18 fDirection(kUndefined), fHysteresisPos(0), fHysteresisNeg(0), 17 fPos(0), fVel(0), fAcc(0), fPosRes(0), fTurns(0), 19 18 fLabel(NULL), fUpdPos(0), 20 19 fPosHasChanged(false), fDirHasChanged(false), 21 fReport(NULL), fMotor(NULL), 22 fOffset(0), fDirChangedPos(0), fDirChangedOffset(0) 23 { 24 } 25 /* 26 void ShaftEncoder::CheckTwin(Int_t diff) const 27 { 28 if (!fTwin) 29 return; 30 31 if (fTwin->fIsUpdated) 32 fTwin->fIsUpdated = kFALSE; 33 else 34 fTwin->fOffset += diff; 35 } 36 */ 20 fReport(NULL) 21 { 22 } 23 37 24 void ShaftEncoder::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv) 38 25 { … … 95 82 gLog << inf2 << "- Reported position: " << dec << (Int_t)val << endl; 96 83 fPos = val; 97 fTurn = 0;98 fDirChangedPos = val;99 fOffset = fMotor ? fMotor->GetPdoPos() : 0;100 fPosHasChanged = true;101 fDirHasChanged = true;102 fDirection = kUndefined;103 //fIsUpdated=kTRUE;104 //fOffset = 0;105 84 return; 106 85 107 86 108 87 case 0x6501: 109 gLog << inf2 << "- P hys.Ticks/Revolution: " << dec << val << endl;110 f Ticks = val;88 gLog << inf2 << "- Position resolution Ticks/Revolution: " << dec << val << endl; 89 fPosRes = val; 111 90 return; 112 91 … … 179 158 } 180 159 181 void ShaftEncoder::DisplayVal()182 {183 const LWORDS_t pos = GetPos();184 if (IsZombieNode())185 {186 fLabel->SetText(new TGString(""));187 fUpdPos = ~pos;188 return;189 }190 191 char text[21]="";192 if (pos!=fUpdPos && fLabel)193 {194 sprintf(text, "%ld", pos);195 fLabel->SetText(new TGString(text));196 fUpdPos = pos;197 }198 }199 200 160 void ShaftEncoder::HandlePDOType0(const BYTE_t *data, const timeval_t &tv) 201 161 { … … 207 167 //if (pos==fPos) 208 168 // return; 209 210 // Warning: A multiturn shaftencoder is assumed!211 if ((pos>fDirChangedPos && pos<fPos) ||212 (pos<fDirChangedPos && pos>fPos))213 {214 fDirChangedPos = pos;215 fDirHasChanged = true;216 }217 else218 fOffset = fMotor ? fMotor->GetPdoPos() : 0;219 169 220 170 fPos = pos; … … 243 193 //if (fPos==pos) 244 194 // return; 245 246 // Warning: A multiturn shaftencoder is assumed!247 if ((pos>fDirChangedPos && pos<fPos) ||248 (pos<fDirChangedPos && pos>fPos))249 {250 fDirChangedPos = pos;251 fDirHasChanged = true;252 }253 else254 fOffset = fMotor ? fMotor->GetPdoPos() : 0;255 195 256 196 //CheckTwin(fPos-pos); … … 284 224 fAcc = data[6] | (data[7]<<8); 285 225 286 const int dnlim = fTicks/10; 287 const int uplim = fTurns*fTicks-dnlim; 288 289 int turn = fTurn; 290 291 if (fPos > uplim && pos < dnlim) 292 turn++; 293 294 if (fPos < dnlim && pos > uplim) 295 turn--; 296 297 LWORDS_t multipos = pos+turn*fTicks; // SE position of multiturn shaftencoder 226 // LWORDS_t multipos = pos+turn*fTicks; // SE position of multiturn shaftencoder 298 227 299 228 //if (fPos==pos && fTurn==fTurn) … … 302 231 //CheckTwin(fPos-pos); 303 232 304 fOffset = fMotor ? fMotor->GetPdoPos() : 0;305 306 // Warning: A multiturn shaftencoder is assumed!307 if ((multipos>fDirChangedPos && multipos<fPos) ||308 (multipos<fDirChangedPos && multipos>fPos))309 {310 fDirChangedPos = GetPos();311 fDirHasChanged = true;312 fDirChangedOffset = fOffset;313 }314 else315 {316 fDirHasChanged = false;317 }318 319 if (multipos>GetPos())320 fDirection = kForward;321 else322 if (multipos<GetPos())323 fDirection = kBackward;324 else325 fDirection = kUndefined;326 327 328 233 fPos = pos; 329 fTurn = turn;234 //fTurn = turn; 330 235 331 236 fTime.Set(tv); … … 338 243 fReport->Lock("ShaftEncoder::HandlePDOType2"); 339 244 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO2 " << pos << " " << fVel << " " << fAcc << " " << GetNodeName() << endl; 340 *fReport << "DIR-REPORT " << (int)GetId() << " " << (Int_t)fDirHasChanged << " " << (Int_t)fDirChangedPos << endl;245 //*fReport << "DIR-REPORT " << (int)GetId() << " " << (Int_t)fDirHasChanged << " " << (Int_t)fDirChangedPos << endl; 341 246 fReport->UnLock("ShaftEncoder::HandlePDOType2"); 342 247 } … … 390 295 391 296 // 392 // Set logic ticks/revolution = physical ticks/revolution => scale factor = 1393 //394 gLog << inf2 << "- " << GetNodeName() << ": Configuring log. tick/rev (0x6001)." << endl;395 SendSDO(0x6001, fTicks);396 WaitForSdo(0x6001);397 398 //399 // Set maximum number of ticks (ticks * turns)400 //401 gLog << inf2 << "- " << GetNodeName() << ": Configuring max number of ticks (0x6002)." << endl;402 SendSDO(0x6002, (LWORD_t)(fTicks*fTurns));403 WaitForSdo(0x6002);404 405 //406 // Delete preset Value407 //408 gLog << inf2 << "- " << GetNodeName() << ": Delete preset value (0x6003)." << endl;409 SendSDO(0x6003, (LWORD_t)0xffffffff);410 WaitForSdo(0x6003);411 412 //413 297 // Configure PDOs 414 298 // … … 428 312 gLog << inf2 << "- " << GetNodeName() << ": Start Node (NMT)." << endl; 429 313 SendNMT(kNMT_START); 430 431 /*432 cout << "---1---" << endl;433 MTimeout t(1000);434 while (!t.HasTimedOut())435 usleep(1);436 cout << "---2---" << endl;437 */438 439 // StartGuarding(200, 1, kTRUE); // 175440 // StartGuarding(10*GetId(), 2); // 175441 314 } 442 315 … … 458 331 } 459 332 460 void ShaftEncoder::SetPreset(LWORD_t pre)461 {462 gLog << inf2 << "- " << GetNodeName() << ": Setting Preset." << endl;463 464 SendSDO(0x6003, (LWORD_t)pre);465 if (!WaitForSdo(0x6003))466 return;467 468 fPos = pre%fTicks;469 fTurn = pre/fTicks;470 fDirChangedPos = fPos;471 fOffset = fMotor ? fMotor->GetPdoPos() : 0;472 473 fPosHasChanged = true;474 fDirHasChanged = true;475 476 fDirection = kUndefined;477 }478 479 333 void ShaftEncoder::StopDevice() 480 334 { … … 482 336 SendNMT(kNMT_STOP); 483 337 } 484 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r8862 r9431 18 18 { 19 19 private: 20 LWORDS_t fPos; // ticks 21 WORDS_t fVel; // ticks per 5ms 22 WORDS_t fAcc; // ticks per 25ms^2 23 WORDS_t fTurn; // Number of turn 24 LWORD_t fTicks; // Number of ticks per revolution (resolution) 25 WORD_t fTurns; // Number of possible turns 26 27 Direction_t fDirection; 28 29 Float_t fHysteresisPos; 30 Float_t fHysteresisNeg; 20 LWORDS_t fPos; // ticks 21 WORDS_t fVel; // ticks per 5ms 22 WORDS_t fAcc; // ticks per 25ms^2 23 LWORD_t fPosRes; // Number of ticks per revolution (resolution) 24 WORD_t fTurns; // Number of possible turns 31 25 32 26 TGLabel *fLabel; // … … 38 32 MTime fTime; 39 33 MLog *fReport; 40 41 Macs *fMotor; // Corresponding Motor/MACS42 Int_t fOffset; // offset between SE and Motor43 Int_t fDirChangedPos; // Last position at which the SE changed its moving direction44 Int_t fDirChangedOffset; // Offset between SE and Motor when SE changed its moving direction last45 46 34 47 35 void HandlePDOType0(const BYTE_t *data, const timeval_t &tv); … … 60 48 void StopDevice(); 61 49 62 void SetDisplay(TGLabel *label) { fLabel = label; }63 void SetMotor(Macs *m) { fMotor = m; }64 //void SetTwin(ShaftEncoder *se) { fTwin = se; }65 66 50 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv); 67 51 void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv); 68 /* 69 void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv) { NodeDrv::HandleSDOOK(idx, subidx, tv); } 70 void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); } 71 */ 52 72 53 void HandlePDO1(const BYTE_t *data, const timeval_t &tv) { HandlePDOType2(data, tv); } 73 54 void HandlePDO2(const BYTE_t *data, const timeval_t &tv) { HandlePDOType2(data, tv); } 74 55 75 LWORDS_t GetPos() const { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?76 Int_t GetDirection() const { return IsZombieNode() ? 0 : fPos-fDirChangedPos; } // FIXME? 0?77 Int_t GetDirChangedPos() const { return IsZombieNode() ? 0 : fDirChangedPos; } // FIXME? 0?78 LWORD_t GetPhysRes() const { return fTicks; }79 Int_t GetOffset() const { return fOffset; }80 Int_t GetDirChangedOffset() const { return fDirChangedOffset; }81 82 Int_t GetPosDirCorrected() const83 {84 return DirHasChanged() ? GetDirChangedPos() : GetPos();85 }86 Int_t GetOffsetDirCorrected() const87 {88 return DirHasChanged() ? GetDirChangedOffset() : GetOffset();89 }90 91 void SetOffset(Int_t off) { fOffset = off; }92 93 56 double GetMjd(); 94 95 void SetPreset(LWORD_t pre=0);96 97 void DisplayVal();98 99 bool PosHasChanged() const { return fPosHasChanged; }100 bool DirHasChanged() const { return fDirHasChanged; }101 void ResetPosHasChanged() { fPosHasChanged = false; }102 void ResetDirHasChanged() { fDirHasChanged = false; }103 104 void SetReport(MLog *log) { fReport = log; }105 106 void SetHysteresisNeg(Float_t f) { fHysteresisNeg = f; }107 void SetHysteresisPos(Float_t f) { fHysteresisPos = f; }108 109 Float_t GetPosCorrected() const110 {111 switch (fDirection)112 {113 case kUndefined:114 return GetPos();115 case kForward:116 return GetPos()-fHysteresisPos;117 case kBackward:118 return GetPos()+fHysteresisNeg;119 }120 return 0;121 }122 57 123 58 ClassDef(ShaftEncoder, 0)
Note:
See TracChangeset
for help on using the changeset viewer.