Skip to content

Commit 87e814a

Browse files
fix(autoware_mpc_lateral_controller): fix calculation method of predicted trajectory (autowarefoundation#9048)
* fix(vehicle_model): fix calculation method of predicted trajectory Signed-off-by: Kyoichi Sugahara <kyoichi.sugahara@tier4.jp> --------- Signed-off-by: Kyoichi Sugahara <kyoichi.sugahara@tier4.jp>
1 parent 5db3bae commit 87e814a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

control/autoware_mpc_lateral_controller/src/vehicle_model/vehicle_model_bicycle_kinematics.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,25 @@ MPCTrajectory KinematicsBicycleModel::calculatePredictedTrajectoryInWorldCoordin
8383

8484
// create initial state in the world coordinate
8585
Eigen::VectorXd state_w = [&]() {
86-
Eigen::VectorXd state = Eigen::VectorXd::Zero(4);
86+
Eigen::VectorXd state = Eigen::VectorXd::Zero(3);
8787
const auto lateral_error_0 = x0(0);
8888
const auto yaw_error_0 = x0(1);
8989
state(0, 0) = t.x.at(0) - std::sin(t.yaw.at(0)) * lateral_error_0; // world-x
9090
state(1, 0) = t.y.at(0) + std::cos(t.yaw.at(0)) * lateral_error_0; // world-y
9191
state(2, 0) = t.yaw.at(0) + yaw_error_0; // world-yaw
92-
state(3, 0) = x0(2); // steering
9392
return state;
9493
}();
9594

9695
// update state in the world coordinate
9796
const auto updateState = [&](
98-
const Eigen::VectorXd & state_w, const Eigen::MatrixXd & input,
99-
const double dt, const double velocity) {
97+
const Eigen::VectorXd & state_w, const double & input, const double dt,
98+
const double velocity) {
10099
const auto yaw = state_w(2);
101-
const auto steer = state_w(3);
102-
const auto desired_steer = input(0);
103100

104101
Eigen::VectorXd dstate = Eigen::VectorXd::Zero(4);
105102
dstate(0) = velocity * std::cos(yaw);
106103
dstate(1) = velocity * std::sin(yaw);
107-
dstate(2) = velocity * std::tan(steer) / m_wheelbase;
108-
dstate(3) = -(steer - desired_steer) / m_steer_tau;
104+
dstate(2) = velocity * std::tan(input) / m_wheelbase;
109105

110106
// Note: don't do "return state_w + dstate * dt", which does not work due to the lazy evaluation
111107
// in Eigen.
@@ -117,7 +113,7 @@ MPCTrajectory KinematicsBicycleModel::calculatePredictedTrajectoryInWorldCoordin
117113
const auto DIM_U = getDimU();
118114

119115
for (size_t i = 0; i < reference_trajectory.size(); ++i) {
120-
state_w = updateState(state_w, Uex.block(i * DIM_U, 0, DIM_U, 1), dt, t.vx.at(i));
116+
state_w = updateState(state_w, Uex(i * DIM_U, 0), dt, t.vx.at(i));
121117
mpc_predicted_trajectory.push_back(
122118
state_w(0), state_w(1), t.z.at(i), state_w(2), t.vx.at(i), t.k.at(i), t.smooth_k.at(i),
123119
t.relative_time.at(i));

0 commit comments

Comments
 (0)