25 #include <canopen_chain_node/GetObject.h> 26 #include <canopen_chain_node/SetObject.h> 28 #include <prbt_hardware_support/BrakeTest.h> 29 #include <prbt_hardware_support/BrakeTestErrorCodes.h> 66 canopen_chain_node::GetObject srv;
67 srv.request.node = node_name;
69 srv.request.cached =
false;
71 ROS_INFO_STREAM(
"Call \"brake test duration\" service for \"" << node_name <<
"\"");
75 BrakeTestErrorCodes::GET_DURATION_FAILURE);
78 if (!srv.response.success)
83 ROS_INFO_STREAM(
"Brake test duration for node \"" << node_name <<
"\" is: " << srv.response.value <<
"ms");
84 return ros::Duration(std::stoi(srv.response.value) / 1000, 0);
89 std::vector<ros::Duration> durations;
90 std::transform(node_names.begin(), node_names.end(), std::back_inserter(durations),
92 return *std::max_element(durations.begin(), durations.end());
97 canopen_chain_node::SetObject srv;
98 srv.request.node = node_name;
100 srv.request.value =
"1";
101 srv.request.cached =
false;
103 ROS_INFO_STREAM(
"Call \"trigger brake test\" service for \"" << node_name <<
"\"");
107 BrakeTestErrorCodes::START_BRAKE_TEST_FAILURE);
110 if (!srv.response.success)
119 canopen_chain_node::GetObject srv;
120 srv.request.node = node_name;
122 srv.request.cached =
false;
124 ROS_INFO_STREAM(
"Call \"get status brake test\" service for \"" << node_name <<
"\"");
128 BrakeTestErrorCodes::GET_STATUS_FAILURE);
131 if (!srv.response.success)
134 BrakeTestErrorCodes::GET_STATUS_FAILURE);
138 status.first =
static_cast<int8_t
>(srv.response.value.data()[0]);
139 status.second = srv.response.message;
146 if (status.first != BrakeTestErrorCodes::STATUS_SUCCESS)
148 ROS_ERROR(
"Brake test for %s failed (Status: %d)", node_name.c_str(), status.first);
161 std::vector<std::string> node_names;
162 for (
auto& rpci : rpc)
164 auto node_name = rpci.first.c_str();
173 node_names.push_back(node_name);
187 BrakeTestErrorCodes::GET_NODE_NAMES_FAILURE);
202 for (
const auto& node_name : node_names)
204 ROS_INFO_STREAM(
"Perform brake test for node \"" << node_name <<
"\"...");
207 max_duration.sleep();
209 std::for_each(node_names.begin(), node_names.end(),
215 response.success =
false;
217 response.error_msg = ex.what();
221 response.success =
true;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
static const std::string SET_START_BRAKETEST_OBJECT
void checkBrakeTestResultForNode(const std::string &node_name)
static const std::string NODE_BRAKETEST_ENABLED_PARAMETER
BrakeTestStatus getBrakeTestStatusForNode(const std::string &node_name)
static const std::string GET_BRAKETEST_STATUS_OBJECT
bool call(MReq &req, MRes &res)
const std::string & getMessage() const
ros::ServiceClient canopen_srv_set_client_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::Duration getMaximumBrakeTestDuration(const std::vector< std::string > &node_names)
ros::ServiceClient canopen_srv_get_client_
ros::ServiceServer brake_test_srv_
Service which triggers brake tests for all joints.
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
CANOpenBrakeTestAdapter(ros::NodeHandle &nh)
bool getParam(const std::string &key, std::string &s) const
bool triggerBrakeTests(BrakeTest::Request &req, BrakeTest::Response &response)
void triggerBrakeTestForNode(const std::string &node_name)
int8_t getErrorValue() const
static const std::string CANOPEN_NODES_PARAMETER_NAME
std::vector< std::string > getNodeNames()
#define ROS_INFO_STREAM(args)
ros::Duration getBrakeTestDuration(const std::string &node_name)
const std::string & getNamespace() const
static const std::string CANOPEN_GETOBJECT_SERVICE_NAME
Exception thrown by the CANOpenBrakeTestAdapter.
static const std::string CANOPEN_SETOBJECT_SERVICE_NAME
std::pair< int8_t, std::string > BrakeTestStatus
#define ROS_ERROR_STREAM(args)
static const std::string GET_BRAKETEST_DURATION_OBJECT
static constexpr double WAIT_FOR_SERVICE_TIMEOUT_S
static const std::string TRIGGER_BRAKETEST_SERVICE_NAME