libcpp4ec
C++ for EtherCat Library
 All Classes Functions Variables Typedefs Enumerations Enumerator
EcSlaveSGDV.h
1 #ifndef ECSLAVESGDV_H
2 #define ECSLAVESGDV_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/ethercatprint.h>
17 }
18 
19 #include <vector>
20 #include <mutex>
21 
22 typedef struct
23 {
24  std::string name;
25  unsigned int index;
26  unsigned int offset;
27  unsigned int byteSize;
28  unsigned int entry;
29  std::string type;
30 }PDOobject;
31 
32 typedef struct
33 {
34  int32 position;
35  int32 velocity;
36  int16 torque;
37  int64 timestamp;
39 
40 namespace cpp4ec
41 {
47 class EcSlaveSGDV: public EcSlave
48 {
49 public:
50  //PDO Entries
54  typedef enum
55  {
56  FIRST_ENTRY,
57  SECOND_ENTRY,
58  THIRD_ENTRY,
59  FOURTH_ENTRY,
60  FIFTH_ENTRY,
61  SIXTH_ENTRY,
62  SEVENTH_ENTRY,
63  EIGHTH_ENTRY
64  } EcPDOEntry;
65 
69  typedef enum
70  {
71  CW_QUICK_STOP = 0x02,
72  CW_SHUTDOWN = 0x06,
73  CW_SWITCH_ON = 0x07,
74  CW_ENABLE_OP = 0x0F,
75  CW_DIASABLE_OP = 0x07,
76  CW_DISABLE_VOLTAGE = 0x00,
77  CW_FAULT_RESET = 0x80,
78  CW_HALT = 0x09,
91  } EcControlWord;
92 
96  typedef enum
97  {
98  SW_NOT_READY_SWICH_ON = 0x00,
99  SW_SWITCH_ON_DISABLED = 0x40,
100  SW_READY_SWITCH_ON = 0x31,
101  SW_SWITCHED_ON = 0x33,
102  SW_OPERATION_ENABLED = 0x37,
103  SW_QUICK_STOP_ACTIVE = 0x07,
104  SW_FAULT = 0x08,
105  SW_FAULT_RACTION_ACTIVE = 0x0F,
106  SW_HIGH_MASK = 0x00FF,
107  SW_LOW_MASK = 0xFF00,
108  } EcStatusWord;
109 
115  EcSlaveSGDV (ec_slavet* mem_loc);
116 
121  ~EcSlaveSGDV();
122 
127  const std::string& getName() const;
128 
134  bool configure() throw(EcErrorSGDV);
135 
143  void start() throw(EcErrorSGDV);
144 
151  void update();
152 
159  void stop() throw(EcErrorSGDV);
160 
171  void setDC(bool active, unsigned int sync0Time, unsigned int sync0Shift) throw(EcErrorSGDV);
172 
182  void setPDOBuffer(char * input, char * output);
183 
192  bool writePDO (EcPDOEntry entry, int value);
193 
201  bool readPDO (EcPDOEntry entry, int &value);
202 
210  bool readActualValue (ActualValue &value);
211 
219  bool writeControlWord (uint16_t controlWord);
220 
228  bool readStatusWord (uint16_t &statusWord);
229 
237  bool writePosition (int32_t position);
238 
246  bool readPosition (int32_t &position);
247 
255  bool writeVelocity (int32_t velocity);
256 
264  bool readVelocity (int32_t &velocity);
265 
273  bool writeTorque (int16_t torque);
274 
282  bool readTorque (int16_t &torque);
283 
291  bool readTimestamp (int64& time);
292 
303  void setSGDVObject(uint16_t index, uint8_t subindex, int psize, void * param);
304 
314  void getSGDVObject(uint16_t index, uint8_t subindex, int *psize, void *param);
315 
323  boost::signals2::signal<void (int, uint16_t, int32_t, int32_t, int16_t, int64_t)> slaveValues;
324 
325 private:
326 
327  int outputSize;
328  int inputSize;
329  int inputShift;
330 
331 
332 #ifdef HRT
333  char* pBufferOut;
334  char* pBufferIn;
335  char* inputBuf;
336 #endif
337 
338 #ifdef RT
339  uint8* pBufferOut;
340  uint8* pBufferIn;
341 #endif
342 
343 #ifdef NRT
344  uint8* pBufferOut;
345  uint8* pBufferIn;
346  char* inputBuf;
347 #endif
348 
349 
350  bool readXML() throw(EcErrorSGDV);
351  bool enableSpecificFunctions();
352  void loadDefaultPDO();
353  void loadParameters();
354  void si_PDOassign(uint16 slave, uint16 PDOassign);
355 
356  int controlWordEntry;
357  int targetPositionEntry;
358  int targetVelocityEntry;
359  int targetTorqueEntry;
360  int statusWordEntry;
361  int actualPositionEntry;
362  int actualVelocityEntry;
363  int actualTorqueEntry;
364 
365  bool wControlWordCapable;
366  bool wPositionCapable;
367  bool wVelocityCapable;
368  bool wTorqueCapable;
369  bool rStatusWordCapable;
370  bool rPositionCapable;
371  bool rVelocityCapable;
372  bool rTorqueCapable;
373  bool parameterSetting;
374  bool PDOmapping;
375 
376 
377 
378 #ifdef HRT
379  std::mutex slaveOutMutex;
380  std::mutex slaveInMutex;
381 #endif
382 
383 #ifdef NRT
384  std::mutex slaveInMutex;
385 #endif
386 
387  std::vector <CoEparameter> m_params;
388  std::vector <PDOobject> inputObjects;
389  std::vector <PDOobject> outputObjects;
390 
391  //PDO objects
392  typedef enum
393  {
394  CONTROL_WORD = 0x6040,
395  TARGET_POSITION = 0x607A,
396  TARGET_VELOCITY = 0x60FF,
397  TARGET_TORQUE = 0x6071,
398  }EcRecieveObjects;
399 
400  typedef enum
401  {
402  STATUS_WORD = 0x6041,
403  ACTUAL_POSITION = 0x6064,
404  ACTUAL_VELOCITY = 0x606C,
405  ACTUAL_TORQUE = 0x6077,
406  }EcTransmitObjects;
407 };
408 }
409 #endif
Class EcSlave.
Definition: EcSlave.h:53
bool writePosition(int32_t position)
Write on the position object.
Definition: EcSlaveSGDV.cpp:311
void update()
Update the data.
Definition: EcSlaveSGDV.cpp:66
Definition: EcSlaveSGDV.h:32
EcPDOEntry
Definition: EcSlaveSGDV.h:54
bool readPDO(EcPDOEntry entry, int &value)
Read on the input PDOentry.
Definition: EcSlaveSGDV.cpp:231
EcStatusWord
Definition: EcSlaveSGDV.h:96
const std::string & getName() const
Gets the name.
Definition: EcSlaveSGDV.cpp:86
bool writeControlWord(uint16_t controlWord)
Write on the Controlword object.
Definition: EcSlaveSGDV.cpp:278
bool writePDO(EcPDOEntry entry, int value)
Writes on the output PDOentry.
Definition: EcSlaveSGDV.cpp:211
bool readActualValue(ActualValue &value)
read Actual values structure
Definition: EcSlaveSGDV.cpp:253
EcSlaveSGDV(ec_slavet *mem_loc)
Constructor.
Definition: EcSlaveSGDV.cpp:31
bool writeTorque(int16_t torque)
Write on the torque object.
Definition: EcSlaveSGDV.cpp:376
void setSGDVObject(uint16_t index, uint8_t subindex, int psize, void *param)
Set an SGDV object.
Definition: EcSlaveSGDV.cpp:822
boost::signals2::signal< void(int, uint16_t, int32_t, int32_t, int16_t, int64_t)> slaveValues
A signal to emit information.
Definition: EcSlaveSGDV.h:323
Class EcSlaveSGDV.
Definition: EcSlaveSGDV.h:47
bool writeVelocity(int32_t velocity)
Write on the velocity object.
Definition: EcSlaveSGDV.cpp:344
~EcSlaveSGDV()
Destructor.
Definition: EcSlaveSGDV.cpp:59
Class EcErrorSGDV.
Definition: EcErrorSGDV.h:11
bool readPosition(int32_t &position)
Read the position object.
Definition: EcSlaveSGDV.cpp:328
bool readVelocity(int32_t &velocity)
Read the velocity object.
Definition: EcSlaveSGDV.cpp:360
EcControlWord
Definition: EcSlaveSGDV.h:69
void stop()
Stop motors.
Definition: EcSlaveSGDV.cpp:176
void setPDOBuffer(char *input, char *output)
Sets locations Buffer.
Definition: EcSlaveSGDV.cpp:165
bool readStatusWord(uint16_t &statusWord)
Read the Statusword object.
Definition: EcSlaveSGDV.cpp:295
void start()
Start motors.
Definition: EcSlaveSGDV.cpp:127
void setDC(bool active, unsigned int sync0Time, unsigned int sync0Shift)
Set DC.
Definition: EcSlaveSGDV.cpp:158
bool readTimestamp(int64 &time)
Read the actual timestamp.
Definition: EcSlaveSGDV.cpp:196
bool readTorque(int16_t &torque)
Read the torque object.
Definition: EcSlaveSGDV.cpp:392
void getSGDVObject(uint16_t index, uint8_t subindex, int *psize, void *param)
Set an SGDV object.
Definition: EcSlaveSGDV.cpp:827
bool configure()
Configure the SGDV servopack.
Definition: EcSlaveSGDV.cpp:91
Definition: EcMaster.h:37