254
short RealShadowhand::setConfig( std::vector<std::string> myConfig )
278
short RealShadowhand::setConfig( std::vector<std::string> myConfig )
256
280
ROS_WARN("The set config function is not implemented in the real shadowhand.");
259
hand_protocol_config_t cfg;
260
hand_protocol_get_config(cfg);
262
//set the transmit rate value
263
int value = msg->rate_value;
264
cfg->u.palm.tx_freq[num]=value;
266
//send the config to the palm.
267
hand_protocol_set_config(cfg);
283
hand_protocol_config_t cfg;
284
hand_protocol_get_config(cfg);
286
//set the transmit rate value
287
int value = msg->rate_value;
288
cfg->u.palm.tx_freq[num]=value;
290
//send the config to the palm.
291
hand_protocol_set_config(cfg);
273
void RealShadowhand::getConfig( std::string joint_name )
297
void RealShadowhand::getConfig( std::string joint_name )
275
299
ROS_WARN("The get config function is not yet implement in the real shadow hand.");
279
char* ShadowhandDiagnosticer::get_setpoint_name(uint16_t s_num)
281
// struct sensor temp;
282
static char name_buff[256];
284
snprintf(name_buff, 256, "%s.%d", "smart_motor_setpoints", s_num);
286
//TODO: get the sensor name
287
if (0==robot_channel_to_sensor("smart_motor_setpoints", s_num, &temp))
289
const char *name = robot_sensor_calibration_name(&temp);
295
std::vector<DiagnosticData> RealShadowhand::getDiagnostics()
302
std::vector<DiagnosticData> RealShadowhand::getDiagnostics()
304
//it's alright to do the tests when we're publishing the diagnostics
305
self_test->checkTest();
297
307
std::vector<DiagnosticData> returnVector;
299
309
DiagnosticData tmpData;
301
//concatenate the flags in a stringstream
302
310
std::stringstream ss;
304
312
//get the data from the hand
305
313
for( unsigned int index = 0; index < START_OF_ARM; ++index )
307
tmpData.joint_name = std::string(hand_joints[index].joint_name);
310
tmpData.position = robot_read_sensor(&hand_joints[index].position);
311
tmpData.target = robot_read_sensor(&hand_joints[index].joint_target);
314
if( hand_joints[index].a.smartmotor.has_sensors )
316
tmpData.temperature = robot_read_sensor(&hand_joints[index].a.smartmotor.temperature);
317
tmpData.current = robot_read_sensor(&hand_joints[index].a.smartmotor.current);
318
tmpData.force = robot_read_sensor(&hand_joints[index].a.smartmotor.torque);
320
//check for error_flags
321
uint64_t uuid = robot_node_id(hand_joints[index].a.smartmotor.nodename);
322
struct hand_protocol_flags fl;
323
fl = hand_protocol_get_status_flags(uuid);
326
struct hand_protocol_flags_smart_motor f;
327
f = fl.u.smart_motor;
329
//empty the stringstream
332
bool at_least_one_error_flag = false;
335
at_least_one_error_flag = true;
337
ROS_WARN( "[%s]: NFAULT", hand_joints[index].joint_name );
339
if( f.temperature_cutout )
341
at_least_one_error_flag = true;
344
if( f.current_throttle )
346
at_least_one_error_flag = true;
349
if( f.force_hard_limit )
351
at_least_one_error_flag = true;
354
if( hand_protocol_dead(uuid) )
356
at_least_one_error_flag = true;
360
//set the message flags
361
tmpData.flags = ss.str();
362
//if a flag is up, then print a warning as well
363
if( at_least_one_error_flag )
365
ROS_WARN( "[%s]: %s", hand_joints[index].joint_name, (ss.str()).c_str());
371
returnVector.push_back(tmpData);
315
tmpData.joint_name = std::string(hand_joints[index].joint_name);
318
tmpData.position = robot_read_sensor(&hand_joints[index].position);
319
tmpData.target = robot_read_sensor(&hand_joints[index].joint_target);
322
if( hand_joints[index].a.smartmotor.has_sensors )
324
//reads the number of received sensor msgs from the debug node.
326
if( *(&hand_joints[index].a.smartmotor.debug_nodename) != NULL)
328
std::string debug_node_name = *(&hand_joints[index].a.smartmotor.debug_nodename);
330
//get all the debug values
331
std::map<const std::string, const unsigned int>::const_iterator iter;
332
for(iter = debug_values::names_and_offsets.begin();
333
iter != debug_values::names_and_offsets.end(); ++iter)
335
struct sensor sensor_tmp;
337
res = robot_channel_to_sensor(debug_node_name.c_str(), iter->second, &sensor_tmp);
338
tmpData.debug_values[iter->first] = robot_read_incoming(&sensor_tmp);
342
// ROS_ERROR_STREAM(tmpData.joint_name << ": no debug sensor" );
343
//reads temperature current and force.
344
tmpData.temperature = robot_read_sensor(&hand_joints[index].a.smartmotor.temperature);
345
tmpData.current = robot_read_sensor(&hand_joints[index].a.smartmotor.current);
346
tmpData.force = robot_read_sensor(&hand_joints[index].a.smartmotor.torque);
348
//check for error_flags
350
struct hand_protocol_flags fl;
351
uint64_t uuid = robot_node_id(hand_joints[index].a.smartmotor.nodename);
352
fl = hand_protocol_get_status_flags(uuid);
356
struct hand_protocol_flags_smart_motor f;
357
f = fl.u.smart_motor;
359
bool at_least_one_error_flag = false;
362
at_least_one_error_flag = true;
364
ROS_WARN( "[%s]: NFAULT", hand_joints[index].joint_name );
366
if( f.temperature_cutout )
368
at_least_one_error_flag = true;
371
if( f.current_throttle )
373
at_least_one_error_flag = true;
376
if( f.force_hard_limit )
378
at_least_one_error_flag = true;
381
if( hand_protocol_dead(uuid) )
383
at_least_one_error_flag = true;
387
//if a flag is up, then print a warning as well
388
if( at_least_one_error_flag )
390
ROS_WARN( "[%s]: %s", hand_joints[index].joint_name, (ss.str()).c_str());
394
tmpData.flags = ss.str();
398
returnVector.push_back(tmpData);
374
400
return returnVector;
406
void RealShadowhand::pretest(diagnostic_updater::DiagnosticStatusWrapper& status)
408
ROS_INFO("Preparing the environment to run self tests.");
410
//lock all the mutexes to make sure we're not publishing other messages
411
joints_map_mutex.lock();
412
parameters_map_mutex.lock();
413
controllers_map_mutex.lock();
415
//TODO: set the palm transmit rate to max?
419
status.summary(diagnostic_msgs::DiagnosticStatus::OK, "Pretest completed successfully.");
422
void RealShadowhand::posttest(diagnostic_updater::DiagnosticStatusWrapper& status)
424
ROS_INFO("Restoring the environment after the self tests.");
426
//test finished, unlocking all the mutexes
427
joints_map_mutex.unlock();
428
parameters_map_mutex.unlock();
429
controllers_map_mutex.unlock();
431
//TODO: reset the palm transmit rate to previous state?
433
status.summary(diagnostic_msgs::DiagnosticStatus::OK, "Postest completed successfully.");
436
void RealShadowhand::test_messages(diagnostic_updater::DiagnosticStatusWrapper& status)
438
ROS_WARN("Starting the test: Number of messages Received");
440
std::pair<unsigned char, std::string> test_result;
441
test_result.first = diagnostic_msgs::DiagnosticStatus::OK;
443
for(unsigned int index_freq=0; index_freq < sr_self_tests::msgs_frequency_size; ++index_freq)
445
ros::Rate test_rate(sr_self_tests::msgs_frequency[index_freq]);
446
for(unsigned int index_joint=0; index_joint < sr_self_tests::joints_to_test_size; ++index_joint)
448
std::pair<unsigned char, std::string> tmp_test_result;
449
tmp_test_result = test_messages_routine(sr_self_tests::joints_to_test[index_joint], sr_self_tests::nb_targets_to_send, test_rate);
451
if( tmp_test_result.first == diagnostic_msgs::DiagnosticStatus::ERROR)
452
test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
454
std::stringstream ss;
455
ss << "\n[" << sr_self_tests::msgs_frequency[index_freq] << "Hz]: ";
456
ss << tmp_test_result.second;
458
test_result.second += ss.str();
461
status.summary(test_result.first, test_result.second);
464
std::pair<unsigned char, std::string> RealShadowhand::test_messages_routine(std::string joint_name, unsigned int repeat, ros::Rate rate)
466
std::pair<unsigned char, std::string> test_result;
468
//id should be motor board number
469
std::string ID = "1";
470
self_test->setID(ID.c_str());
472
unsigned int nb_msgs_sent = 0;
473
unsigned int nb_msgs_received = 0;
475
//sending lots of data to one joint
476
JointsMap::iterator iter_joints_map = joints_map.find(joint_name);
478
struct sensor sensor_msgs_received;
480
if( iter_joints_map == joints_map.end() )
482
std::stringstream ss;
483
ss << "No messages sent: couldn't find joint "<<joint_name;
485
test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
486
test_result.second = ss.str();
491
JointData tmpData = joints_map.find(joint_name)->second;
492
int index_hand_joints = tmpData.jointIndex;
493
float target = hand_joints[index_hand_joints].min_angle;
495
//testing a joint which doesn't have a smartmotor
496
if( !hand_joints[index_hand_joints].a.smartmotor.has_sensors )
498
std::stringstream ss;
499
ss << "No messages sent: joint["<<joint_name<<"] doesn't have any motor attached";
501
test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
502
test_result.second = ss.str();
506
ROS_DEBUG("Checking the current number of received messages");
509
std::string debug_node_name = *(&hand_joints[index_hand_joints].a.smartmotor.debug_nodename);
510
std::map<const std::string, const unsigned int>::const_iterator iter_debug_values = debug_values::names_and_offsets.find("Num sensor Msgs received");
512
res = robot_channel_to_sensor(debug_node_name.c_str(), iter_debug_values->second, &sensor_msgs_received);
514
//check the number of messages already received when starting the test
515
nb_msgs_received = robot_read_incoming(&sensor_msgs_received) - nb_msgs_received;
519
//check if no other messages have been received
520
if( nb_msgs_received != robot_read_incoming(&sensor_msgs_received))
522
std::stringstream ss;
523
ss << "New messages were received on the joint[" << joint_name.c_str() << "]." ;
524
test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
525
test_result.second = ss.str();
529
//ok still the same number of messages
531
ROS_DEBUG("Sending lots of messages.");
533
for(; nb_msgs_sent < repeat; ++nb_msgs_sent)
535
//send values to the sensor
536
robot_update_sensor(&hand_joints[index_hand_joints].joint_target, target);
538
ROS_DEBUG_STREAM("msg "<< nb_msgs_sent<< "/"<<sr_self_tests::nb_targets_to_send);
541
ROS_DEBUG("Done sending the messages.");
542
//wait for all the messages to be received?
545
ROS_DEBUG("Reading the number of received messages.");
546
//compute the number of messages received during the test
547
nb_msgs_received = robot_read_incoming(&sensor_msgs_received) - nb_msgs_received;
549
if( nb_msgs_sent == nb_msgs_received)
551
std::stringstream ss;
552
ss << nb_msgs_sent << " messages sent, all received";
553
test_result.first = diagnostic_msgs::DiagnosticStatus::OK;
554
test_result.second = ss.str();
559
std::stringstream ss;
560
ss << nb_msgs_sent << " messages sent, "<<nb_msgs_received << " messages received";
561
test_result.first = diagnostic_msgs::DiagnosticStatus::ERROR;
562
test_result.second = ss.str();
376
566
} //end namespace
568
/* For the emacs weenies in the crowd.