Go to the documentation of this file.00001
00009
00010
00011
00012
00013 #ifndef KOBUKI_ACCELERATION_LIMITER_HPP_
00014 #define KOBUKI_ACCELERATION_LIMITER_HPP_
00015
00016
00017
00018
00019
00020 #include <vector>
00021 #include <iomanip>
00022 #include <sstream>
00023 #include <iostream>
00024 #include <stdint.h>
00025 #include <ecl/time.hpp>
00026
00027
00028
00029
00030
00031 namespace kobuki {
00032
00033
00034
00035
00036
00050 class AccelerationLimiter {
00051 public:
00052 AccelerationLimiter() :
00053 is_enabled(true),
00054 last_speed(0),
00055 last_timestamp(ecl::TimeStamp())
00056 {}
00057 void init(bool enable_acceleration_limiter
00058 , double linear_acceleration_max_= 0.5, double angular_acceleration_max_= 3.5
00059 , double linear_deceleration_max_=-0.5*1.2, double angular_deceleration_max_=-3.5*1.2)
00060 {
00061 is_enabled = enable_acceleration_limiter;
00062 linear_acceleration_max = linear_acceleration_max_ ;
00063 linear_deceleration_max = linear_deceleration_max_ ;
00064 angular_acceleration_max = angular_acceleration_max_;
00065 angular_deceleration_max = angular_deceleration_max_;
00066 }
00067
00068 bool isEnabled() const { return is_enabled; }
00069
00078 std::vector<double> limit(const std::vector<double> &command) { return limit(command[0], command[1]); }
00079
00080 std::vector<double> limit(const double &vx, const double &wz)
00081 {
00082 if( is_enabled ) {
00083
00084 ecl::TimeStamp curr_timestamp;
00085
00086 ecl::TimeStamp duration = curr_timestamp - last_timestamp;
00087
00088 double linear_acceleration = ((double)(vx - last_vx)) / duration;
00089 double angular_acceleration = ((double)(wz - last_wz)) / duration;
00090
00091
00092
00093
00094
00095
00096
00097
00098 if( linear_acceleration > linear_acceleration_max )
00099 command_vx = last_vx + linear_acceleration_max * duration;
00100 else if( linear_acceleration < linear_deceleration_max )
00101 command_vx = last_vx + linear_deceleration_max * duration;
00102 else
00103 command_vx = vx;
00104 last_vx = command_vx;
00105
00106 if( angular_acceleration > angular_acceleration_max )
00107 command_wz = last_wz + angular_acceleration_max * duration;
00108 else if( angular_acceleration < angular_deceleration_max )
00109 command_wz = last_wz + angular_deceleration_max * duration;
00110 else
00111 command_wz = wz;
00112 last_wz = command_wz;
00113
00114 last_timestamp = curr_timestamp;
00115
00116
00117
00118
00119 std::vector<double> ret_val;
00120 ret_val.push_back(command_vx);
00121 ret_val.push_back(command_wz);
00122 return ret_val;
00123 }
00124 }
00125
00126 private:
00127 bool is_enabled;
00128 short last_speed;
00129 short last_radius;
00130
00131 ecl::TimeStamp last_timestamp;
00132
00133 double last_vx, last_wz;
00134 double command_vx, command_wz;
00135 double linear_acceleration_max, linear_deceleration_max;
00136 double angular_acceleration_max, angular_deceleration_max;
00137 };
00138
00139 }
00140
00141 #endif