31 #include <boost/foreach.hpp> 40 #include <controller_manager_msgs/ListControllers.h> 43 #define SERIOUS_ERROR_FLAGS PALM_0200_EDC_SERIOUS_ERROR_FLAGS 44 #define error_flag_names palm_0200_edc_error_flag_names 50 using std::ostringstream;
51 using sr_actuator::SrMotorActuator;
66 using boost::ptr_vector;
71 #ifdef DEBUG_PUBLISHER 73 template<
class StatusType,
class CommandType>
74 const int SrRobotLib<StatusType, CommandType>::nb_debug_publishers_const = 20;
79 template <
class StatusType,
class CommandType>
82 template <
class StatusType,
class CommandType>
85 "TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ",
86 "TACTILE_SENSOR_TYPE_MANUFACTURER",
87 "TACTILE_SENSOR_TYPE_SERIAL_NUMBER",
88 "TACTILE_SENSOR_TYPE_SOFTWARE_VERSION",
89 "TACTILE_SENSOR_TYPE_PCB_VERSION",
90 "TACTILE_SENSOR_TYPE_WHICH_SENSORS",
91 "TACTILE_SENSOR_TYPE_PST3_PRESSURE_TEMPERATURE",
92 "TACTILE_SENSOR_TYPE_PST3_PRESSURE_RAW_ZERO_TRACKING",
93 "TACTILE_SENSOR_TYPE_PST3_DAC_VALUE",
94 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_1",
95 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_2",
96 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_3",
97 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_4",
98 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_5",
99 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_6",
100 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_7",
101 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_8",
102 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_9",
103 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_10",
104 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_11",
105 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_12",
106 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_13",
107 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_14",
108 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_15",
109 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_16",
110 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_17",
111 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_18",
112 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_19",
113 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_20",
114 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_21",
115 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_22",
116 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_23",
117 "TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_24",
118 "TACTILE_SENSOR_TYPE_BIOTAC_PDC",
119 "TACTILE_SENSOR_TYPE_BIOTAC_TAC",
120 "TACTILE_SENSOR_TYPE_BIOTAC_TDC",
121 "TACTILE_SENSOR_TYPE_UBI0_TACTILE" 124 template <
class StatusType,
class CommandType>
166 template<
class StatusType,
class CommandType>
169 template<
class StatusType,
class CommandType>
172 : main_pic_idle_time(0),
173 main_pic_idle_time_min(1000),
176 device_id_(device_id),
177 joint_prefix_(joint_prefix),
178 nullify_demand_(false),
184 nullify_demand_server_(
192 generic_sensor_update_rate_configs_vector(
193 read_update_rate_configs(
"generic_sensor_data_update_rate/", nb_sensor_data,
194 human_readable_sensor_data_types, sensor_data_types)),
197 pst3_sensor_update_rate_configs_vector(
198 read_update_rate_configs(
"pst3_sensor_data_update_rate/", nb_sensor_data,
199 human_readable_sensor_data_types, sensor_data_types)),
202 biotac_sensor_update_rate_configs_vector(
203 read_update_rate_configs(
"biotac_sensor_data_update_rate/", nb_sensor_data,
204 human_readable_sensor_data_types, sensor_data_types)),
207 ubi0_sensor_update_rate_configs_vector(
208 read_update_rate_configs(
"ubi0_sensor_data_update_rate/", nb_sensor_data,
209 human_readable_sensor_data_types, sensor_data_types)),
211 tactile_init_max_duration(tactile_timeout),
214 tactile_check_init_timeout_timer(
215 this->nh_tilde.createTimer(tactile_init_max_duration,
218 CommandType>::tactile_init_timer_callback,
223 generic_sensor_update_rate_configs_vector,
227 calibration_map(read_joint_calibration()),
229 coupled_calibration_map(read_coupled_joint_calibration())
231 std::vector<std::string> calibration_map_keys = calibration_map.keys();
232 for (
auto & coupled_calibration : coupled_calibration_map)
234 if (std::find(calibration_map_keys.begin(),
235 calibration_map_keys.end(), coupled_calibration.first)
236 != calibration_map_keys.end())
238 ROS_WARN_STREAM(
"Calibration for joint " << coupled_calibration.first <<
" present in both regular and " 239 "coupled form in the calibration file. Only coupled calibration will be used!");
244 template<
class StatusType,
class CommandType>
250 generic_sensor_update_rate_configs_vector,
255 template<
class StatusType,
class CommandType>
257 sr_robot_msgs::NullifyDemand::Response &response)
259 if (request.nullify_demand)
261 "Nullifying the demand sent to the motor. " 262 "Will ignore the values computed by the controllers and send 0.");
264 ROS_INFO_STREAM(
"Using the value computed by the controllers to send the demands to the motors.");
266 nullify_demand_ = request.nullify_demand;
270 template<
class StatusType,
class CommandType>
274 boost::mutex::scoped_lock l(*lock_tactile_init_timeout_);
278 if (tactiles_init->sensor_updater->build_init_command(command)
283 tactile_check_init_timeout_timer.stop();
285 switch (tactiles_init->tactiles_vector->at(0).which_sensor)
290 pst3_sensor_update_rate_configs_vector,
292 tactiles_init->tactiles_vector));
294 ROS_INFO(
"PST3 tactiles initialized");
300 biotac_sensor_update_rate_configs_vector,
302 tactiles_init->tactiles_vector));
304 ROS_INFO(
"Biotac tactiles initialized");
311 tactiles_init->tactiles_vector));
313 ROS_INFO(
"UBI0 tactiles initialized");
327 tactile_current_state =
tactiles->sensor_updater->build_command(command);
331 template<
class StatusType,
class CommandType>
335 boost::mutex::scoped_lock l(*lock_tactile_init_timeout_);
338 if (tactiles_init != NULL)
340 tactiles_init->update(status);
352 template<
class StatusType,
class CommandType>
358 nodehandle_.getParam(
"sr_calibrations", calib);
361 for (int32_t index_cal = 0; index_cal < calib.
size(); ++index_cal)
368 string joint_name =
static_cast<string> (calib[index_cal][0]);
369 vector<joint_calibration::Point> calib_table_tmp;
372 for (int32_t index_table = 0; index_table < calib[index_cal][1].
size(); ++index_table)
376 ROS_ASSERT(calib[index_cal][1][index_table].size() == 2);
380 joint_calibration::Point point_tmp;
381 point_tmp.raw_value =
static_cast<double> (calib[index_cal][1][index_table][0]);
382 point_tmp.calibrated_value = sr_math_utils::to_rad(static_cast<double> (calib[index_cal][1][index_table][1]));
383 calib_table_tmp.push_back(point_tmp);
387 new shadow_robot::JointCalibration(calib_table_tmp)));
390 return joint_calibration;
393 template<
class StatusType,
class CommandType>
399 nodehandle_.getParam(
"sr_calibrations_coupled", calib);
402 ROS_WARN(
"No coupled calibration specified.");
403 return coupled_joint_calibration;
408 for (int32_t cal_index = 0; cal_index < calib.
size(); ++cal_index)
410 std::vector<std::string> joint_pair;
411 std::vector<double> raw_values_coupled_0, raw_values_coupled_1, calibrated_values_0, calibrated_values_1;
418 for (int32_t raw_and_calibrated_value_index = 0;
419 raw_and_calibrated_value_index < calib[cal_index][1].
size();
420 ++raw_and_calibrated_value_index)
423 ROS_ASSERT(3 == calib[cal_index][1][raw_and_calibrated_value_index].size());
426 ROS_ASSERT(2 == calib[cal_index][1][raw_and_calibrated_value_index][0].size());
428 calib[cal_index][1][raw_and_calibrated_value_index][0][0].getType());
430 calib[cal_index][1][raw_and_calibrated_value_index][0][1].getType());
432 calib[cal_index][1][raw_and_calibrated_value_index][1].getType());
434 calib[cal_index][1][raw_and_calibrated_value_index][2].getType());
436 raw_values_coupled_0.push_back(static_cast<double>(calib[cal_index][1][raw_and_calibrated_value_index][0][0]));
437 raw_values_coupled_0.push_back(static_cast<double>(calib[cal_index][1][raw_and_calibrated_value_index][0][1]));
438 raw_values_coupled_1.push_back(static_cast<double>(calib[cal_index][1][raw_and_calibrated_value_index][0][1]));
439 raw_values_coupled_1.push_back(static_cast<double>(calib[cal_index][1][raw_and_calibrated_value_index][0][0]));
440 calibrated_values_0.push_back(sr_math_utils::to_rad(static_cast<double>
441 (calib[cal_index][1][raw_and_calibrated_value_index][1])));
442 calibrated_values_1.push_back(sr_math_utils::to_rad(static_cast<double>
443 (calib[cal_index][1][raw_and_calibrated_value_index][2])));
449 std::string joint_0_name =
static_cast<string>(calib[cal_index][0][0]);
450 std::string joint_1_name =
static_cast<string>(calib[cal_index][0][1]);
452 CoupledJoint coupled_joint_0(joint_0_name, joint_1_name, raw_values_coupled_0, calibrated_values_0);
453 CoupledJoint coupled_joint_1(joint_1_name, joint_0_name, raw_values_coupled_1, calibrated_values_1);
455 coupled_joint_calibration.insert(std::pair<std::string, CoupledJoint>(joint_0_name, coupled_joint_0));
456 coupled_joint_calibration.insert(std::pair<std::string, CoupledJoint>(joint_1_name, coupled_joint_1));
458 return coupled_joint_calibration;
461 template<
class StatusType,
class CommandType>
464 vector<JointToSensor> joint_to_sensor_vect;
466 map<string, int> sensors_map;
469 sensors_map[sensor_names[i]] = i;
473 nodehandle_.getParam(
"joint_to_sensor_mapping", joint_to_sensor_mapping);
475 for (int32_t i = 0; i < joint_to_sensor_mapping.
size(); ++i)
488 if (1 == static_cast<int> (map_one_joint[0]))
506 for (int32_t i = param_index; i < map_one_joint.
size(); ++i)
512 tmp_vect.
sensor_names.push_back(static_cast<string> (map_one_joint[i][0]));
513 tmp_joint_to_sensor.
sensor_id = sensors_map[
static_cast<string> (map_one_joint[i][0])];
516 tmp_joint_to_sensor.
coeff =
static_cast<double> (map_one_joint[i][1]);
519 joint_to_sensor_vect.push_back(tmp_vect);
522 return joint_to_sensor_vect;
525 template<
class StatusType,
class CommandType>
527 CommandType>::read_update_rate_configs(
string base_param,
529 const char *human_readable_data_types[],
530 const int32u data_types[])
532 vector<UpdateConfig> update_rate_configs_vector;
533 typedef pair<string, int32u> ConfPair;
534 vector<ConfPair> config;
536 for (
int i = 0; i < nb_data_defined; ++i)
540 ROS_DEBUG_STREAM(
" read " << base_param <<
" config [" << i <<
"] = " << human_readable_data_types[i]);
542 tmp.first = base_param + human_readable_data_types[i];
543 tmp.second = data_types[i];
544 config.push_back(tmp);
547 for (
unsigned int i = 0; i < config.size(); ++i)
550 if (nodehandle_.getParam(config[i].first, rate))
556 update_rate_configs_vector.push_back(config_tmp);
559 " read " << base_param <<
" config [" << i <<
"] = " <<
"what: " << config_tmp.
what_to_update <<
564 return update_rate_configs_vector;
567 template<
class StatusType,
class CommandType>
571 boost::mutex::scoped_lock l(*lock_tactile_init_timeout_);
578 ubi0_sensor_update_rate_configs_vector,
580 tactiles_init->tactiles_vector));
581 ROS_WARN_STREAM(
"Tactile Initialization Timeout: considering UBI0 tactiles");
585 CoupledJoint::CoupledJoint(std::string joint_name, std::string joint_sibling_name,
586 std::vector<double> raw_values_coupled_vector,
587 std::vector<double> calibrated_values_vector)
590 sibling_name_ = joint_sibling_name;
592 calibration_points_ = raw_values_coupled_vector.size() / 2;
593 total_points_ = calibration_points_ + nb_surrounding_points_;
595 for (
int i = 0; i < 2*total_points_; i++)
597 raw_values_coupled_.push_back(0);
600 for (
int i = 0; i < total_points_; i++)
602 calibrated_values_.push_back(0);
605 for (
int i = 0; i < 3*2*total_points_; i++)
607 triangle_.push_back(0);
608 element_neighbor_.push_back(0);
611 for (std::vector<double>::size_type i = 0; i != raw_values_coupled_vector.size(); i++)
613 raw_values_coupled_[i] = raw_values_coupled_vector[i];
616 for (std::vector<double>::size_type i = 0; i != calibrated_values_vector.size(); i++)
618 calibrated_values_[i] = calibrated_values_vector[i];
621 process_calibration_values();
624 CoupledJoint::~CoupledJoint()
628 void CoupledJoint::process_calibration_values()
631 add_surrounding_points(calibration_points_, &raw_values_coupled_[0],
632 &calibrated_values_[0], nb_surrounding_points_);
636 r8tris2(total_points_, &raw_values_coupled_[0], element_num_, &triangle_[0], &element_neighbor_[0]);
638 for (
int j = 0; j < element_num_; j++)
640 for (
int i = 0; i < 3; i++)
642 if ( 0 < element_neighbor_[i+j*3] )
644 element_neighbor_[i+j*3] = element_neighbor_[i+j*3] - 1;
TACTILE_SENSOR_PROTOCOL_TYPE_CONFLICTING
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_20
TACTILE_SENSOR_TYPE_PST3_PRESSURE_TEMPERATURE
std::map< std::string, CoupledJoint > CoupledJointMapType
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_9
TACTILE_SENSOR_TYPE_SOFTWARE_VERSION
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_15
SrRobotLib(hardware_interface::HardwareInterface *hw, ros::NodeHandle nh, ros::NodeHandle nhtilde, std::string device_id, std::string joint_prefix)
TACTILE_SENSOR_PROTOCOL_TYPE_BIOTAC_2_3
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_4
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_1
TACTILE_SENSOR_TYPE_BIOTAC_TDC
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_22
TACTILE_SENSOR_TYPE_MANUFACTURER
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_18
static const double tactile_timeout
Timeout handling variables for UBI sensors.
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_5
std::vector< std::string > sensor_names
TACTILE_SENSOR_TYPE_BIOTAC_PDC
static const int32u sensor_data_types[]
TACTILE_SENSOR_TYPE_PST3_DAC_VALUE
TACTILE_SENSOR_TYPE_BIOTAC_TAC
ServiceServer advertiseService(ros::NodeHandle n, std::string name, boost::function< bool(const typename ActionSpec::_action_goal_type::_goal_type &, typename ActionSpec::_action_result_type::_result_type &result)> service_cb)
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_10
TACTILE_SENSOR_TYPE_UBI0_TACTILE
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_19
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_3
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_8
TACTILE_SENSOR_PROTOCOL_TYPE_INVALID
Type const & getType() const
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_13
std::vector< PartialJointToSensor > joint_to_sensor_vector
static const char * human_readable_sensor_data_types[]
TACTILE_SENSOR_TYPE_SERIAL_NUMBER
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_6
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_17
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_11
TACTILE_SENSOR_TYPE_PST3_PRESSURE_RAW_ZERO_TRACKING
TACTILE_SENSOR_TYPE_PCB_VERSION
static const int nb_sensor_data
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
TACTILE_SENSOR_PROTOCOL_TYPE_PST3
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_14
TACTILE_SENSOR_TYPE_WHICH_SENSORS
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_24
TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ
#define ROS_INFO_STREAM(args)
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_21
TACTILE_SENSOR_PROTOCOL_TYPE_UBI0
threadsafe::Map< boost::shared_ptr< shadow_robot::JointCalibration > > CalibrationMap
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_12
bool calibrate_after_combining_sensors
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_2
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_7
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_23
TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_16