Skip to content

Commit b17e42e

Browse files
committed
Revert "fix(autoware_mpc_lateral_controller): delete the zero speed constraint (#7673)"
This reverts commit 69258bd.
1 parent f28ccd8 commit b17e42e

File tree

2 files changed

+18
-7
lines changed
  • control/autoware_mpc_lateral_controller

2 files changed

+18
-7
lines changed

control/autoware_mpc_lateral_controller/include/autoware/mpc_lateral_controller/mpc.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class MPC
271271
*/
272272
std::pair<bool, VectorXd> executeOptimization(
273273
const MPCMatrix & mpc_matrix, const VectorXd & x0, const double prediction_dt,
274-
const MPCTrajectory & trajectory);
274+
const MPCTrajectory & trajectory, const double current_velocity);
275275

276276
/**
277277
* @brief Resample the trajectory with the MPC resampling time.
@@ -386,7 +386,8 @@ class MPC
386386
* @param reference_trajectory The reference trajectory.
387387
* @param current_velocity current velocity of ego.
388388
*/
389-
VectorXd calcSteerRateLimitOnTrajectory(const MPCTrajectory & trajectory) const;
389+
VectorXd calcSteerRateLimitOnTrajectory(
390+
const MPCTrajectory & trajectory, const double current_velocity) const;
390391

391392
//!< @brief logging with warn and return false
392393
template <typename... Args>

control/autoware_mpc_lateral_controller/src/mpc.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ bool MPC::calculateMPC(
7676
const auto mpc_matrix = generateMPCMatrix(mpc_resampled_ref_trajectory, prediction_dt);
7777

7878
// solve Optimization problem
79-
const auto [success_opt, Uex] =
80-
executeOptimization(mpc_matrix, x0_delayed, prediction_dt, mpc_resampled_ref_trajectory);
79+
const auto [success_opt, Uex] = executeOptimization(
80+
mpc_matrix, x0_delayed, prediction_dt, mpc_resampled_ref_trajectory,
81+
current_kinematics.twist.twist.linear.x);
8182
if (!success_opt) {
8283
return fail_warn_throttle("optimization failed. Stop MPC.");
8384
}
@@ -543,7 +544,8 @@ MPCMatrix MPC::generateMPCMatrix(
543544
* [ -au_lim * dt ] < [uN-uN-1] < [ au_lim * dt ] (*N... DIM_U)
544545
*/
545546
std::pair<bool, VectorXd> MPC::executeOptimization(
546-
const MPCMatrix & m, const VectorXd & x0, const double prediction_dt, const MPCTrajectory & traj)
547+
const MPCMatrix & m, const VectorXd & x0, const double prediction_dt, const MPCTrajectory & traj,
548+
const double current_velocity)
547549
{
548550
VectorXd Uex;
549551

@@ -576,7 +578,7 @@ std::pair<bool, VectorXd> MPC::executeOptimization(
576578
VectorXd ub = VectorXd::Constant(DIM_U_N, m_steer_lim); // max steering angle
577579

578580
// steering angle rate limit
579-
VectorXd steer_rate_limits = calcSteerRateLimitOnTrajectory(traj);
581+
VectorXd steer_rate_limits = calcSteerRateLimitOnTrajectory(traj, current_velocity);
580582
VectorXd ubA = steer_rate_limits * prediction_dt;
581583
VectorXd lbA = -steer_rate_limits * prediction_dt;
582584
ubA(0) = m_raw_steer_cmd_prev + steer_rate_limits(0) * m_ctrl_period;
@@ -728,7 +730,8 @@ double MPC::calcDesiredSteeringRate(
728730
return steer_rate;
729731
}
730732

731-
VectorXd MPC::calcSteerRateLimitOnTrajectory(const MPCTrajectory & trajectory) const
733+
VectorXd MPC::calcSteerRateLimitOnTrajectory(
734+
const MPCTrajectory & trajectory, const double current_velocity) const
732735
{
733736
const auto interp = [&](const auto & steer_rate_limit_map, const auto & current) {
734737
std::vector<double> reference, limits;
@@ -762,6 +765,13 @@ VectorXd MPC::calcSteerRateLimitOnTrajectory(const MPCTrajectory & trajectory) c
762765
return reference.back();
763766
};
764767

768+
// when the vehicle is stopped, no steering rate limit.
769+
constexpr double steer_rate_lim = 5.0;
770+
const bool is_vehicle_stopped = std::fabs(current_velocity) < 0.01;
771+
if (is_vehicle_stopped) {
772+
return steer_rate_lim * VectorXd::Ones(m_param.prediction_horizon);
773+
}
774+
765775
// calculate steering rate limit
766776
VectorXd steer_rate_limits = VectorXd::Zero(m_param.prediction_horizon);
767777
for (int i = 0; i < m_param.prediction_horizon; ++i) {

0 commit comments

Comments
 (0)