28#include <gtsam/geometry/Unit3.h>
54 std::shared_ptr<Params> p_;
85 virtual void resetIntegration() = 0;
90 void resetIntegrationAndSetBias(
const Bias& biasHat);
94 return p_.get() == other.p_.get();
98 const std::shared_ptr<Params>&
params()
const {
112 double deltaTij()
const {
return deltaTij_; }
114 virtual Vector3 deltaPij()
const = 0;
115 virtual Vector3 deltaVij()
const = 0;
116 virtual Rot3 deltaRij()
const = 0;
117 virtual NavState deltaXij()
const = 0;
120 virtual Vector3 so3TangentAt(
double t)
const;
128 ConstMatrixView points,
129 const Vector3& velocity_i = Vector3::Zero())
const;
132 Matrix deskewPointsAtTimes(
133 ConstMatrixView points,
const Vector& times,
134 const Vector3& velocity_i = Vector3::Zero())
const;
137 Vector6 biasHatVector()
const {
return biasHat_.
vector(); }
142 GTSAM_EXPORT
friend std::ostream& operator<<(std::ostream& os,
const PreintegrationBase& pim);
143 virtual void print(
const std::string& s=
"")
const;
154 std::pair<Vector3, Vector3> correctMeasurementsBySensorPose(
155 const Vector3& unbiasedAcc,
const Vector3& unbiasedOmega,
156 OptionalJacobian<3, 3> correctedAcc_H_unbiasedAcc = {},
157 OptionalJacobian<3, 3> correctedAcc_H_unbiasedOmega = {},
158 OptionalJacobian<3, 3> correctedOmega_H_unbiasedOmega = {})
const;
165 virtual void update(
const Vector3& measuredAcc,
const Vector3& measuredOmega,
166 const double dt, Matrix9* A, Matrix93* B, Matrix93* C) = 0;
170 const Vector3& measuredOmega,
const double dt);
174 const Matrix& measuredOmegas,
const Matrix& dts);
188 const Vector3& n_gravity,
190 OptionalJacobian<9, 6> H2 = {},
191 OptionalJacobian<9, 3> H3 = {})
const;
194 NavState predict(
const NavState& state_i,
const imuBias::ConstantBias& bias_i,
195 OptionalJacobian<9, 9> H1 = {},
196 OptionalJacobian<9, 6> H2 = {})
const;
199#if GTSAM_ENABLE_BOOST_SERIALIZATION
201 friend class boost::serialization::access;
202 template<
class ARCHIVE>
203 void serialize(ARCHIVE & ar,
const unsigned int ) {
204 ar & BOOST_SERIALIZATION_NVP(p_);
205 ar & BOOST_SERIALIZATION_NVP(biasHat_);
206 ar & BOOST_SERIALIZATION_NVP(deltaTij_);
219 OptionalJacobian<9, 6> H3 = {}, OptionalJacobian<9, 3> H4 = {}) {
220 Matrix9 D_predict_state_i;
221 Matrix96 D_predict_bias_i;
222 Matrix93 D_predict_gravity;
223 const NavState predictedState_j = pim.predict(
224 state_i, bias_i, n_gravity, H1 ? &D_predict_state_i :
nullptr,
225 H3 ? &D_predict_bias_i :
nullptr,
226 H4 ? &D_predict_gravity :
nullptr);
228 Matrix9 D_error_state_j, D_error_predict;
231 switch (pim.params()->getImuFactorErrorMode()) {
233 useLogmap = PIM::kLegacyUsesLogmap;
242 throw std::invalid_argument(
"Unknown ImuFactorErrorMode");
246 error = state_j.
logmap(predictedState_j,
247 H2 ? &D_error_state_j :
nullptr,
248 H1 || H3 || H4 ? &D_error_predict :
nullptr);
250 error = internal::navStateComponentWiseLocalCoordinates(
251 state_j, predictedState_j, H2 ? &D_error_state_j :
nullptr,
252 H1 || H3 || H4 ? &D_error_predict :
nullptr);
255 if (H1) *H1 = D_error_predict * D_predict_state_i;
256 if (H2) *H2 = D_error_state_j;
257 if (H3) *H3 = D_error_predict * D_predict_bias_i;
258 if (H4) *H4 = D_error_predict * D_predict_gravity;
268 OptionalJacobian<9, 6> H3 = {}) {
270 pim.params()->n_gravity, H1, H2, H3);
276 const PIM& pim,
const Pose3& pose_i,
const Vector3& vel_i,
277 const Pose3& pose_j,
const Vector3& vel_j,
280 OptionalJacobian<9, 6> H3 = {}, OptionalJacobian<9, 3> H4 = {},
281 OptionalJacobian<9, 6> H5 = {}, OptionalJacobian<9, 3> H6 = {}) {
282 const NavState state_i(pose_i, vel_i), state_j(pose_j, vel_j);
284 Matrix9 D_error_state_i, D_error_state_j;
286 pim, state_i, state_j, bias_i, n_gravity,
287 H1 || H2 ? &D_error_state_i :
nullptr,
288 H3 || H4 ? &D_error_state_j :
nullptr, H5, H6);
292 if (H1) *H1 = D_error_state_i.leftCols<6>();
293 if (H2) *H2 = D_error_state_i.rightCols<3>() * state_i.
R().transpose();
294 if (H3) *H3 = D_error_state_j.leftCols<6>();
295 if (H4) *H4 = D_error_state_j.rightCols<3>() * state_j.
R().transpose();
302 const PIM& pim,
const Pose3& pose_i,
const Vector3& vel_i,
303 const Pose3& pose_j,
const Vector3& vel_j,
306 OptionalJacobian<9, 6> H3 = {}, OptionalJacobian<9, 3> H4 = {},
307 OptionalJacobian<9, 6> H5 = {}) {
309 pim, pose_i, vel_i, pose_j, vel_j, bias_i,
310 pim.params()->n_gravity, H1, H2, H3, H4, H5);
321template <
class GRAVITY>
326 constexpr static int dimension = 2;
327 constexpr static bool usesMagnitude =
true;
328 static Vector3 vector(
const Unit3& gravity,
double magnitude,
330 return gravity.
scaled(magnitude, H);
336 constexpr static int dimension = 3;
337 constexpr static bool usesMagnitude =
false;
338 static Vector3 vector(
const Point3& gravity,
double ,
340 if (H) H->setIdentity();
355template <
class GRAVITY,
class PIM>
357 const std::optional<double>& gravityMagnitude) {
359 if (gravityMagnitude)
360 throw std::invalid_argument(
361 factorName +
": gravityMagnitude is only used by the Unit3 "
362 "parametrization; the Point3 parametrization optimizes the magnitude "
363 "as part of the gravity variable - to constrain it, add a "
364 "VectorNormFactor<3> on the gravity variable instead");
367 if (!gravityMagnitude && !pim.params())
368 throw std::invalid_argument(
369 factorName +
": the preintegrated measurements have no params to take "
370 "the default gravityMagnitude from");
371 const double magnitude =
372 gravityMagnitude ? *gravityMagnitude : pim.params()->n_gravity.norm();
373 if (!(magnitude > 0.0))
374 throw std::invalid_argument(factorName +
375 ": gravityMagnitude must be positive");
typedef and functions to augment Eigen's MatrixXd
Navigation state composing of attitude, position, and velocity.
Vector9 preintegrationError(const PIM &pim, const NavState &state_i, const NavState &state_j, const imuBias::ConstantBias &bias_i, const Vector3 &n_gravity, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={}, OptionalJacobian< 9, 6 > H3={}, OptionalJacobian< 9, 3 > H4={})
Calculate the 9-dof preintegration error for an explicit gravity vector.
Definition PreintegrationBase.h:215
double resolveGravityMagnitude(const std::string &factorName, const PIM &pim, const std::optional< double > &gravityMagnitude)
Resolve the gravity magnitude stored by the gravity-aware IMU factors at construction.
Definition PreintegrationBase.h:356
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
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
@ Legacy
Historical backend-dependent error chart.
Definition PreintegrationParams.h:30
@ ComponentWise
Use the component-wise NavState error for every backend.
Definition PreintegrationParams.h:31
@ Logmap
Use the SE_2(3) NavState Logmap for every backend.
Definition PreintegrationParams.h:32
TangentVector logmap(const Class &g) const
logmap as required by manifold concept Applies logarithmic map to group element that takes *this to g
Definition Lie.h:161
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Represents a 3D point on a unit sphere.
Definition Unit3.h:44
Vector3 scaled(double magnitude, OptionalJacobian< 3, 2 > H_this={}, OptionalJacobian< 3, 1 > H_magnitude={}) const
Return this direction scaled by a magnitude, i.e.
Definition Unit3.cpp:158
Vector6 vector() const
return the accelerometer and gyro biases in a single vector
Definition ImuBias.h:61
Navigation state: Pose (rotation, translation) + velocity Following Barrau20icra, this class belongs ...
Definition NavState.h:45
Matrix3 R() const
Return rotation matrix. Induces computation in quaternion mode.
Definition NavState.h:119
PreintegrationBase is the base class for PreintegratedMeasurements (in ImuFactor) and CombinedPreinte...
Definition PreintegrationBase.h:45
double deltaTij_
Time interval from i to j.
Definition PreintegrationBase.h:60
const std::shared_ptr< Params > & params() const
shared pointer to params
Definition PreintegrationBase.h:98
virtual ~PreintegrationBase()
Virtual destructor for serialization.
Definition PreintegrationBase.h:66
bool matchesParamsWith(const PreintegrationBase &other) const
check parameters equality: checks whether shared pointer points to same Params object.
Definition PreintegrationBase.h:93
static constexpr bool kLegacyUsesLogmap
Legacy factor-error choice for this preintegration backend.
Definition PreintegrationBase.h:51
Params & p() const
const reference to params
Definition PreintegrationBase.h:103
virtual Vector9 biasCorrectedDelta(const imuBias::ConstantBias &bias_i, OptionalJacobian< 9, 6 > H={}) const =0
Given the estimate of the bias, return a NavState tangent vector summarizing the preintegrated IMU me...
Bias biasHat_
Acceleration and gyro bias used for preintegration.
Definition PreintegrationBase.h:57
PreintegrationBase()
Default constructor for serialization.
Definition PreintegrationBase.h:63
void integrateMeasurements(const Matrix &measuredAccs, const Matrix &measuredOmegas, const Matrix &dts)
Add multiple measurements, in matrix columns.
Definition PreintegrationBase.cpp:119
virtual void update(const Vector3 &measuredAcc, const Vector3 &measuredOmega, const double dt, Matrix9 *A, Matrix93 *B, Matrix93 *C)=0
Update preintegrated measurements and get derivatives It takes measured quantities in the j frame Mod...
virtual void integrateMeasurement(const Vector3 &measuredAcc, const Vector3 &measuredOmega, const double dt)
Version without derivatives.
Definition PreintegrationBase.cpp:109
Adapter mapping a gravity parametrization GRAVITY to the nav-frame gravity vector expected by Preinte...
Definition PreintegrationBase.h:322
Parameters for pre-integration: Usage: Create just a single Params and pass a shared pointer to the c...
Definition PreintegrationParams.h:37