1 | #ifndef MACS_H
|
---|
2 | #define MACS_H
|
---|
3 |
|
---|
4 | #include <TObject.h>
|
---|
5 |
|
---|
6 | #include "nodedrv.h"
|
---|
7 | #include "base/timer.h"
|
---|
8 |
|
---|
9 | class Macs : public NodeDrv, public TObject
|
---|
10 | {
|
---|
11 | private:
|
---|
12 | BYTE_t fMacId;
|
---|
13 |
|
---|
14 | LWORD_t fSoftVersion;
|
---|
15 |
|
---|
16 | LWORD_t fVelRes;
|
---|
17 | LWORDS_t fVel;
|
---|
18 |
|
---|
19 | LWORDS_t fPos;
|
---|
20 | Timer fPosTime;
|
---|
21 |
|
---|
22 | LWORD_t fRes; // Encoder resolution
|
---|
23 |
|
---|
24 | LWORDS_t fPdoPos;
|
---|
25 | Timer fPdoTime;
|
---|
26 |
|
---|
27 | BYTE_t fPosActive;
|
---|
28 | BYTE_t fRpmActive;
|
---|
29 | BYTE_t fInControl;
|
---|
30 | BYTE_t fStatus;
|
---|
31 |
|
---|
32 | TTimer *fTimeout;
|
---|
33 | Bool_t fTimerOn;
|
---|
34 | LWORD_t fGuardTime;
|
---|
35 | double fTimeoutTime;
|
---|
36 |
|
---|
37 | LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
|
---|
38 | {
|
---|
39 | return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3);
|
---|
40 | }
|
---|
41 |
|
---|
42 | void ResetTimeout();
|
---|
43 | Bool_t HandleTimer(TTimer *t);
|
---|
44 |
|
---|
45 | void Init();
|
---|
46 | //bool Reboot();
|
---|
47 |
|
---|
48 | //bool InitDevice(Network *);
|
---|
49 |
|
---|
50 | //void StartDevice();
|
---|
51 | void StopDevice();
|
---|
52 |
|
---|
53 | 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); }
|
---|
56 |
|
---|
57 | void HandlePDO1(BYTE_t *data, timeval_t *tv);
|
---|
58 | void HandlePDO2(BYTE_t *data, timeval_t *tv);
|
---|
59 |
|
---|
60 | void CheckConnection();
|
---|
61 |
|
---|
62 | public:
|
---|
63 | enum
|
---|
64 | {
|
---|
65 | kNoSync = BIT(0),
|
---|
66 | kPosSync = BIT(1),
|
---|
67 | kVelSync = BIT(2)
|
---|
68 | };
|
---|
69 | enum
|
---|
70 | {
|
---|
71 | kNotMoving = BIT(0), // motor not moving
|
---|
72 | kPosActive = BIT(1), // positioning active
|
---|
73 | kRpmActive = BIT(2), // RPM mode switched on
|
---|
74 | // BIT(3-5) unsused
|
---|
75 | kOutOfControl = BIT(6), // motor uncontrolled
|
---|
76 | kAxisReset = BIT(7) // axis resetted (after errclr, motor stop, motor on)
|
---|
77 | };
|
---|
78 |
|
---|
79 | Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
|
---|
80 | virtual ~Macs();
|
---|
81 |
|
---|
82 | void SendMsg(BYTE_t data[6]);
|
---|
83 | void SendMsg(BYTE_t d0=0, BYTE_t d1=0, BYTE_t d2=0,
|
---|
84 | BYTE_t d3=0, BYTE_t d4=0, BYTE_t d5=0);
|
---|
85 |
|
---|
86 | void ReqPos();
|
---|
87 | void ReqVel();
|
---|
88 | //void ReqAxEnd();
|
---|
89 | void ReqVelRes();
|
---|
90 | void ReqRes();
|
---|
91 | void SetHome(LWORDS_t pos=0, WORD_t maxtime=25);
|
---|
92 | void SetAcceleration(LWORD_t acc);
|
---|
93 | void SetDeceleration(LWORD_t dec);
|
---|
94 | void SetVelocity(LWORD_t vel);
|
---|
95 | void SetNoWait(BYTE_t flag=TRUE);
|
---|
96 | void SetRpmMode(BYTE_t mode=TRUE);
|
---|
97 | void SetRpmVelocity(LWORDS_t cvel);
|
---|
98 | void SetPDO1On(BYTE_t flag=TRUE);
|
---|
99 | void SetPosEndswitch(LWORDS_t val);
|
---|
100 | void SetNegEndswitch(LWORDS_t val);
|
---|
101 |
|
---|
102 | void EnableEndswitches(bool neg=true, bool pos=true);
|
---|
103 |
|
---|
104 | void StartVelSync();
|
---|
105 | void StartPosSync();
|
---|
106 |
|
---|
107 | void StartRelPos(LWORDS_t pos);
|
---|
108 | void StartAbsPos(LWORDS_t pos);
|
---|
109 |
|
---|
110 | void SetTimeoutTime(LWORD_t ms);
|
---|
111 | void ReqTimeoutTime();
|
---|
112 |
|
---|
113 | void EnableTimeout(bool enable=true, LWORDS_t ms=-1);
|
---|
114 |
|
---|
115 | void StopMotor();
|
---|
116 |
|
---|
117 | int IsPositioning() const { return fPosActive; }
|
---|
118 | BYTE_t GetStatus() const { return fStatus; }
|
---|
119 |
|
---|
120 | double GetTime();
|
---|
121 | double GetMjd();
|
---|
122 |
|
---|
123 | double GetPdoTime();
|
---|
124 | double GetPdoMjd();
|
---|
125 |
|
---|
126 | LWORDS_t GetPdoPos() const { return fPdoPos; }
|
---|
127 |
|
---|
128 | LWORDS_t GetPos() const { return fPos; }
|
---|
129 | LWORDS_t GetVel() const { return fVel; }
|
---|
130 | LWORD_t GetVelRes() const { return fVelRes; } // Velocity units (would be 100 for %)
|
---|
131 | LWORD_t GetRes() const { return fRes; } // Encoder resolution
|
---|
132 |
|
---|
133 | void HandleError();
|
---|
134 |
|
---|
135 | ClassDef(Macs, 0)
|
---|
136 | };
|
---|
137 |
|
---|
138 | #endif
|
---|