6 #include <ceres/ceres.h>
15 Motion2DFactor(
const Eigen::Vector2d motion_2d,
const Eigen::MatrixXd sqrt_inf,
const double dt)
22 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
26 Eigen::Affine3d T_delta = Eigen::Affine3d::Identity();
28 T_delta.translation() <<
_dx, 0, 0;
30 Eigen::Map<Vector6d> err(residuals);
33 if (jacobians != NULL) {
34 if (jacobians[0] != NULL) {
35 Eigen::Map<Eigen::Matrix<double, 6, 6, Eigen::RowMajor>> J_k(jacobians[0]);
38 Eigen::Affine3d T_gamma = T_delta * T_fkp1_w;
39 Eigen::Vector3d w =
geometry::log_so3(T_fk_w.linear().transpose() * T_gamma.linear());
43 J_k.block<3, 3>(3, 0) =
44 T_fk_w.linear().transpose() *
geometry::skewMatrix(T_gamma.translation() - T_fk_w.translation()) *
46 J_k.block<3, 3>(3, 3) = -T_fk_w.linear().transpose();
50 if (jacobians[1] != NULL) {
51 Eigen::Map<Eigen::Matrix<double, 6, 6, Eigen::RowMajor>> J_kp1(jacobians[1]);
54 Eigen::Affine3d T_beta = T_fk_w.inverse() * T_delta;
58 J_kp1.block<3, 3>(3, 3) = T_beta.linear();
79 const Eigen::Affine3d T_w_b,
80 const Eigen::Affine3d T_a_b_prior,
81 const Eigen::MatrixXd sqrt_inf)
85 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
86 Eigen::Map<Vector6d> err(residuals);
90 Eigen::Affine3d T = T_b_a_prior * T_w_a_up.inverse() * T_w_b_up;
93 if (jacobians != NULL) {
95 Eigen::Vector3d tb = T_w_b_up.translation();
96 Eigen::Vector3d ta = T_w_a_up.translation();
99 if (jacobians[0] != NULL) {
100 Eigen::Map<Eigen::Matrix<double, 6, 6, Eigen::RowMajor>> J(jacobians[0]);
102 Eigen::Vector3d dw = Eigen::Vector3d(parameters[0][0], parameters[0][1], parameters[0][2]);
109 J.block(3, 0, 3, 3) = T_b_a_prior.rotation() * T_w_a_up.rotation().transpose() *
114 J.block(3, 3, 3, 3) = -T_b_a_prior.rotation();
118 if (jacobians[1] != NULL) {
119 Eigen::Map<Eigen::Matrix<double, 6, 6, Eigen::RowMajor>> J(jacobians[1]);
121 Eigen::Vector3d dw = Eigen::Vector3d(parameters[1][0], parameters[1][1], parameters[1][2]);
127 J.block(3, 3, 3, 3) = T_b_a_prior.rotation() * T_w_a_up.rotation().transpose() * T_w_b_up.rotation();
145 class IMUFactor :
public ceres::SizedCostFunction<9, 6, 6, 3, 3, 3, 3> {
149 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
152 Eigen::Affine3d T_fi_w =
154 Eigen::Affine3d T_fj_w =
156 Eigen::Vector3d v_i =
_imu_i->getVelocity() + Eigen::Map<const Eigen::Vector3d>(parameters[2]);
157 Eigen::Vector3d v_j =
_imu_j->getVelocity() + Eigen::Map<const Eigen::Vector3d>(parameters[3]);
158 Eigen::Vector3d d_ba = Eigen::Map<const Eigen::Vector3d>(parameters[4]);
159 Eigen::Vector3d d_bg = Eigen::Map<const Eigen::Vector3d>(parameters[5]);
160 double dtij = (
_imu_j->getFrame()->getTimestamp() -
_imu_i->getFrame()->getTimestamp()) * 1e-9;
163 Eigen::MatrixXd cov =
_imu_j->getCov();
165 Eigen::Matrix<double, 9, 9> inf_sqrt =
166 Eigen::LLT<Eigen::Matrix<double, 9, 9>>(cov.inverse()).matrixL().transpose();
170 T_fi_w.rotation() * T_fj_w.rotation().transpose();
172 Eigen::Vector3d r_dv = T_fi_w.rotation() * (v_j - v_i - g * dtij) -
174 Eigen::Vector3d r_dp = T_fi_w.rotation() * (T_fj_w.inverse().translation() - T_fi_w.inverse().translation() -
175 v_i * dtij - 0.5 * g * dtij * dtij) -
177 Eigen::Map<Eigen::Matrix<double, 9, 1>> err(residuals);
178 err.block(0, 0, 3, 1) = r_dr;
179 err.block(3, 0, 3, 1) = r_dv;
180 err.block(6, 0, 3, 1) = r_dp;
181 err = inf_sqrt * err;
183 if (jacobians != NULL) {
186 if (jacobians[0] != NULL) {
187 Eigen::Map<Eigen::Matrix<double, 9, 6, Eigen::RowMajor>> J_dTfi(jacobians[0]);
188 J_dTfi = Eigen::Matrix<double, 9, 6, Eigen::RowMajor>::Zero();
189 Eigen::Vector3d w_dfi = Eigen::Vector3d(parameters[0][0], parameters[0][1], parameters[0][2]);
192 J_dTfi.block(3, 0, 3, 3) = -T_fi_w.rotation() *
geometry::skewMatrix(v_j - v_i - g * dtij) * J_r_wdfi;
193 J_dTfi.block(6, 0, 3, 3) =
197 J_dTfi.block(6, 3, 3, 3) =
_imu_i->getFrame()->getWorld2FrameTransform().rotation();
198 J_dTfi = inf_sqrt * J_dTfi;
202 if (jacobians[1] != NULL) {
203 Eigen::Map<Eigen::Matrix<double, 9, 6, Eigen::RowMajor>> J_dTfj(jacobians[1]);
204 J_dTfj = Eigen::Matrix<double, 9, 6, Eigen::RowMajor>::Zero();
205 Eigen::Vector3d w_dfj = Eigen::Vector3d(parameters[1][0], parameters[1][1], parameters[1][2]);
208 J_dTfj.block(6, 0, 3, 3) = -T_fi_w.rotation() * T_fj_w.rotation().transpose() *
210 J_dTfj.block(6, 3, 3, 3) = -T_fi_w.rotation() *
geometry::exp_so3(w_dfj).transpose();
211 J_dTfj = inf_sqrt * J_dTfj;
215 if (jacobians[2] != NULL) {
216 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dvi(jacobians[2]);
217 J_dvi = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
218 J_dvi.block(3, 0, 3, 3) = -T_fi_w.rotation();
219 J_dvi.block(6, 0, 3, 3) = -T_fi_w.rotation() * dtij;
220 J_dvi = inf_sqrt * J_dvi;
224 if (jacobians[3] != NULL) {
225 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dvj(jacobians[3]);
226 J_dvj = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
227 J_dvj.block(3, 0, 3, 3) = T_fi_w.rotation();
228 J_dvj = inf_sqrt * J_dvj;
232 if (jacobians[4] != NULL) {
233 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dba(jacobians[4]);
234 J_dba = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
235 J_dba.block(3, 0, 3, 3) = -
_imu_j->_J_dv_ba;
236 J_dba.block(6, 0, 3, 3) = -
_imu_j->_J_dp_ba;
237 J_dba = inf_sqrt * J_dba;
241 if (jacobians[5] != NULL) {
242 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dbg(jacobians[5]);
243 J_dbg = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
246 J_dbg.block(3, 0, 3, 3) = -
_imu_j->_J_dv_bg;
247 J_dbg.block(6, 0, 3, 3) = -
_imu_j->_J_dp_bg;
248 J_dbg = inf_sqrt * J_dbg;
266 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
267 Eigen::Vector3d d_bai = Eigen::Map<const Eigen::Vector3d>(parameters[0]);
268 Eigen::Vector3d d_bgi = Eigen::Map<const Eigen::Vector3d>(parameters[1]);
269 Eigen::Vector3d d_baj = Eigen::Map<const Eigen::Vector3d>(parameters[2]);
270 Eigen::Vector3d d_bgj = Eigen::Map<const Eigen::Vector3d>(parameters[3]);
271 double dtij = (
_imu_j->getFrame()->getTimestamp() -
_imu_i->getFrame()->getTimestamp()) * 1e-9;
273 double sigma2_dba = dtij *
_imu_i->getbAccNoise() *
_imu_i->getbAccNoise();
274 Eigen::Matrix3d sqrt_inf_ba = Eigen::Matrix3d::Identity() * (1 / std::sqrt(sigma2_dba));
275 double sigma2_dbg = dtij *
_imu_i->getbGyrNoise() *
_imu_i->getbGyrNoise();
276 Eigen::Matrix3d sqrt_inf_bg = Eigen::Matrix3d::Identity() * (1 / std::sqrt(sigma2_dbg));
278 Eigen::Map<Eigen::Matrix<double, 6, 1>> err(residuals);
279 err.block(0, 0, 3, 1) = sqrt_inf_ba * (
_imu_j->getBa() + d_baj -
_imu_i->getBa() - d_bai);
280 err.block(3, 0, 3, 1) = sqrt_inf_bg * (
_imu_j->getBg() + d_bgj -
_imu_i->getBg() - d_bgi);
282 if (jacobians != NULL) {
284 if (jacobians[0] != NULL) {
285 Eigen::Map<Eigen::Matrix<double, 6, 3, Eigen::RowMajor>> J_dba(jacobians[0]);
286 J_dba = Eigen::Matrix<double, 6, 3, Eigen::RowMajor>::Zero();
287 J_dba.block(0, 0, 3, 3) = -sqrt_inf_ba;
290 if (jacobians[1] != NULL) {
291 Eigen::Map<Eigen::Matrix<double, 6, 3, Eigen::RowMajor>> J_dbg(jacobians[1]);
292 J_dbg = Eigen::Matrix<double, 6, 3, Eigen::RowMajor>::Zero();
293 J_dbg.block(3, 0, 3, 3) = -sqrt_inf_bg;
296 if (jacobians[2] != NULL) {
297 Eigen::Map<Eigen::Matrix<double, 6, 3, Eigen::RowMajor>> J_dba(jacobians[2]);
298 J_dba = Eigen::Matrix<double, 6, 3, Eigen::RowMajor>::Zero();
299 J_dba.block(0, 0, 3, 3) = sqrt_inf_ba;
302 if (jacobians[3] != NULL) {
303 Eigen::Map<Eigen::Matrix<double, 6, 3, Eigen::RowMajor>> J_dbg(jacobians[3]);
304 J_dbg = Eigen::Matrix<double, 6, 3, Eigen::RowMajor>::Zero();
305 J_dbg.block(3, 0, 3, 3) = sqrt_inf_bg;
319 class IMUFactorInit :
public ceres::SizedCostFunction<9, 2, 3, 3, 3, 3, 1> {
323 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
326 Eigen::Vector3d w_w_i = Eigen::Vector3d(parameters[0][0], parameters[0][1], 0);
328 Eigen::Vector3d v_i =
_imu_i->getVelocity() + Eigen::Map<const Eigen::Vector3d>(parameters[1]);
329 Eigen::Vector3d v_j =
_imu_j->getVelocity() + Eigen::Map<const Eigen::Vector3d>(parameters[2]);
330 Eigen::Vector3d d_ba = Eigen::Map<const Eigen::Vector3d>(parameters[3]);
331 Eigen::Vector3d d_bg = Eigen::Map<const Eigen::Vector3d>(parameters[4]);
332 double lambda = *parameters[5];
333 Eigen::Affine3d T_fi_w =
_imu_i->getFrame()->getWorld2FrameTransform();
334 Eigen::Affine3d T_fj_w =
_imu_j->getFrame()->getWorld2FrameTransform();
335 double dtij = (
_imu_j->getFrame()->getTimestamp() -
_imu_i->getFrame()->getTimestamp()) * 1e-9;
338 Eigen::MatrixXd cov =
_imu_j->getCov();
339 Eigen::Matrix<double, 9, 9> inf_sqrt =
340 Eigen::LLT<Eigen::Matrix<double, 9, 9>>(cov.inverse()).matrixL().transpose();
344 T_fi_w.rotation() * T_fj_w.rotation().transpose();
346 Eigen::Vector3d r_dv = T_fi_w.rotation() * R_w_i * ((v_j - v_i) - g * dtij) -
348 Eigen::Vector3d r_dp =
349 T_fi_w.rotation() * R_w_i *
350 (std::exp(lambda) * (T_fj_w.inverse().translation() - T_fi_w.inverse().translation()) - v_i * dtij -
351 0.5 * g * dtij * dtij) -
353 Eigen::Map<Eigen::Matrix<double, 9, 1>> err(residuals);
354 err.block(0, 0, 3, 1) = r_dr;
355 err.block(3, 0, 3, 1) = r_dv;
356 err.block(6, 0, 3, 1) = r_dp;
357 err = inf_sqrt * err;
359 if (jacobians != NULL) {
362 if (jacobians[0] != NULL) {
363 Eigen::Map<Eigen::Matrix<double, 9, 2, Eigen::RowMajor>> J_Rwi(jacobians[0]);
364 J_Rwi = Eigen::Matrix<double, 9, 2, Eigen::RowMajor>::Zero();
365 J_Rwi.block(3, 0, 3, 2) = -T_fi_w.rotation() * R_w_i *
geometry::skewMatrix((v_j - v_i) - g * dtij) *
367 J_Rwi.block(6, 0, 3, 2) = -T_fi_w.rotation() * R_w_i *
369 T_fi_w.inverse().translation()) -
370 v_i * dtij - 0.5 * g * dtij * dtij) *
372 J_Rwi = inf_sqrt * J_Rwi;
376 if (jacobians[1] != NULL) {
377 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_vi(jacobians[1]);
378 J_vi = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
379 J_vi.block(3, 0, 3, 3) = -(T_fi_w.rotation() * R_w_i);
380 J_vi.block(6, 0, 3, 3) = -(T_fi_w.rotation() * R_w_i) * dtij;
381 J_vi = inf_sqrt * J_vi;
385 if (jacobians[2] != NULL) {
386 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_vj(jacobians[2]);
387 J_vj = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
388 J_vj.block(3, 0, 3, 3) = T_fi_w.rotation() * R_w_i;
389 J_vj = inf_sqrt * J_vj;
393 if (jacobians[3] != NULL) {
394 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dba(jacobians[3]);
395 J_dba = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
396 J_dba.block(3, 0, 3, 3) = -
_imu_j->_J_dv_ba;
397 J_dba.block(6, 0, 3, 3) = -
_imu_j->_J_dp_ba;
398 J_dba = inf_sqrt * J_dba;
402 if (jacobians[4] != NULL) {
403 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dbg(jacobians[4]);
404 J_dbg = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
407 J_dbg.block(3, 0, 3, 3) = -
_imu_j->_J_dv_bg;
408 J_dbg.block(6, 0, 3, 3) = -
_imu_j->_J_dp_bg;
409 J_dbg = inf_sqrt * J_dbg;
413 if (jacobians[5] != NULL) {
414 Eigen::Map<Eigen::Matrix<double, 9, 1>> J_scale(jacobians[5]);
415 J_scale = Eigen::Matrix<double, 9, 1>::Zero();
416 J_scale.block(6, 0, 3, 1) =
417 T_fi_w.rotation() * R_w_i * (T_fj_w.inverse().translation() - T_fi_w.inverse().translation());
418 J_scale = inf_sqrt * J_scale;
436 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
439 Eigen::Vector3d w_w_i = Eigen::Vector3d(parameters[0][0], parameters[0][1], 0);
441 Eigen::Vector3d d_ba = Eigen::Map<const Eigen::Vector3d>(parameters[1]);
442 Eigen::Vector3d d_bg = Eigen::Map<const Eigen::Vector3d>(parameters[2]);
443 double lambda = *parameters[3];
444 Eigen::Vector3d v_i =
_imu_i->getVelocity();
445 Eigen::Vector3d v_j =
_imu_j->getVelocity();
446 Eigen::Affine3d T_fi_w =
_imu_i->getFrame()->getWorld2FrameTransform();
447 Eigen::Affine3d T_fj_w =
_imu_j->getFrame()->getWorld2FrameTransform();
448 double dtij = (
_imu_j->getFrame()->getTimestamp() -
_imu_i->getFrame()->getTimestamp()) * 1e-9;
451 Eigen::MatrixXd cov =
_imu_j->getCov();
452 Eigen::Matrix<double, 9, 9> inf_sqrt =
453 Eigen::LLT<Eigen::Matrix<double, 9, 9>>(cov.inverse()).matrixL().transpose();
457 T_fi_w.rotation() * T_fj_w.rotation().transpose();
459 Eigen::Vector3d r_dv = T_fi_w.rotation() * R_w_i * (std::exp(lambda) * (v_j - v_i) - g * dtij) -
461 Eigen::Vector3d r_dp =
462 T_fi_w.rotation() * R_w_i *
463 (std::exp(lambda) * (T_fj_w.inverse().translation() - T_fi_w.inverse().translation()) -
464 std::exp(lambda) * v_i * dtij - 0.5 * g * dtij * dtij) -
466 Eigen::Map<Eigen::Matrix<double, 9, 1>> err(residuals);
467 err.block(0, 0, 3, 1) = r_dr;
468 err.block(3, 0, 3, 1) = r_dv;
469 err.block(6, 0, 3, 1) = r_dp;
470 err = inf_sqrt * err;
472 if (jacobians != NULL) {
475 if (jacobians[0] != NULL) {
476 Eigen::Map<Eigen::Matrix<double, 9, 2, Eigen::RowMajor>> J_Rwi(jacobians[0]);
477 J_Rwi = Eigen::Matrix<double, 9, 2, Eigen::RowMajor>::Zero();
478 J_Rwi.block(3, 0, 3, 2) = -T_fi_w.rotation() * R_w_i *
481 J_Rwi.block(6, 0, 3, 2) =
482 -T_fi_w.rotation() * R_w_i *
484 T_fi_w.inverse().translation() - v_i * dtij) -
485 0.5 * g * dtij * dtij) *
487 J_Rwi = inf_sqrt * J_Rwi;
491 if (jacobians[1] != NULL) {
492 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dba(jacobians[1]);
493 J_dba = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
494 J_dba.block(3, 0, 3, 3) = -
_imu_j->_J_dv_ba;
495 J_dba.block(6, 0, 3, 3) = -
_imu_j->_J_dp_ba;
496 J_dba = inf_sqrt * J_dba;
500 if (jacobians[2] != NULL) {
501 Eigen::Map<Eigen::Matrix<double, 9, 3, Eigen::RowMajor>> J_dbg(jacobians[2]);
502 J_dbg = Eigen::Matrix<double, 9, 3, Eigen::RowMajor>::Zero();
505 J_dbg.block(3, 0, 3, 3) = -
_imu_j->_J_dv_bg;
506 J_dbg.block(6, 0, 3, 3) = -
_imu_j->_J_dp_bg;
507 J_dbg = inf_sqrt * J_dbg;
511 if (jacobians[3] != NULL) {
512 Eigen::Map<Eigen::Matrix<double, 9, 1>> J_scale(jacobians[3]);
513 J_scale = Eigen::Matrix<double, 9, 1>::Zero();
514 J_scale.block(3, 0, 3, 1) = T_fi_w.rotation() * R_w_i * (v_j - v_i);
515 J_scale.block(6, 0, 3, 1) =
516 T_fi_w.rotation() * R_w_i *
517 (T_fj_w.inverse().translation() - T_fi_w.inverse().translation() - v_i * dtij);
532 Landmark3DPrior(
const Eigen::Vector3d prior,
const Eigen::Vector3d lmk,
const Eigen::Matrix3d sqrt_inf)
536 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
537 Eigen::Map<Eigen::Vector3d> err(residuals);
540 if (jacobians != NULL) {
541 Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> J(jacobians[0]);
558 const Eigen::Vector3d lmk0,
559 const Eigen::Vector3d lmk1,
560 const Eigen::Matrix3d sqrt_inf)
564 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
565 Eigen::Map<Eigen::Vector3d> err(residuals);
566 err =
_sqrt_inf * ((
_lmk0 + Eigen::Map<const Eigen::Vector3d>(parameters[0])) -
567 (
_lmk1 + Eigen::Map<const Eigen::Vector3d>(parameters[1])) -
_delta);
569 if (jacobians != NULL) {
571 if (jacobians[0] != NULL) {
572 Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> J_l0(jacobians[0]);
576 if (jacobians[1] != NULL) {
577 Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> J_l1(jacobians[1]);
594 const Eigen::Affine3d T_f_w,
595 const Eigen::Vector3d t_w_lmk,
596 const Eigen::Matrix3d sqrt_inf)
600 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
601 Eigen::Map<Eigen::Vector3d> err(residuals);
603 Eigen::Vector3d t_w_lmk =
_t_w_lmk + Eigen::Map<const Eigen::Vector3d>(parameters[1]);
607 if (jacobians != NULL) {
609 if (jacobians[0] != NULL) {
610 Eigen::Map<Eigen::Matrix<double, 3, 6, Eigen::RowMajor>> J_f(jacobians[0]);
611 Eigen::Vector3d w_df = Eigen::Vector3d(parameters[0][0], parameters[0][1], parameters[0][2]);
618 if (jacobians[1] != NULL) {
619 Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> J_l(jacobians[1]);
636 PosePriordx(
const Eigen::Affine3d T,
const Eigen::Affine3d T_prior,
const Eigen::MatrixXd sqrt_inf)
640 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
641 Eigen::Map<Vector6d> err(residuals);
645 if (jacobians != NULL) {
646 Eigen::Map<Eigen::Matrix<double, 6, 6, Eigen::RowMajor>> J(jacobians[0]);
648 Eigen::Vector3d dw = Eigen::Vector3d(parameters[0][0], parameters[0][1], parameters[0][2]);
651 J.block(0, 0, 3, 3) =
653 J.block(3, 0, 3, 3) = T.rotation() *
656 J.block(3, 3, 3, 3) =
_T.rotation();
670 class IMUPriordx :
public ceres::SizedCostFunction<15, 6, 3, 3, 3> {
673 const Eigen::Affine3d T_prior,
674 const Eigen::Vector3d v,
675 const Eigen::Vector3d v_prior,
676 const Eigen::Vector3d ba,
677 const Eigen::Vector3d ba_prior,
678 const Eigen::Vector3d bg,
679 const Eigen::Vector3d bg_prior,
680 const Eigen::MatrixXd sqrt_inf)
685 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
686 Eigen::Map<Eigen::Matrix<double, 15, 1>> err(residuals);
689 err.block(6, 0, 3, 1) =
_v + Eigen::Map<const Eigen::Vector3d>(parameters[1]) -
_v_prior;
690 err.block(9, 0, 3, 1) =
_ba + Eigen::Map<const Eigen::Vector3d>(parameters[2]) -
_ba_prior;
691 err.block(12, 0, 3, 1) =
_bg + Eigen::Map<const Eigen::Vector3d>(parameters[3]) -
_bg_prior;
694 if (jacobians != NULL) {
696 if (jacobians[0] != NULL) {
697 Eigen::Map<Eigen::Matrix<double, 15, 6, Eigen::RowMajor>> J(jacobians[0]);
699 Eigen::Vector3d dw = Eigen::Vector3d(parameters[0][0], parameters[0][1], parameters[0][2]);
702 J.block(0, 0, 3, 3) =
704 J.block(3, 0, 3, 3) = T.rotation() *
707 J.block(3, 3, 3, 3) =
_T.rotation();
711 if (jacobians[1] != NULL) {
712 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_v(jacobians[1]);
714 J_v.block(6, 0, 3, 3) = Eigen::Matrix3d::Identity();
717 if (jacobians[2] != NULL) {
718 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_ba(jacobians[2]);
720 J_ba.block(9, 0, 3, 3) = Eigen::Matrix3d::Identity();
723 if (jacobians[3] != NULL) {
724 Eigen::Map<Eigen::Matrix<double, 15, 3, Eigen::RowMajor>> J_bg(jacobians[3]);
726 J_bg.block(12, 0, 3, 3) = Eigen::Matrix3d::Identity();
746 virtual bool Evaluate(
double const *
const *parameters,
double *residuals,
double **jacobians)
const {
747 residuals[0] =
_sqrt_inf * (1 - parameters[0][0]);
749 if (jacobians != NULL) {
760 #endif // RESIDUALS_H