Skip to content

Commit 7e2c2cb

Browse files
authored
fix(motion_utils): properly use negative jerk in calculate_stop_distance (#870)
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent 14bf5e7 commit 7e2c2cb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

common/autoware_motion_utils/include/autoware/motion_utils/distance/distance.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace autoware::motion_utils
3434
* * If the vehicle reaches a full stop during phase 1 or phase 2, the calculation
3535
* terminates early and returns the exact distance covered up to the point where v = 0.
3636
*
37-
* @param current_vel Current longitudinal speed v₀ [m/s].
38-
* @param current_acc Current longitudinal acceleration a₀ [m/s²].
37+
* @param v0 Current longitudinal speed v₀ [m/s].
38+
* @param a0 Current longitudinal acceleration a₀ [m/s²].
3939
* @param decel_limit Maximum braking deceleration [m/s²]
4040
* @param jerk_limit Maximum braking jerk [m/s³]
4141
* @param initial_time_delay Latency before any braking jerk is applied t₁ [s]. Defaults to 0.0.
@@ -45,8 +45,8 @@ namespace autoware::motion_utils
4545
* Returns std::nullopt if the kinematic limits are invalid (e.g., limits are 0).
4646
*/
4747
[[nodiscard]] std::optional<double> calculate_stop_distance(
48-
const double current_vel, const double current_acc, const double acc_limit,
49-
const double jerk_limit, const double initial_time_delay = 0.0);
48+
const double v0, const double a0, const double decel_limit, const double jerk_limit,
49+
const double initial_time_delay = 0.0);
5050

5151
} // namespace autoware::motion_utils
5252

common/autoware_motion_utils/src/distance/distance.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,22 @@ std::optional<double> calcDecelDistWithJerkAndAccConstraints(
305305
if (v2 <= 0.0) {
306306
// The vehicle reaches v = 0 before hitting the maximum deceleration limit.
307307
// Solve for t where 0 = v1 + a1*t + 0.5*j*t^2
308-
const double discriminant = a1 * a1 - 2.0 * jerk_limit * v1;
308+
const double discriminant = a1 * a1 - 2.0 * negative_jerk_limit * v1;
309309

310310
// should be impossible
311311
if (discriminant < 0.0) {
312312
return std::nullopt;
313313
}
314314

315-
const double t2 = -(a1 + std::sqrt(discriminant)) / jerk_limit;
316-
const auto [x_stop, v_stop, a_stop] = update(x1, v1, a1, jerk_limit, t2);
315+
const double t2 = std::max(0.0, -(a1 + std::sqrt(discriminant)) / negative_jerk_limit);
316+
const auto [x_stop, v_stop, a_stop] = update(x1, v1, a1, negative_jerk_limit, t2);
317317

318318
return std::max(0.0, x_stop);
319319
}
320320

321321
// The vehicle successfully reaches the maximum deceleration limit.
322-
const double t2 = (negative_decel_limit - a1) / jerk_limit;
323-
const auto [x2, v2_final, a2_final] = update(x1, v1, a1, jerk_limit, t2);
322+
const double t2 = std::max(0.0, (negative_decel_limit - a1) / negative_jerk_limit);
323+
const auto [x2, v2_final, a2_final] = update(x1, v1, a1, negative_jerk_limit, t2);
324324

325325
// Phase 3: Constant maximum deceleration
326326
// Decelerate at acc_limit from v2_final down to 0.

0 commit comments

Comments
 (0)