| 1 | #ifndef COSY_ShafTEncoder
|
|---|
| 2 | #define COSY_ShafTEncoder
|
|---|
| 3 |
|
|---|
| 4 | #ifndef COSY_NodeDrv
|
|---|
| 5 | #include "nodedrv.h"
|
|---|
| 6 | #endif
|
|---|
| 7 |
|
|---|
| 8 | #ifndef MARS_MTime
|
|---|
| 9 | #include "MTime.h"
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | class Macs;
|
|---|
| 13 | class TGLabel;
|
|---|
| 14 |
|
|---|
| 15 | enum Direction_t { kUndefined, kForward, kBackward };
|
|---|
| 16 |
|
|---|
| 17 | class ShaftEncoder : public NodeDrv
|
|---|
| 18 | {
|
|---|
| 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 turn
|
|---|
| 25 | WORD_t fTurns; // Number of possible turns
|
|---|
| 26 |
|
|---|
| 27 | Direction_t fDirection;
|
|---|
| 28 |
|
|---|
| 29 | Float_t fHysteresisPos;
|
|---|
| 30 | Float_t fHysteresisNeg;
|
|---|
| 31 |
|
|---|
| 32 | TGLabel *fLabel; //
|
|---|
| 33 | LWORDS_t fUpdPos; // ticks
|
|---|
| 34 |
|
|---|
| 35 | bool fPosHasChanged; //!
|
|---|
| 36 | bool fDirHasChanged; //!
|
|---|
| 37 |
|
|---|
| 38 | MTime fTime;
|
|---|
| 39 | MLog *fReport;
|
|---|
| 40 |
|
|---|
| 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 |
|
|---|
| 46 |
|
|---|
| 47 | void HandlePDOType0(BYTE_t *data, timeval_t *tv);
|
|---|
| 48 | void HandlePDOType1(BYTE_t *data, timeval_t *tv);
|
|---|
| 49 | void HandlePDOType2(BYTE_t *data, timeval_t *tv);
|
|---|
| 50 |
|
|---|
| 51 | void ReqPos();
|
|---|
| 52 |
|
|---|
| 53 | void Init();
|
|---|
| 54 | void CheckConnection();
|
|---|
| 55 | // void CheckTwin(Int_t diff) const;
|
|---|
| 56 |
|
|---|
| 57 | public:
|
|---|
| 58 | ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
|
|---|
| 59 |
|
|---|
| 60 | void StopDevice();
|
|---|
| 61 |
|
|---|
| 62 | void SetDisplay(TGLabel *label) { fLabel = label; }
|
|---|
| 63 | void SetMotor(Macs *m) { fMotor = m; }
|
|---|
| 64 | //void SetTwin(ShaftEncoder *se) { fTwin = se; }
|
|---|
| 65 |
|
|---|
| 66 | void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
|
|---|
| 67 | void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, 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 | */
|
|---|
| 72 | void HandlePDO1(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
|
|---|
| 73 | void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
|
|---|
| 74 |
|
|---|
| 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() const
|
|---|
| 83 | {
|
|---|
| 84 | return DirHasChanged() ? GetDirChangedPos() : GetPos();
|
|---|
| 85 | }
|
|---|
| 86 | Int_t GetOffsetDirCorrected() const
|
|---|
| 87 | {
|
|---|
| 88 | return DirHasChanged() ? GetDirChangedOffset() : GetOffset();
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void SetOffset(Int_t off) { fOffset = off; }
|
|---|
| 92 |
|
|---|
| 93 | 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() const
|
|---|
| 110 | {
|
|---|
| 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 |
|
|---|
| 123 | ClassDef(ShaftEncoder, 0)
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | #endif
|
|---|