gtsam
Loading...
Searching...
No Matches
ImuFactorWithGravity.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
16
17#pragma once
18
20
21namespace gtsam {
22
41template <class PIM = PreintegratedImuMeasurements, class GRAVITY = Unit3>
42class GTSAM_EXPORT ImuFactorWithGravityT
43 : public NoiseModelFactorN<Pose3, Vector3, Pose3, Vector3,
44 imuBias::ConstantBias, GRAVITY> {
45private:
46
48 typedef NoiseModelFactorN<Pose3, Vector3, Pose3, Vector3,
49 imuBias::ConstantBias, GRAVITY> Base;
50
51 PIM pim_;
52 double gravityMagnitude_;
53
54public:
55
56 // Provide access to the Matrix& version of evaluateError:
58
60 typedef std::shared_ptr<This> shared_ptr;
61
63 ImuFactorWithGravityT() : gravityMagnitude_(0.0) {}
64
81 ImuFactorWithGravityT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias,
82 Key gravity, const PIM& preintegratedMeasurements,
83 std::optional<double> gravityMagnitude = {})
84 : Base(noiseModel::Gaussian::Covariance(
85 preintegratedMeasurements.residualCovariance()),
86 pose_i, vel_i, pose_j, vel_j, bias, gravity),
87 pim_(preintegratedMeasurements),
88 gravityMagnitude_(internal::resolveGravityMagnitude<GRAVITY>(
89 "ImuFactorWithGravityT", preintegratedMeasurements,
90 gravityMagnitude)) {}
91
92 ~ImuFactorWithGravityT() override {
93 }
94
96 gtsam::NonlinearFactor::shared_ptr clone() const override {
97 return std::make_shared<This>(*this);
98 }
99
102 void print(const std::string& s = "", const KeyFormatter& keyFormatter =
103 DefaultKeyFormatter) const override;
104 bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override;
106
108 const PIM& preintegratedMeasurements() const {
109 return pim_;
110 }
111
113 double gravityMagnitude() const {
114 return gravityMagnitude_;
115 }
116
118
120 Vector evaluateError(const Pose3& pose_i, const Vector3& vel_i,
121 const Pose3& pose_j, const Vector3& vel_j,
122 const imuBias::ConstantBias& bias_i,
123 const GRAVITY& gravity, OptionalMatrixType H1,
126 OptionalMatrixType H6) const override;
127
129 template <typename MethodPIMArg = PIM,
130 typename = typename std::enable_if<
131 std::is_same<MethodPIMArg, PreintegratedImuMeasurementsT<TangentPreintegration>>::value
132 >::type
133 >
137 ) {
138 if (f01->template key<5>() != f12->template key<5>())
139 throw std::domain_error("ImuFactorWithGravityT::Merge: IMU bias keys must be the same");
140
141 if (f01->template key<6>() != f12->template key<6>())
142 throw std::domain_error("ImuFactorWithGravityT::Merge: gravity keys must be the same");
143
145 std::abs(f01->gravityMagnitude() - f12->gravityMagnitude()) > 1e-9)
146 throw std::domain_error(
147 "ImuFactorWithGravityT::Merge: gravity magnitudes must be the same");
148
149 if (f01->template key<3>() != f12->template key<1>() || f01->template key<4>() != f12->template key<2>())
150 throw std::domain_error(
151 "ImuFactorWithGravityT::Merge: intermediate pose, velocity keys need to match up");
152
153 auto pim02 = ImuFactorT<MethodPIMArg>::Merge(f01->preintegratedMeasurements(),
154 f12->preintegratedMeasurements());
155
156 return std::make_shared<This>(
157 f01->template key<1>(), // P0
158 f01->template key<2>(), // V0
159 f12->template key<3>(), // P2
160 f12->template key<4>(), // V2
161 f01->template key<5>(), // B
162 f01->template key<6>(), // G
163 pim02,
165 ? std::optional<double>(f01->gravityMagnitude())
166 : std::nullopt);
167 }
168
169 private:
170#if GTSAM_ENABLE_BOOST_SERIALIZATION
172 friend class boost::serialization::access;
173 template<class ARCHIVE>
174 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
175 // Archive name for the base follows the sibling factors' convention:
176 ar & boost::serialization::make_nvp("NoiseModelFactor6",
177 boost::serialization::base_object<Base>(*this));
178 ar & BOOST_SERIALIZATION_NVP(pim_);
179 ar & BOOST_SERIALIZATION_NVP(gravityMagnitude_);
180 }
181#endif
182};
183// class ImuFactorWithGravityT
184
197
209
210// operator<< for ImuFactorWithGravityT
211template <class PIM, class GRAVITY>
212GTSAM_EXPORT std::ostream& operator<<(std::ostream& os,
214
215template <class PIM, class GRAVITY>
216struct traits<ImuFactorWithGravityT<PIM, GRAVITY>>
217 : public Testable<ImuFactorWithGravityT<PIM, GRAVITY>> {};
218
233template <class PIM = PreintegratedImuMeasurements, class GRAVITY = Unit3>
234class GTSAM_EXPORT ImuFactor2WithGravityT
235 : public NoiseModelFactorT<Vector9, NavState, NavState,
236 imuBias::ConstantBias, GRAVITY> {
237private:
238
241 GRAVITY>
242 Base;
243
244 PIM pim_;
245 double gravityMagnitude_;
246
247public:
248
249 // Provide access to the Matrix& version of evaluateError:
251
253 ImuFactor2WithGravityT() : gravityMagnitude_(0.0) {}
254
269 ImuFactor2WithGravityT(Key state_i, Key state_j, Key bias, Key gravity,
270 const PIM& preintegratedMeasurements,
271 std::optional<double> gravityMagnitude = {})
272 : Base(noiseModel::Gaussian::Covariance(
273 preintegratedMeasurements.residualCovariance()),
274 state_i, state_j, bias, gravity),
275 pim_(preintegratedMeasurements),
276 gravityMagnitude_(internal::resolveGravityMagnitude<GRAVITY>(
277 "ImuFactor2WithGravityT", preintegratedMeasurements,
278 gravityMagnitude)) {}
279
280 ~ImuFactor2WithGravityT() override {
281 }
282
284 gtsam::NonlinearFactor::shared_ptr clone() const override {
285 return std::make_shared<This>(*this);
286 }
287
290 void print(const std::string& s = "", const KeyFormatter& keyFormatter =
291 DefaultKeyFormatter) const override;
292 bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override;
294
296 const PIM& preintegratedMeasurements() const {
297 return pim_;
298 }
299
301 double gravityMagnitude() const {
302 return gravityMagnitude_;
303 }
304
306
308 Vector9 evaluateError(const NavState& state_i, const NavState& state_j,
309 const imuBias::ConstantBias& bias_i,
310 const GRAVITY& gravity, OptionalMatrixType H1,
312 OptionalMatrixType H4) const override;
313
314 private:
315#if GTSAM_ENABLE_BOOST_SERIALIZATION
317 friend class boost::serialization::access;
318 template<class ARCHIVE>
319 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
320 // Archive name for the base follows the sibling factors' convention:
321 ar & boost::serialization::make_nvp("NoiseModelFactor4",
322 boost::serialization::base_object<Base>(*this));
323 ar & BOOST_SERIALIZATION_NVP(pim_);
324 ar & BOOST_SERIALIZATION_NVP(gravityMagnitude_);
325 }
326#endif
327};
328// class ImuFactor2WithGravityT
329
336
343
344// operator<< for ImuFactor2WithGravityT
345template <class PIM, class GRAVITY>
346GTSAM_EXPORT std::ostream& operator<<(std::ostream& os,
348
349template <class PIM, class GRAVITY>
350struct traits<ImuFactor2WithGravityT<PIM, GRAVITY>>
351 : public Testable<ImuFactor2WithGravityT<PIM, GRAVITY>> {};
352
353}
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
ImuFactor2WithGravityT< PreintegratedImuMeasurements, Unit3 > ImuFactor2WithGravityDirection
ImuFactor2 variant with the gravity direction as an optimized Unit3 variable and a fixed,...
Definition ImuFactorWithGravity.h:334
ImuFactor2WithGravityT< PreintegratedImuMeasurements, Point3 > ImuFactor2WithGravityVector
ImuFactor2 variant with the gravity vector as a free Point3 variable, ie.
Definition ImuFactorWithGravity.h:341
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
ImuFactorWithGravityT< PreintegratedImuMeasurements, Point3 > ImuFactorWithGravityVector
ImuFactor variant with the gravity vector as a free Point3 variable, ie.
Definition ImuFactorWithGravity.h:207
ImuFactorWithGravityT< PreintegratedImuMeasurements, Unit3 > ImuFactorWithGravityDirection
ImuFactor variant with the gravity direction as an optimized Unit3 variable and a fixed,...
Definition ImuFactorWithGravity.h:195
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
Definition ImuBias.h:34
static MethodPIMArg Merge(const MethodPIMArg &pim01, const MethodPIMArg &pim12)
Merge two pre-integrated measurement classes.
Definition ImuFactor.h:364
ImuFactorWithGravityT is a 6-ways factor: in addition to the previous and current states (pose and ve...
Definition ImuFactorWithGravity.h:44
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition ImuFactorWithGravity.cpp:43
Vector evaluateError(const Pose3 &pose_i, const Vector3 &vel_i, const Pose3 &pose_j, const Vector3 &vel_j, const imuBias::ConstantBias &bias_i, const GRAVITY &gravity, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5, OptionalMatrixType H6) const override
implement functions needed to derive from Factor
Definition ImuFactorWithGravity.cpp:65
static ImuFactorWithGravityT< MethodPIMArg, GRAVITY >::shared_ptr Merge(const typename ImuFactorWithGravityT< MethodPIMArg, GRAVITY >::shared_ptr &f01, const typename ImuFactorWithGravityT< MethodPIMArg, GRAVITY >::shared_ptr &f12)
Merge two factors sharing bias and gravity keys, with consecutive states.
Definition ImuFactorWithGravity.h:134
ImuFactorWithGravityT(Key pose_i, Key vel_i, Key pose_j, Key vel_j, Key bias, Key gravity, const PIM &preintegratedMeasurements, std::optional< double > gravityMagnitude={})
Constructor.
Definition ImuFactorWithGravity.h:81
const PIM & preintegratedMeasurements() const
Definition ImuFactorWithGravity.h:108
double gravityMagnitude() const
Definition ImuFactorWithGravity.h:113
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Check if two factors are equal.
Definition ImuFactorWithGravity.cpp:55
std::shared_ptr< This > shared_ptr
Definition ImuFactorWithGravity.h:60
ImuFactorWithGravityT()
Default constructor - only use for serialization.
Definition ImuFactorWithGravity.h:63
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition ImuFactorWithGravity.h:96
ImuFactor2WithGravityT is the NavState version of ImuFactorWithGravityT, just as ImuFactor2T is the N...
Definition ImuFactorWithGravity.h:236
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition ImuFactorWithGravity.cpp:97
const PIM & preintegratedMeasurements() const
Definition ImuFactorWithGravity.h:296
double gravityMagnitude() const
Definition ImuFactorWithGravity.h:301
ImuFactor2WithGravityT(Key state_i, Key state_j, Key bias, Key gravity, const PIM &preintegratedMeasurements, std::optional< double > gravityMagnitude={})
Constructor.
Definition ImuFactorWithGravity.h:269
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Check if two factors are equal.
Definition ImuFactorWithGravity.cpp:109
ImuFactor2WithGravityT()
Default constructor - only use for serialization.
Definition ImuFactorWithGravity.h:253
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition ImuFactorWithGravity.h:284
Vector9 evaluateError(const NavState &state_i, const NavState &state_j, const imuBias::ConstantBias &bias_i, const GRAVITY &gravity, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override
implement functions needed to derive from Factor
Definition ImuFactorWithGravity.cpp:119
Navigation state: Pose (rotation, translation) + velocity Following Barrau20icra, this class belongs ...
Definition NavState.h:45
Adapter mapping a gravity parametrization GRAVITY to the nav-frame gravity vector expected by Preinte...
Definition PreintegrationBase.h:322
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Key key() const
Definition NoiseModelFactorN.h:307
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