@@ -427,11 +427,18 @@ Lateral MpcLateralController::getInitialControlCommand() const
427
427
428
428
bool MpcLateralController::isStoppedState () const
429
429
{
430
+ const double current_vel = m_current_kinematic_state.twist .twist .linear .x ;
430
431
// If the nearest index is not found, return false
431
- if (m_current_trajectory.points .empty ()) {
432
+ if (
433
+ m_current_trajectory.points .empty () || std::fabs (current_vel) > m_stop_state_entry_ego_speed) {
432
434
return false ;
433
435
}
434
436
437
+ const auto latest_published_cmd = m_ctrl_cmd_prev; // use prev_cmd as a latest published command
438
+ if (m_keep_steer_control_until_converged && !isSteerConverged (latest_published_cmd)) {
439
+ return false ; // not stopState: keep control
440
+ }
441
+
435
442
// Note: This function used to take into account the distance to the stop line
436
443
// for the stop state judgement. However, it has been removed since the steering
437
444
// control was turned off when approaching/exceeding the stop line on a curve or
@@ -440,21 +447,23 @@ bool MpcLateralController::isStoppedState() const
440
447
m_current_trajectory.points , m_current_kinematic_state.pose .pose , m_ego_nearest_dist_threshold,
441
448
m_ego_nearest_yaw_threshold);
442
449
443
- const double current_vel = m_current_kinematic_state.twist .twist .linear .x ;
444
- const double target_vel = m_current_trajectory.points .at (nearest).longitudinal_velocity_mps ;
445
-
446
- const auto latest_published_cmd = m_ctrl_cmd_prev; // use prev_cmd as a latest published command
447
- if (m_keep_steer_control_until_converged && !isSteerConverged (latest_published_cmd)) {
448
- return false ; // not stopState: keep control
449
- }
450
+ // It is possible that stop is executed earlier than stop point, and velocity controller
451
+ // will not start when the distance from ego to stop point is less than 0.5 meter.
452
+ // So we use a distance margin to ensure we can detect stopped state.
453
+ static constexpr double distance_margin = 1.0 ;
454
+ const double target_vel = std::invoke ([&]() -> double {
455
+ auto min_vel = m_current_trajectory.points .at (nearest).longitudinal_velocity_mps ;
456
+ auto covered_distance = 0.0 ;
457
+ for (auto i = nearest + 1 ; i < m_current_trajectory.points .size (); ++i) {
458
+ min_vel = std::min (min_vel, m_current_trajectory.points .at (i).longitudinal_velocity_mps );
459
+ covered_distance += autoware::universe_utils::calcDistance2d (
460
+ m_current_trajectory.points .at (i - 1 ).pose , m_current_trajectory.points .at (i).pose );
461
+ if (covered_distance > distance_margin) break ;
462
+ }
463
+ return min_vel;
464
+ });
450
465
451
- if (
452
- std::fabs (current_vel) < m_stop_state_entry_ego_speed &&
453
- std::fabs (target_vel) < m_stop_state_entry_target_speed) {
454
- return true ;
455
- } else {
456
- return false ;
457
- }
466
+ return std::fabs (target_vel) < m_stop_state_entry_target_speed;
458
467
}
459
468
460
469
Lateral MpcLateralController::createCtrlCmdMsg (const Lateral & ctrl_cmd)
0 commit comments