Skip to content

Commit 2594504

Browse files
fix(autoware_mpc_lateral_controller): replace Eigen::VectorXd with Eigen::Vector3d for state representation (autowarefoundation#10235)
* fix(autoware_mpc_lateral_controller): replace Eigen::VectorXd with Eigen::Vector3d for state representation Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp> * docs(autoware_mpc_lateral_controller): update comments for state representation and discretization considerations Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp> --------- Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
1 parent c3134c2 commit 2594504

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

control/autoware_mpc_lateral_controller/src/vehicle_model/vehicle_model_bicycle_kinematics.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,41 @@ MPCTrajectory KinematicsBicycleModel::calculatePredictedTrajectoryInWorldCoordin
7676
const MPCTrajectory & reference_trajectory, const double dt) const
7777
{
7878
// Calculate predicted state in world coordinate since there is modeling errors in Frenet
79-
// Relative coordinate x = [lat_err, yaw_err, steer]
80-
// World coordinate x = [x, y, yaw, steer]
79+
// Relative coordinate state = [lat_err, yaw_err, steer]
80+
// World coordinate state_w = [x, y, yaw]
81+
82+
// Note: Ideally, the first-order delay of the steering should be considered, as in the control
83+
// model. However, significant accuracy degradation was observed when discretizing with a long dt,
84+
// so it has been ignored here. If the accuracy of the discretization improves,an appropriate
85+
// model should be considered.
8186

8287
const auto & t = reference_trajectory;
8388

8489
// create initial state in the world coordinate
85-
Eigen::VectorXd state_w = [&]() {
86-
Eigen::VectorXd state = Eigen::VectorXd::Zero(3);
90+
Eigen::Vector3d state_w = [&]() {
91+
Eigen::Vector3d state = Eigen::Vector3d::Zero();
8792
const auto lateral_error_0 = x0(0);
8893
const auto yaw_error_0 = x0(1);
89-
state(0, 0) = t.x.at(0) - std::sin(t.yaw.at(0)) * lateral_error_0; // world-x
90-
state(1, 0) = t.y.at(0) + std::cos(t.yaw.at(0)) * lateral_error_0; // world-y
91-
state(2, 0) = t.yaw.at(0) + yaw_error_0; // world-yaw
94+
state(0) = t.x.at(0) - std::sin(t.yaw.at(0)) * lateral_error_0; // world-x
95+
state(1) = t.y.at(0) + std::cos(t.yaw.at(0)) * lateral_error_0; // world-y
96+
state(2) = t.yaw.at(0) + yaw_error_0; // world-yaw
9297
return state;
9398
}();
9499

95100
// update state in the world coordinate
96101
const auto updateState = [&](
97-
const Eigen::VectorXd & state_w, const double & input, const double dt,
102+
const Eigen::Vector3d & state_w, const double & input, const double dt,
98103
const double velocity) {
99104
const auto yaw = state_w(2);
100105

101-
Eigen::VectorXd dstate = Eigen::VectorXd::Zero(4);
106+
Eigen::Vector3d dstate = Eigen::Vector3d::Zero();
102107
dstate(0) = velocity * std::cos(yaw);
103108
dstate(1) = velocity * std::sin(yaw);
104109
dstate(2) = velocity * std::tan(input) / m_wheelbase;
105110

106111
// Note: don't do "return state_w + dstate * dt", which does not work due to the lazy evaluation
107112
// in Eigen.
108-
const Eigen::VectorXd next_state = state_w + dstate * dt;
113+
const Eigen::Vector3d next_state = state_w + dstate * dt;
109114
return next_state;
110115
};
111116

0 commit comments

Comments
 (0)