gtsam
Loading...
Searching...
No Matches
CombinedImuFactor.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
22
23#pragma once
24
25/* GTSAM includes */
29
30#include <type_traits>
31
32namespace gtsam {
33
34#ifdef GTSAM_LIEGROUP_PREINTEGRATION
35typedef LieGroupPreintegration DefaultPreintegrationType;
36#elif defined(GTSAM_TANGENT_PREINTEGRATION)
37typedef TangentPreintegration DefaultPreintegrationType;
38#else
39typedef ManifoldPreintegration DefaultPreintegrationType;
40#endif
41
42/*
43 * If you are using the factor, please cite:
44 * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, Eliminating
45 * conditionally independent sets in factor graphs: a unifying perspective based
46 * on smart factors, Int. Conf. on Robotics and Automation (ICRA), 2014.
47 *
48 * REFERENCES:
49 * [1] G.S. Chirikjian, "Stochastic Models, Information Theory, and Lie Groups",
50 * Volume 2, 2008.
51 * [2] T. Lupton and S.Sukkarieh, "Visual-Inertial-Aided Navigation for
52 * High-Dynamic Motion in Built Environments Without Initial Conditions",
53 * TRO, 28(1):61-76, 2012.
54 * [3] L. Carlone, S. Williams, R. Roberts, "Preintegrated IMU factor:
55 * Computation of the Jacobian Matrices", Tech. Report, 2013.
56 * Available in this repo as "PreintegratedIMUJacobians.pdf".
57 * [4] C. Forster, L. Carlone, F. Dellaert, D. Scaramuzza, IMU Preintegration on
58 * Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation,
59 * Robotics: Science and Systems (RSS), 2015.
60 */
61
72template <class PreintegrationType>
73class GTSAM_EXPORT PreintegratedCombinedMeasurementsT : public PreintegrationType {
74 public:
75 typedef PreintegrationCombinedParams Params;
76
77 protected:
78 /* Covariance matrix of the preintegrated measurements
79 * COVARIANCE OF: [PreintROTATION PreintPOSITION PreintVELOCITY BiasAcc
80 * BiasOmega] (first-order propagation from *measurementCovariance*).
81 * PreintegratedCombinedMeasurements also include the biases and keep the
82 * correlation between the preintegrated measurements and the biases
83 */
84 Eigen::Matrix<double, 15, 15> preintMeasCov_;
85
86 template <class PIM> friend class CombinedImuFactorT;
87
88 public:
91
94
102 const std::shared_ptr<Params>& p,
104 const Eigen::Matrix<double, 15, 15>& preintMeasCov =
105 Eigen::Matrix<double, 15, 15>::Zero())
106 : PreintegrationType(p, biasHat), preintMeasCov_(preintMeasCov) {
107 this->PreintegrationType::resetIntegration();
108 }
109
117 const PreintegrationType& base,
118 const Eigen::Matrix<double, 15, 15>& preintMeasCov)
119 : PreintegrationType(base), preintMeasCov_(preintMeasCov) {
120 this->PreintegrationType::resetIntegration();
121 }
122
125
127
130
132 void resetIntegration() override;
133
135 Params& p() const { return *std::static_pointer_cast<Params>(this->p_); }
137
141 Matrix preintMeasCov() const { return preintMeasCov_; }
142
174 Matrix residualCovariance() const {
175 // An endpoint attitude is needed only for the rotating-frame lift.
176 if (!this->params() || !this->p().omegaCoriolis ||
177 this->p().omegaCoriolis->isZero(0.0)) {
178 return residualCovarianceAt(Rot3());
179 }
181 this->predict(NavState(), this->biasHat()).attitude());
182 }
183
192 Matrix residualCovarianceAt(const Rot3& predictedAttitude) const {
193 Eigen::Matrix<double, 15, 15> physicalChart =
194 Eigen::Matrix<double, 15, 15>::Identity();
195 if (this->params() && this->p().omegaCoriolis) {
196 const Matrix3 rotation = predictedAttitude.matrix();
197 physicalChart.template block<3, 3>(6, 3) =
198 -rotation.transpose() *
199 skewSymmetric(*this->p().omegaCoriolis) * rotation;
200 }
201 Eigen::Matrix<double, 15, 15> chartJacobian =
202 Eigen::Matrix<double, 15, 15>::Identity();
203 chartJacobian.bottomRightCorner<6, 6>() = -I_6x6;
204
205 if constexpr (std::is_same_v<PreintegrationType, TangentPreintegration>) {
206 Matrix9 preintegrationChartJacobian;
208 NavState(), this->preintegrated_, {},
209 &preintegrationChartJacobian);
210 chartJacobian.topLeftCorner<9, 9>() = preintegrationChartJacobian;
211 }
212
213 physicalChart *= chartJacobian;
214 return physicalChart * preintMeasCov_ * physicalChart.transpose();
215 }
216
217
221 void print(
222 const std::string& s = "Preintegrated Measurements:") const override;
225 double tol = 1e-9) const;
227
230
241 void integrateMeasurement(const Vector3& measuredAcc,
242 const Vector3& measuredOmega,
243 const double dt) override;
244
246
247#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
249 void resetIntegration(const gtsam::Matrix6& Q_init) {
250 std::cerr << "Warning: setBiasAccOmegaInit() is deprecated and no longer used." << std::endl;
251 PreintegrationType::resetIntegration();
252 preintMeasCov_.setZero();
253 }
254#endif
255
256 private:
257#if GTSAM_ENABLE_BOOST_SERIALIZATION
259 friend class boost::serialization::access;
260 template <class ARCHIVE>
261 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
262 namespace bs = ::boost::serialization;
263 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(PreintegrationType);
264 ar& BOOST_SERIALIZATION_NVP(preintMeasCov_);
265 }
266#endif
267};
268
269// For backward compatibility:
270using PreintegratedCombinedMeasurements = PreintegratedCombinedMeasurementsT<DefaultPreintegrationType>;
271
290template <class PIM = PreintegratedCombinedMeasurements>
291class GTSAM_EXPORT CombinedImuFactorT
292 : public NoiseModelFactorN<Pose3, Vector3, Pose3, Vector3,
293 imuBias::ConstantBias, imuBias::ConstantBias> {
294 public:
295 private:
296 typedef CombinedImuFactorT<PIM> This;
297 typedef NoiseModelFactorN<Pose3, Vector3, Pose3, Vector3,
299 Base;
300
301 PIM pim_;
302
303 public:
304 // Provide access to Matrix& version of evaluateError:
306
308 typedef std::shared_ptr<This> shared_ptr;
309
312
328 CombinedImuFactorT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i,
329 Key bias_j, const PIM& preintegratedMeasurements)
330 : Base(noiseModel::Gaussian::Covariance(
331 preintegratedMeasurements.residualCovariance()),
332 pose_i, vel_i, pose_j, vel_j, bias_i, bias_j),
334
352 template <class Measurement = PIM>
353 CombinedImuFactorT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i,
354 Key bias_j,
355 const Measurement& preintegratedMeasurements,
356 const Rot3& predictedAttitude)
357 : Base(noiseModel::Gaussian::Covariance(
358 preintegratedMeasurements.residualCovarianceAt(
359 predictedAttitude)),
360 pose_i, vel_i, pose_j, vel_j, bias_i, bias_j),
362
363 ~CombinedImuFactorT() override {}
364
366 gtsam::NonlinearFactor::shared_ptr clone() const override {
367 return std::make_shared<This>(*this);
368 }
369
371
375 void print(const std::string& s = "", const KeyFormatter& keyFormatter =
376 DefaultKeyFormatter) const override;
377
379 bool equals(const NonlinearFactor& expected,
380 double tol = 1e-9) const override;
382
384
385 const PIM& preintegratedMeasurements() const {
386 return pim_;
387 }
388
390
392 Vector evaluateError(const Pose3& pose_i, const Vector3& vel_i,
393 const Pose3& pose_j, const Vector3& vel_j,
394 const imuBias::ConstantBias& bias_i,
395 const imuBias::ConstantBias& bias_j,
399 OptionalMatrixType H6) const override;
400
401 private:
402#if GTSAM_ENABLE_BOOST_SERIALIZATION
404 friend class boost::serialization::access;
405 template <class ARCHIVE>
406 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
407 // NoiseModelFactor6 instead of NoiseModelFactorN for backward compatibility
408 ar& boost::serialization::make_nvp(
409 "NoiseModelFactor6", boost::serialization::base_object<Base>(*this));
410 ar& BOOST_SERIALIZATION_NVP(pim_);
411 }
412#endif
413};
414// class CombinedImuFactorT
415
416// For backward compatibility:
417using CombinedImuFactor = CombinedImuFactorT<>;
418
419// operator<< for CombinedImuFactorT
420template <class PIM>
421GTSAM_EXPORT std::ostream& operator<<(std::ostream& os, const CombinedImuFactorT<PIM>& f);
422
423namespace internal {
429template <class PIM>
430Vector combinedImuError(const PIM& pim, const Pose3& pose_i,
431 const Vector3& vel_i, const Pose3& pose_j, const Vector3& vel_j,
432 const imuBias::ConstantBias& bias_i, const imuBias::ConstantBias& bias_j,
433 const Vector3& n_gravity, OptionalMatrixType H1, OptionalMatrixType H2,
435 OptionalMatrixType H6, Matrix93* D_r_gvec) {
436 // error wrt bias evolution model (random walk)
437 Matrix6 Hbias_i, Hbias_j;
438 Vector6 fbias = traits<imuBias::ConstantBias>::Between(bias_j, bias_i,
439 H6 ? &Hbias_j : 0, H5 ? &Hbias_i : 0).vector();
440
441 Matrix96 D_r_pose_i, D_r_pose_j, D_r_bias_i;
442 Matrix93 D_r_vel_i, D_r_vel_j;
443
444 // error wrt preintegrated measurements
446 pim, pose_i, vel_i, pose_j, vel_j, bias_i, n_gravity,
447 H1 ? &D_r_pose_i : nullptr, H2 ? &D_r_vel_i : nullptr,
448 H3 ? &D_r_pose_j : nullptr, H4 ? &D_r_vel_j : nullptr,
449 H5 ? &D_r_bias_i : nullptr, D_r_gvec);
450
451 // if we need the jacobians
452 if (H1) {
453 H1->resize(15, 6);
454 H1->block<9, 6>(0, 0) = D_r_pose_i;
455 // adding: [dBiasAcc/dPi ; dBiasOmega/dPi]
456 H1->block<6, 6>(9, 0).setZero();
457 }
458 if (H2) {
459 H2->resize(15, 3);
460 H2->block<9, 3>(0, 0) = D_r_vel_i;
461 // adding: [dBiasAcc/dVi ; dBiasOmega/dVi]
462 H2->block<6, 3>(9, 0).setZero();
463 }
464 if (H3) {
465 H3->resize(15, 6);
466 H3->block<9, 6>(0, 0) = D_r_pose_j;
467 // adding: [dBiasAcc/dPj ; dBiasOmega/dPj]
468 H3->block<6, 6>(9, 0).setZero();
469 }
470 if (H4) {
471 H4->resize(15, 3);
472 H4->block<9, 3>(0, 0) = D_r_vel_j;
473 // adding: [dBiasAcc/dVi ; dBiasOmega/dVi]
474 H4->block<6, 3>(9, 0).setZero();
475 }
476 if (H5) {
477 H5->resize(15, 6);
478 H5->block<9, 6>(0, 0) = D_r_bias_i;
479 // adding: [dBiasAcc/dBias_i ; dBiasOmega/dBias_i]
480 H5->block<6, 6>(9, 0) = Hbias_i;
481 }
482 if (H6) {
483 H6->resize(15, 6);
484 H6->block<9, 6>(0, 0).setZero();
485 // adding: [dBiasAcc/dBias_j ; dBiasOmega/dBias_j]
486 H6->block<6, 6>(9, 0) = Hbias_j;
487 }
488
489 // overall error
490 Vector r(15);
491 r << r_Rpv, fbias; // vector of size 15
492 return r;
493}
494} // namespace internal
495
496template <>
498 : public Testable<PreintegrationCombinedParams> {};
499
500template <class PreintegrationType>
502 : public Testable<PreintegratedCombinedMeasurementsT<PreintegrationType>> {};
503
504template <class PIM>
505struct traits<CombinedImuFactorT<PIM>> : public Testable<CombinedImuFactorT<PIM>> {};
506
507} // namespace gtsam
GTSAM_EXPORT NavState navStateComponentWiseRetract(const NavState &state, const Vector9 &v, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={})
Component-wise NavState retraction independent of the optimization chart.
Definition NavState.cpp:147
Vector9 preintegrationErrorAndJacobians(const PIM &pim, const Pose3 &pose_i, const Vector3 &vel_i, const Pose3 &pose_j, const Vector3 &vel_j, const imuBias::ConstantBias &bias_i, const Vector3 &n_gravity, OptionalJacobian< 9, 6 > H1={}, OptionalJacobian< 9, 3 > H2={}, OptionalJacobian< 9, 6 > H3={}, OptionalJacobian< 9, 3 > H4={}, OptionalJacobian< 9, 6 > H5={}, OptionalJacobian< 9, 3 > H6={})
Assemble pose/velocity Jacobians for an explicit gravity vector.
Definition PreintegrationBase.h:275
Vector combinedImuError(const PIM &pim, const Pose3 &pose_i, const Vector3 &vel_i, const Pose3 &pose_j, const Vector3 &vel_j, const imuBias::ConstantBias &bias_i, const imuBias::ConstantBias &bias_j, const Vector3 &n_gravity, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5, OptionalMatrixType H6, Matrix93 *D_r_gvec)
Shared 15-dof error and block-Jacobian assembly for CombinedImuFactorT and CombinedImuFactorWithGravi...
Definition CombinedImuFactor.h:430
IMU preintegration using the SE_2(3) group structure of NavState.
Base class for noise model factors with N variables.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
Matrix3 skewSymmetric(double wx, double wy, double wz)
skew symmetric matrix returns this: 0 -wz wy wz 0 -wx -wy wx 0
Definition Matrix.h:365
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65
Matrix3 matrix() const
return 3*3 rotation matrix
Definition Rot3M.cpp:261
PreintegratedCombinedMeasurements integrates the IMU measurements (rotation rates and accelerations) ...
Definition CombinedImuFactor.h:73
bool equals(const PreintegratedCombinedMeasurementsT< PreintegrationType > &expected, double tol=1e-9) const
equals
Definition CombinedImuFactor.cpp:69
PreintegratedCombinedMeasurementsT(const PreintegrationType &base, const Eigen::Matrix< double, 15, 15 > &preintMeasCov)
Construct preintegrated directly from members: base class and preintMeasCov.
Definition CombinedImuFactor.h:116
Matrix residualCovariance() const
Express the propagated covariance in the combined IMU factor residual chart.
Definition CombinedImuFactor.h:174
void integrateMeasurement(const Vector3 &measuredAcc, const Vector3 &measuredOmega, const double dt) override
Add a single IMU measurement to the preintegration.
Definition CombinedImuFactor.cpp:239
Matrix residualCovarianceAt(const Rot3 &predictedAttitude) const
Definition CombinedImuFactor.h:192
PreintegratedCombinedMeasurementsT()
Default constructor only for serialization and wrappers.
Definition CombinedImuFactor.h:93
Params & p() const
Definition CombinedImuFactor.h:135
PreintegratedCombinedMeasurementsT(const std::shared_ptr< Params > &p, const imuBias::ConstantBias &biasHat=imuBias::ConstantBias(), const Eigen::Matrix< double, 15, 15 > &preintMeasCov=Eigen::Matrix< double, 15, 15 >::Zero())
Default constructor, initializes the class with no measurements.
Definition CombinedImuFactor.h:101
~PreintegratedCombinedMeasurementsT() override
Virtual destructor.
Definition CombinedImuFactor.h:124
CombinedImuFactor is a 6-ways factor involving previous state (pose and velocity of the vehicle,...
Definition CombinedImuFactor.h:293
std::shared_ptr< This > shared_ptr
Definition CombinedImuFactor.h:308
Vector evaluateError(const Pose3 &pose_i, const Vector3 &vel_i, const Pose3 &pose_j, const Vector3 &vel_j, const imuBias::ConstantBias &bias_i, const imuBias::ConstantBias &bias_j, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5, OptionalMatrixType H6) const override
implement functions needed to derive from Factor
Definition CombinedImuFactor.cpp:285
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition CombinedImuFactor.cpp:278
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition CombinedImuFactor.h:366
CombinedImuFactorT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i, Key bias_j, const PIM &preintegratedMeasurements)
Constructor.
Definition CombinedImuFactor.h:328
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition CombinedImuFactor.cpp:265
CombinedImuFactorT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i, Key bias_j, const Measurement &preintegratedMeasurements, const Rot3 &predictedAttitude)
Construct a Combined factor whose rotating-frame covariance is expressed at a supplied nominal endpoi...
Definition CombinedImuFactor.h:353
const PIM & preintegratedMeasurements() const
Definition CombinedImuFactor.h:385
CombinedImuFactorT()
Default constructor - only use for serialization.
Definition CombinedImuFactor.h:311
Definition ImuBias.h:34
IMU preintegration using the SE_2(3) Lie-group structure of NavState.
Definition LieGroupPreintegration.h:32
IMU pre-integration on NavState manifold.
Definition ManifoldPreintegration.h:33
Navigation state: Pose (rotation, translation) + velocity Following Barrau20icra, this class belongs ...
Definition NavState.h:45
NavState predict(const NavState &state_i, const imuBias::ConstantBias &bias_i, const Vector3 &n_gravity, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 6 > H2={}, OptionalJacobian< 9, 3 > H3={}) const
Predict state at time j, for a given gravity vector in the nav frame.
Definition PreintegrationBase.cpp:205
const std::shared_ptr< Params > & params() const
shared pointer to params
Definition PreintegrationBase.h:98
Parameters for pre-integration using PreintegratedCombinedMeasurements: Usage: Create just a single P...
Definition PreintegrationCombinedParams.h:37
Integrate on the 9D tangent space of the NavState manifold.
Definition TangentPreintegration.h:28
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Nonlinear factor base class.
Definition NonlinearFactor.h:70
Gaussian implements the mathematical model |R*x|^2 = |y|^2 with R'*R=inv(Sigma) where y = whiten(x) =...
Definition NoiseModel.h:192