Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[velocity_smoother] Fix accel and deccel inverted for negative speeds #3529

Merged
merged 13 commits into from
Apr 18, 2023
22 changes: 20 additions & 2 deletions nav2_velocity_smoother/src/velocity_smoother.cpp
AlexeyMerzlyakov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,26 @@ double VelocitySmoother::applyConstraints(
const double accel, const double decel, const double eta)
{
double dv = v_cmd - v_curr;
const double v_component_max = accel / smoothing_frequency_;
const double v_component_min = decel / smoothing_frequency_;

double v_component_max;
double v_component_min;

// Accelerating if magnitude of v_cmd is above magnitude of v_curr
// and if v_cmd and v_curr have the same sign (i.e. speed is NOT passing through 0.0)
// Deccelerating otherwise
doisyg marked this conversation as resolved.
Show resolved Hide resolved
if (v_curr * v_cmd >= 0.0) {
if (abs(v_cmd) >= abs(v_curr)) {
v_component_max = accel / smoothing_frequency_;
v_component_min = -accel / smoothing_frequency_;
} else {
v_component_max = -decel / smoothing_frequency_;
v_component_min = decel / smoothing_frequency_;
}
} else {
v_component_max = -decel / smoothing_frequency_;
v_component_min = decel / smoothing_frequency_;
}
doisyg marked this conversation as resolved.
Show resolved Hide resolved

return v_curr + std::clamp(eta * dv, v_component_min, v_component_max);
}

Expand Down