33 void CpiV1::feed_IMU(
double t_0,
double t_1, Eigen::Matrix<double, 3, 1> w_m_0, Eigen::Matrix<double, 3, 1> a_m_0,
34 Eigen::Matrix<double, 3, 1> w_m_1, Eigen::Matrix<double, 3, 1> a_m_1) {
37 double delta_t = t_1 - t_0;
46 Eigen::Matrix<double, 3, 1> w_hat = w_m_0 -
b_w_lin;
47 Eigen::Matrix<double, 3, 1> a_hat = a_m_0 -
b_a_lin;
58 Eigen::Matrix<double, 3, 1> w_hatdt = w_hat * delta_t;
61 double w_1 = w_hat(0, 0);
62 double w_2 = w_hat(1, 0);
63 double w_3 = w_hat(2, 0);
66 double mag_w = w_hat.norm();
67 double w_dt = mag_w * delta_t;
70 bool small_w = (mag_w < 0.008726646);
73 double dt_2 = pow(delta_t, 2);
74 double cos_wt = cos(w_dt);
75 double sin_wt = sin(w_dt);
77 Eigen::Matrix<double, 3, 3> w_x =
skew_x(w_hat);
78 Eigen::Matrix<double, 3, 3> a_x =
skew_x(a_hat);
79 Eigen::Matrix<double, 3, 3> w_tx =
skew_x(w_hatdt);
80 Eigen::Matrix<double, 3, 3> w_x_2 = w_x * w_x;
87 Eigen::Matrix<double, 3, 3> R_tau2tau1 = small_w ?
eye3 - delta_t * w_x + (pow(delta_t, 2) / 2) * w_x_2
88 :
eye3 - (sin_wt / mag_w) * w_x + ((1.0 - cos_wt) / (pow(mag_w, 2.0))) * w_x_2;
91 Eigen::Matrix<double, 3, 3> R_k2tau1 = R_tau2tau1 *
R_k2tau;
92 Eigen::Matrix<double, 3, 3> R_tau12k = R_k2tau1.transpose();
101 f_1 = -(pow(delta_t, 3) / 3);
102 f_2 = (pow(delta_t, 4) / 8);
103 f_3 = -(pow(delta_t, 2) / 2);
104 f_4 = (pow(delta_t, 3) / 6);
106 f_1 = (w_dt * cos_wt - sin_wt) / (pow(mag_w, 3));
107 f_2 = (pow(w_dt, 2) - 2 * cos_wt - 2 * w_dt * sin_wt + 2) / (2 * pow(mag_w, 4));
108 f_3 = -(1 - cos_wt) / pow(mag_w, 2);
109 f_4 = (w_dt - sin_wt) / pow(mag_w, 3);
113 Eigen::Matrix<double, 3, 3> alpha_arg = ((dt_2 / 2.0) *
eye3 + f_1 * w_x + f_2 * w_x_2);
114 Eigen::Matrix<double, 3, 3> Beta_arg = (delta_t *
eye3 + f_3 * w_x + f_4 * w_x_2);
117 Eigen::MatrixXd H_al = R_tau12k * alpha_arg;
118 Eigen::MatrixXd H_be = R_tau12k * Beta_arg;
129 Eigen::Matrix<double, 3, 3> J_r_tau1 =
130 small_w ?
eye3 - .5 * w_tx + (1.0 / 6.0) * w_tx * w_tx
131 :
eye3 - ((1 - cos_wt) / (pow((w_dt), 2.0))) * w_tx + ((w_dt - sin_wt) / (pow(w_dt, 3.0))) * w_tx * w_tx;
134 J_q = R_tau2tau1 *
J_q + J_r_tau1 * delta_t;
142 Eigen::MatrixXd d_R_bw_1 = -R_tau12k *
skew_x(
J_q *
e_1);
143 Eigen::MatrixXd d_R_bw_2 = -R_tau12k *
skew_x(
J_q *
e_2);
144 Eigen::MatrixXd d_R_bw_3 = -R_tau12k *
skew_x(
J_q *
e_3);
164 double df_1_dw_mag = -(pow(delta_t, 5) / 15);
165 df_1_dbw_1 = w_1 * df_1_dw_mag;
166 df_1_dbw_2 = w_2 * df_1_dw_mag;
167 df_1_dbw_3 = w_3 * df_1_dw_mag;
169 double df_2_dw_mag = (pow(delta_t, 6) / 72);
170 df_2_dbw_1 = w_1 * df_2_dw_mag;
171 df_2_dbw_2 = w_2 * df_2_dw_mag;
172 df_2_dbw_3 = w_3 * df_2_dw_mag;
174 double df_3_dw_mag = -(pow(delta_t, 4) / 12);
175 df_3_dbw_1 = w_1 * df_3_dw_mag;
176 df_3_dbw_2 = w_2 * df_3_dw_mag;
177 df_3_dbw_3 = w_3 * df_3_dw_mag;
179 double df_4_dw_mag = (pow(delta_t, 5) / 60);
180 df_4_dbw_1 = w_1 * df_4_dw_mag;
181 df_4_dbw_2 = w_2 * df_4_dw_mag;
182 df_4_dbw_3 = w_3 * df_4_dw_mag;
184 double df_1_dw_mag = (pow(w_dt, 2) * sin_wt - 3 * sin_wt + 3 * w_dt * cos_wt) / pow(mag_w, 5);
185 df_1_dbw_1 = w_1 * df_1_dw_mag;
186 df_1_dbw_2 = w_2 * df_1_dw_mag;
187 df_1_dbw_3 = w_3 * df_1_dw_mag;
189 double df_2_dw_mag = (pow(w_dt, 2) - 4 * cos_wt - 4 * w_dt * sin_wt + pow(w_dt, 2) * cos_wt + 4) / (pow(mag_w, 6));
190 df_2_dbw_1 = w_1 * df_2_dw_mag;
191 df_2_dbw_2 = w_2 * df_2_dw_mag;
192 df_2_dbw_3 = w_3 * df_2_dw_mag;
194 double df_3_dw_mag = (2 * (cos_wt - 1) + w_dt * sin_wt) / (pow(mag_w, 4));
195 df_3_dbw_1 = w_1 * df_3_dw_mag;
196 df_3_dbw_2 = w_2 * df_3_dw_mag;
197 df_3_dbw_3 = w_3 * df_3_dw_mag;
199 double df_4_dw_mag = (2 * w_dt + w_dt * cos_wt - 3 * sin_wt) / (pow(mag_w, 5));
200 df_4_dbw_1 = w_1 * df_4_dw_mag;
201 df_4_dbw_2 = w_2 * df_4_dw_mag;
202 df_4_dbw_3 = w_3 * df_4_dw_mag;
207 J_a.block(0, 0, 3, 1) +=
208 (d_R_bw_1 * alpha_arg + R_tau12k * (df_1_dbw_1 * w_x - f_1 *
e_1x + df_2_dbw_1 * w_x_2 - f_2 * (
e_1x * w_x + w_x *
e_1x))) * a_hat;
209 J_a.block(0, 1, 3, 1) +=
210 (d_R_bw_2 * alpha_arg + R_tau12k * (df_1_dbw_2 * w_x - f_1 *
e_2x + df_2_dbw_2 * w_x_2 - f_2 * (
e_2x * w_x + w_x *
e_2x))) * a_hat;
211 J_a.block(0, 2, 3, 1) +=
212 (d_R_bw_3 * alpha_arg + R_tau12k * (df_1_dbw_3 * w_x - f_1 *
e_3x + df_2_dbw_3 * w_x_2 - f_2 * (
e_3x * w_x + w_x *
e_3x))) * a_hat;
213 J_b.block(0, 0, 3, 1) +=
214 (d_R_bw_1 * Beta_arg + R_tau12k * (df_3_dbw_1 * w_x - f_3 *
e_1x + df_4_dbw_1 * w_x_2 - f_4 * (
e_1x * w_x + w_x *
e_1x))) * a_hat;
215 J_b.block(0, 1, 3, 1) +=
216 (d_R_bw_2 * Beta_arg + R_tau12k * (df_3_dbw_2 * w_x - f_3 *
e_2x + df_4_dbw_2 * w_x_2 - f_4 * (
e_2x * w_x + w_x *
e_2x))) * a_hat;
217 J_b.block(0, 2, 3, 1) +=
218 (d_R_bw_3 * Beta_arg + R_tau12k * (df_3_dbw_3 * w_x - f_3 *
e_3x + df_4_dbw_3 * w_x_2 - f_4 * (
e_3x * w_x + w_x *
e_3x))) * a_hat;
225 Eigen::Matrix<double, 3, 3> R_mid =
226 small_w ?
eye3 - .5 * delta_t * w_x + (pow(.5 * delta_t, 2) / 2) * w_x_2
227 :
eye3 - (sin(mag_w * .5 * delta_t) / mag_w) * w_x + ((1.0 - cos(mag_w * .5 * delta_t)) / (pow(mag_w, 2.0))) * w_x_2;
234 Eigen::Matrix<double, 15, 15> F_k1 = Eigen::Matrix<double, 15, 15>::Zero();
235 F_k1.block(0, 0, 3, 3) = -w_x;
236 F_k1.block(0, 3, 3, 3) = -
eye3;
237 F_k1.block(6, 0, 3, 3) = -
R_k2tau.transpose() * a_x;
238 F_k1.block(6, 9, 3, 3) = -
R_k2tau.transpose();
239 F_k1.block(12, 6, 3, 3) =
eye3;
242 Eigen::Matrix<double, 15, 12> G_k1 = Eigen::Matrix<double, 15, 12>::Zero();
243 G_k1.block(0, 0, 3, 3) = -
eye3;
244 G_k1.block(3, 3, 3, 3) =
eye3;
245 G_k1.block(6, 6, 3, 3) = -
R_k2tau.transpose();
246 G_k1.block(9, 9, 3, 3) =
eye3;
249 Eigen::Matrix<double, 15, 15> P_dot_k1 = F_k1 *
P_meas +
P_meas * F_k1.transpose() + G_k1 *
Q_c * G_k1.transpose();
254 Eigen::Matrix<double, 15, 15> F_k2 = Eigen::Matrix<double, 15, 15>::Zero();
255 F_k2.block(0, 0, 3, 3) = -w_x;
256 F_k2.block(0, 3, 3, 3) = -
eye3;
257 F_k2.block(6, 0, 3, 3) = -R_mid.transpose() * a_x;
258 F_k2.block(6, 9, 3, 3) = -R_mid.transpose();
259 F_k2.block(12, 6, 3, 3) =
eye3;
262 Eigen::Matrix<double, 15, 12> G_k2 = Eigen::Matrix<double, 15, 12>::Zero();
263 G_k2.block(0, 0, 3, 3) = -
eye3;
264 G_k2.block(3, 3, 3, 3) =
eye3;
265 G_k2.block(6, 6, 3, 3) = -R_mid.transpose();
266 G_k2.block(9, 9, 3, 3) =
eye3;
269 Eigen::Matrix<double, 15, 15> P_k2 =
P_meas + P_dot_k1 * delta_t / 2.0;
270 Eigen::Matrix<double, 15, 15> P_dot_k2 = F_k2 * P_k2 + P_k2 * F_k2.transpose() + G_k2 *
Q_c * G_k2.transpose();
276 Eigen::Matrix<double, 15, 15> F_k3 = F_k2;
277 Eigen::Matrix<double, 15, 12> G_k3 = G_k2;
280 Eigen::Matrix<double, 15, 15> P_k3 =
P_meas + P_dot_k2 * delta_t / 2.0;
281 Eigen::Matrix<double, 15, 15> P_dot_k3 = F_k3 * P_k3 + P_k3 * F_k3.transpose() + G_k3 *
Q_c * G_k3.transpose();
286 Eigen::Matrix<double, 15, 15> F_k4 = Eigen::Matrix<double, 15, 15>::Zero();
287 F_k4.block(0, 0, 3, 3) = -w_x;
288 F_k4.block(0, 3, 3, 3) = -
eye3;
289 F_k4.block(6, 0, 3, 3) = -R_k2tau1.transpose() * a_x;
290 F_k4.block(6, 9, 3, 3) = -R_k2tau1.transpose();
291 F_k4.block(12, 6, 3, 3) =
eye3;
294 Eigen::Matrix<double, 15, 12> G_k4 = Eigen::Matrix<double, 15, 12>::Zero();
295 G_k4.block(0, 0, 3, 3) = -
eye3;
296 G_k4.block(3, 3, 3, 3) =
eye3;
297 G_k4.block(6, 6, 3, 3) = -R_k2tau1.transpose();
298 G_k4.block(9, 9, 3, 3) =
eye3;
301 Eigen::Matrix<double, 15, 15> P_k4 =
P_meas + P_dot_k3 * delta_t;
302 Eigen::Matrix<double, 15, 15> P_dot_k4 = F_k4 * P_k4 + P_k4 * F_k4.transpose() + G_k4 *
Q_c * G_k4.transpose();
308 P_meas += (delta_t / 6.0) * (P_dot_k1 + 2.0 * P_dot_k2 + 2.0 * P_dot_k3 + P_dot_k4);