gtsam
Loading...
Searching...
No Matches
FullIMUFactor.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
17
18#pragma once
19
20#include <gtsam/config.h>
21
22#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
23
27
28#include <cassert>
29
30namespace gtsam {
31
41template<class POSE>
42class FullIMUFactor : public NoiseModelFactorT<Vector9, POSE, POSE> {
43public:
44 typedef NoiseModelFactorT<Vector9, POSE, POSE> Base;
45 typedef FullIMUFactor<POSE> This;
46
47protected:
48
50 Vector3 accel_, gyro_;
51 double dt_;
52
53public:
54
55 // Provide access to the Matrix& version of evaluateError:
56 using Base::evaluateError;
57
59 FullIMUFactor(const Vector3& accel, const Vector3& gyro,
60 double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
61 : Base(model, key1, key2), accel_(accel), gyro_(gyro), dt_(dt) {
62 assert(model->dim() == 9);
63 }
64
66 FullIMUFactor(const Vector6& imu,
67 double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
68 : Base(model, key1, key2), accel_(imu.head(3)), gyro_(imu.tail(3)), dt_(dt) {
69 assert(imu.size() == 6);
70 assert(model->dim() == 9);
71 }
72
73 ~FullIMUFactor() override {}
74
76 gtsam::NonlinearFactor::shared_ptr clone() const override {
77 return std::static_pointer_cast<gtsam::NonlinearFactor>(
78 gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
79
81 bool equals(const NonlinearFactor& e, double tol = 1e-9) const override {
82 const This* const f = dynamic_cast<const This*>(&e);
83 return f && Base::equals(e) &&
84 equal_with_abs_tol(accel_, f->accel_, tol) &&
85 equal_with_abs_tol(gyro_, f->gyro_, tol) &&
86 std::abs(dt_ - f->dt_) < tol;
87 }
88
89 void print(const std::string& s="", const gtsam::KeyFormatter& formatter = gtsam::DefaultKeyFormatter) const override {
90 std::string a = "FullIMUFactor: " + s;
91 Base::print(a, formatter);
92 gtsam::print((Vector)accel_, "accel");
93 gtsam::print((Vector)gyro_, "gyro");
94 std::cout << "dt: " << dt_ << std::endl;
95 }
96
97 // access
98 const Vector3& gyro() const { return gyro_; }
99 const Vector3& accel() const { return accel_; }
100 Vector6 z() const { return (Vector(6) << accel_, gyro_).finished(); }
101
106 Vector9 evaluateError(const PoseRTV& x1, const PoseRTV& x2,
107 OptionalMatrixType H1,
108 OptionalMatrixType H2) const override {
109 Vector9 z;
110 z.head(3).operator=(accel_); // Strange syntax to work around ambiguous operator error with clang
111 z.segment(3, 3).operator=(gyro_); // Strange syntax to work around ambiguous operator error with clang
112 z.tail(3).operator=(x2.t()); // Strange syntax to work around ambiguous operator error with clang
113 if (H1) *H1 = numericalDerivative21<Vector9, PoseRTV, PoseRTV>(
114 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_), x1, x2, 1e-5);
115 if (H2) *H2 = numericalDerivative22<Vector9, PoseRTV, PoseRTV>(
116 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_), x1, x2, 1e-5);
117 return z - predict_proxy(x1, x2, dt_);
118 }
119
121 virtual Vector evaluateError(const Pose3& x1, const Pose3& x2,
122 OptionalMatrixType H1, OptionalMatrixType H2) const {
123 assert(false);
124 return Vector6::Zero();
125 }
126
127private:
128
130 static Vector9 predict_proxy(const PoseRTV& x1, const PoseRTV& x2, double dt) {
131 Vector9 hx;
132 hx.head(6).operator=(x1.imuPrediction(x2, dt)); // Strange syntax to work around ambiguous operator error with clang
133 hx.tail(3).operator=(x1.translationIntegration(x2, dt)); // Strange syntax to work around ambiguous operator error with clang
134 return hx;
135 }
136};
137
138} // \namespace gtsam
139
140#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
Numerical derivative helpers for manifold-valued functions.
Non-linear factor base classes.
Pose3 with translational velocity.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
equals with a tolerance
Definition Matrix.h:81
A convenient base class for creating your own NoiseModelFactor with n variables.
Definition NoiseModelFactorN.h:155