@@ -76,36 +76,41 @@ MPCTrajectory KinematicsBicycleModel::calculatePredictedTrajectoryInWorldCoordin
76
76
const MPCTrajectory & reference_trajectory, const double dt) const
77
77
{
78
78
// 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.
81
86
82
87
const auto & t = reference_trajectory;
83
88
84
89
// 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 ();
87
92
const auto lateral_error_0 = x0 (0 );
88
93
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
92
97
return state;
93
98
}();
94
99
95
100
// update state in the world coordinate
96
101
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,
98
103
const double velocity) {
99
104
const auto yaw = state_w (2 );
100
105
101
- Eigen::VectorXd dstate = Eigen::VectorXd ::Zero (4 );
106
+ Eigen::Vector3d dstate = Eigen::Vector3d ::Zero ();
102
107
dstate (0 ) = velocity * std::cos (yaw);
103
108
dstate (1 ) = velocity * std::sin (yaw);
104
109
dstate (2 ) = velocity * std::tan (input) / m_wheelbase;
105
110
106
111
// Note: don't do "return state_w + dstate * dt", which does not work due to the lazy evaluation
107
112
// in Eigen.
108
- const Eigen::VectorXd next_state = state_w + dstate * dt;
113
+ const Eigen::Vector3d next_state = state_w + dstate * dt;
109
114
return next_state;
110
115
};
111
116
0 commit comments