@@ -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