Skip to content

Commit df22f58

Browse files
committed
implement adt kinematics foc mpc vehicle_model
Signed-off-by: Autumn60 <harada.akiro@gmail.com>
1 parent 968219d commit df22f58

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

control/autoware_mpc_lateral_controller/include/autoware/mpc_lateral_controller/vehicle_model/vehicle_model_adt_kinematics.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class KinematicsAdtModel : public VehicleModelInterface
109109
double m_rear_wheelbase; //!< @brief rear wheelbase length [m]
110110
double m_steer_lim; //!< @brief steering angle limit [rad]
111111
double m_steer_tau; //!< @brief steering time constant for 1d-model [s]
112+
113+
const double m_wheelbase_diff;
114+
const double m_wheelbase_squared_diff;
112115
};
113116
} // namespace autoware::motion::control::mpc_lateral_controller
114117
#endif // AUTOWARE__MPC_LATERAL_CONTROLLER__VEHICLE_MODEL__VEHICLE_MODEL_ADT_KINEMATICS_HPP_

control/autoware_mpc_lateral_controller/src/vehicle_model/vehicle_model_adt_kinematics.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ KinematicsAdtModel::KinematicsAdtModel(
2222
const double front_wheelbase, const double rear_wheelbase, const double steer_lim,
2323
const double steer_tau)
2424
: VehicleModelInterface(
25-
/* dim_x */ 3, /* dim_u */ 1, /* dim_y */ 2, front_wheelbase + rear_wheelbase)
25+
/* dim_x */ 3, /* dim_u */ 1, /* dim_y */ 2, front_wheelbase + rear_wheelbase),
26+
m_wheelbase_diff(front_wheelbase - rear_wheelbase),
27+
m_wheelbase_squared_diff(rear_wheelbase * rear_wheelbase - front_wheelbase * front_wheelbase)
2628
{
2729
m_front_wheelbase = front_wheelbase;
2830
m_rear_wheelbase = rear_wheelbase;
@@ -37,27 +39,34 @@ void KinematicsAdtModel::calculateDiscreteMatrix(
3739
auto sign = [](double x) { return (x > 0.0) - (x < 0.0); };
3840

3941
/* Linearize delta around delta_r (reference delta) */
40-
double delta_r = atan(m_wheelbase * m_curvature);
42+
const double curvature_squared = m_curvature * m_curvature;
43+
double delta_r = std::atan(
44+
(1.0 - std::sqrt(m_wheelbase_squared_diff * curvature_squared + 1.0)) /
45+
(m_wheelbase_diff * m_curvature));
4146
if (std::abs(delta_r) >= m_steer_lim) {
4247
delta_r = m_steer_lim * static_cast<double>(sign(delta_r));
4348
}
44-
double cos_delta_r_squared_inv = 1 / (cos(delta_r) * cos(delta_r));
49+
4550
double velocity = m_velocity;
4651
if (std::abs(m_velocity) < 1e-04) {
4752
velocity = 1e-04 * (m_velocity >= 0 ? 1 : -1);
4853
}
4954

50-
a_d << 0.0, velocity, 0.0, 0.0, 0.0, velocity / m_wheelbase * cos_delta_r_squared_inv, 0.0, 0.0,
51-
-1.0 / m_steer_tau;
55+
const double front_wheelbase_c_rear_wheelbase_inv =
56+
1.0 / (m_front_wheelbase + m_rear_wheelbase * cos(delta_r));
57+
58+
const double turning_velocity = velocity * sin(delta_r) * front_wheelbase_c_rear_wheelbase_inv;
59+
const double pd_turning_velocity =
60+
velocity * (m_front_wheelbase * cos(delta_r) + m_rear_wheelbase) *
61+
front_wheelbase_c_rear_wheelbase_inv * front_wheelbase_c_rear_wheelbase_inv;
62+
63+
a_d << 0.0, velocity, 0.0, 0.0, 0.0, pd_turning_velocity, 0.0, 0.0, -1.0 / m_steer_tau;
5264

5365
b_d << 0.0, 0.0, 1.0 / m_steer_tau;
5466

5567
c_d << 1.0, 0.0, 0.0, 0.0, 1.0, 0.0;
5668

57-
w_d << 0.0,
58-
-velocity * m_curvature +
59-
velocity / m_wheelbase * (tan(delta_r) - delta_r * cos_delta_r_squared_inv),
60-
0.0;
69+
w_d << 0.0, -velocity * m_curvature + turning_velocity - pd_turning_velocity * delta_r, 0.0;
6170

6271
// bilinear discretization for ZOH system
6372
// no discretization is needed for Cd
@@ -108,7 +117,8 @@ MPCTrajectory KinematicsAdtModel::calculatePredictedTrajectoryInWorldCoordinate(
108117
Eigen::VectorXd dstate = Eigen::VectorXd::Zero(4);
109118
dstate(0) = velocity * std::cos(yaw);
110119
dstate(1) = velocity * std::sin(yaw);
111-
dstate(2) = velocity * std::tan(steer) / m_wheelbase;
120+
dstate(2) =
121+
velocity * std::sin(steer) / (m_front_wheelbase + m_rear_wheelbase * std::cos(steer));
112122
dstate(3) = -(steer - desired_steer) / m_steer_tau;
113123

114124
// Note: don't do "return state_w + dstate * dt", which does not work due to the lazy evaluation

0 commit comments

Comments
 (0)