source: trunk/MagicSoft/Cosy/devdrv/macs.h@ 9421

Last change on this file since 9421 was 8865, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 3.8 KB
Line 
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
12class Macs : public NodeDrv
13{
14private:
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 bool fArmed;
38
39 void Init();
40 void StopDevice();
41
42 TString EvalStatusDKC(UInt_t stat) const;
43 Bool_t EvalStatus(LWORD_t val) const;
44 Bool_t EvalStatus(UInt_t errnum, UInt_t errinf) const
45 {
46 return EvalStatus(errnum|(errinf<<16));
47 }
48 void CheckErrorDKC(LWORD_t val);
49 void CheckErrorDKC(UInt_t errnum, UInt_t errinf)
50 {
51 CheckErrorDKC(errnum|(errinf<<16));
52 }
53
54
55 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
56 void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv);
57 //void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); }
58
59 void HandlePDO1(const BYTE_t *data, const timeval_t &tv);
60 void HandlePDO2(const BYTE_t *data, const timeval_t &tv);
61 void HandlePDO3(const BYTE_t *data, const timeval_t &tv);
62 //void HandleNodeguard(timeval_t *tv);
63
64 void SendNodeguard();
65
66 void CheckConnection();
67
68public:
69 enum
70 {
71 kNoSync = BIT(0),
72 kPosSync = BIT(1),
73 kVelSync = BIT(2)
74 };
75 enum
76 {
77 kIsArmed = BIT(0), // Macs will accept movement commands
78 kNotMoving = BIT(0), // motor not moving
79 kPosActive = BIT(1), // positioning active
80 kRpmActive = BIT(2), // RPM mode switched on
81 // BIT(3-5) unsused
82 kOutOfControl = BIT(6), // motor uncontrolled
83 kAxisReset = BIT(7) // axis resetted (after errclr, motor stop, motor on)
84 };
85
86 Macs(const BYTE_t nodeid, const char *name=NULL);
87 virtual ~Macs();
88
89 static LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
90 {
91 return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3);
92 }
93
94 void SendMsg(BYTE_t data[6]);
95 void SendMsg(BYTE_t d0=0, BYTE_t d1=0, BYTE_t d2=0,
96 BYTE_t d3=0, BYTE_t d4=0, BYTE_t d5=0);
97
98 void ReqPos();
99 void ReqVel();
100 //void ReqAxEnd();
101 void ReqVelRes();
102 void ReqRes();
103 //void SetHome(LWORDS_t pos=0, WORD_t maxtime=25);
104 void SetAcceleration(LWORD_t acc);
105 void SetDeceleration(LWORD_t dec);
106 void SetVelocity(LWORD_t vel);
107 //void SetNoWait(BYTE_t flag=TRUE);
108 void SetRpmMode(BYTE_t mode=TRUE);
109 void SetRpmVelocity(LWORDS_t cvel);
110 void SetPDO1On(BYTE_t flag=TRUE);
111 void SetPosEndswitch(LWORDS_t val);
112 void SetNegEndswitch(LWORDS_t val);
113
114 void EnableEndswitches(bool neg=true, bool pos=true);
115
116 void StartVelSync();
117 void StartPosSync();
118
119 void StartRelPos(LWORDS_t pos);
120 void StartAbsPos(LWORDS_t pos);
121
122 //void StopMotor();
123
124 void StartNode();
125
126 bool IsArmed() const { return fArmed; }
127 void Arm();
128 void Disarm();
129
130 int IsPositioning() const { return fPosActive; }
131 BYTE_t GetStatus() const { return fStatus; }
132
133 LWORDS_t GetPdoPos() const { return fPdoPos; }
134
135 LWORDS_t GetPos() const { return fPos; }
136 LWORDS_t GetVel() const { return fVel; }
137 LWORD_t GetVelRes() const { return fVelRes; } // Velocity units (would be 100 for %)
138 LWORD_t GetRes() const { return fRes; } // Encoder resolution
139
140 void StartHostGuarding();
141 void StopHostGuarding();
142
143 void HandleError();
144
145 Double_t GetPosTime() const { return fPosTime; }
146 Double_t GetMjd() const { return fPosTime.GetMjd(); }
147 Double_t GetPdoMjd() const { return fPdoTime.GetMjd(); }
148
149 ClassDef(Macs, 0)
150};
151
152#endif
Note: See TracBrowser for help on using the repository browser.