velocity_smoother.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #ifndef VELOCITY_SMOOTHER_HPP_
00019 #define VELOCITY_SMOOTHER_HPP_
00020 
00021 /*****************************************************************************
00022  ** Includes
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 ** Namespaces
00032 *****************************************************************************/
00033 
00034 namespace cob_base_velocity_smoother {
00035 
00036 /*****************************************************************************
00037 ** VelocitySmoother
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     // Return the median element of an doubles vector
00095     nth_element(values.begin(), values.begin() + values.size()/2, values.end());
00096     return values[values.size()/2];
00097   };
00098 
00099   /*********************
00100   ** Dynamic Reconfigure
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 } // cob_base_velocity_smoother
00108 
00109 #endif /* VELOCITY_SMOOTHER_HPP_ */


cob_base_velocity_smoother
Author(s): Florian Mirus , Benjamin Maidel
autogenerated on Thu Jun 6 2019 21:18:55