Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <controller_interface/controller.h>
00008 #include <hardware_interface/joint_command_interface.h>
00009 #include <pluginlib/class_list_macros.h>
00010
00011 #include <nav_msgs/Odometry.h>
00012 #include <tf/tfMessage.h>
00013
00014 #include <realtime_tools/realtime_buffer.h>
00015 #include <realtime_tools/realtime_publisher.h>
00016
00017 #include <robotican_controllers/odometry.h>
00018 #include <robotican_controllers/speed_limiter.h>
00019
00020 namespace diff_drive_controller{
00021
00031 class DiffDriveController
00032 : public controller_interface::Controller<hardware_interface::VelocityJointInterface>
00033 {
00034 public:
00035 DiffDriveController();
00036
00043 bool init(hardware_interface::VelocityJointInterface* hw,
00044 ros::NodeHandle& root_nh,
00045 ros::NodeHandle &controller_nh);
00046
00052 void update(const ros::Time& time, const ros::Duration& period);
00053
00058 void starting(const ros::Time& time);
00059
00064 void stopping(const ros::Time& );
00065
00066 private:
00067 std::string name_;
00068
00070 ros::Duration publish_period_;
00071 ros::Time last_state_publish_time_;
00072 bool open_loop_;
00073
00075 std::vector<hardware_interface::JointHandle> left_wheel_joints_;
00076 std::vector<hardware_interface::JointHandle> right_wheel_joints_;
00077
00079 struct Commands
00080 {
00081 double lin;
00082 double ang;
00083 ros::Time stamp;
00084
00085 Commands() : lin(0.0), ang(0.0), stamp(0.0) {}
00086 };
00087 realtime_tools::RealtimeBuffer<Commands> command_;
00088 Commands command_struct_;
00089 ros::Subscriber sub_command_;
00090
00092 boost::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::Odometry> > odom_pub_;
00093 boost::shared_ptr<realtime_tools::RealtimePublisher<tf::tfMessage> > tf_odom_pub_;
00094 Odometry odometry_;
00095
00097 double wheel_separation_;
00098
00100 double wheel_radius_;
00101
00103 double wheel_separation_multiplier_;
00104 double wheel_radius_multiplier_;
00105
00107 double cmd_vel_timeout_;
00108
00110 bool allow_multiple_cmd_vel_publishers_;
00111
00113 std::string base_frame_id_;
00114
00116 std::string odom_frame_id_;
00117
00119 bool enable_odom_tf_;
00120
00122 size_t wheel_joints_size_;
00123
00125 Commands last1_cmd_;
00126 Commands last0_cmd_;
00127 SpeedLimiter limiter_lin_;
00128 SpeedLimiter limiter_ang_;
00129
00130 private:
00134 void brake();
00135
00140 void cmdVelCallback(const geometry_msgs::Twist& command);
00141
00150 bool getWheelNames(ros::NodeHandle& controller_nh,
00151 const std::string& wheel_param,
00152 std::vector<std::string>& wheel_names);
00153
00160 bool setOdomParamsFromUrdf(ros::NodeHandle& root_nh,
00161 const std::string& left_wheel_name,
00162 const std::string& right_wheel_name,
00163 bool lookup_wheel_separation,
00164 bool lookup_wheel_radius);
00165
00171 void setOdomPubFields(ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
00172
00173 };
00174
00175 PLUGINLIB_EXPORT_CLASS(diff_drive_controller::DiffDriveController, controller_interface::ControllerBase);
00176 }
00177