Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions nav2_velocity_smoother/src/velocity_smoother.cpp
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
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_;
}
Comment on lines +206 to +223

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
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_;
}
double v_component_max = -decel / smoothing_frequency_;
double v_component_min = decel / smoothing_frequency_;
// 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
if (v_curr * v_cmd >= 0.0 && abs(v_cmd) >= abs(v_curr)) {
v_component_max = accel / smoothing_frequency_;
v_component_min = -accel / smoothing_frequency_;
}

Above reads a little better for me as it shows there is one well defined case to ever accelerate at a glance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reads better but less efficient, v_component_max / v_component_min are computed twice ~50% of the time


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

Expand Down