13 SDO_PDO_retries_(SDO_PDO_retries),
14 interface_timeout_(interface_timeout),
45 std::vector<std::vector<std::string>> all_index,
46 std::vector<std::vector<std::string>> all_sub_index,
47 std::vector<std::vector<std::string>> all_datatype)
67 ROS_INFO_STREAM(
"[" << __func__ <<
"] Init on " << ifname <<
" succeeded");
110 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
111 " mapped. Set slave to SAFE_OP");
115 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" is on SAFE_OP state");
119 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
120 " does not reached SAFE_OP state");
130 ROS_INFO_STREAM(
"[" << __func__ <<
"] Creating Process Data thread...");
135 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Will not create Process Data thread.");
148 bool b_result =
true;
156 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Set slave" <<
static_cast<int>(slave_index) <<
" state to OP");
160 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" is on OP state");
170 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" does not reach OP state");
172 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" State=" <<
183 ROS_INFO_STREAM(
"[" << __func__ <<
"] Creating Error Check thread...");
188 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Will not create Error Check thread.");
200 bool b_result =
false;
201 bool b_timeout =
false;
210 while(!b_timeout && (0 < sequence_retries))
212 while(index < control_word_state.size())
214 CW_return_val =
setControlWord(slave_number, status_word_state[index], control_word_state[index]);
237 if(!b_result && !b_timeout)
239 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
240 " StatusWord did not recover from FAULT state.");
244 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
245 " StatusWord state is on Operation Enabled");
294 double end_time = start_time;
304 <<
" is on FAULT, resetting...");
309 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
310 " did not respond while changing Control Word. Timeout!");
326 <<
" Controlword to " << requested_CW);
327 output_pdo_[slave_number]->control_word = requested_CW;
331 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
332 " did not respond while changing CW. Timeout!");
342 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
343 " ControlWord succesfully set to " << requested_CW);
357 bool b_result =
true;
363 statusword =
input_pdo_[slave_number]->status_word;
394 ROS_INFO_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
396 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" is on INIT");
400 ROS_ERROR_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
410 ROS_INFO_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
412 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" is on PRE_OP");
416 ROS_ERROR_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
426 ROS_INFO_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
428 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" is on SAFE_OP");
432 ROS_ERROR_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
442 ROS_INFO_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
444 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" is on OPERATIONAL");
448 ROS_ERROR_STREAM(
"[" << __func__ <<
"] State Change for Slave" <<
static_cast<int>(slave_number) <<
456 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" Error is Acknowledged");
483 std::string index_str =
"";
485 std::string sub_index_str =
"";
490 const int val_int = 0;
492 bool b_result =
false;
494 ROS_DEBUG_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"][High-Level] called");
498 while(!b_result && (column <=
all_obj_name_[slave_number].size()))
512 index_int = std::stoi(index_str,
nullptr, 16);
514 sub_index_int = std::stoi(sub_index_str,
nullptr, 16);
519 *value = readSDO<uint32_t>(slave_number, index_int, sub_index_int, val_uint_max);
525 *value = readSDO<uint8_t>(slave_number, index_int, sub_index_int,
static_cast<uint8_t>(val_int));
529 *value = readSDO<uint16_t>(slave_number, index_int, sub_index_int,
static_cast<uint16_t>(val_int));
533 *value = readSDO<int8_t>(slave_number, index_int, sub_index_int,
static_cast<int8_t>(val_int));
537 *value = readSDO<int16_t>(slave_number, index_int, sub_index_int,
static_cast<int16_t>(val_int));
541 *value = readSDO<int32_t>(slave_number, index_int, sub_index_int, val_int);
547 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Object Name: " << object_name <<
" not found");
552 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave Number: " <<
static_cast<int>(slave_number) <<
" not found");
571 std::string index_str =
"";
573 std::string sub_index_str =
"";
580 bool b_result =
false;
582 ROS_DEBUG_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"][High-Level] called");
586 while(!b_result && (column <=
all_obj_name_[slave_number].size()))
600 index_int = std::stoi(index_str,
nullptr, 16);
602 sub_index_int = std::stoi(sub_index_str,
nullptr, 16);
607 val_uint_max = std::stoull(*value);
608 *value = writeSDO<uint32_t>(slave_number, index_int, sub_index_int, val_uint_max);
612 val_int = std::stoi(*value);
616 *value = writeSDO<uint8_t>(slave_number, index_int, sub_index_int,
static_cast<uint8_t>(val_int));
620 *value = writeSDO<uint16_t>(slave_number, index_int, sub_index_int,
static_cast<uint16_t>(val_int));
624 *value = writeSDO<int8_t>(slave_number, index_int, sub_index_int,
static_cast<int8_t>(val_int));
628 *value = writeSDO<int16_t>(slave_number, index_int, sub_index_int,
static_cast<int16_t>(val_int));
632 *value = writeSDO<int32_t>(slave_number, index_int, sub_index_int, val_int);
638 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Object Name: " << object_name <<
" not found");
643 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave Number: " <<
static_cast<int>(slave_number) <<
" not found");
660 std::string slave_name =
"";
670 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_number) <<
" is not enabled");
729 ROS_INFO_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"] Process Data Thread running");
756 bool b_error_cleared =
false;
759 double start_time = 0;
762 ROS_INFO_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"] Error Check Thread running");
767 end_time = start_time;
778 b_error_cleared =
true;
782 b_error_cleared =
false;
791 b_error_cleared =
true;
797 ROS_WARN_STREAM(
"[" << __func__ <<
"] Command Coding Transition fail, changing state back to SAFE OP");
802 ROS_DEBUG_STREAM(
"[" << __func__ <<
"] Command Coding Transition success!");
809 ROS_ERROR_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
810 " is lost, trying to recover...");
813 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" recovered");
818 ROS_ERROR_STREAM(
"[" << __func__ <<
"]Slave" <<
static_cast<int>(slave_index) <<
819 " is on SAFE_OP state with ERROR : " <<
832 ROS_INFO_STREAM(
"[" << __func__ <<
"] Slave" <<
static_cast<int>(slave_index) <<
" reconfigured!");
859 template <
typename T>
862 int val_size =
sizeof(value);
863 std::string result_value =
"";
864 bool b_result =
false;
867 ROS_DEBUG_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"][Low-Level] called");
869 while(0 < n_retries_)
874 result_value = std::to_string(value);
878 ROS_WARN_STREAM(
"[" << __func__ <<
"] SDO Read [" <<
static_cast<int>(n_retries_) <<
"] Retry");
898 template <
typename T>
901 std::string result_value =
"";
902 bool b_result =
false;
905 ROS_DEBUG_STREAM(
"[TmcCoeInterpreter::" << __func__ <<
"][Low-Level] called");
907 while(0 < n_retries_)
912 result_value = std::to_string(value);
916 ROS_WARN_STREAM(
"[" << __func__ <<
"] SDO Write [" <<
static_cast<int>(n_retries_) <<
"] Retry");
930 template std::string TmcCoeInterpreter::readSDO<uint8_t>(
uint8_t slave_number,
uint16_t index_number,
932 template std::string TmcCoeInterpreter::readSDO<uint16_t>(
uint8_t slave_number,
uint16_t index_number,
934 template std::string TmcCoeInterpreter::readSDO<uint32_t>(
uint8_t slave_number,
uint16_t index_number,
936 template std::string TmcCoeInterpreter::readSDO<int8_t>(
uint8_t slave_number,
uint16_t index_number,
938 template std::string TmcCoeInterpreter::readSDO<int16_t>(
uint8_t slave_number,
uint16_t index_number,
940 template std::string TmcCoeInterpreter::readSDO<int32_t>(
uint8_t slave_number,
uint16_t index_number,
943 template std::string TmcCoeInterpreter::writeSDO<uint8_t>(
uint8_t slave_number,
uint16_t index_number,
945 template std::string TmcCoeInterpreter::writeSDO<uint16_t>(
uint8_t slave_number,
uint16_t index_number,
947 template std::string TmcCoeInterpreter::writeSDO<uint32_t>(
uint8_t slave_number,
uint16_t index_number,
949 template std::string TmcCoeInterpreter::writeSDO<int8_t>(
uint8_t slave_number,
uint16_t index_number,
951 template std::string TmcCoeInterpreter::writeSDO<int16_t>(
uint8_t slave_number,
uint16_t index_number,
953 template std::string TmcCoeInterpreter::writeSDO<int32_t>(
uint8_t slave_number,
uint16_t index_number,