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