ros2_control - rolling
speed_limiter.hpp
1 // Copyright 2020 PAL Robotics S.L.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 /*
16  * Author: Enrique Fernández
17  */
18 
19 #ifndef DIFF_DRIVE_CONTROLLER__SPEED_LIMITER_HPP_
20 #define DIFF_DRIVE_CONTROLLER__SPEED_LIMITER_HPP_
21 
22 #include <cmath>
23 
24 namespace diff_drive_controller
25 {
27 {
28 public:
42  bool has_velocity_limits = false, bool has_acceleration_limits = false,
43  bool has_jerk_limits = false, double min_velocity = NAN, double max_velocity = NAN,
44  double min_acceleration = NAN, double max_acceleration = NAN, double min_jerk = NAN,
45  double max_jerk = NAN);
46 
55  double limit(double & v, double v0, double v1, double dt);
56 
62  double limit_velocity(double & v);
63 
71  double limit_acceleration(double & v, double v0, double dt);
72 
82  double limit_jerk(double & v, double v0, double v1, double dt);
83 
84 private:
85  // Enable/Disable velocity/acceleration/jerk limits:
86  bool has_velocity_limits_;
87  bool has_acceleration_limits_;
88  bool has_jerk_limits_;
89 
90  // Velocity limits:
91  double min_velocity_;
92  double max_velocity_;
93 
94  // Acceleration limits:
95  double min_acceleration_;
96  double max_acceleration_;
97 
98  // Jerk limits:
99  double min_jerk_;
100  double max_jerk_;
101 };
102 
103 } // namespace diff_drive_controller
104 
105 #endif // DIFF_DRIVE_CONTROLLER__SPEED_LIMITER_HPP_
Definition: speed_limiter.hpp:27
double limit_jerk(double &v, double v0, double v1, double dt)
Limit the jerk.
Definition: speed_limiter.cpp:117
double limit(double &v, double v0, double v1, double dt)
Limit the velocity and acceleration.
Definition: speed_limiter.cpp:77
double limit_acceleration(double &v, double v0, double dt)
Limit the acceleration.
Definition: speed_limiter.cpp:100
SpeedLimiter(bool has_velocity_limits=false, bool has_acceleration_limits=false, bool has_jerk_limits=false, double min_velocity=NAN, double max_velocity=NAN, double min_acceleration=NAN, double max_acceleration=NAN, double min_jerk=NAN, double max_jerk=NAN)
Constructor.
Definition: speed_limiter.cpp:26
double limit_velocity(double &v)
Limit the velocity.
Definition: speed_limiter.cpp:88