Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef STEER_BOT_HARDWARE_GAZEBO_H
00040 #define STEER_BOT_HARDWARE_GAZEBO_H
00041
00042 #include <vector>
00043 #include <string>
00044
00045 #include <control_toolbox/pid.h>
00046
00047 #include <hardware_interface/robot_hw.h>
00048 #include <hardware_interface/joint_state_interface.h>
00049 #include <hardware_interface/joint_command_interface.h>
00050 #include <joint_limits_interface/joint_limits_interface.h>
00051
00052 #include <gazebo_ros_control/robot_hw_sim.h>
00053
00054 #include <gazebo/gazebo.hh>
00055 #include <gazebo/physics/physics.hh>
00056 #include <gazebo/common/common.hh>
00057
00058 namespace steer_bot_hardware_gazebo
00059 {
00060
00061 double clamp(const double val, const double min_val, const double max_val)
00062 {
00063 return std::min(std::max(val, min_val), max_val);
00064 }
00065
00066 class SteerBotHardwareGazebo : public gazebo_ros_control::RobotHWSim
00067 {
00068 public:
00069
00070 SteerBotHardwareGazebo();
00071
00072 bool initSim(const std::string& robot_namespace,
00073 ros::NodeHandle model_nh,
00074 gazebo::physics::ModelPtr parent_model,
00075 const urdf::Model* const urdf_model,
00076 std::vector<transmission_interface::TransmissionInfo> transmissions);
00077
00078 void readSim(ros::Time time, ros::Duration period);
00079
00080 void writeSim(ros::Time time, ros::Duration period);
00081
00082 private:
00083 void CleanUp();
00084
00085 void GetJointNames(ros::NodeHandle &_nh);
00086 void GetWheelJointNames(ros::NodeHandle &_nh);
00087 void GetSteerJointNames(ros::NodeHandle &_nh);
00088
00089 void RegisterHardwareInterfaces();
00090 void RegisterWheelInterface();
00091 void RegisterSteerInterface();
00092 void RegisterInterfaceHandles(
00093 hardware_interface::JointStateInterface& _jnt_state_interface,
00094 hardware_interface::JointCommandInterface& _jnt_cmd_interface,
00095 const std::string _jnt_name, double& _jnt_pos, double& _jnt_vel, double& _jnt_eff, double& _jnt_cmd);
00096 void RegisterJointStateInterfaceHandle(
00097 hardware_interface::JointStateInterface& _jnt_state_interface,
00098 const std::string _jnt_name, double& _jnt_pos, double& _jnt_vel, double& _jnt_eff);
00099 void RegisterCommandJointInterfaceHandle(
00100 hardware_interface::JointStateInterface& _jnt_state_interface,
00101 hardware_interface::JointCommandInterface& _jnt_cmd_interface,
00102 const std::string _jnt_name, double& _jnt_cmd);
00103 double ComputeEffCommandFromVelError(const int _index, ros::Duration _period);
00104
00105 void GetCurrentState(std::vector<double>& _jnt_pos, std::vector<double>& _jnt_vel, std::vector<double>& _jnt_eff,
00106 const int _if_index, const int _sim_jnt_index);
00107
00108 private:
00109
00110 enum {
00111 INDEX_RIGHT = 0,
00112 INDEX_LEFT = 1
00113 };
00114
00115 unsigned int n_dof_;
00116 std::vector<gazebo::physics::JointPtr> sim_joints_;
00117
00118
00119 joint_limits_interface::PositionJointSoftLimitsInterface jnt_limits_interface_;
00120
00121
00122 std::vector<control_toolbox::Pid> pids_;
00123
00124
00125 ros::NodeHandle nh_;
00126 std::string ns_;
00127
00128
00129 hardware_interface::JointStateInterface jnt_state_interface_;
00130
00131
00132
00133
00134 std::string rear_wheel_jnt_name_;
00135
00136 double rear_wheel_jnt_pos_;
00137 double rear_wheel_jnt_vel_;
00138 double rear_wheel_jnt_eff_;
00139
00140 double rear_wheel_jnt_vel_cmd_;
00141
00142 hardware_interface::VelocityJointInterface rear_wheel_jnt_vel_cmd_interface_;
00143
00144
00145
00146
00147 std::vector<std::string> virtual_rear_wheel_jnt_names_;
00148
00149 std::vector<double> virtual_rear_wheel_jnt_pos_;
00150 std::vector<double> virtual_rear_wheel_jnt_vel_;
00151 std::vector<double> virtual_rear_wheel_jnt_eff_;
00152
00153 std::vector<double> virtual_rear_wheel_jnt_vel_cmd_;
00154
00155
00156 std::vector<std::string> virtual_front_wheel_jnt_names_;
00157
00158 std::vector<double> virtual_front_wheel_jnt_pos_;
00159 std::vector<double> virtual_front_wheel_jnt_vel_;
00160 std::vector<double> virtual_front_wheel_jnt_eff_;
00161
00162 std::vector<double> virtual_front_wheel_jnt_vel_cmd_;
00163
00164
00165
00166
00167 std::string front_steer_jnt_name_;
00168
00169 double front_steer_jnt_pos_;
00170 double front_steer_jnt_vel_;
00171 double front_steer_jnt_eff_;
00172
00173 double front_steer_jnt_pos_cmd_;
00174
00175 hardware_interface::PositionJointInterface front_steer_jnt_pos_cmd_interface_;
00176
00177
00178
00179
00180 std::vector<std::string> virtual_front_steer_jnt_names_;
00181
00182 std::vector<double> virtual_front_steer_jnt_pos_;
00183 std::vector<double> virtual_front_steer_jnt_vel_;
00184 std::vector<double> virtual_front_steer_jnt_eff_;
00185
00186 std::vector<double> virtual_front_steer_jnt_pos_cmd_;
00187
00188 hardware_interface::VelocityJointInterface front_wheel_jnt_vel_cmd_interface_;
00189
00190
00191 bool enable_ackermann_link_ ;
00192 double wheel_separation_w_;
00193 double wheel_separation_h_;
00194
00195 int log_cnt_;
00196
00197 template <class T>
00198 std::string containerToString(const T& cont, const std::string& prefix)
00199 {
00200 std::stringstream ss;
00201 ss << prefix;
00202 std::copy(cont.begin(), --cont.end(), std::ostream_iterator<typename T::value_type>(ss, prefix.c_str()));
00203 ss << *(--cont.end());
00204 return ss.str();
00205 }
00206
00207 };
00208
00209 }
00210
00211 #endif // STEER_BOT_HARDWARE_GAZEBO_H