29 Eigen::Vector4d &q_KtoK1, Eigen::Vector3d &ba_lin, Eigen::Vector3d &bg_lin, Eigen::Matrix3d &J_q,
30 Eigen::Matrix3d &J_beta, Eigen::Matrix3d &J_alpha, Eigen::Matrix3d &H_beta, Eigen::Matrix3d &H_alpha,
31 Eigen::Matrix<double, 15, 15> &covariance) {
51 Eigen::MatrixXd I = Eigen::MatrixXd::Identity(covariance.rows(), covariance.rows());
52 Eigen::MatrixXd information = covariance.llt().solve(I);
53 if (std::isnan(information.norm())) {
54 std::cerr <<
"P - " << std::endl << covariance << std::endl << std::endl;
55 std::cerr <<
"Pinv - " << std::endl << covariance.inverse() << std::endl << std::endl;
56 std::exit(EXIT_FAILURE);
60 Eigen::LLT<Eigen::MatrixXd> lltOfI(information);
64 set_num_residuals(15);
65 mutable_parameter_block_sizes()->push_back(4);
66 mutable_parameter_block_sizes()->push_back(3);
67 mutable_parameter_block_sizes()->push_back(3);
68 mutable_parameter_block_sizes()->push_back(3);
69 mutable_parameter_block_sizes()->push_back(3);
70 mutable_parameter_block_sizes()->push_back(4);
71 mutable_parameter_block_sizes()->push_back(3);
72 mutable_parameter_block_sizes()->push_back(3);
73 mutable_parameter_block_sizes()->push_back(3);
74 mutable_parameter_block_sizes()->push_back(3);
81 Eigen::Matrix<double, 15, 15> sqrtI =
sqrtI_save;
87 Eigen::Vector4d q_1 = Eigen::Map<const Eigen::Vector4d>(parameters[0]);
89 Eigen::Vector4d q_2 = Eigen::Map<const Eigen::Vector4d>(parameters[5]);
92 Eigen::Vector3d b_w1 = Eigen::Map<const Eigen::Vector3d>(parameters[1]);
93 Eigen::Vector3d b_w2 = Eigen::Map<const Eigen::Vector3d>(parameters[6]);
96 Eigen::Vector3d b_a1 = Eigen::Map<const Eigen::Vector3d>(parameters[3]);
97 Eigen::Vector3d b_a2 = Eigen::Map<const Eigen::Vector3d>(parameters[8]);
100 Eigen::Vector3d v_1 = Eigen::Map<const Eigen::Vector3d>(parameters[2]);
101 Eigen::Vector3d v_2 = Eigen::Map<const Eigen::Vector3d>(parameters[7]);
104 Eigen::Vector3d p_1 = Eigen::Map<const Eigen::Vector3d>(parameters[4]);
105 Eigen::Vector3d p_2 = Eigen::Map<const Eigen::Vector3d>(parameters[9]);
108 Eigen::Vector3d dbw = b_w1 - b_w_lin;
109 Eigen::Vector3d dba = b_a1 - b_a_lin;
114 q_b.block(0, 0, 3, 1) = 0.5 *
J_q * dbw;
116 q_b = q_b / q_b.norm();
130 Eigen::Matrix<double, 15, 1> res;
131 res.block(0, 0, 3, 1) = 2 * q_res_plus.block(0, 0, 3, 1);
132 res.block(3, 0, 3, 1) = b_w2 - b_w1;
133 res.block(6, 0, 3, 1) = R_1 * (v_2 - v_1 + gravity *
dt) -
J_b * dbw -
H_b * dba -
beta;
134 res.block(9, 0, 3, 1) = b_a2 - b_a1;
135 res.block(12, 0, 3, 1) = R_1 * (p_2 - p_1 - v_1 *
dt + .5 * gravity * std::pow(
dt, 2)) -
J_a * dbw -
H_a * dba -
alpha;
139 for (
int i = 0; i < res.rows(); i++) {
140 residuals[i] = res(i, 0);
151 Eigen::Matrix<double, 15, 30> Jacobian = Eigen::Matrix<double, 15, 30>::Zero();
154 Eigen::Matrix<double, 3, 3> eye = Eigen::MatrixXd::Identity(3, 3);
158 Jacobian.block(0, 0, 3, 3) = -((q_1_to_2(3, 0) * eye -
ov_core::skew_x(q_1_to_2.block(0, 0, 3, 1))) *
159 (q_meas_plus(3, 0) * eye +
ov_core::skew_x(q_meas_plus.block(0, 0, 3, 1))) -
160 q_1_to_2.block(0, 0, 3, 1) * q_meas_plus.block(0, 0, 3, 1).transpose());
163 Jacobian.block(0, 15, 3, 3) = q_res_plus(3, 0) * eye +
ov_core::skew_x(q_res_plus.block(0, 0, 3, 1));
166 Jacobian.block(0, 3, 3, 3) = (q_res_minus(3, 0) * eye -
ov_core::skew_x(q_res_minus.block(0, 0, 3, 1))) *
J_q;
169 Jacobian.block(3, 3, 3, 3) = -eye;
170 Jacobian.block(3, 18, 3, 3) = eye;
176 Jacobian.block(6, 6, 3, 3) = -R_1;
179 Jacobian.block(6, 21, 3, 3) = R_1;
182 Jacobian.block(6, 3, 3, 3) = -
J_b;
185 Jacobian.block(6, 9, 3, 3) = -
H_b;
188 Jacobian.block(9, 9, 3, 3) = -eye;
189 Jacobian.block(9, 24, 3, 3) = eye;
192 Jacobian.block(12, 0, 3, 3) =
ov_core::skew_x(R_1 * (p_2 - p_1 - v_1 *
dt + .5 * gravity * std::pow(
dt, 2)));
194 Jacobian.block(12, 6, 3, 3) = -R_1 *
dt;
196 Jacobian.block(12, 12, 3, 3) = -R_1;
199 Jacobian.block(12, 27, 3, 3) = R_1;
202 Jacobian.block(12, 3, 3, 3) = -
J_a;
204 Jacobian.block(12, 9, 3, 3) = -
H_a;
207 Jacobian = sqrtI * Jacobian;
212 Eigen::Map<Eigen::Matrix<double, 15, 4, Eigen::RowMajor>> J_th1(jacobians[0], 15, 4);
213 J_th1.block(0, 0, 15, 3) = Jacobian.block(0, 0, 15, 3);
214 J_th1.block(0, 3, 15, 1).setZero();
218 Eigen::Map<Eigen::Matrix<double, 15, 4, Eigen::RowMajor>> J_th2(jacobians[5], 15, 4);
219 J_th2.block(0, 0, 15, 3) = Jacobian.block(0, 15, 15, 3);
220 J_th2.block(0, 3, 15, 1).setZero();
224 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_bw1(jacobians[1], 15, 3);
225 J_bw1.block(0, 0, 15, 3) = Jacobian.block(0, 3, 15, 3);
229 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_bw2(jacobians[6], 15, 3);
230 J_bw2.block(0, 0, 15, 3) = Jacobian.block(0, 18, 15, 3);
234 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_v1(jacobians[2], 15, 3);
235 J_v1.block(0, 0, 15, 3) = Jacobian.block(0, 6, 15, 3);
239 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_v2(jacobians[7], 15, 3);
240 J_v2.block(0, 0, 15, 3) = Jacobian.block(0, 21, 15, 3);
244 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_ba1(jacobians[3], 15, 3);
245 J_ba1.block(0, 0, 15, 3) = Jacobian.block(0, 9, 15, 3);
249 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_ba2(jacobians[8], 15, 3);
250 J_ba2.block(0, 0, 15, 3) = Jacobian.block(0, 24, 15, 3);
254 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_p1(jacobians[4], 15, 3);
255 J_p1.block(0, 0, 15, 3) = Jacobian.block(0, 12, 15, 3);
259 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_p2(jacobians[9], 15, 3);
260 J_p2.block(0, 0, 15, 3) = Jacobian.block(0, 27, 15, 3);