sr_robot_lib.hpp
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/thread.hpp>
00033 #include <boost/thread/mutex.hpp>
00034 #include <vector>
00035 #include <utility>
00036 #include <string>
00037 #include <deque>
00038 
00039 // used to publish debug values
00040 #include <std_msgs/Int16.h>
00041 
00042 #include <sr_hardware_interface/sr_actuator.hpp>
00043 
00044 #include <diagnostic_msgs/DiagnosticStatus.h>
00045 #include <diagnostic_updater/DiagnosticStatusWrapper.h>
00046 
00047 #include <ros_ethercat_model/robot_state.hpp>
00048 
00049 #include <sr_robot_msgs/NullifyDemand.h>
00050 #include <sr_robot_msgs/SetDebugData.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_self_test/sr_self_test.hpp>
00057 
00058 #include "sr_robot_lib/sr_joint_motor.hpp"
00059 #include "sr_robot_lib/generic_tactiles.hpp"
00060 
00061 #include <sr_external_dependencies/types_for_external.h>
00062 
00063 extern "C"
00064 {
00065 #include <sr_external_dependencies/external/0220_palm_edc/0220_palm_edc_ethercat_protocol.h>
00066 #include <sr_external_dependencies/external/0230_palm_edc_TS/0230_palm_edc_ethercat_protocol.h>
00067 #include <sr_external_dependencies/external/0320_palm_edc_muscle/0320_palm_edc_ethercat_protocol.h>
00068 #include <sr_external_dependencies/external/simplemotor-bootloader/bootloader.h>
00069 }
00070 
00071 namespace operation_mode
00072 {
00073 namespace robot_state
00074 {
00075   enum RobotState
00076   {
00077     INITIALIZATION,
00078     OPERATION,
00079     SHUTDOWN
00080   };
00081 }  // namespace robot_state
00082 }  // namespace operation_mode
00083 
00084 namespace crc_unions
00085 {
00086 union CRCUnion
00087 {
00088   int16u word;
00089   int8u byte[2];
00090 };
00091 
00092 typedef CRCUnion union16;
00093 }
00094 
00095 namespace shadow_robot
00096 {
00097 template<class StatusType, class CommandType>
00098 class SrRobotLib
00099 {
00100 public:
00101   SrRobotLib(hardware_interface::HardwareInterface *hw, ros::NodeHandle nh, ros::NodeHandle nhtilde,
00102              std::string device_id, std::string joint_prefix);
00103 
00104   virtual ~SrRobotLib()
00105   {
00106   }
00107 
00116   virtual void update(StatusType *status_data) = 0;
00117 
00123   virtual void build_command(CommandType *command) = 0;
00124 
00130   void build_tactile_command(CommandType *command);
00131 
00137   void update_tactile_info(StatusType *status);
00138 
00143   virtual void add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00144                                diagnostic_updater::DiagnosticStatusWrapper &d) = 0;
00145 
00149   void reinitialize_sensors();
00150 
00163   bool nullify_demand_callback(sr_robot_msgs::NullifyDemand::Request &request,
00164                                sr_robot_msgs::NullifyDemand::Response &response);
00165 
00166 
00172   boost::shared_ptr<tactiles::GenericTactiles<StatusType, CommandType> > tactiles;
00173 
00178   int main_pic_idle_time;
00179 
00185   int main_pic_idle_time_min;
00186 
00187   // Current update state of the sensors (initialization, operation..)
00188   operation_mode::device_update_state::DeviceUpdateState tactile_current_state;
00189 
00190   ros_ethercat_model::RobotState *hw_;
00191 
00192 protected:
00193   // True if we want to set the demand to 0 (stop the controllers)
00194   bool nullify_demand_;
00195 
00197   std::vector<shadow_joints::Joint> joints_vector;
00198 
00206   virtual void initialize(std::vector<std::string> joint_names, std::vector<int> actuator_ids,
00207                           std::vector<shadow_joints::JointToSensor> joint_to_sensors) = 0;
00208 
00216   virtual void calibrate_joint(std::vector<shadow_joints::Joint>::iterator joint_tmp, StatusType *status_data) = 0;
00217 
00227   virtual ros_ethercat_model::Actuator *get_joint_actuator(std::vector<shadow_joints::Joint>::iterator joint_tmp) = 0;
00228 
00236   std::vector<shadow_joints::JointToSensor> read_joint_to_sensor_mapping();
00237 
00244   shadow_joints::CalibrationMap read_joint_calibration();
00245 
00256   std::vector<generic_updater::UpdateConfig> read_update_rate_configs(std::string base_param, int nb_data_defined,
00257                                                                       const char *human_readable_data_types[],
00258                                                                       const int32u data_types[]);
00259 
00263   void tactile_init_timer_callback(const ros::TimerEvent &event);
00264 
00266   boost::shared_ptr<shadow_robot::JointCalibration> calibration_tmp;
00267 
00268 
00270   ros::NodeHandle nh_tilde;
00271 
00272   // The ROS service handler for nullifying the demand
00273   ros::ServiceServer nullify_demand_server_;
00274 
00275   // boost::shared_ptr<SrSelfTest> self_tests_;
00276 
00277   // Thread for running the tests in parallel when doing the tests on real hand
00278   boost::shared_ptr<boost::thread> self_test_thread_;
00279 
00281   ros::NodeHandle nodehandle_;
00282 
00284   std::string joint_prefix_;
00286   std::string device_id_;
00287 
00288 
00289 #ifdef DEBUG_PUBLISHER
00290   // These publishers are useful for debugging
00291   static const int nb_debug_publishers_const;
00292   std::vector<ros::Publisher> debug_publishers;
00300   std::vector<boost::shared_ptr<std::pair<int, int> > > debug_motor_indexes_and_data;
00301   // static const int debug_mutex_lock_wait_time;
00302   // boost::shared_mutex debug_mutex;
00303   ros::NodeHandle node_handle;
00304   std_msgs::Int16 msg_debug;
00305 #endif
00306 
00307   // The update rate for each sensor information type
00308   std::vector<generic_updater::UpdateConfig> generic_sensor_update_rate_configs_vector;
00309   // The update rate for each sensor information type
00310   std::vector<generic_updater::UpdateConfig> pst3_sensor_update_rate_configs_vector;
00311   // The update rate for each sensor information type
00312   std::vector<generic_updater::UpdateConfig> biotac_sensor_update_rate_configs_vector;
00313   // The update rate for each sensor information type
00314   std::vector<generic_updater::UpdateConfig> ubi0_sensor_update_rate_configs_vector;
00315 
00316   static const int nb_sensor_data;
00317   static const char *human_readable_sensor_data_types[];
00318   static const int32u sensor_data_types[];
00319 
00321   // This avoids the tests blocking the main thread
00322   void checkSelfTests();
00323 
00324 public:
00326   static const double tactile_timeout;
00327   ros::Duration tactile_init_max_duration;
00328   ros::Timer tactile_check_init_timeout_timer;
00329 
00331   boost::shared_ptr<boost::mutex> lock_tactile_init_timeout_;
00332 
00333   boost::shared_ptr<tactiles::GenericTactiles<StatusType, CommandType> > tactiles_init;
00334 
00336   shadow_joints::CalibrationMap calibration_map;
00337 };  // end class
00338 }  // namespace shadow_robot
00339 
00340 /* For the emacs weenies in the crowd.
00341 Local Variables:
00342    c-basic-offset: 2
00343 End:
00344  */
00345 
00346 #endif


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Mon Jul 1 2019 20:06:26