tmc_coe_interpreter.h
Go to the documentation of this file.
1 
6 #ifndef TMC_COE_INTERPRETER_H
7 #define TMC_COE_INTERPRETER_H
8 
9 #include <ros/ros.h>
10 #include <stdio.h>
11 #include <string>
12 #include <vector>
13 #include <boost/thread/thread.hpp>
14 #include "osal.h"
15 
16 /* Network Management States */
17 typedef enum
18 {
19  INIT = 1,
20  PRE_OP = 2,
21  SAFE_OP = 4,
26 
27 /* Control Word State Commands */
28 typedef enum
29 {
30  SHUTDOWN = 6,
31  SWITCH_ON = 7,
33  FAULT_RESET = 128,
35 
37 /* Statusword State Coding for bit masking */
38 
39 //Not ready to switch on, 0b0000_0000_0100_1111, 0b0000_0000_0000_0000
40 //Switch on disable, 0b0000_0000_0100_1111, 0b0000_0000_0100_0000
41 //Ready to switch on, 0b0000_0000_0110_1111, 0b0000_0000_0010_0001
42 //Switched on, 0b0000_0000_0110_1111, 0b0000_0000_0010_0011
43 //Operation enabled, 0b0000_0000_0110_1111, 0b0000_0000_0010_0111
44 //Quick stop active, 0b0000_0000_0110_1111, 0b0000_0000_0000_0111
45 //Fault reaction active, 0b0000_0000_0100_1111, 0b0000_0000_0000_1111
46 //Fault, 0b0000_0000_0100_1111, 0b0000_0000_0000_1000
47 //Set Point Ack, 0b0001_0000_0000_0000, 0b0000_0000_0000_0000
48 
49 /* Finite State Automation States */
50 typedef enum
51 {
61 } fsa_state_t;
62 
63 /* Status Word Coding Values */
64 typedef enum
65 {
73  FAULT_VAL = 8,
76 
84  FAULT_VAL,
86 
87 /* Statusword Bit position */
88 typedef enum
89 {
90  RTSO_BIT = 0,
97  SPA_BIT = 12,
99 
100 /* Statusword State bitmask */
101 std::vector<int> status_state_mask_ = {
102  (1<<SOD_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
103  (1<<SOD_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
104  (1<<SOD_BIT)|(1<<QS_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
105  (1<<SOD_BIT)|(1<<QS_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
106  (1<<SOD_BIT)|(1<<QS_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
107  (1<<SOD_BIT)|(1<<QS_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
108  (1<<SOD_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
109  (1<<SOD_BIT)|(1<<F_BIT)|(1<<OE_BIT)|(1<<SO_BIT)|(1<<RTSO_BIT),
110  (1<<SPA_BIT)
111  };
112 
114 
115 /* Output PDOs (Sync Manager 2) - Read/Write access */
116 typedef struct PACKED
117 {
118  int8_t modes_of_operation;
119  uint16_t control_word;
120  int32_t target_position;
121  int32_t target_velocity;
122  int16_t target_torque;
123 } output_pdo_t;
124 
125 /* Output PDOs (Sync Manager 3) - Read only access*/
126 typedef struct PACKED
127 {
128  int8_t modes_of_operation_display;
129  uint16_t status_word;
130  int32_t position_demand_value;
131  int32_t position_actual_value;
132  int32_t velocity_demand_value;
133  int32_t velocity_actual_value;
134  int16_t torque_demand_value;
135  int16_t torque_actual_value;
136 } input_pdo_t;
137 
138 /* Constants */
139 const uint32_t IOMAP_SIZE = 4096;
143 const uint16_t PROCESS_DATA_DELAY = 1000; // Standard PLC cycle time
144 const uint16_t ERROR_CHECK_DELAY = 10000; // Based on SOEM's simple_test script
145 const uint8_t TOTAL_WORK_COUNTER_PER_SLAVE = 3; // 2counts of outputPDO workcount + 1count of inputPDO workcount
146 const uint8_t DEBUG_PERIOD = 1; // Period of debug logs in seconds
147 
149 {
150 private:
151  void processData();
152  boost::thread processdata_thread_;
153  void errorCheck();
154  boost::thread error_check_thread_;
155  int8_t setControlWord(uint8_t slave_number, fsa_state_t response_SW, control_word_state_t requested_CW);
156  template <typename T>
157  std::string readSDO(uint8_t slave_number, uint16_t index_number, uint16_t subindex_number, T value);
158  template <typename T>
159  std::string writeSDO(uint8_t slave_number, uint16_t index_number, uint16_t subindex_number, T value);
160 
162  std::vector<int> slave_;
163  std::vector<std::vector<std::string>> all_obj_name_;
164  std::vector<std::vector<std::string>> all_index_;
165  std::vector<std::vector<std::string>> all_sub_index_;
166  std::vector<std::vector<std::string>> all_datatype_;
167 
176 
177 public:
178  TmcCoeInterpreter(uint8_t SDO_PDO_retries, double interface_timeout);
180  void paramTransfer(std::vector<std::vector<std::string>> all_obj_name,
181  std::vector<std::vector<std::string>> all_index,
182  std::vector<std::vector<std::string>> all_sub_index,
183  std::vector<std::vector<std::string>> all_datatype);
184  uint8_t initInterface(std::string ifname);
185  bool safeOPstate(std::vector<int> en_slave);
186  bool OPstate();
187  void stopInterface();
188  bool statusWordState(uint8_t slave_number, fsa_state_t state);
189  uint8_t deviceStateChange(uint8_t slave_number, nmt_state_t state);
190  bool readSDO(uint8_t slave_number, std::string object_name, std::string *value);
191  bool writeSDO(uint8_t slave_number, std::string object_name, std::string *value);
192  bool commandCodingTransition(uint8_t slave_number);
193  std::string getSlaveName(uint8_t slave_number);
194  bool isCycleFinished();
197  void startCycleCounter();
198  void stopCycleCounter();
199 
200  std::vector<input_pdo_t*> input_pdo_;
201  std::vector<output_pdo_t*> output_pdo_;
203 };
204 
205 #endif /* TMC_COE_INTERPRETER_H */
SET_POINT_ACK_IN_PROCESS
@ SET_POINT_ACK_IN_PROCESS
Definition: tmc_coe_interpreter.h:60
SWITCH_ON_DISABLE_VAL
@ SWITCH_ON_DISABLE_VAL
Definition: tmc_coe_interpreter.h:67
uint8_t
unsigned char uint8_t
int8_t
signed char int8_t
TmcCoeInterpreter::b_cycle_finished_
bool b_cycle_finished_
Definition: tmc_coe_interpreter.h:172
FAULT_REACTION_ACTIVE
@ FAULT_REACTION_ACTIVE
Definition: tmc_coe_interpreter.h:58
TmcCoeInterpreter::input_pdo_
std::vector< input_pdo_t * > input_pdo_
Definition: tmc_coe_interpreter.h:200
TmcCoeInterpreter::initInterface
uint8_t initInterface(std::string ifname)
Definition: tmc_coe_interpreter.cpp:61
TmcCoeInterpreter::b_interface_unresponsive_
bool b_interface_unresponsive_
Definition: tmc_coe_interpreter.h:175
SPA_BIT
@ SPA_BIT
Definition: tmc_coe_interpreter.h:97
TmcCoeInterpreter::error_check_thread_
boost::thread error_check_thread_
Definition: tmc_coe_interpreter.h:154
uint16_t
unsigned short uint16_t
SAFE_OP_ERROR
@ SAFE_OP_ERROR
Definition: tmc_coe_interpreter.h:23
TOTAL_WORK_COUNTER_PER_SLAVE
const uint8_t TOTAL_WORK_COUNTER_PER_SLAVE
Definition: tmc_coe_interpreter.h:145
status_word_val_t
status_word_val_t
Definition: tmc_coe_interpreter.h:64
statusword_pos_t
statusword_pos_t
Definition: tmc_coe_interpreter.h:88
ros.h
FAULT_RESET
@ FAULT_RESET
Definition: tmc_coe_interpreter.h:33
TmcCoeInterpreter::all_obj_name_
std::vector< std::vector< std::string > > all_obj_name_
Definition: tmc_coe_interpreter.h:163
TmcCoeInterpreter::readSDO
std::string readSDO(uint8_t slave_number, uint16_t index_number, uint16_t subindex_number, T value)
Definition: tmc_coe_interpreter.cpp:860
IOMAP_SIZE
const uint32_t IOMAP_SIZE
Definition: tmc_coe_interpreter.h:139
TmcCoeInterpreter::SDO_PDO_retries_
uint8_t SDO_PDO_retries_
Definition: tmc_coe_interpreter.h:168
ENABLE_OPERATION
@ ENABLE_OPERATION
Definition: tmc_coe_interpreter.h:32
QUICK_STOP_ACTIVE_VAL
@ QUICK_STOP_ACTIVE_VAL
Definition: tmc_coe_interpreter.h:71
nmt_state_t
nmt_state_t
Definition: tmc_coe_interpreter.h:17
osal.h
PROCESS_DATA_DELAY
const uint16_t PROCESS_DATA_DELAY
Definition: tmc_coe_interpreter.h:143
QUICK_STOP_ACTIVE
@ QUICK_STOP_ACTIVE
Definition: tmc_coe_interpreter.h:57
status_state_mask_
std::vector< int > status_state_mask_
Definition: tmc_coe_interpreter.h:101
FAULT_REACTION_ACTIVE_VAL
@ FAULT_REACTION_ACTIVE_VAL
Definition: tmc_coe_interpreter.h:72
SET_POINT_ACK_IN_PROCESS_VAL
@ SET_POINT_ACK_IN_PROCESS_VAL
Definition: tmc_coe_interpreter.h:74
TmcCoeInterpreter::statusWordState
bool statusWordState(uint8_t slave_number, fsa_state_t state)
Definition: tmc_coe_interpreter.cpp:355
TmcCoeInterpreter::errorCheck
void errorCheck()
Definition: tmc_coe_interpreter.cpp:754
int16_t
signed short int16_t
TmcCoeInterpreter::all_datatype_
std::vector< std::vector< std::string > > all_datatype_
Definition: tmc_coe_interpreter.h:166
SWITCHED_ON_VAL
@ SWITCHED_ON_VAL
Definition: tmc_coe_interpreter.h:69
CONTROL_WORD_FAIL
const int8_t CONTROL_WORD_FAIL
Definition: tmc_coe_interpreter.h:140
DEBUG_PERIOD
const uint8_t DEBUG_PERIOD
Definition: tmc_coe_interpreter.h:146
input_pdo_t
struct PACKED input_pdo_t
OPERATION_ENABLED
@ OPERATION_ENABLED
Definition: tmc_coe_interpreter.h:56
TmcCoeInterpreter::processData
void processData()
Definition: tmc_coe_interpreter.cpp:727
PACKED
Definition: tmc_coe_interpreter.h:116
QS_BIT
@ QS_BIT
Definition: tmc_coe_interpreter.h:95
uint32_t
unsigned int uint32_t
TmcCoeInterpreter::slave_
std::vector< int > slave_
Definition: tmc_coe_interpreter.h:162
READY_TO_SWITCH_ON_VAL
@ READY_TO_SWITCH_ON_VAL
Definition: tmc_coe_interpreter.h:68
SAFE_OP_ERROR_ACK
@ SAFE_OP_ERROR_ACK
Definition: tmc_coe_interpreter.h:24
SOD_BIT
@ SOD_BIT
Definition: tmc_coe_interpreter.h:96
CONTROL_WORD_TIMEOUT
const int8_t CONTROL_WORD_TIMEOUT
Definition: tmc_coe_interpreter.h:142
NOT_READY_TO_SWITCH_ON_VAL
@ NOT_READY_TO_SWITCH_ON_VAL
Definition: tmc_coe_interpreter.h:66
OPERATIONAL
@ OPERATIONAL
Definition: tmc_coe_interpreter.h:22
SO_BIT
@ SO_BIT
Definition: tmc_coe_interpreter.h:91
TmcCoeInterpreter::getSlaveName
std::string getSlaveName(uint8_t slave_number)
Definition: tmc_coe_interpreter.cpp:658
FAULT
@ FAULT
Definition: tmc_coe_interpreter.h:59
TmcCoeInterpreter::isCycleFinished
bool isCycleFinished()
Definition: tmc_coe_interpreter.cpp:679
output_pdo_t
struct PACKED output_pdo_t
SWITCH_ON
@ SWITCH_ON
Definition: tmc_coe_interpreter.h:31
TmcCoeInterpreter::stopCycleCounter
void stopCycleCounter()
Definition: tmc_coe_interpreter.cpp:707
NOT_READY_TO_SWITCH_ON
@ NOT_READY_TO_SWITCH_ON
Definition: tmc_coe_interpreter.h:52
state_coding_val_
std::vector< int > state_coding_val_
Definition: tmc_coe_interpreter.h:77
TmcCoeInterpreter::~TmcCoeInterpreter
~TmcCoeInterpreter()
Definition: tmc_coe_interpreter.cpp:31
TmcCoeInterpreter::OPstate
bool OPstate()
Definition: tmc_coe_interpreter.cpp:145
TmcCoeInterpreter::nmt_state_
nmt_state_t nmt_state_
Definition: tmc_coe_interpreter.h:202
SWITCHED_ON
@ SWITCHED_ON
Definition: tmc_coe_interpreter.h:55
SAFE_OP
@ SAFE_OP
Definition: tmc_coe_interpreter.h:21
TmcCoeInterpreter::work_count_
int work_count_
Definition: tmc_coe_interpreter.h:170
ERROR_CHECK_DELAY
const uint16_t ERROR_CHECK_DELAY
Definition: tmc_coe_interpreter.h:144
TmcCoeInterpreter::interface_timeout_
double interface_timeout_
Definition: tmc_coe_interpreter.h:169
control_word_state_t
control_word_state_t
Definition: tmc_coe_interpreter.h:28
TmcCoeInterpreter::getCycleCounter
uint8_t getCycleCounter()
Definition: tmc_coe_interpreter.cpp:689
TmcCoeInterpreter::b_start_cycle_count_
bool b_start_cycle_count_
Definition: tmc_coe_interpreter.h:173
TmcCoeInterpreter::cycle_counter_
uint8_t cycle_counter_
Definition: tmc_coe_interpreter.h:174
TmcCoeInterpreter::commandCodingTransition
bool commandCodingTransition(uint8_t slave_number)
Definition: tmc_coe_interpreter.cpp:198
TmcCoeInterpreter::b_exit_threads_
bool b_exit_threads_
Definition: tmc_coe_interpreter.h:171
int32_t
signed int int32_t
TmcCoeInterpreter::paramTransfer
void paramTransfer(std::vector< std::vector< std::string >> all_obj_name, std::vector< std::vector< std::string >> all_index, std::vector< std::vector< std::string >> all_sub_index, std::vector< std::vector< std::string >> all_datatype)
Definition: tmc_coe_interpreter.cpp:44
TmcCoeInterpreter::all_index_
std::vector< std::vector< std::string > > all_index_
Definition: tmc_coe_interpreter.h:164
TmcCoeInterpreter
Definition: tmc_coe_interpreter.h:148
TmcCoeInterpreter::output_pdo_
std::vector< output_pdo_t * > output_pdo_
Definition: tmc_coe_interpreter.h:201
TmcCoeInterpreter::startCycleCounter
void startCycleCounter()
Definition: tmc_coe_interpreter.cpp:698
SHUTDOWN
@ SHUTDOWN
Definition: tmc_coe_interpreter.h:30
TmcCoeInterpreter::TmcCoeInterpreter
TmcCoeInterpreter(uint8_t SDO_PDO_retries, double interface_timeout)
Definition: tmc_coe_interpreter.cpp:12
TmcCoeInterpreter::isInterfaceUnresponsive
bool isInterfaceUnresponsive()
Definition: tmc_coe_interpreter.cpp:718
OE_BIT
@ OE_BIT
Definition: tmc_coe_interpreter.h:92
INIT
@ INIT
Definition: tmc_coe_interpreter.h:19
OPERATION_ENABLED_VAL
@ OPERATION_ENABLED_VAL
Definition: tmc_coe_interpreter.h:70
TmcCoeInterpreter::IOmap
char IOmap[IOMAP_SIZE]
Definition: tmc_coe_interpreter.h:161
TmcCoeInterpreter::stopInterface
void stopInterface()
Definition: tmc_coe_interpreter.cpp:253
READY_TO_SWITCH_ON
@ READY_TO_SWITCH_ON
Definition: tmc_coe_interpreter.h:54
FAULT_VAL
@ FAULT_VAL
Definition: tmc_coe_interpreter.h:73
CONTROL_WORD_SUCCESS
const int8_t CONTROL_WORD_SUCCESS
Definition: tmc_coe_interpreter.h:141
TmcCoeInterpreter::setControlWord
int8_t setControlWord(uint8_t slave_number, fsa_state_t response_SW, control_word_state_t requested_CW)
Definition: tmc_coe_interpreter.cpp:289
F_BIT
@ F_BIT
Definition: tmc_coe_interpreter.h:93
fsa_state_t
fsa_state_t
Definition: tmc_coe_interpreter.h:50
VE_BIT
@ VE_BIT
Definition: tmc_coe_interpreter.h:94
TmcCoeInterpreter::safeOPstate
bool safeOPstate(std::vector< int > en_slave)
Definition: tmc_coe_interpreter.cpp:90
TmcCoeInterpreter::all_sub_index_
std::vector< std::vector< std::string > > all_sub_index_
Definition: tmc_coe_interpreter.h:165
TmcCoeInterpreter::writeSDO
std::string writeSDO(uint8_t slave_number, uint16_t index_number, uint16_t subindex_number, T value)
Definition: tmc_coe_interpreter.cpp:899
TmcCoeInterpreter::processdata_thread_
boost::thread processdata_thread_
Definition: tmc_coe_interpreter.h:152
TmcCoeInterpreter::deviceStateChange
uint8_t deviceStateChange(uint8_t slave_number, nmt_state_t state)
Definition: tmc_coe_interpreter.cpp:379
SWITCH_ON_DISABLE
@ SWITCH_ON_DISABLE
Definition: tmc_coe_interpreter.h:53
PRE_OP
@ PRE_OP
Definition: tmc_coe_interpreter.h:20
RTSO_BIT
@ RTSO_BIT
Definition: tmc_coe_interpreter.h:90


adi_tmc_coe
Author(s):
autogenerated on Sun Feb 2 2025 03:07:24