14 p_tmc_coe_interpreter_(nullptr)
25 for(slave_index = 0; slave_index <
p_motor_.size(); slave_index++)
27 for(motor_index = 0; motor_index <
p_motor_[slave_index].size(); motor_index++)
29 delete p_motor_[slave_index][motor_index];
30 p_motor_[slave_index][motor_index] =
nullptr;
31 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Deleting Slave" <<
static_cast<int>(slave_index) <<
" motor" <<
32 static_cast<int>(motor_index));
38 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Deleting Interpreter and NodeHandle");
135 bool b_result =
true;
140 const std::string s_interface_name =
s_node_name_ +
"/interface_name";
143 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Failed to get interface_name. Exiting!");
148 const std::string s_SDO_PDO_retries =
s_node_name_ +
"/SDO_PDO_retries";
153 ROS_WARN_STREAM(
"[" << __func__ <<
"] Failed to get SDO_PDO_retries, Setting to default value: " <<
158 if(param_SDO_PDO_retries_ < SDO_PDO_RETRIES_MIN || param_SDO_PDO_retries_ >
SDO_PDO_RETRIES_MAX)
162 ROS_WARN_STREAM(
"[" << __func__ <<
"] Set value to SDO_PDO_retries is out of range, "
168 const std::string s_interface_timeout =
s_node_name_ +
"/interface_timeout";
173 ROS_WARN_STREAM(
"[" << __func__ <<
"] Failed to get interface_timeout, Setting to default value: " <<
178 if(param_interface_timeout_ < TIMEOUT_MIN || param_interface_timeout_ >
TIMEOUT_MAX)
182 ROS_WARN_STREAM(
"[" << __func__ <<
"] Set value to interface_timeout is out of range, "
191 std::vector<std::string> param_obj_name;
192 std::vector<std::string> param_index;
193 std::vector<std::string> param_sub_index;
194 std::vector<std::string> param_datatype;
195 std::vector<std::vector<std::string>> all_obj_name;
196 std::vector<std::vector<std::string>> all_index;
197 std::vector<std::vector<std::string>> all_sub_index;
198 std::vector<std::vector<std::string>> all_datatype;
200 bool b_result =
true;
205 all_obj_name.push_back(std::vector<std::string>());
206 all_index.push_back(std::vector<std::string>());
207 all_sub_index.push_back(std::vector<std::string>());
208 all_datatype.push_back(std::vector<std::string>());
219 "Check autogenerated YAML if broken or missing. Exiting!");
226 "Check autogenerated YAML if broken or missing. Exiting!");
230 if(b_result && !
p_nh_->
getParam(s_sub_index, param_sub_index))
233 "Check autogenerated YAML if broken or missing. Exiting!");
240 "Check autogenerated YAML if broken or missing. Exiting!");
245 if(b_result && (param_obj_name.size() != param_index.size()) &&
246 (param_index.size() != param_sub_index.size()) && (param_sub_index.size() != param_datatype.size()))
248 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Vector size mismatch between obj_name, index, sub_index and datatype."
249 "Check autogenerated YAML. Exiting!");
254 all_obj_name.push_back(param_obj_name);
255 all_index.push_back(param_index);
256 all_sub_index.push_back(param_sub_index);
257 all_datatype.push_back(param_datatype);
281 for(slave_index = 1; slave_index <=
total_slaves_; slave_index ++)
289 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" name: " <<
302 slave_index, motor_index);
303 p_motor_[slave_index][motor_index]->init();
314 slave_index, motor_index);
315 p_motor_[slave_index][motor_index]->init();
324 slave_index, motor_index);
325 p_motor_[slave_index][motor_index]->init();
330 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Invalid Motor Type. Will not create Motor Class on slave"
331 <<
static_cast<int>(slave_index));
337 ROS_INFO_STREAM(
"[" << __func__ <<
"] No enabled motor in Slave" <<
static_cast<int>(slave_index) <<
"\n");
344 std::vector<int> local_vector;
351 const std::string s_param_name =
s_node_name_ + param_name;
354 for(index = 0; index < max_val; index++)
356 local_vector.push_back(0);
359 ROS_WARN_STREAM(
"[" << __func__ <<
"] Failed to get " << param_name <<
", setting to default value: 0");
364 if((local_vector.size()) < max_val)
366 for(index = local_vector.size(); index < max_val; index++)
368 local_vector.push_back(0);
370 ROS_WARN_STREAM(
"[" << __func__ <<
"] Missing indeces for " << param_name <<
371 ", setting missing value to default: 0");
373 else if((local_vector.size()) > max_val)
375 local_vector.erase(local_vector.begin() + max_val, local_vector.end());
376 ROS_WARN_STREAM(
"[" << __func__ <<
"] Indeces exceeded total " << param_name <<
377 " available, deleting unused indeces");
380 for(index = 0; index < local_vector.size(); index++)
382 if(local_vector[index] != 0 && local_vector[index] != 1)
384 local_vector[index] = 0;
385 ROS_WARN_STREAM(
"[" << __func__ <<
"] Set value for " << param_name <<
static_cast<int>(index) <<
386 " is out of range, setting value to default:" << local_vector[index]);
388 if(local_vector[index] == 1)
393 param_var = std::move(local_vector);
397 return total_en_param_;
404 ROS_INFO_STREAM(
"[" << __func__ <<
"] Successfully de-initialized TMC-CoE.");
415 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Interface is Unresponsive! Exiting...");
431 std::string s_read_sdo_srvname =
s_namespace_ +
"/read_SDO";
432 std::string s_write_sdo_srvname =
s_namespace_ +
"/write_SDO";
433 std::string s_read_pdo_srvname =
s_namespace_ +
"/read_PDO";
434 std::string s_write_pdo_srvname =
s_namespace_ +
"/write_PDO";
435 std::string s_state_change_srvname =
s_namespace_ +
"/state_change";
436 std::string s_cyclic_sync_srvname =
s_namespace_ +
"/cyclic_sync_mode";
441 ROS_INFO_STREAM(
"[" << __func__ <<
"] read_sdo server advertised. Service name: " << s_read_sdo_srvname);
445 ROS_WARN_STREAM(
"[" << __func__ <<
"] read_sdo server failed to advertise.");
451 ROS_INFO_STREAM(
"[" << __func__ <<
"] write_sdo server advertised. Service name: " << s_write_sdo_srvname);
455 ROS_WARN_STREAM(
"[" << __func__ <<
"] write_sdo server failed to advertise.");
461 ROS_INFO_STREAM(
"[" << __func__ <<
"] read_pdo server advertised. Service name: " << s_read_pdo_srvname);
465 ROS_WARN_STREAM(
"[" << __func__ <<
"] read_pdo server failed to advertise.");
471 ROS_INFO_STREAM(
"[" << __func__ <<
"] write_pdo server advertised. Service name: " << s_write_pdo_srvname);
475 ROS_WARN_STREAM(
"[" << __func__ <<
"] write_pdo server failed to advertise.");
481 ROS_INFO_STREAM(
"[" << __func__ <<
"] state_change server advertised. Service name: " << s_state_change_srvname);
485 ROS_WARN_STREAM(
"[" << __func__ <<
"] state_change server failed to advertise.");
491 ROS_INFO_STREAM(
"[" << __func__ <<
"] cyclic_sync server advertised. Service name: " <<
492 s_cyclic_sync_srvname <<
"\n");
496 ROS_WARN_STREAM(
"[" << __func__ <<
"] cyclic_sync server failed to advertise.\n");
504 adi_tmc_coe::read_write_SDO::Response& res)
506 bool b_result =
true;
507 std::string local_value =
"";
511 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
525 res.output = local_value;
526 res.result = b_result;
533 adi_tmc_coe::read_write_SDO::Response& res)
535 bool b_result =
true;
536 std::string local_value = req.value;
540 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
554 res.output = local_value;
555 res.result = b_result;
562 bool b_result =
true;
568 std::transform(req.cmd.begin(), req.cmd.end(), req.cmd.begin(), ::toupper);
570 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
574 if(req.cmd ==
"MODES OF OPERATION")
591 ROS_ERROR_STREAM(
"[" << __func__ <<
"]Modes of Operation not set properly");
597 else if(req.cmd ==
"CONTROLWORD")
609 else if(req.cmd ==
"TARGET POSITION")
621 else if(req.cmd ==
"TARGET VELOCITY")
633 else if(req.cmd ==
"TARGET TORQUE")
658 res.actual_value = actual_value;
659 res.result = b_result;
666 bool b_result =
true;
672 std::transform(req.cmd.begin(), req.cmd.end(), req.cmd.begin(), ::toupper);
674 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
676 if(req.cmd ==
"MODES OF OPERATION DISPLAY")
680 else if(req.cmd ==
"STATUSWORD")
684 else if(req.cmd ==
"ACTUAL POSITION")
688 else if(req.cmd ==
"DEMAND POSITION")
692 else if(req.cmd ==
"ACTUAL VELOCITY")
696 else if(req.cmd ==
"DEMAND VELOCITY")
700 else if(req.cmd ==
"ACTUAL TORQUE")
704 else if(req.cmd ==
"DEMAND TORQUE")
720 res.actual_value = actual_value;
721 res.result = b_result;
728 bool b_result =
true;
731 std::string current_state_str =
"";
735 std::transform(req.request_state.begin(), req.request_state.end(), req.request_state.begin(), ::toupper);
737 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
739 if(req.request_state ==
"INIT")
743 else if(req.request_state ==
"PREOP")
747 else if(req.request_state ==
"SAFEOP")
751 else if(req.request_state ==
"OPERATIONAL")
774 ROS_ERROR_STREAM(
"[" << __func__ <<
"] State Change Failed. Current device state: " <<
775 static_cast<int>(current_state));
779 switch (current_state)
782 current_state_str =
"INIT";
785 current_state_str =
"PREOP";
788 current_state_str =
"SAFEOP";
791 current_state_str =
"OPERATIONAL";
798 res.current_state = current_state_str;
801 res.result = b_result;
808 bool b_result =
true;
811 double interpolation_time = req.interpolation_time_period * pow(10, req.interpolation_time_index);
812 std::string interpolation_time_period = std::to_string(req.interpolation_time_period);
813 std::string interpolation_time_index = std::to_string(req.interpolation_time_index);
817 std::transform(req.CS_cmd.begin(), req.CS_cmd.end(), req.CS_cmd.begin(), ::toupper);
825 if(req.slave_number <=
total_slaves_ && req.slave_number > 0)
827 if(req.interpolation_time_period >= 0 && req.interpolation_time_period <=
UINT8_MAX &&
834 &interpolation_time_period))
844 &interpolation_time_index))
856 "Interpolation Time Period - Interpolation time period value", &interpolation_time_period))
866 "Interpolation Time Period - Interpolation time index", &interpolation_time_index))
884 if(req.CS_cmd ==
"CSP")
901 ROS_ERROR_STREAM(
"[" << __func__ <<
"]Modes of Operation not set properly");
907 for(index = 0; index < req.value.size(); index++)
916 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Cyclic Synchronous Position Failed");
919 else if(req.CS_cmd ==
"CSV")
936 ROS_ERROR_STREAM(
"[" << __func__ <<
"]Modes of Operation not set properly");
942 for(index = 0; index < req.value.size(); index++)
951 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Cyclic Synchronous Velocity Failed");
954 else if(req.CS_cmd ==
"CST")
971 ROS_ERROR_STREAM(
"[" << __func__ <<
"]Modes of Operation not set properly");
977 for(index = 0; index < req.value.size(); index++)
1002 res.result = b_result;