Alex exoskeleton
ALEX SoftwareDocumentation
Drive.h
Go to the documentation of this file.
1 
10 #ifndef DRIVE_H_INCLUDED
11 #define DRIVE_H_INCLUDED
12 
13 #include <CANopen.h>
14 #include <CO_command.h>
15 #include <string.h>
16 
17 #include <map>
18 #include <sstream>
19 #include <vector>
20 
21 // Constant for a CAN Message
22 #define CANMESSAGELENGTH 100
23 
24 // Constants representing the control mode of the drive
30  ERROR = -1
31 };
32 
33 enum DriveState {
34  DISABLED = 0,
36  ENABLED = 2,
37 };
38 
43 enum OD_Entry_t {
48  TARGET_POS = 11,
50 };
51 
57 static std::map<OD_Entry_t, int> OD_Addresses = {
58  {STATUS_WORD, 0x6041},
59  {ACTUAL_POS, 0x6064},
60  {ACTUAL_VEL, 0x606C},
61  {ACTUAL_TOR, 0x6077},
62  {TARGET_POS, 0x607A},
63  {TARGET_VEL, 0x60FF},
64 };
65 
71 static std::map<OD_Entry_t, int> OD_Data_Size = {
72  {STATUS_WORD, 0x0010},
73  {ACTUAL_POS, 0x0020},
74  {ACTUAL_VEL, 0x0020},
75  {ACTUAL_TOR, 0x0010},
76  {TARGET_POS, 0x0020},
77  {TARGET_VEL, 0x0020},
78 };
83 struct motorProfile {
87 };
88 
93 class Drive {
94  protected:
99  int NodeID;
100 
109  std::vector<std::string> generateTPDOConfigSDO(std::vector<OD_Entry_t> items, int PDO_Num, int SyncRate);
110 
119  std::vector<std::string> generateRPDOConfigSDO(std::vector<OD_Entry_t> items, int PDO_Num, int UpdateTiming);
120 
138  std::vector<std::string> generatePosControlConfigSDO(motorProfile positionProfile);
139 
145  int sendSDOMessages(std::vector<std::string> messages);
146 
147  private:
153 
158  int error;
159 
164  DriveState driveState = DISABLED;
165 
170  ControlMode controlMode = UNCONFIGURED;
171 
172  public:
177  Drive();
178 
184  Drive(int NodeID);
185 
190  virtual ~Drive(){};
191 
197  virtual bool Init() = 0;
198 
212  virtual bool initPDOs();
213 
224  virtual bool initPosControl(motorProfile posControlMotorProfile) = 0;
225 
234  virtual bool initVelControl() = 0;
235 
244  virtual bool initTorqControl() = 0;
245 
251  virtual int updateDriveStatus();
252 
259  virtual bool setPos(int position);
260 
267  virtual bool setVel(int velocity);
268 
275  virtual bool setTorque(int torque);
276 
282  virtual int getPos();
283 
289  virtual int getVel();
290 
296  virtual int getTorque();
297 
298  // Drive State Modifiers
308  virtual bool readyToSwitchOn();
309 
319  virtual bool enable();
320 
330  virtual bool disable();
331 
338  virtual bool posControlConfirmSP();
339 
345  virtual DriveState getDriveState();
346 
347  // CANOpen
353  int getNodeID();
354 };
355 
356 #endif
OD_Entry_t
Commonly-used entries defined in the Object Dictionary for CiA402 Drives.
Definition: Drive.h:43
int profileAccelration
Definition: Drive.h:85
Definition: Drive.h:34
Abstract class describing a Drive used to communicate with a CANbus device. Note that many functions ...
Definition: Drive.h:93
ControlMode
Definition: Drive.h:25
Definition: Drive.h:36
int error
Current error state of the drive.
Definition: Drive.h:158
int profileDeceleration
Definition: Drive.h:86
int NodeID
The CAN Node ID used to address this particular drive on the CAN bus.
Definition: Drive.h:99
int profileVelocity
Definition: Drive.h:84
struct to hold desired velocity, acceleration and deceleration values for a drives motor controller p...
Definition: Drive.h:83
DriveState
Definition: Drive.h:33
virtual ~Drive()
Destroy the Drive object.
Definition: Drive.h:190
Definition: Drive.h:30
int statusWord
Current status word of the drive.
Definition: Drive.h:152