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 #ifndef VELOCITY_SMOOTHER_HPP_
00019 #define VELOCITY_SMOOTHER_HPP_
00020
00021
00022
00023
00024
00025 #include <ros/ros.h>
00026 #include <dynamic_reconfigure/server.h>
00027 #include <cob_base_velocity_smoother/paramsConfig.h>
00028 #include <nav_msgs/Odometry.h>
00029
00030
00031
00032
00033
00034 namespace cob_base_velocity_smoother {
00035
00036
00037
00038
00039
00040 class VelocitySmoother
00041 {
00042 public:
00043 VelocitySmoother(const std::string &name);
00044
00045 ~VelocitySmoother()
00046 {
00047 if (dynamic_reconfigure_server != NULL)
00048 delete dynamic_reconfigure_server;
00049 }
00050
00051 bool init(ros::NodeHandle& nh);
00052 void spin();
00053 void shutdown() { shutdown_req = true; };
00054
00055 private:
00056 enum RobotFeedbackType
00057 {
00058 NONE,
00059 ODOMETRY,
00060 COMMANDS
00061 } robot_feedback;
00063 std::string name;
00064 double speed_lim_vx, accel_lim_vx, decel_lim_vx, decel_lim_vx_safe;
00065 double speed_lim_vy, accel_lim_vy, decel_lim_vy, decel_lim_vy_safe;
00066 double speed_lim_w, accel_lim_w, decel_lim_w, decel_lim_w_safe;
00067 double decel_factor, decel_factor_safe;
00068
00069 double frequency;
00070
00071 geometry_msgs::Twist last_cmd_vel;
00072 geometry_msgs::Twist current_vel;
00073 geometry_msgs::Twist target_vel;
00074
00075 bool shutdown_req;
00076 bool input_active;
00077 double cb_avg_time;
00078 ros::Time last_cb_time;
00079 std::vector<double> period_record;
00080 unsigned int pr_next;
00082 ros::Subscriber odometry_sub;
00083 ros::Subscriber current_vel_sub;
00084 ros::Subscriber raw_in_vel_sub;
00085 ros::Publisher smooth_vel_pub;
00087 void velocityCB(const geometry_msgs::Twist::ConstPtr& msg);
00088 void robotVelCB(const geometry_msgs::Twist::ConstPtr& msg);
00089 void odometryCB(const nav_msgs::Odometry::ConstPtr& msg);
00090
00091 double sign(double x) { return x < 0.0 ? -1.0 : +1.0; };
00092
00093 double median(std::vector<double> values) {
00094
00095 nth_element(values.begin(), values.begin() + values.size()/2, values.end());
00096 return values[values.size()/2];
00097 };
00098
00099
00100
00101
00102 dynamic_reconfigure::Server<cob_base_velocity_smoother::paramsConfig> * dynamic_reconfigure_server;
00103 dynamic_reconfigure::Server<cob_base_velocity_smoother::paramsConfig>::CallbackType dynamic_reconfigure_callback;
00104 void reconfigCB(cob_base_velocity_smoother::paramsConfig &config, uint32_t unused_level);
00105 };
00106
00107 }
00108
00109 #endif