@@ -76,8 +76,9 @@ bool MPC::calculateMPC(
76
76
const auto mpc_matrix = generateMPCMatrix (mpc_resampled_ref_trajectory, prediction_dt);
77
77
78
78
// 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 );
81
82
if (!success_opt) {
82
83
return fail_warn_throttle (" optimization failed. Stop MPC." );
83
84
}
@@ -543,7 +544,8 @@ MPCMatrix MPC::generateMPCMatrix(
543
544
* [ -au_lim * dt ] < [uN-uN-1] < [ au_lim * dt ] (*N... DIM_U)
544
545
*/
545
546
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)
547
549
{
548
550
VectorXd Uex;
549
551
@@ -576,7 +578,7 @@ std::pair<bool, VectorXd> MPC::executeOptimization(
576
578
VectorXd ub = VectorXd::Constant (DIM_U_N, m_steer_lim); // max steering angle
577
579
578
580
// steering angle rate limit
579
- VectorXd steer_rate_limits = calcSteerRateLimitOnTrajectory (traj);
581
+ VectorXd steer_rate_limits = calcSteerRateLimitOnTrajectory (traj, current_velocity );
580
582
VectorXd ubA = steer_rate_limits * prediction_dt;
581
583
VectorXd lbA = -steer_rate_limits * prediction_dt;
582
584
ubA (0 ) = m_raw_steer_cmd_prev + steer_rate_limits (0 ) * m_ctrl_period;
@@ -728,7 +730,8 @@ double MPC::calcDesiredSteeringRate(
728
730
return steer_rate;
729
731
}
730
732
731
- VectorXd MPC::calcSteerRateLimitOnTrajectory (const MPCTrajectory & trajectory) const
733
+ VectorXd MPC::calcSteerRateLimitOnTrajectory (
734
+ const MPCTrajectory & trajectory, const double current_velocity) const
732
735
{
733
736
const auto interp = [&](const auto & steer_rate_limit_map, const auto & current) {
734
737
std::vector<double > reference, limits;
@@ -762,6 +765,13 @@ VectorXd MPC::calcSteerRateLimitOnTrajectory(const MPCTrajectory & trajectory) c
762
765
return reference.back ();
763
766
};
764
767
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
+
765
775
// calculate steering rate limit
766
776
VectorXd steer_rate_limits = VectorXd::Zero (m_param.prediction_horizon );
767
777
for (int i = 0 ; i < m_param.prediction_horizon ; ++i) {
0 commit comments