Skip to content

Commit 1cd4ca1

Browse files
mkqudashmpwk
authored andcommitted
fix(mpc_lateral_controller): prevent unstable steering command while stopped (autowarefoundation#9690)
* modify logic of function isStoppedState Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * use a constant distance margin instead of wheelbase length Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * add comment to implementation Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> --------- Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp>
1 parent 9313d1d commit 1cd4ca1

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

control/autoware_mpc_lateral_controller/src/mpc_lateral_controller.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,18 @@ Lateral MpcLateralController::getInitialControlCommand() const
427427

428428
bool MpcLateralController::isStoppedState() const
429429
{
430+
const double current_vel = m_current_kinematic_state.twist.twist.linear.x;
430431
// 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) {
432434
return false;
433435
}
434436

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+
435442
// Note: This function used to take into account the distance to the stop line
436443
// for the stop state judgement. However, it has been removed since the steering
437444
// control was turned off when approaching/exceeding the stop line on a curve or
@@ -440,21 +447,23 @@ bool MpcLateralController::isStoppedState() const
440447
m_current_trajectory.points, m_current_kinematic_state.pose.pose, m_ego_nearest_dist_threshold,
441448
m_ego_nearest_yaw_threshold);
442449

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+
});
450465

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;
458467
}
459468

460469
Lateral MpcLateralController::createCtrlCmdMsg(const Lateral & ctrl_cmd)

0 commit comments

Comments
 (0)