libcpp4ec
C++ for EtherCat Library
 All Classes Functions Variables Typedefs Enumerations Enumerator
EcSlaveTrack.h
1 #ifndef ECSLAVETRACK_H
2 #define ECSLAVETRACK_H
3 
4 #include "EcSlave.h"
5 #include "EcError.h"
6 #include "EcErrorSGDV.h"
7 extern "C"
8 {
9 #include <soem/ethercattype.h>
10 #include <soem/ethercatbase.h>
11 #include <soem/ethercatmain.h>
12 #include <soem/ethercatconfig.h>
13 #include <soem/ethercatdc.h>
14 #include <soem/nicdrv.h>
15 #include <soem/ethercatcoe.h>
16 #include <soem/ethercatsoe.h>
17 #include <soem/ethercatprint.h>
18 }
19 
20 #include <boost/signals2/signal.hpp>
21 #include <vector>
22 #include <iostream>
23 #include <mutex>
24 
25 //MTD objects
26 typedef enum
27 {
28  CONTROL_WORD = 0x0086, //(S-0-0134)
29  TARGET_POSITION = 0x002F, //(S-0-0047)
30  TARGET_VELOCITY = 0x0024, //S-0-0036)
31  TARGET_TORQUE = 0x0050, //(S-0-0080)
32 }EcRecieveObjects;
33 
34 //AT objects
35 typedef enum
36 {
37  STATUS_WORD = 0x0087, //(S-0-0135)
38  ACTUAL_POSITION_1 = 0x0033, //(S-0-0051)
39  ACTUAL_POSITION_2 = 0x0035, //(S-0-0053)
40  ACTUAL_VELOCITY = 0x0028, //(S-0-0040)
41  ACTUAL_TORQUE = 0x0054, //(S-0-0084)
42 }EcTransmitObjects;
43 
44 //MTD Entries
45 typedef enum
46 {
47  FIRST_ENTRY, // first = 0
48  SECOND_ENTRY,
49  THIRD_ENTRY,
50  FOURTH_ENTRY,
51  FIFTH_ENTRY,
52  SIXTH_ENTRY,
53  SEVENTH_ENTRY,
54  EIGHTH_ENTRY,
55  NINTH_ENTRY,
56  TENTH_ENTRY,
57  ELEVENTH_ENTRY,
58  TWELFTH_ENTRY,
59  THIRTEENTH_ENTRY,
60  FOURTEENTH_ENTRY,
61  FIFTEENTH_ENTRY,
62 }EcPDOEntry;
63 
64 typedef enum
65 {
66  VZ0 =0, //MDT: no cyclic data, AT: no cyclic data
67  VZ1 =1, //MDT: S-0-0080 torque command, AT: no cyclic data
68  VZ2 =2, //MDT: S-0-0036 velocity command, AT: S-0-0040 velocity feedback
69  VZ3 =3, //MDT: S-0-0036 velocity command, AT: S-0-0051/53 position feedback 1/2
70  VZ4 =4, //MDT: S-0-0047 position command, AT: S-0-0051/53 position feedback 1/2
71  VZ5 =5, //MDT: S-0-0047 position command and S-0-0036 velocity command, AT:S-0-0051/53 position feedback 1/2 and S-0-0040 velocity feedback
72  VZ6 =6, //MDT: S-0-0036 velocity command, AT: no cyclic data
73  VZ7 =7, //Configurable, you will need to set up the telegrams by yourself using the functions setMDT and setAT
74 }EcTelegramType;
75 
76 
77 typedef enum
78 {
79  TORQUE_CONTROL =1,
80  VELOCITY_CONTROL =2,
81  POSITION_CONTROL =3,
82  DRIVEINTERNALINTERPOLATION_CONTROL =19,
83 }EcMode;
84 
85 //ControlWord S-0-0134
86 typedef enum
87 {
88 
89  CW_DRIVE_ENABLE = 0x4000, //Bit 14 a 1,
90  CW_DRIVE_DISABLE = 0x0000, //TODO A 0
91  CW_DRIVE_ON = 0xC000, //0x4000+0x8000 Bit 15 y 14 a 1,
92  CW_DRIVE_OFF = 0x4000, //bit 15 a 0, 14 a 1.
93  CW_DRIVE_HALT = 0xE000, //0x4000+0x8000+0x2000, bits 13,14,15 a 1
94  CW_PRIMARY_MODE = 0xC000, //
95  CW_SECONDARY_MODE_1 = 0xC800,
96  CW_SECONDARY_MODE_2 = 0xC200,
97  CW_SECONDARY_MODE_3 = 0xCA00,
98  CW_SECONDARY_MODE_4 = 0xC100,
99  CW_SECONDARY_MODE_5 = 0xC900,
100  CW_SECONDARY_MODE_6 = 0xC300,
101  CW_SECONDARY_MODE_7 = 0xCB00,
102 
103 
104 }EcControlWord;
105 
106 //StatusWord values CARRIL P-0-0116
107 /*typedef enum
108 {
109  SW_BBRELAY_CONTROL = 0x01,
110  SW_DRIVE_READY = 0x02,
111  SW_DRIVE_FOLLOW_COMAND = 0x08,
112  SW_DRIVE_HALT_ON = 0x10,
113  SW_CHANGE_COMMAND_STATUS = 0x20,
114  SW_OPERATION_MODE_INITIALIZED = 0x80,
115  SW_PRIMARY_MODE = 0x00, //BITS 8/9/11 a 0
116  SW_SECONDARY_MODE_1 = 0x0800,
117  SW_SECONDARY_MODE_2 = 0x0200,
118  SW_SECONDARY_MODE_3 = 0x0A00,
119  SW_SECONDARY_MODE_4 = 0x0100,
120  SW_SECONDARY_MODE_5 = 0x0900,
121  SW_SECONDARY_MODE_6 = 0x0300,
122  SW_SECONDARY_MODE_7 = 0x0B00,
123  SW_DRIVE_ERROR = 0x2000,
124  SW_CONTROL_READY = 0x8000,
125  SW_CONTROL_POWER_READY = 0x4000,
126  SW_DRIVE_TORQUE = 0xC000,
127 }EcStatusWord2;
128 */
129 
130 //StatusWord values CARRIL S-0-0135, hay que comprobar bit a bit, con un & o algo asi
131 typedef enum
132 {
133  SW_NOT_READY = 0x00, //drive not ready for power on, because internal checks not positively completed
134  SW_READY = 0x4000, //ready for power on
135  SW_READY_FREE = 0x8000, //control section and power section ready for operation, torque-free
136  SW_READY_COMPL = 0xC000, //in operation, with torque
137  SW_CHANGE_COMMAND_STATUS = 0x20,
138  SW_OPERATION_MODE_INITIALIZED = 0x80,
139  SW_PRIMARY_MODE = 0x00, //BITS 8/9/11 a 0
140  SW_SECONDARY_MODE_1 = 0x0100,
141  SW_SECONDARY_MODE_2 = 0x0200,
142  SW_SECONDARY_MODE_3 = 0x0300,
143  SW_SECONDARY_MODE_4 = 0x0400,
144  SW_SECONDARY_MODE_5 = 0x0500,
145  SW_SECONDARY_MODE_6 = 0x0600,
146  SW_SECONDARY_MODE_7 = 0x0700,
147 
148 }EcStatusWord;
149 
150 typedef struct
151 {
152  std::string name;
153  unsigned int offset;
154  unsigned int byteSize;
155  std::string type;
156 }PDOobject;
157 
158 namespace cpp4ec
159 {
165 class EcSlaveTrack: public EcSlave
166 {
167 public:
173  EcSlaveTrack (ec_slavet* mem_loc);
174 
179  ~EcSlaveTrack();
180 
185  const std::string& getName() const;
186 
192  bool configure() throw(EcErrorSGDV);
193 
201  void start() throw(EcErrorSGDV);
202 
209  void update();
210 
217  void stop() throw(EcErrorSGDV);
218 
228  void setPDOBuffer(char * input, char * output);
229 
230  void setDC(bool active, unsigned int sync0Time, unsigned int sync0Shift) throw(EcErrorSGDV);
231 
240  bool writeMDT (EcPDOEntry entry, int value)throw(EcErrorSGDV);
241 
249  bool readAT (EcPDOEntry entry, int &value);
250 
258  bool writeControlWord (uint16_t controlWord);
259 
267  bool readStatusWord (uint16_t &statusWord);
268 
276  bool writePosition (int32_t position);
277 
285  bool readPosition (int32_t &position);
286 
294  bool writeVelocity (int32_t velocity);
295 
303  bool readVelocity (int32_t &velocity);
304 
312  bool writeTorque (int16_t torque);
313 
321  bool readTorque (int16_t &torque);
322 
333  void setSGDVOject(uint16_t idn, uint8_t elementflags, int psize, void * param);
334 
344  void getSGDVObject(uint16_t idn, uint8_t elementflags, int *psize, void *param);
345 
353  std::vector<int> readIDNofIDNs(int idn, bool print);
354 
361  void setMDT(std::vector<int> listidn);
362 
369  void setAT(std::vector<int> listidn);
370 
380  void modeSetUp(EcMode mode, int nmode);
381 
396  void TelegramType(EcTelegramType type);
397 
398  void DefaultParameters();
399 
400  void ClearError();
401 
402 
403 
404 
405 // void refresh();
406  boost::signals2::signal<void (int, uint16_t, int32_t, int32_t, int16_t)> slaveValues;
407 
408 
409 private:
410 
411  //Variables used for the properties
412  bool useDC;
413  unsigned int PDOerrorsTolerance;
414  unsigned int SYNC0TIME;
415  unsigned int SHIFT;
416  unsigned int SHIFTMASTER;
417 
418  int minPosition;
419  int maxPosition;
420  int initPosition;
421  int m_mutex;
422 
423  int outputSize;
424  int inputSize;
425 
426  int transmitEntry;
427  int recieveEntry;
428 
429  void readXML() throw(EcErrorSGDV);
430  bool addPDOobject(std::string PDOentry,int value, int subindex);
431 
432  int controlWordEntry;
433  int targetPositionEntry;
434  int targetVelocityEntry;
435  int targetTorqueEntry;
436  int statusWordEntry;
437  int actualPositionEntry;
438  int actualVelocityEntry;
439  int actualTorqueEntry;
440 
441  bool wControlWordCapable;
442  bool wPositionCapable;
443  bool wVelocityCapable;
444  bool wTorqueCapable;
445  bool rStatusWordCapable;
446  bool rPositionCapable;
447  bool rVelocityCapable;
448  bool rTorqueCapable;
449 
450  char* outputBuf;
451  char* inputBuf;
452  char* inputNull;
453  char* pBufferOut;
454  char* pBufferIn;
455 
456 
457 
458  std::mutex slaveInMutex;
459  std::mutex slaveOutMutex;
460 
461  std::vector <SoEparameter> m_params;
462  std::vector <PDOobject> inputObjects;
463  std::vector <PDOobject> outputObjects;
464  std::vector <char*> bufferList;
465 };
466 }
467 #endif
void TelegramType(EcTelegramType type)
Set the telegram type.
Definition: EcSlaveTrack.cpp:561
bool readAT(EcPDOEntry entry, int &value)
Read on the input PDOentry.
Definition: EcSlaveTrack.cpp:213
bool writeMDT(EcPDOEntry entry, int value)
Writes on the output PDOentry.
Definition: EcSlaveTrack.cpp:195
Class EcSlave.
Definition: EcSlave.h:53
bool readVelocity(int32_t &velocity)
Read the velocity object.
Definition: EcSlaveTrack.cpp:272
EcSlaveTrack(ec_slavet *mem_loc)
Constructor.
Definition: EcSlaveTrack.cpp:18
void modeSetUp(EcMode mode, int nmode)
Set the operation mode.
Definition: EcSlaveTrack.cpp:556
std::vector< int > readIDNofIDNs(int idn, bool print)
Read the IDN that are contained in a IDN.
Definition: EcSlaveTrack.cpp:488
void stop()
Stop motors.
Definition: EcSlaveTrack.cpp:179
void setPDOBuffer(char *input, char *output)
Sets locations Buffer.
Definition: EcSlaveTrack.cpp:173
const std::string & getName() const
Gets the name.
Definition: EcSlaveTrack.cpp:83
void setDC(bool active, unsigned int sync0Time, unsigned int sync0Shift)
Set the Distributed clock.
Definition: EcSlaveTrack.cpp:187
void update()
Update the data.
Definition: EcSlaveTrack.cpp:47
void setAT(std::vector< int > listidn)
Set the IDN that will be contained in the AT.
Definition: EcSlaveTrack.cpp:537
bool writeTorque(int16_t torque)
Write on the torque object.
Definition: EcSlaveTrack.cpp:281
void setMDT(std::vector< int > listidn)
Set the IDN that will be contained in the MDT.
Definition: EcSlaveTrack.cpp:518
void start()
Start motors.
Definition: EcSlaveTrack.cpp:162
bool readTorque(int16_t &torque)
Read the torque object.
Definition: EcSlaveTrack.cpp:290
~EcSlaveTrack()
Destructor.
Definition: EcSlaveTrack.cpp:37
bool writePosition(int32_t position)
Write on the position object.
Definition: EcSlaveTrack.cpp:245
bool readPosition(int32_t &position)
Read the position object.
Definition: EcSlaveTrack.cpp:254
bool writeVelocity(int32_t velocity)
Write on the velocity object.
Definition: EcSlaveTrack.cpp:263
Class EcErrorSGDV.
Definition: EcErrorSGDV.h:11
bool writeControlWord(uint16_t controlWord)
Write on the Controlword object.
Definition: EcSlaveTrack.cpp:226
void setSGDVOject(uint16_t idn, uint8_t elementflags, int psize, void *param)
Set an SGDV object.
Definition: EcSlaveTrack.cpp:475
void getSGDVObject(uint16_t idn, uint8_t elementflags, int *psize, void *param)
Set an SGDV object.
Definition: EcSlaveTrack.cpp:482
EcSlaveTrack.
Definition: EcSlaveTrack.h:165
bool readStatusWord(uint16_t &statusWord)
Read the Statusword object.
Definition: EcSlaveTrack.cpp:235
bool configure()
Configure the SGDV servopack.
Definition: EcSlaveTrack.cpp:100
Definition: EcMaster.h:37