cob_base_velocity_smoother.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef COB_BASE_VELOCITY_SMOOTHER_H
19 #define COB_BASE_VELOCITY_SMOOTHER_H
20 
21 //**************************** includes ************************/
22 
23 // standard includes
24 #include <XmlRpc.h>
25 #include <pthread.h>
26 #include <deque>
27 #include <sstream>
28 #include <iostream>
29 #include <boost/circular_buffer.hpp>
30 #include <boost/bind.hpp>
31 
32 // ros includes
33 #include <ros/ros.h>
34 #include <geometry_msgs/Twist.h>
35 #include <ros/console.h>
36 #include <std_msgs/String.h>
37 /****************************************************************
38  * the ros navigation doesn't run very smoothly because acceleration is too high
39  * --> cob has strong base motors and therefore reacts with shaking behavior
40  * (PR2 has much more mechanical damping)
41  * solution: the additional node cob_base_velocity_smoother smooths the velocities
42  * comming from ROS-navigation or teleoperation, by calculating the mean values of a certain number
43  * of past messages and limiting the acceleration under a given threshold.
44  * cob_base_velocity_smoother subsribes (input) and publishes (output) geometry_msgs::Twist.
45  ****************************************************************/
47 {
48 private:
49  //capacity for circular buffers (to be loaded from parameter server, otherwise set to default value 12)
51  //maximal time-delay in seconds for stored messages in Circular Buffer (to be loaded from parameter server, otherwise set to default value 4)
52  double store_delay_;
53  // maximal time-delay in seconds to wait until filling the circular buffer with zero messages when the subscriber doesn't hear anything
55  //threshhold for maximal allowed acceleration (to be loaded from parameter server, otherwise set to default value 0.02)
56  double acc_limit_;
57  // ros loop rate (to be loaded from parameter server, otherwise set to default value 30)
58  double loop_rate_;
59  // delay between received commands that is allowed. After that, fill buffer with zeros.
61  //geometry message filled with zero values
62  geometry_msgs::Twist zero_values_;
63  // subscribed geometry message
64  geometry_msgs::Twist sub_msg_;
65 
66  pthread_mutex_t m_mutex;
68 
69  // function for checking wether a new msg has been received, triggering publishers accordingly
70  void set_new_msg_received(bool received);
71  bool get_new_msg_received();
72 
73 public:
74  // constructor
76 
77  // destructor
79 
80  //create node handle
82 
83  //circular buffers for velocity, output and time
84  boost::circular_buffer<geometry_msgs::Twist> cb_;
85  boost::circular_buffer<geometry_msgs::Twist> cb_out_;
86  boost::circular_buffer<ros::Time> cb_time_;
87 
88  // declaration of ros subscribers
90 
91  // decalaration of ros publishers
93 
94  //callback function to subsribe to the geometry messages
95  void geometryCallback(const geometry_msgs::Twist::ConstPtr &cmd_vel);
96  //calculation function called periodically in main
97  void calculationStep();
98  //function that updates the circular buffer after receiving a new geometry message
99  void reviseCircBuff(ros::Time now, geometry_msgs::Twist cmd_vel);
100  //function to limit the acceleration under the given threshhold thresh
101  void limitAcceleration(ros::Time now, geometry_msgs::Twist& cmd_vel);
102 
103  //boolean function that returns true if all messages stored in the circular buffer are older than store_delay, false otherwise
104  bool circBuffOutOfDate(ros::Time now);
105  // function to compare two geometry messages
106  bool IsEqual(geometry_msgs::Twist msg1, geometry_msgs::Twist msg2);
107 
108  //boolean function that returns true if the input msg cmd_vel equals zero_values, false otherwise
109  bool IsZeroMsg(geometry_msgs::Twist cmd_vel);
110 
111  //help-function that returns the signum of a double variable
112  int signum(double var);
113 
114  //functions to calculate the mean values for each direction
115  double meanValueX();
116  double meanValueY();
117  double meanValueZ();
118 
119  // function to make the loop rate available outside the class
120  double getLoopRate();
121 
122  //function for the actual computation
123  //calls the reviseCircBuff and the meanValue-functions and limits the acceleration under thresh
124  //returns the resulting geometry message to be published to the base_controller
125  geometry_msgs::Twist setOutput(ros::Time now, geometry_msgs::Twist cmd_vel);
126 };
127 
128 #endif
void limitAcceleration(ros::Time now, geometry_msgs::Twist &cmd_vel)
geometry_msgs::Twist setOutput(ros::Time now, geometry_msgs::Twist cmd_vel)
void reviseCircBuff(ros::Time now, geometry_msgs::Twist cmd_vel)
bool IsEqual(geometry_msgs::Twist msg1, geometry_msgs::Twist msg2)
bool IsZeroMsg(geometry_msgs::Twist cmd_vel)
boost::circular_buffer< geometry_msgs::Twist > cb_out_
boost::circular_buffer< geometry_msgs::Twist > cb_
void geometryCallback(const geometry_msgs::Twist::ConstPtr &cmd_vel)
boost::circular_buffer< ros::Time > cb_time_


cob_base_velocity_smoother
Author(s): Florian Mirus , Benjamin Maidel
autogenerated on Thu Apr 8 2021 02:39:30