65 void predict(
float dx_local,
float dy_local,
float dtheta) {
67 if (std::abs(dtheta) < 1e-4f) {
68 s = 1.0f - (dtheta * dtheta) / 6.0f;
71 s = std::sin(dtheta) / dtheta;
72 c = (1.0f - std::cos(dtheta)) / dtheta;
75 Eigen::Vector2f local_d(dx_local, dy_local);
76 Eigen::Matrix2f R_arc;
78 Eigen::Vector2f arc_d = R_arc * local_d;
80 float prev_theta = x(2);
81 float cos_t = std::cos(prev_theta);
82 float sin_t = std::sin(prev_theta);
84 Eigen::Matrix2f R_global;
85 R_global << cos_t, sin_t, -sin_t, cos_t;
86 Eigen::Vector2f global_d = R_global * arc_d;
88 x.head<2>() += global_d;
90 x(2) = std::remainder(x(2), 2.0f * M_PI);
92 Eigen::Matrix3f F = Eigen::Matrix3f::Identity();
93 F(0, 2) = global_d.y();
94 F(1, 2) = -global_d.x();
96 Eigen::Matrix3f Q_step = Eigen::Matrix3f::Zero();
97 float var_x = xProcessNoise * std::abs(dx_local) + 1e-6f;
98 float var_y = yProcessNoise * std::abs(dy_local) + 1e-6f;
99 Eigen::Matrix2f Q_local;
100 Q_local << var_x, 0, 0, var_y;
102 Q_step.block<2, 2>(0, 0) = R_global * Q_local * R_global.transpose();
103 Q_step(2, 2) = thetaProcessNoise * std::abs(dtheta) + 1e-7f;
105 P = F * P * F.transpose() + Q_step;
115 float y = measured_theta - x(2);
116 y = std::remainder(y, 2.0f * M_PI);
117 float S = (H * P * H.transpose())(0, 0) + dynamic_R;
118 Eigen::Vector3f K = P * H.transpose() / S;
120 x(2) = std::remainder(x(2), 2.0f * M_PI);
121 P = (Eigen::Matrix3f::Identity() - K * H) * P;
136 const Eigen::VectorXf &measured_deltas,
137 float dx_local,
float dy_local,
float dtheta,
139 const int n =
static_cast<int>(configs.size());
140 if (n == 0 || measured_deltas.size() != n)
143 float cos_t = std::cos(theta);
144 float sin_t = std::sin(theta);
146 Eigen::MatrixXf H_tw(n, 3);
147 Eigen::VectorXf z_pred(n);
149 for (
int i = 0; i < n; ++i) {
150 float ox = configs[i].xOffset;
151 float oy = configs[i].yOffset;
154 z_pred(i) = dy_local - ox * dtheta;
160 z_pred(i) = dx_local + oy * dtheta;
167 Eigen::VectorXf y_innov = measured_deltas - z_pred;
168 Eigen::MatrixXf R_tw = Eigen::MatrixXf::Identity(n, n) * wheel_noise;
169 Eigen::MatrixXf S = H_tw * P * H_tw.transpose() + R_tw;
170 Eigen::MatrixXf K = P * H_tw.transpose() * S.inverse();
172 x(2) = std::remainder(x(2), 2.0f *
static_cast<float>(M_PI));
174 Eigen::Matrix3f I3 = Eigen::Matrix3f::Identity();
175 Eigen::Matrix3f IKH = I3 - K * H_tw;
176 P = IKH * P * IKH.transpose() + K * R_tw * K.transpose();