acceleration_limiter.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Ifdefs
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_ACCELERATION_LIMITER_HPP_
14 #define KOBUKI_ACCELERATION_LIMITER_HPP_
15 
16 /*****************************************************************************
17 ** Includes
18 *****************************************************************************/
19 
20 #include <vector>
21 #include <iomanip>
22 #include <sstream>
23 #include <iostream>
24 #include <stdint.h>
25 #include <ecl/time.hpp>
26 
27 /*****************************************************************************
28 ** Namespaces
29 *****************************************************************************/
30 
31 namespace kobuki {
32 
33 /*****************************************************************************
34 ** Interfaces
35 *****************************************************************************/
36 
50 class AccelerationLimiter {
51 public:
53  is_enabled(true),
54  last_speed(0),
55  last_timestamp(ecl::TimeStamp()),
56  last_vx(0.0),
57  last_wz(0.0)
58  {
59  (void) last_speed;
60  (void) last_radius;
61  }
62 
63  void init(bool enable_acceleration_limiter
64  , double linear_acceleration_max_= 0.5, double angular_acceleration_max_= 3.5
65  , double linear_deceleration_max_=-0.5*1.2, double angular_deceleration_max_=-3.5*1.2)
66  {
67  is_enabled = enable_acceleration_limiter;
68  linear_acceleration_max = linear_acceleration_max_ ;
69  linear_deceleration_max = linear_deceleration_max_ ;
70  angular_acceleration_max = angular_acceleration_max_;
71  angular_deceleration_max = angular_deceleration_max_;
72  }
73 
74  bool isEnabled() const { return is_enabled; }
75 
83  std::vector<double> limit(const std::vector<double> &command) { return limit(command[0], command[1]); }
84 
85  std::vector<double> limit(const double &vx, const double &wz)
86  {
87  if( is_enabled ) {
88  //get current time
89  ecl::TimeStamp curr_timestamp;
90  //get time difference
91  ecl::TimeStamp duration = curr_timestamp - last_timestamp;
92  //calculate acceleration
93  double linear_acceleration = ((double)(vx - last_vx)) / duration; // in [m/s^2]
94  double angular_acceleration = ((double)(wz - last_wz)) / duration; // in [rad/s^2]
95 
96  //std::ostringstream oss;
97  //oss << std::fixed << std::setprecision(4);
98  //oss << "[" << std::setw(6) << (double)duration << "]";
99  //oss << "[" << std::setw(6) << last_vx << ", " << std::setw(6) << last_wz << "]";
100  //oss << "[" << std::setw(6) << vx << ", " << std::setw(6) << wz << "]";
101  //oss << "[" << std::setw(6) << linear_acceleration << ", " << std::setw(6) << angular_acceleration << "]";
102 
103  if( linear_acceleration > linear_acceleration_max )
105  else if( linear_acceleration < linear_deceleration_max )
107  else
108  command_vx = vx;
110 
111  if( angular_acceleration > angular_acceleration_max )
113  else if( angular_acceleration < angular_deceleration_max )
115  else
116  command_wz = wz;
118 
119  last_timestamp = curr_timestamp;
120 
121  //oss << "[" << std::setw(6) << command_vx << ", " << std::setw(6) << command_wz << "]";
122  //std::cout << oss.str() << std::endl;
123 
124  std::vector<double> ret_val;
125  ret_val.push_back(command_vx);
126  ret_val.push_back(command_wz);
127  return ret_val;
128  }
129 
130  return {};
131  }
132 
133 private:
134  bool is_enabled;
135  short last_speed;
136  short last_radius;
137 // unsigned short last_timestamp;
138  ecl::TimeStamp last_timestamp;
139 
140  double last_vx, last_wz; // In [m/s] and [rad/s]
141  double command_vx, command_wz; // In [m/s] and [rad/s]
142  double linear_acceleration_max, linear_deceleration_max; // In [m/s^2]
143  double angular_acceleration_max, angular_deceleration_max; // In [rad/s^2]
144 };
145 
146 } // namespace kobuki
147 
148 #endif /* KOBUKI_ACCELERATION_LIMITER__HPP_ */
kobuki::AccelerationLimiter::command_wz
double command_wz
Definition: acceleration_limiter.hpp:155
kobuki::AccelerationLimiter::AccelerationLimiter
AccelerationLimiter()
Definition: acceleration_limiter.hpp:66
kobuki
Definition: command.hpp:31
kobuki::AccelerationLimiter::last_speed
short last_speed
Definition: acceleration_limiter.hpp:149
kobuki::AccelerationLimiter::last_wz
double last_wz
Definition: acceleration_limiter.hpp:154
kobuki::AccelerationLimiter::last_radius
short last_radius
Definition: acceleration_limiter.hpp:150
kobuki::AccelerationLimiter::init
void init(bool enable_acceleration_limiter, double linear_acceleration_max_=0.5, double angular_acceleration_max_=3.5, double linear_deceleration_max_=-0.5 *1.2, double angular_deceleration_max_=-3.5 *1.2)
Definition: acceleration_limiter.hpp:77
kobuki::AccelerationLimiter::is_enabled
bool is_enabled
Definition: acceleration_limiter.hpp:148
kobuki::AccelerationLimiter::last_timestamp
ecl::TimeStamp last_timestamp
Definition: acceleration_limiter.hpp:152
kobuki::AccelerationLimiter::angular_acceleration_max
double angular_acceleration_max
Definition: acceleration_limiter.hpp:157
kobuki::AccelerationLimiter::last_vx
double last_vx
Definition: acceleration_limiter.hpp:154
kobuki::AccelerationLimiter::command_vx
double command_vx
Definition: acceleration_limiter.hpp:155
kobuki::AccelerationLimiter::angular_deceleration_max
double angular_deceleration_max
Definition: acceleration_limiter.hpp:157
kobuki::AccelerationLimiter::isEnabled
bool isEnabled() const
Definition: acceleration_limiter.hpp:88
kobuki::AccelerationLimiter::linear_deceleration_max
double linear_deceleration_max
Definition: acceleration_limiter.hpp:156
kobuki::AccelerationLimiter::limit
std::vector< double > limit(const std::vector< double > &command)
Limits the input velocity commands if gatekeeper is enabled.
Definition: acceleration_limiter.hpp:97
kobuki::AccelerationLimiter::linear_acceleration_max
double linear_acceleration_max
Definition: acceleration_limiter.hpp:156
time.hpp
ecl


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14