35 #include <robot/config.h> 36 #include <robot/robot.h> 37 #include <robot/hand_protocol.h> 38 #include <robot/hand.h> 41 #define LAST_HAND_JOINT NUM_FINGER_JOINTS 43 #define LAST_HAND_JOINT START_OF_ARM 94 std::string name = hand_joints[i].joint_name;
99 ROS_DEBUG(
"NAME[%d]: %s ", i, name.c_str());
146 JointsMap::iterator iter =
joints_map.find(joint_name);
154 if (target < hand_joints[index_hand_joints].min_angle)
156 target = hand_joints[index_hand_joints].min_angle;
158 if (target > hand_joints[index_hand_joints].max_angle)
160 target = hand_joints[index_hand_joints].max_angle;
164 robot_update_sensor(&hand_joints[index_hand_joints].joint_target, target);
169 ROS_DEBUG(
"Joint %s not found", joint_name.c_str());
179 JointsMap::iterator iter =
joints_map.find(joint_name);
184 ROS_ERROR(
"Joint %s not found.", joint_name.c_str());
188 noData.temperature = 0.0;
189 noData.current = 0.0;
192 noData.jointIndex = 0;
202 tmpData.
position = robot_read_sensor(&hand_joints[index].position);
203 tmpData.
target = robot_read_sensor(&hand_joints[index].joint_target);
206 if (hand_joints[index].a.smartmotor.has_sensors)
208 tmpData.
temperature = robot_read_sensor(&hand_joints[index].a.smartmotor.temperature);
209 tmpData.
current = robot_read_sensor(&hand_joints[index].a.smartmotor.current);
210 tmpData.
force = robot_read_sensor(&hand_joints[index].a.smartmotor.torque);
232 std::string fingername(
"FF");
234 JointsMap::iterator it_j0 =
joints_map.find(fingername +
"J0");
235 JointsMap::iterator it_j1 =
joints_map.find(fingername +
"J1");
236 JointsMap::iterator it_j2 =
joints_map.find(fingername +
"J2");
237 it_j1->second.target = it_j0->second.target / 2.0;
238 it_j2->second.target = it_j0->second.target / 2.0;
240 fingername.assign(
"MF");
244 it_j1->second.target = it_j0->second.target / 2.0;
245 it_j2->second.target = it_j0->second.target / 2.0;
247 fingername.assign(
"RF");
251 it_j1->second.target = it_j0->second.target / 2.0;
252 it_j2->second.target = it_j0->second.target / 2.0;
254 fingername.assign(
"LF");
258 it_j1->second.target = it_j0->second.target / 2.0;
259 it_j2->second.target = it_j0->second.target / 2.0;
273 struct controller_config myConfig;
274 memset(&myConfig, 0,
sizeof(myConfig));
277 myConfig.nodename = contrlr_name.c_str();
279 controller_read_from_hardware(&myConfig);
280 ROS_DEBUG(
"%s", controller_to_string(&myConfig));
282 for (
unsigned int i = 0; i < ctrlr_data.
data.size(); ++i)
284 std::string name = ctrlr_data.
data[i].name;
290 ROS_ERROR(
"Parameter %s not found.", name.c_str());
295 controller_update_param(&myConfig, (controller_param) iter->second, ctrlr_data.
data[i].value.c_str());
300 int result_ctrlr = controller_write_to_hardware(&myConfig);
303 ROS_ERROR(
"Failed to update contrlr (%s)", myConfig.nodename);
312 struct controller_config myConfig;
313 memset(&myConfig, 0,
sizeof(myConfig));
316 myConfig.nodename = contrlr_name.c_str();
318 controller_read_from_hardware(&myConfig);
322 ROS_WARN(
"The get contrlr function is not implemented in the real shadowhand.");
329 ROS_WARN(
"The set config function is not implemented in the real shadowhand.");
348 ROS_WARN(
"The get config function is not yet implement in the real shadow hand.");
356 std::vector <DiagnosticData> returnVector;
359 std::stringstream ss;
362 for (
unsigned int index = 0; index < START_OF_ARM; ++index)
364 tmpData.
joint_name = std::string(hand_joints[index].joint_name);
367 tmpData.
position = robot_read_sensor(&hand_joints[index].position);
368 tmpData.
target = robot_read_sensor(&hand_joints[index].joint_target);
371 if (hand_joints[index].a.smartmotor.has_sensors)
375 if (*(&hand_joints[index].a.smartmotor.debug_nodename) != NULL)
377 std::string debug_node_name = *(&hand_joints[index].a.smartmotor.debug_nodename);
380 std::map<const std::string, const unsigned int>::const_iterator iter;
384 struct sensor sensor_tmp;
386 res = robot_channel_to_sensor(debug_node_name.c_str(), iter->second, &sensor_tmp);
387 tmpData.
debug_values[iter->first] = robot_read_incoming(&sensor_tmp);
393 tmpData.
temperature = robot_read_sensor(&hand_joints[index].a.smartmotor.temperature);
394 tmpData.
current = robot_read_sensor(&hand_joints[index].a.smartmotor.current);
395 tmpData.
force = robot_read_sensor(&hand_joints[index].a.smartmotor.torque);
399 struct hand_protocol_flags fl;
400 uint64_t uuid = robot_node_id(hand_joints[index].a.smartmotor.nodename);
401 fl = hand_protocol_get_status_flags(uuid);
405 struct hand_protocol_flags_smart_motor f;
406 f = fl.u.smart_motor;
408 bool at_least_one_error_flag =
false;
411 at_least_one_error_flag =
true;
413 ROS_WARN(
"[%s]: NFAULT", hand_joints[index].joint_name);
415 if (f.temperature_cutout)
417 at_least_one_error_flag =
true;
420 if (f.current_throttle)
422 at_least_one_error_flag =
true;
425 if (f.force_hard_limit)
427 at_least_one_error_flag =
true;
430 if (hand_protocol_dead(uuid))
432 at_least_one_error_flag =
true;
437 if (at_least_one_error_flag)
439 ROS_WARN(
"[%s]: %s", hand_joints[index].joint_name, (ss.str()).c_str());
443 tmpData.
flags = ss.str();
447 returnVector.push_back(tmpData);
457 ROS_INFO(
"Preparing the environment to run self tests.");
468 status.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Pretest completed successfully.");
473 ROS_INFO(
"Restoring the environment after the self tests.");
482 status.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Postest completed successfully.");
487 ROS_WARN(
"Starting the test: Number of messages Received");
489 std::pair<unsigned char, std::string> test_result;
490 test_result.first = diagnostic_msgs::DiagnosticStatus::OK;
497 std::pair<unsigned char, std::string> tmp_test_result;
501 if (tmp_test_result.first == diagnostic_msgs::DiagnosticStatus::ERROR)
503 test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
506 std::stringstream ss;
508 ss << tmp_test_result.second;
510 test_result.second += ss.str();
513 status.
summary(test_result.first, test_result.second);
519 std::pair<unsigned char, std::string> test_result;
522 std::string ID =
"1";
525 unsigned int nb_msgs_sent = 0;
526 unsigned int nb_msgs_received = 0;
529 JointsMap::iterator iter_joints_map =
joints_map.find(joint_name);
531 struct sensor sensor_msgs_received;
535 std::stringstream ss;
536 ss <<
"No messages sent: couldn't find joint " << joint_name;
538 test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
539 test_result.second = ss.str();
546 float target = hand_joints[index_hand_joints].min_angle;
549 if (!hand_joints[index_hand_joints].a.smartmotor.has_sensors)
551 std::stringstream ss;
552 ss <<
"No messages sent: joint[" << joint_name <<
"] doesn't have any motor attached";
554 test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
555 test_result.second = ss.str();
559 ROS_DEBUG(
"Checking the current number of received messages");
562 std::string debug_node_name = *(&hand_joints[index_hand_joints].a.smartmotor.debug_nodename);
563 std::map<const std::string, const unsigned int>::const_iterator
566 res = robot_channel_to_sensor(debug_node_name.c_str(), iter_debug_values->second, &sensor_msgs_received);
569 nb_msgs_received = robot_read_incoming(&sensor_msgs_received) - nb_msgs_received;
574 if (nb_msgs_received != robot_read_incoming(&sensor_msgs_received))
576 std::stringstream ss;
577 ss <<
"New messages were received on the joint[" << joint_name.c_str() <<
"].";
578 test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
579 test_result.second = ss.str();
587 for (; nb_msgs_sent < repeat; ++nb_msgs_sent)
590 robot_update_sensor(&hand_joints[index_hand_joints].joint_target, target);
599 ROS_DEBUG(
"Reading the number of received messages.");
601 nb_msgs_received = robot_read_incoming(&sensor_msgs_received) - nb_msgs_received;
603 if (nb_msgs_sent == nb_msgs_received)
605 std::stringstream ss;
606 ss << nb_msgs_sent <<
" messages sent, all received";
607 test_result.first = diagnostic_msgs::DiagnosticStatus::OK;
608 test_result.second = ss.str();
613 std::stringstream ss;
614 ss << nb_msgs_sent <<
" messages sent, " << nb_msgs_received <<
" messages received";
615 test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
616 test_result.second = ss.str();
virtual int16_t setContrl(std::string contrlr_name, JointControllerData ctrlr_data)
void pretest(diagnostic_updater::DiagnosticStatusWrapper &status)
void summary(unsigned char lvl, const std::string s)
static const std::string joints_to_test[joints_to_test_size]
virtual void getConfig(std::string joint_name)
virtual JointsMap getAllJointsData()
virtual int16_t sendupdate(std::string joint_name, double target)
std::string flags
a string containing flags: FORCE, TEMPERATURE, ... indicating the different cutouts / warning sent by...
std::string joint_name
the name of the joint
static const unsigned int nb_targets_to_send
The number of targets to send during the test.
std::map< std::string, JointData > JointsMap
static const std::map< const std::string, const unsigned int > names_and_offsets
a map containing the names and offsets of the smart motor node
static const unsigned int msgs_frequency_size
the size of the msgs_frequency array
boost::mutex parameters_map_mutex
static const int msgs_frequency[msgs_frequency_size]
the rate at which we'll publish the data
virtual JointControllerData getContrl(std::string contrlr_name)
virtual std::vector< DiagnosticData > getDiagnostics()
std::map< std::string, int > debug_values
the debug values
JointsMap joints_map
A mapping between the joint names and the information regarding those joints.
virtual int16_t setConfig(std::vector< std::string > myConfig)
void posttest(diagnostic_updater::DiagnosticStatusWrapper &status)
#define ROS_DEBUG_STREAM(args)
void test_messages(diagnostic_updater::DiagnosticStatusWrapper &status)
ParametersMap parameters_map
A mapping between the parameter names and their values.
This is a parent class for the different types of Shadowhand we can have. It makes it possible to swa...
virtual ~RealShadowhand()
The real shadowhand is the ROS interface to Shadow Robot robotic hand.
double temperature
temperature value
boost::mutex joints_map_mutex
std::vector< Parameters > data
std::pair< unsigned char, std::string > test_messages_routine(std::string joint_name, unsigned int repeat, ros::Rate rate)
virtual JointData getJointData(std::string joint_name)
double current
current value
int16_t level
the level of alert: 0 = OK, 1 = WARNING, 2 = ERROR
boost::mutex controllers_map_mutex
double target
the actual value of the target
static const unsigned int joints_to_test_size
the size of the joints_to_test array
double position
the actual value of the position