2013-08-03 00:04:17 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file CombinedImuFactor.h
|
2014-11-28 18:16:04 +08:00
|
|
|
* @author Luca Carlone
|
|
|
|
* @author Stephen Williams
|
|
|
|
* @author Richard Roberts
|
|
|
|
* @author Vadim Indelman
|
|
|
|
* @author David Jensen
|
|
|
|
* @author Frank Dellaert
|
2013-08-03 00:04:17 +08:00
|
|
|
**/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/* GTSAM includes */
|
2014-11-03 18:02:15 +08:00
|
|
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
2014-12-27 01:23:14 +08:00
|
|
|
#include <gtsam/navigation/PreintegrationBase.h>
|
2015-07-19 09:30:42 +08:00
|
|
|
#include <gtsam/base/Matrix.h>
|
2013-08-03 00:04:17 +08:00
|
|
|
|
|
|
|
namespace gtsam {
|
|
|
|
|
2015-07-21 11:57:47 +08:00
|
|
|
/*
|
|
|
|
* If you are using the factor, please cite:
|
|
|
|
* L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, Eliminating
|
|
|
|
* conditionally independent sets in factor graphs: a unifying perspective based
|
|
|
|
* on smart factors, Int. Conf. on Robotics and Automation (ICRA), 2014.
|
|
|
|
*
|
|
|
|
* REFERENCES:
|
|
|
|
* [1] G.S. Chirikjian, "Stochastic Models, Information Theory, and Lie Groups",
|
|
|
|
* Volume 2, 2008.
|
|
|
|
* [2] T. Lupton and S.Sukkarieh, "Visual-Inertial-Aided Navigation for
|
|
|
|
* High-Dynamic Motion in Built Environments Without Initial Conditions",
|
|
|
|
* TRO, 28(1):61-76, 2012.
|
|
|
|
* [3] L. Carlone, S. Williams, R. Roberts, "Preintegrated IMU factor:
|
|
|
|
* Computation of the Jacobian Matrices", Tech. Report, 2013.
|
|
|
|
* [4] C. Forster, L. Carlone, F. Dellaert, D. Scaramuzza, IMU Preintegration on
|
|
|
|
* Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation,
|
|
|
|
* Robotics: Science and Systems (RSS), 2015.
|
|
|
|
*/
|
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/**
|
2015-07-19 09:30:42 +08:00
|
|
|
* PreintegratedCombinedMeasurements integrates the IMU measurements
|
|
|
|
* (rotation rates and accelerations) and the corresponding covariance matrix.
|
|
|
|
* The measurements are then used to build the CombinedImuFactor. Integration
|
|
|
|
* is done incrementally (ideally, one integrates the measurement as soon as
|
|
|
|
* it is received from the IMU) so as to avoid costly integration at time of
|
|
|
|
* factor construction.
|
2015-07-21 11:57:47 +08:00
|
|
|
*
|
|
|
|
* @addtogroup SLAM
|
2015-07-19 09:30:42 +08:00
|
|
|
*/
|
|
|
|
class PreintegratedCombinedMeasurements : public PreintegrationBase {
|
|
|
|
|
|
|
|
/// Parameters for pre-integration:
|
|
|
|
/// Usage: Create just a single Params and pass a shared pointer to the constructor
|
|
|
|
struct Params : PreintegrationBase::Params {
|
|
|
|
Matrix3 biasAccCovariance; ///< continuous-time "Covariance" describing accelerometer bias random walk
|
|
|
|
Matrix3 biasOmegaCovariance; ///< continuous-time "Covariance" describing gyroscope bias random walk
|
|
|
|
Matrix6 biasAccOmegaInit; ///< covariance of bias used for pre-integration
|
|
|
|
|
2015-07-24 19:22:32 +08:00
|
|
|
/// See two named constructors below for good values of n_gravity in body frame
|
|
|
|
Params(const Vector3& n_gravity) :
|
|
|
|
PreintegrationBase::Params(n_gravity), biasAccCovariance(I_3x3), biasOmegaCovariance(
|
2015-07-23 23:00:07 +08:00
|
|
|
I_3x3), biasAccOmegaInit(I_6x6) {
|
|
|
|
}
|
|
|
|
|
2015-07-24 19:22:32 +08:00
|
|
|
// Default Params for a Z-down navigation frame, such as NED: gravity points along positive Z-axis
|
|
|
|
static boost::shared_ptr<Params> MakeSharedD(double g = 9.81) {
|
2015-07-23 23:00:07 +08:00
|
|
|
return boost::make_shared<Params>(Vector3(0, 0, g));
|
|
|
|
}
|
|
|
|
|
2015-07-24 19:22:32 +08:00
|
|
|
// Default Params for a Z-up navigation frame, such as ENU: gravity points along negative Z-axis
|
|
|
|
static boost::shared_ptr<Params> MakeSharedU(double g = 9.81) {
|
2015-07-23 23:00:07 +08:00
|
|
|
return boost::make_shared<Params>(Vector3(0, 0, -g));
|
|
|
|
}
|
2015-07-19 09:30:42 +08:00
|
|
|
|
|
|
|
private:
|
2015-07-23 23:00:07 +08:00
|
|
|
/// Default constructor makes unitialized params struct
|
|
|
|
Params() {}
|
|
|
|
|
2015-07-19 09:30:42 +08:00
|
|
|
/** Serialization function */
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template <class ARCHIVE>
|
|
|
|
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
|
|
|
|
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(PreintegratedRotation::Params);
|
|
|
|
ar& BOOST_SERIALIZATION_NVP(biasAccCovariance);
|
|
|
|
ar& BOOST_SERIALIZATION_NVP(biasOmegaCovariance);
|
|
|
|
ar& BOOST_SERIALIZATION_NVP(biasAccOmegaInit);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Covariance matrix of the preintegrated measurements
|
|
|
|
* COVARIANCE OF: [PreintPOSITION PreintVELOCITY PreintROTATION BiasAcc BiasOmega]
|
|
|
|
* (first-order propagation from *measurementCovariance*).
|
|
|
|
* PreintegratedCombinedMeasurements also include the biases and keep the correlation
|
|
|
|
* between the preintegrated measurements and the biases
|
|
|
|
*/
|
|
|
|
Eigen::Matrix<double, 15, 15> preintMeasCov_;
|
|
|
|
|
|
|
|
PreintegratedCombinedMeasurements() {}
|
|
|
|
|
|
|
|
friend class CombinedImuFactor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor, initializes the class with no measurements
|
|
|
|
* @param bias Current estimate of acceleration and rotation rate biases
|
|
|
|
*/
|
2015-07-27 02:51:51 +08:00
|
|
|
PreintegratedCombinedMeasurements(const boost::shared_ptr<Params>& p,
|
2015-07-19 09:30:42 +08:00
|
|
|
const imuBias::ConstantBias& biasHat)
|
|
|
|
: PreintegrationBase(p, biasHat) {
|
|
|
|
preintMeasCov_.setZero();
|
|
|
|
}
|
|
|
|
|
2015-07-27 02:51:51 +08:00
|
|
|
Params& p() const { return *boost::static_pointer_cast<Params>(p_);}
|
2015-07-19 09:30:42 +08:00
|
|
|
|
|
|
|
/// print
|
|
|
|
void print(const std::string& s = "Preintegrated Measurements:") const;
|
|
|
|
|
|
|
|
/// equals
|
|
|
|
bool equals(const PreintegratedCombinedMeasurements& expected,
|
|
|
|
double tol = 1e-9) const;
|
|
|
|
|
|
|
|
/// Re-initialize PreintegratedCombinedMeasurements
|
|
|
|
void resetIntegration();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a single IMU measurement to the preintegration.
|
|
|
|
* @param measuredAcc Measured acceleration (in body frame, as given by the
|
|
|
|
* sensor)
|
|
|
|
* @param measuredOmega Measured angular velocity (as given by the sensor)
|
|
|
|
* @param deltaT Time interval between two consecutive IMU measurements
|
|
|
|
* @param body_P_sensor Optional sensor frame (pose of the IMU in the body
|
|
|
|
* frame)
|
|
|
|
*/
|
2015-08-01 06:32:16 +08:00
|
|
|
void integrateMeasurement(const Vector3& measuredAcc,
|
2015-08-01 06:42:22 +08:00
|
|
|
const Vector3& measuredOmega, double deltaT);
|
2015-07-19 09:30:42 +08:00
|
|
|
|
|
|
|
/// methods to access class variables
|
|
|
|
Matrix preintMeasCov() const { return preintMeasCov_; }
|
|
|
|
|
|
|
|
/// deprecated constructor
|
2015-07-24 19:22:32 +08:00
|
|
|
/// NOTE(frank): assumes Z-Down convention, only second order integration supported
|
2015-07-19 09:30:42 +08:00
|
|
|
PreintegratedCombinedMeasurements(const imuBias::ConstantBias& biasHat,
|
|
|
|
const Matrix3& measuredAccCovariance,
|
|
|
|
const Matrix3& measuredOmegaCovariance,
|
|
|
|
const Matrix3& integrationErrorCovariance,
|
|
|
|
const Matrix3& biasAccCovariance, const Matrix3& biasOmegaCovariance,
|
2015-07-23 23:00:07 +08:00
|
|
|
const Matrix6& biasAccOmegaInit, const bool use2ndOrderIntegration = true);
|
2015-07-19 09:30:42 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Serialization function
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template <class ARCHIVE>
|
|
|
|
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
|
|
|
|
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(PreintegrationBase);
|
|
|
|
ar& BOOST_SERIALIZATION_NVP(preintMeasCov_);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-12-27 01:23:14 +08:00
|
|
|
* CombinedImuFactor is a 6-ways factor involving previous state (pose and
|
|
|
|
* velocity of the vehicle, as well as bias at previous time step), and current
|
|
|
|
* state (pose, velocity, bias at current time step). Following the pre-
|
|
|
|
* integration scheme proposed in [2], the CombinedImuFactor includes many IMU
|
2015-07-19 09:30:42 +08:00
|
|
|
* measurements, which are "summarized" using the PreintegratedCombinedMeasurements
|
2014-12-27 01:23:14 +08:00
|
|
|
* class. There are 3 main differences wrpt the ImuFactor class:
|
|
|
|
* 1) The factor is 6-ways, meaning that it also involves both biases (previous
|
|
|
|
* and current time step).Therefore, the factor internally imposes the biases
|
|
|
|
* to be slowly varying; in particular, the matrices "biasAccCovariance" and
|
|
|
|
* "biasOmegaCovariance" described the random walk that models bias evolution.
|
|
|
|
* 2) The preintegration covariance takes into account the noise in the bias
|
|
|
|
* estimate used for integration.
|
2015-07-19 09:30:42 +08:00
|
|
|
* 3) The covariance matrix of the PreintegratedCombinedMeasurements preserves
|
2014-12-27 01:23:14 +08:00
|
|
|
* the correlation between the bias uncertainty and the preintegrated
|
|
|
|
* measurements uncertainty.
|
2015-07-21 11:57:47 +08:00
|
|
|
*
|
|
|
|
* @addtogroup SLAM
|
2014-12-03 05:41:35 +08:00
|
|
|
*/
|
2015-03-11 10:20:51 +08:00
|
|
|
class CombinedImuFactor: public NoiseModelFactor6<Pose3, Vector3, Pose3,
|
2015-07-19 09:30:42 +08:00
|
|
|
Vector3, imuBias::ConstantBias, imuBias::ConstantBias> {
|
2014-12-03 05:41:35 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
private:
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
typedef CombinedImuFactor This;
|
2015-03-11 10:20:51 +08:00
|
|
|
typedef NoiseModelFactor6<Pose3, Vector3, Pose3, Vector3,
|
|
|
|
imuBias::ConstantBias, imuBias::ConstantBias> Base;
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2015-07-19 09:30:42 +08:00
|
|
|
PreintegratedCombinedMeasurements _PIM_;
|
|
|
|
|
|
|
|
/** Default constructor - only use for serialization */
|
|
|
|
CombinedImuFactor() {}
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
/** Shorthand for a smart pointer to a factor */
|
2014-03-26 04:31:51 +08:00
|
|
|
#if !defined(_MSC_VER) && __GNUC__ == 4 && __GNUC_MINOR__ > 5
|
2014-12-03 05:41:35 +08:00
|
|
|
typedef typename boost::shared_ptr<CombinedImuFactor> shared_ptr;
|
2014-03-26 04:31:51 +08:00
|
|
|
#else
|
2014-12-03 05:41:35 +08:00
|
|
|
typedef boost::shared_ptr<CombinedImuFactor> shared_ptr;
|
2014-03-26 04:31:51 +08:00
|
|
|
#endif
|
2014-02-01 22:28:04 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param pose_i Previous pose key
|
|
|
|
* @param vel_i Previous velocity key
|
|
|
|
* @param pose_j Current pose key
|
|
|
|
* @param vel_j Current velocity key
|
|
|
|
* @param bias_i Previous bias key
|
|
|
|
* @param bias_j Current bias key
|
2015-07-19 09:30:42 +08:00
|
|
|
* @param PreintegratedCombinedMeasurements Combined IMU measurements
|
2014-12-03 05:41:35 +08:00
|
|
|
*/
|
2015-07-19 09:30:42 +08:00
|
|
|
CombinedImuFactor(
|
|
|
|
Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i, Key bias_j,
|
|
|
|
const PreintegratedCombinedMeasurements& preintegratedMeasurements);
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2015-07-19 09:30:42 +08:00
|
|
|
virtual ~CombinedImuFactor() {}
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/// @return a deep copy of this factor
|
|
|
|
virtual gtsam::NonlinearFactor::shared_ptr clone() const;
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/** implement functions needed for Testable */
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/// print
|
2015-03-11 10:20:51 +08:00
|
|
|
virtual void print(const std::string& s, const KeyFormatter& keyFormatter =
|
|
|
|
DefaultKeyFormatter) const;
|
2014-10-15 06:08:26 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/// equals
|
2015-03-11 10:20:51 +08:00
|
|
|
virtual bool equals(const NonlinearFactor& expected, double tol = 1e-9) const;
|
2014-10-15 06:08:26 +08:00
|
|
|
|
2014-12-03 05:41:35 +08:00
|
|
|
/** Access the preintegrated measurements. */
|
2013-08-03 00:04:17 +08:00
|
|
|
|
2015-07-19 09:30:42 +08:00
|
|
|
const PreintegratedCombinedMeasurements& preintegratedMeasurements() const {
|
2015-03-11 10:20:51 +08:00
|
|
|
return _PIM_;
|
|
|
|
}
|
2014-12-03 05:41:35 +08:00
|
|
|
|
|
|
|
/** implement functions needed to derive from Factor */
|
|
|
|
|
|
|
|
/// vector of errors
|
2015-03-11 10:20:51 +08:00
|
|
|
Vector evaluateError(const Pose3& pose_i, const Vector3& vel_i,
|
|
|
|
const Pose3& pose_j, const Vector3& vel_j,
|
2014-12-03 05:41:35 +08:00
|
|
|
const imuBias::ConstantBias& bias_i, const imuBias::ConstantBias& bias_j,
|
2015-03-11 10:20:51 +08:00
|
|
|
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
|
|
|
|
boost::none, boost::optional<Matrix&> H3 = boost::none,
|
|
|
|
boost::optional<Matrix&> H4 = boost::none, boost::optional<Matrix&> H5 =
|
|
|
|
boost::none, boost::optional<Matrix&> H6 = boost::none) const;
|
2014-12-03 05:41:35 +08:00
|
|
|
|
2015-07-19 09:30:42 +08:00
|
|
|
/// @deprecated typename
|
|
|
|
typedef gtsam::PreintegratedCombinedMeasurements CombinedPreintegratedMeasurements;
|
|
|
|
|
|
|
|
/// @deprecated constructor
|
|
|
|
CombinedImuFactor(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias_i,
|
|
|
|
Key bias_j, const CombinedPreintegratedMeasurements& pim,
|
2015-07-24 19:22:32 +08:00
|
|
|
const Vector3& n_gravity, const Vector3& omegaCoriolis,
|
2015-07-19 09:30:42 +08:00
|
|
|
const boost::optional<Pose3>& body_P_sensor = boost::none,
|
|
|
|
const bool use2ndOrderCoriolis = false);
|
|
|
|
|
|
|
|
// @deprecated use PreintegrationBase::predict
|
2015-03-11 10:20:51 +08:00
|
|
|
static void Predict(const Pose3& pose_i, const Vector3& vel_i, Pose3& pose_j,
|
2015-07-19 09:30:42 +08:00
|
|
|
Vector3& vel_j, const imuBias::ConstantBias& bias_i,
|
2015-07-19 16:52:23 +08:00
|
|
|
CombinedPreintegratedMeasurements& pim,
|
2015-07-24 19:22:32 +08:00
|
|
|
const Vector3& n_gravity, const Vector3& omegaCoriolis,
|
2015-07-19 09:30:42 +08:00
|
|
|
const bool use2ndOrderCoriolis = false);
|
2014-12-03 05:41:35 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/** Serialization function */
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template<class ARCHIVE>
|
2015-03-06 23:12:09 +08:00
|
|
|
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
|
2014-12-03 05:41:35 +08:00
|
|
|
ar & boost::serialization::make_nvp("NoiseModelFactor6",
|
2015-04-09 18:56:58 +08:00
|
|
|
boost::serialization::base_object<Base>(*this));
|
2014-12-27 01:23:14 +08:00
|
|
|
ar & BOOST_SERIALIZATION_NVP(_PIM_);
|
2014-12-03 05:41:35 +08:00
|
|
|
}
|
2015-03-11 10:20:51 +08:00
|
|
|
};
|
|
|
|
// class CombinedImuFactor
|
2013-08-03 00:04:17 +08:00
|
|
|
|
|
|
|
} /// namespace gtsam
|