35 #ifndef DWB_PLUGINS__ONE_D_VELOCITY_ITERATOR_HPP_
36 #define DWB_PLUGINS__ONE_D_VELOCITY_ITERATOR_HPP_
44 const double EPSILON = 1E-5;
56 inline double projectVelocity(
double v0,
double accel,
double decel,
double dt,
double target)
61 return std::min(target, v1);
64 return std::max(target, v1);
96 double current,
double min,
double max,
double acc_limit,
double decel_limit,
double acc_time,
101 }
else if (current > max) {
104 max_vel_ = projectVelocity(current, acc_limit, decel_limit, acc_time, max);
105 min_vel_ = projectVelocity(current, acc_limit, decel_limit, acc_time, min);
108 if (fabs(min_vel_ - max_vel_) < EPSILON) {
112 num_samples = std::max(2, num_samples);
115 increment_ = (max_vel_ - min_vel_) / std::max(1, (num_samples - 1));
123 if (return_zero_now_) {
return 0.0;}
132 if (return_zero_ && current_ < 0.0 && current_ + increment_ > 0.0 &&
133 current_ + increment_ <= max_vel_ + EPSILON)
135 return_zero_now_ =
true;
136 return_zero_ =
false;
138 current_ += increment_;
139 return_zero_now_ =
false;
151 return_zero_now_ =
false;
159 return current_ > max_vel_ + EPSILON;
163 bool return_zero_, return_zero_now_;
164 double min_vel_, max_vel_;
An iterator for generating a number of samples in a range.
void reset()
Reset back to the first velocity.
OneDVelocityIterator & operator++()
Increment the iterator.
double getVelocity() const
Get the next velocity available.
OneDVelocityIterator(double current, double min, double max, double acc_limit, double decel_limit, double acc_time, int num_samples)
Constructor for the velocity iterator.