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
35 changes: 30 additions & 5 deletions nav2_velocity_smoother/src/velocity_smoother.cpp
AlexeyMerzlyakov marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -182,9 +182,21 @@ double VelocitySmoother::findEtaConstraint(
const double v_curr, const double v_cmd, const double accel, const double decel)
{
// Exploiting vector scaling properties
const double v_component_max = accel / smoothing_frequency_;
const double v_component_min = decel / smoothing_frequency_;
const double dv = v_cmd - v_curr;
double dv = v_cmd - v_curr;

SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
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 (abs(v_cmd) >= abs(v_curr) && v_curr * v_cmd >= 0.0) {
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_;
}

if (dv > v_component_max) {
return v_component_max / dv;
Expand All @@ -202,8 +214,21 @@ 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 (abs(v_cmd) >= abs(v_curr) && v_curr * v_cmd >= 0.0) {
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_;
}

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

Expand Down