Go to the documentation of this file.00001
00027 #ifndef _SR_MUSCLE_ROBOT_LIB_HPP_
00028 #define _SR_MUSCLE_ROBOT_LIB_HPP_
00029
00030 #include "sr_robot_lib/sr_robot_lib.hpp"
00031
00032 #include "sr_robot_lib/muscle_updater.hpp"
00033 #include <sr_utilities/calibration.hpp>
00034 #include <string>
00035 #include <map>
00036 #include <queue>
00037 #include <utility>
00038 #include <list>
00039 #include <vector>
00040
00041 #define NUM_MUSCLE_DRIVERS 4
00042
00043 namespace shadow_robot
00044 {
00045 template<class StatusType, class CommandType>
00046 class SrMuscleRobotLib :
00047 public SrRobotLib<StatusType, CommandType>
00048 {
00049 public:
00050 SrMuscleRobotLib(hardware_interface::HardwareInterface *hw, ros::NodeHandle nh, ros::NodeHandle nhtilde,
00051 std::string device_id, std::string joint_prefix);
00052
00061 void update(StatusType *status_data);
00062
00069 void build_command(CommandType *command);
00070
00075 void add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00076 diagnostic_updater::DiagnosticStatusWrapper &d);
00077
00081 void reinitialize_motors();
00082
00083
00084
00085 operation_mode::device_update_state::DeviceUpdateState muscle_current_state;
00086
00087
00088 protected:
00096 virtual void initialize(std::vector<std::string> joint_names, std::vector<int> actuator_ids,
00097 std::vector<shadow_joints::JointToSensor> joint_to_sensors) = 0;
00098
00106 void calibrate_joint(std::vector<shadow_joints::Joint>::iterator joint_tmp, StatusType *status_data);
00107
00109 shadow_joints::CalibrationMap pressure_calibration_map_;
00111 boost::shared_ptr<shadow_robot::JointCalibration> pressure_calibration_tmp_;
00112
00113
00119 virtual shadow_joints::CalibrationMap read_pressure_calibration();
00120
00121
00129 void read_additional_muscle_data(std::vector<shadow_joints::Joint>::iterator joint_tmp, StatusType *status_data);
00130
00139 void process_position_sensor_data(std::vector<shadow_joints::Joint>::iterator joint_tmp, StatusType *status_data,
00140 double timestamp);
00141
00149 void read_muscle_driver_data(std::vector<shadow_joints::MuscleDriver>::iterator muscle_driver_tmp,
00150 StatusType *status_data);
00151
00160 std::vector<std::pair<std::string, bool> > humanize_flags(int flag);
00161
00169 sr_actuator::SrMuscleActuator *get_joint_actuator(std::vector<shadow_joints::Joint>::iterator joint_tmp)
00170 {
00171 return static_cast<sr_actuator::SrMuscleActuator *>(joint_tmp->actuator_wrapper->actuator);
00172 }
00173
00177 unsigned int get_muscle_pressure(int muscle_driver_id, int muscle_id, StatusType *status_data);
00178
00179 inline void set_muscle_driver_data_received_flags(unsigned int msg_type, int muscle_driver_id);
00180
00181 inline bool check_muscle_driver_data_received_flags();
00182
00192 inline void set_valve_demand(uint8_t *muscle_data_byte_to_set, int8_t valve_value, uint8_t shifting_index);
00193
00197 void init_timer_callback(const ros::TimerEvent &event);
00198
00199 std::vector<shadow_joints::MuscleDriver> muscle_drivers_vector_;
00200
00201
00207 boost::shared_ptr<generic_updater::MuscleUpdater<CommandType> > muscle_updater_;
00208
00209
00210
00211 std::queue<int16_t, std::list<int16_t> > reset_muscle_driver_queue;
00212
00213
00214
00215 std::vector<generic_updater::UpdateConfig> muscle_update_rate_configs_vector;
00216
00223 std::map<unsigned int, unsigned int> from_muscle_driver_data_received_flags_;
00224
00225
00226 ros::Timer check_init_timeout_timer;
00227 static const double timeout;
00228 ros::Duration init_max_duration;
00229
00230
00231 boost::shared_ptr<boost::mutex> lock_init_timeout_;
00232 };
00233 }
00234
00235
00236
00237
00238
00239
00240
00241 #endif