Go to the documentation of this file.00001
00027 #ifndef _SR_ROBOT_LIB_HPP_
00028 #define _SR_ROBOT_LIB_HPP_
00029
00030 #include <boost/smart_ptr.hpp>
00031 #include <boost/ptr_container/ptr_vector.hpp>
00032 #include <boost/thread.hpp>
00033 #include <vector>
00034 #include <deque>
00035
00036
00037 #include <std_msgs/Int16.h>
00038
00039 #include <sr_hardware_interface/sr_actuator.hpp>
00040
00041 #include <diagnostic_msgs/DiagnosticStatus.h>
00042 #include <diagnostic_updater/DiagnosticStatusWrapper.h>
00043
00044 #include <sr_robot_msgs/ForceController.h>
00045 #include <sr_robot_msgs/NullifyDemand.h>
00046 #include <sr_robot_msgs/SetDebugData.h>
00047 #include <sr_robot_msgs/ControlType.h>
00048 #include <sr_robot_msgs/ChangeControlType.h>
00049 #include <sr_robot_msgs/MotorSystemControls.h>
00050 #include <sr_robot_msgs/ChangeMotorSystemControls.h>
00051
00052 #include <sr_utilities/sr_math_utils.hpp>
00053 #include <sr_utilities/calibration.hpp>
00054 #include <sr_utilities/thread_safe_map.hpp>
00055
00056 #include "sr_robot_lib/sr_joint_motor.hpp"
00057 #include "sr_robot_lib/motor_updater.hpp"
00058 #include "sr_robot_lib/generic_tactiles.hpp"
00059 #include "sr_robot_lib/motor_data_checker.hpp"
00060
00061 #include <sr_external_dependencies/types_for_external.h>
00062 extern "C"
00063 {
00064 #include <sr_external_dependencies/external/0220_palm_edc/0220_palm_edc_ethercat_protocol.h>
00065 #include <sr_external_dependencies/external/simplemotor-bootloader/bootloader.h>
00066 }
00067
00068 namespace operation_mode
00069 {
00070 namespace robot_state
00071 {
00072 enum RobotState
00073 {
00074 INITIALIZATION,
00075 OPERATION,
00076 SHUTDOWN
00077 };
00078 }
00079 }
00080
00081 namespace crc_unions
00082 {
00083 typedef union
00084 {
00085 int16u word;
00086 int8u byte[2];
00087 } union16;
00088 }
00089
00090 namespace shadow_robot
00091 {
00092 class SrRobotLib
00093 {
00094 public:
00095 SrRobotLib(pr2_hardware_interface::HardwareInterface *hw);
00096 ~SrRobotLib() {};
00097
00106 void update(ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS* status_data);
00107
00114 void build_motor_command(ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_COMMAND* command);
00115
00120 void add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00121 diagnostic_updater::DiagnosticStatusWrapper &d);
00122
00126 void reinitialize_motors();
00127
00131 void reinitialize_sensors();
00132
00145 bool nullify_demand_callback( sr_robot_msgs::NullifyDemand::Request& request,
00146 sr_robot_msgs::NullifyDemand::Response& response );
00147
00149 shadow_joints::CalibrationMap calibration_map;
00150
00156 boost::shared_ptr<tactiles::GenericTactiles> tactiles;
00157 boost::shared_ptr<tactiles::GenericTactiles> tactiles_init;
00158
00163 int main_pic_idle_time;
00164
00170 int main_pic_idle_time_min;
00171
00173 operation_mode::device_update_state::DeviceUpdateState motor_current_state;
00174
00176 operation_mode::device_update_state::DeviceUpdateState tactile_current_state;
00177
00178 protected:
00180 boost::ptr_vector<shadow_joints::Joint> joints_vector;
00181
00190 virtual void initialize(std::vector<std::string> joint_names,
00191 std::vector<int> motor_ids,
00192 std::vector<shadow_joints::JointToSensor> joint_to_sensors,
00193 std::vector<sr_actuator::SrActuator*> actuators) = 0;
00194
00201 void calibrate_joint(boost::ptr_vector<shadow_joints::Joint>::iterator joint_tmp);
00202
00209 void read_additional_data(boost::ptr_vector<shadow_joints::Joint>::iterator joint_tmp);
00210
00219 std::vector<std::pair<std::string, bool> > humanize_flags(int flag);
00220
00237 void generate_force_control_config(int motor_index, int max_pwm, int sg_left, int sg_right,
00238 int f, int p, int i, int d, int imax,
00239 int deadband, int sign);
00240
00246 boost::shared_ptr<generic_updater::MotorUpdater> motor_updater_;
00247
00248
00254 typedef std::pair<int, std::vector<crc_unions::union16> > ForceConfig;
00258 std::queue<ForceConfig, std::list<ForceConfig> > reconfig_queue;
00260 int config_index;
00261
00263 std::queue<short, std::list<short> > reset_motors_queue;
00264
00266 sr_actuator::SrActuator* actuator;
00268 ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS* status_data;
00270 boost::shared_ptr<shadow_robot::JointCalibration> calibration_tmp;
00271
00273 int motor_index_full;
00275 int index_motor_in_msg;
00276
00277 int8u crc_byte;
00278 int16u crc_result;
00279 int8u crc_i;
00280
00282 ros::NodeHandle nh_tilde;
00283
00284 #ifdef DEBUG_PUBLISHER
00285
00286 static const int nb_debug_publishers_const;
00287 std::vector<ros::Publisher> debug_publishers;
00295 std::vector<boost::shared_ptr<std::pair<int, int> > > debug_motor_indexes_and_data;
00296 static const int debug_mutex_lock_wait_time;
00297 boost::shared_mutex debug_mutex;
00298 ros::NodeHandle node_handle;
00299 std_msgs::Int16 msg_debug;
00300 #endif
00301
00303 std::vector<generic_updater::UpdateConfig> motor_update_rate_configs_vector;
00305 std::vector<generic_updater::UpdateConfig> generic_sensor_update_rate_configs_vector;
00307 std::vector<generic_updater::UpdateConfig> pst3_sensor_update_rate_configs_vector;
00309 std::vector<generic_updater::UpdateConfig> biotac_sensor_update_rate_configs_vector;
00310
00311 boost::shared_ptr<generic_updater::MotorDataChecker> motor_data_checker;
00312
00314 bool nullify_demand_;
00316 ros::ServiceServer nullify_demand_server_;
00317
00319 sr_robot_msgs::ControlType control_type_;
00328 bool control_type_changed_flag_;
00330 ros::ServiceServer change_control_type_;
00332 boost::shared_ptr<boost::mutex> lock_command_sending_;
00333
00343 bool change_control_type_callback_( sr_robot_msgs::ChangeControlType::Request& request,
00344 sr_robot_msgs::ChangeControlType::Response& response );
00345
00355 bool change_control_parameters(int16_t control_type);
00356
00358 std::queue<std::vector<sr_robot_msgs::MotorSystemControls>, std::list<std::vector<sr_robot_msgs::MotorSystemControls> > > motor_system_control_flags_;
00360 ros::ServiceServer motor_system_control_server_;
00361
00372 bool motor_system_controls_callback_( sr_robot_msgs::ChangeMotorSystemControls::Request& request,
00373 sr_robot_msgs::ChangeMotorSystemControls::Response& response );
00374 };
00375 }
00376
00377
00378
00379
00380
00381
00382
00383 #endif
00384