Skip to content

Commit d844b62

Browse files
fix(autoware_mpc_lateral_controller): replace Eigen::VectorXd with Eigen::Vector3d for state representation
Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
1 parent 3b0f98e commit d844b62

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

control/autoware_mpc_lateral_controller/src/vehicle_model/vehicle_model_bicycle_kinematics.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,30 @@ MPCTrajectory KinematicsBicycleModel::calculatePredictedTrajectoryInWorldCoordin
8282
const auto & t = reference_trajectory;
8383

8484
// create initial state in the world coordinate
85-
Eigen::VectorXd state_w = [&]() {
86-
Eigen::VectorXd state = Eigen::VectorXd::Zero(3);
85+
Eigen::Vector3d state_w = [&]() {
86+
Eigen::Vector3d state = Eigen::Vector3d::Zero();
8787
const auto lateral_error_0 = x0(0);
8888
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
89+
state(0) = t.x.at(0) - std::sin(t.yaw.at(0)) * lateral_error_0; // world-x
90+
state(1) = t.y.at(0) + std::cos(t.yaw.at(0)) * lateral_error_0; // world-y
91+
state(2) = t.yaw.at(0) + yaw_error_0; // world-yaw
9292
return state;
9393
}();
9494

9595
// update state in the world coordinate
9696
const auto updateState = [&](
97-
const Eigen::VectorXd & state_w, const double & input, const double dt,
97+
const Eigen::Vector3d & state_w, const double & input, const double dt,
9898
const double velocity) {
9999
const auto yaw = state_w(2);
100100

101-
Eigen::VectorXd dstate = Eigen::VectorXd::Zero(4);
101+
Eigen::Vector3d dstate = Eigen::Vector3d::Zero();
102102
dstate(0) = velocity * std::cos(yaw);
103103
dstate(1) = velocity * std::sin(yaw);
104104
dstate(2) = velocity * std::tan(input) / m_wheelbase;
105105

106106
// Note: don't do "return state_w + dstate * dt", which does not work due to the lazy evaluation
107107
// in Eigen.
108-
const Eigen::VectorXd next_state = state_w + dstate * dt;
108+
const Eigen::Vector3d next_state = state_w + dstate * dt;
109109
return next_state;
110110
};
111111

0 commit comments

Comments
 (0)