Changeset 7230 for trunk/MagicSoft/Cosy/devdrv
- Timestamp:
- 07/28/05 22:24:32 (19 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r4104 r7230 16 16 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out) 17 17 : NodeDrv(nodeid, name, out), fPos(0), fVel(0), fAcc(0), 18 fTurn(0), fLabel(NULL), fPosHasChanged(false), fReport(NULL),/*fTwin(0), 19 fIsUpdated(kFALSE),*/ fMotor(0), fOffset(0) 18 fTurn(0), fLabel(NULL), fPosHasChanged(false), fDirHasChanged(false), 19 fReport(NULL), 20 /*fTwin(0), fIsUpdated(kFALSE),*/ 21 fMotor(0), fOffset(0), fDirChangedPos(0), 22 fDirection(kUndefined), fHysteresisPos(0), fHysteresisNeg(0) 20 23 { 21 24 } … … 93 96 fPos = val; 94 97 fTurn = 0; 98 fDirChangedPos = val; 95 99 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 100 fPosHasChanged = true; 101 fDirHasChanged = true; 102 fDirection = kUndefined; 96 103 //fIsUpdated=kTRUE; 97 104 //fOffset = 0; … … 198 205 // return; 199 206 207 // Warning: A multiturn shaftencoder is assumed! 208 if ((pos>fDirChangedPos && pos<fPos) || 209 (pos<fDirChangedPos && pos>fPos)) 210 { 211 fDirChangedPos = pos; 212 fDirHasChanged = true; 213 } 214 else 215 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 216 200 217 fPos = pos; 201 fOffset = fMotor ? fMotor->GetPdoPos() : 0;202 218 fTime.Set(*tv); 203 219 fPosHasChanged = true; … … 225 241 // return; 226 242 243 // Warning: A multiturn shaftencoder is assumed! 244 if ((pos>fDirChangedPos && pos<fPos) || 245 (pos<fDirChangedPos && pos>fPos)) 246 { 247 fDirChangedPos = pos; 248 fDirHasChanged = true; 249 } 250 else 251 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 252 227 253 //CheckTwin(fPos-pos); 228 254 fPos=pos; 229 fOffset = fMotor ? fMotor->GetPdoPos() : 0;230 255 fTime.Set(*tv); 231 256 fPosHasChanged=true; … … 267 292 turn--; 268 293 294 LWORDS_t multipos = pos+turn*fTicks; // SE position of multiturn shaftencoder 295 269 296 //if (fPos==pos && fTurn==fTurn) 270 297 // return; … … 272 299 //CheckTwin(fPos-pos); 273 300 301 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 302 303 // Warning: A multiturn shaftencoder is assumed! 304 if ((multipos>fDirChangedPos && multipos<fPos) || 305 (multipos<fDirChangedPos && multipos>fPos)) 306 { 307 fDirChangedPos = GetPos(); 308 fDirHasChanged = true; 309 fDirChangedOffset = fOffset; 310 } 311 else 312 { 313 fDirHasChanged = false; 314 } 315 316 if (multipos>GetPos()) fDirection = kForward; 317 else if (multipos<GetPos()) fDirection = kBackward; 318 else fDirection = kUndefined; 319 320 274 321 fPos = pos; 275 322 fTurn = turn; 276 323 277 fOffset = fMotor ? fMotor->GetPdoPos() : 0;278 324 fTime.Set(*tv); 279 325 fPosHasChanged=true; … … 281 327 //fOffset = 0; 282 328 283 284 329 if (fReport) 285 330 { 286 331 fReport->Lock("ShaftEncoder::HandlePDOType2"); 287 332 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO2 " << pos << " " << fVel << " " << fAcc << " " << GetNodeName() << endl; 333 *fReport << "DIR-REPORT " << (int)GetId() << " " << (Int_t)fDirHasChanged << " " << (Int_t)fDirChangedPos << endl; 288 334 fReport->UnLock("ShaftEncoder::HandlePDOType2"); 289 335 } … … 415 461 fPos = pre%16384; 416 462 fTurn = pre/16384; 417 463 fDirChangedPos = fPos; 418 464 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 465 466 fPosHasChanged = true; 467 fDirHasChanged = true; 468 469 fDirection = kUndefined; 419 470 } 420 471 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r4104 r7230 13 13 class TGLabel; 14 14 15 enum Direction_t { kUndefined, kForward, kBackward }; 16 15 17 class ShaftEncoder : public NodeDrv 16 18 { … … 23 25 WORD_t fTurns; // Number of possible turns 24 26 27 Direction_t fDirection; 28 29 Float_t fHysteresisPos; 30 Float_t fHysteresisNeg; 31 25 32 TGLabel *fLabel; // 26 33 LWORDS_t fUpdPos; // ticks 27 34 28 35 bool fPosHasChanged; //! 36 bool fDirHasChanged; //! 29 37 30 38 MTime fTime; 31 39 MLog *fReport; 32 40 33 Macs *fMotor; 34 Int_t fOffset; 41 Macs *fMotor; // Corresponding Motor/MACS 42 Int_t fOffset; // offset between SE and Motor 43 Int_t fDirChangedPos; // Last position at which the SE changed its moving direction 44 Int_t fDirChangedOffset; // Offset between SE and Motor when SE changed its moving direction last 45 35 46 36 47 void HandlePDOType0(BYTE_t *data, timeval_t *tv); … … 62 73 void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); } 63 74 64 LWORDS_t GetPos() const { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0? 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? 65 78 LWORD_t GetPhysRes() const { return fTicks; } 66 79 Int_t GetOffset() const { return fOffset; } 80 Int_t GetDirChangedOffset() const { return fDirChangedOffset; } 81 67 82 void SetOffset(Int_t off) { fOffset = off; } 68 83 … … 74 89 75 90 bool PosHasChanged() const { return fPosHasChanged; } 91 bool DirHasChanged() const { return fDirHasChanged; } 76 92 void ResetPosHasChanged() { fPosHasChanged = false; } 93 void ResetDirHasChanged() { fDirHasChanged = false; } 77 94 78 95 void SetReport(MLog *log) { fReport = log; } 96 97 void SetHysteresisNeg(Float_t f) { fHysteresisNeg = f; } 98 void SetHysteresisPos(Float_t f) { fHysteresisPos = f; } 99 100 Float_t GetPosCorrected() const { 101 switch (fDirection) { 102 case kUndefined: 103 return GetPos(); 104 case kForward: 105 return GetPos()-fHysteresisPos; 106 case kBackward: 107 return GetPos()+fHysteresisNeg; 108 } 109 } 79 110 80 111 ClassDef(ShaftEncoder, 0)
Note:
See TracChangeset
for help on using the changeset viewer.