IMUFactor.h
Go to the documentation of this file.
1 
7 #pragma once
8 
12 
13 #include <cassert>
14 
15 namespace gtsam {
16 
22 template<class POSE>
23 class IMUFactor : public NoiseModelFactorN<POSE, POSE> {
24 public:
27 
28 protected:
29 
32  double dt_;
33 
34 public:
35 
36  // Provide access to the Matrix& version of evaluateError:
37  using Base::evaluateError;
38 
41  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
42  : Base(model, key1, key2), accel_(accel), gyro_(gyro), dt_(dt) {}
43 
45  IMUFactor(const Vector6& imu_vector,
46  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
47  : Base(model, key1, key2), accel_(imu_vector.head(3)), gyro_(imu_vector.tail(3)), dt_(dt) {}
48 
49  ~IMUFactor() override {}
50 
53  return std::static_pointer_cast<gtsam::NonlinearFactor>(
55 
57  bool equals(const NonlinearFactor& e, double tol = 1e-9) const override {
58  const This* const f = dynamic_cast<const This*>(&e);
59  return f && Base::equals(e) &&
60  equal_with_abs_tol(accel_, f->accel_, tol) &&
61  equal_with_abs_tol(gyro_, f->gyro_, tol) &&
62  std::abs(dt_ - f->dt_) < tol;
63  }
64 
65  void print(const std::string& s="", const gtsam::KeyFormatter& formatter = gtsam::DefaultKeyFormatter) const override {
66  std::string a = "IMUFactor: " + s;
68  gtsam::print((Vector)accel_, "accel");
69  gtsam::print((Vector)gyro_, "gyro");
70  std::cout << "dt: " << dt_ << std::endl;
71  }
72 
73  // access
74  const Vector3& gyro() const { return gyro_; }
75  const Vector3& accel() const { return accel_; }
76  Vector6 z() const { return (Vector6() << accel_, gyro_).finished(); }
77 
83  OptionalMatrixType H1, OptionalMatrixType H2) const override {
84  const Vector6 meas = z();
85  if (H1) *H1 = numericalDerivative21<Vector6, PoseRTV, PoseRTV>(
86  std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
87  if (H2) *H2 = numericalDerivative22<Vector6, PoseRTV, PoseRTV>(
88  std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
89  return predict_proxy(x1, x2, dt_, meas);
90  }
91 
93  virtual Vector evaluateError(const Pose3& x1, const Pose3& x2,
95  assert(false); // no corresponding factor here
96  return Vector6::Zero();
97  }
98 
99 private:
101  static Vector6 predict_proxy(const PoseRTV& x1, const PoseRTV& x2,
102  double dt, const Vector6& meas) {
103  Vector6 hx = x1.imuPrediction(x2, dt);
104  return meas - hx;
105  }
106 };
107 
108 } // \namespace gtsam
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::IMUFactor::gyro_
Vector3 gyro_
Definition: IMUFactor.h:31
tail
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type tail(NType n)
Definition: BlockMethods.h:1257
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::IMUFactor::gyro
const Vector3 & gyro() const
Definition: IMUFactor.h:74
gtsam::IMUFactor::equals
bool equals(const NonlinearFactor &e, double tol=1e-9) const override
Definition: IMUFactor.h:57
gtsam::NoiseModelFactorN< POSE, POSE >::evaluateError
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
dt
const double dt
Definition: testVelocityConstraint.cpp:15
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::equal_with_abs_tol
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Definition: base/Matrix.h:80
gtsam::Factor
Definition: Factor.h:70
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:44
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::IMUFactor::z
Vector6 z() const
Definition: IMUFactor.h:76
gtsam::IMUFactor::accel_
Vector3 accel_
Definition: IMUFactor.h:31
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
numericalDerivative.h
Some functions to compute numerical derivatives.
gtsam::IMUFactor::predict_proxy
static Vector6 predict_proxy(const PoseRTV &x1, const PoseRTV &x2, double dt, const Vector6 &meas)
Definition: IMUFactor.h:101
x1
Pose3 x1
Definition: testPose3.cpp:663
gtsam::IMUFactor::evaluateError
Vector evaluateError(const PoseRTV &x1, const PoseRTV &x2, OptionalMatrixType H1, OptionalMatrixType H2) const override
Definition: IMUFactor.h:82
gtsam::KeyFormatter
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
gtsam::Pose3
Definition: Pose3.h:37
gtsam::IMUFactor::evaluateError
virtual Vector evaluateError(const Pose3 &x1, const Pose3 &x2, OptionalMatrixType H1, OptionalMatrixType H2) const
Definition: IMUFactor.h:93
gtsam::IMUFactor::IMUFactor
IMUFactor(const Vector3 &accel, const Vector3 &gyro, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
Definition: IMUFactor.h:40
gtsam::IMUFactor::~IMUFactor
~IMUFactor() override
Definition: IMUFactor.h:49
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:432
gtsam::NoiseModelFactor::print
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: NonlinearFactor.cpp:74
PoseRTV.h
Pose3 with translational velocity.
gtsam::IMUFactor::IMUFactor
IMUFactor(const Vector6 &imu_vector, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
Definition: IMUFactor.h:45
gtsam::NoiseModelFactor::equals
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Definition: NonlinearFactor.cpp:82
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::IMUFactor::Base
NoiseModelFactorN< POSE, POSE > Base
Definition: IMUFactor.h:25
gtsam::NoiseModelFactorN< POSE, POSE >::key1
Key key1() const
Definition: NonlinearFactor.h:732
head
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type head(NType n)
Definition: BlockMethods.h:1208
gtsam::IMUFactor::print
void print(const std::string &s="", const gtsam::KeyFormatter &formatter=gtsam::DefaultKeyFormatter) const override
Definition: IMUFactor.h:65
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
gtsam::IMUFactor::dt_
double dt_
Definition: IMUFactor.h:32
gtsam::IMUFactor
Definition: IMUFactor.h:23
gtsam::IMUFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: IMUFactor.h:52
gtsam::PoseRTV
Definition: PoseRTV.h:23
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
NonlinearFactor.h
Non-linear factor base classes.
gtsam::IMUFactor::This
IMUFactor< POSE > This
Definition: IMUFactor.h:26
gtsam::NoiseModelFactorN< POSE, POSE >::key2
Key key2() const
Definition: NonlinearFactor.h:736
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: SFMdata.h:40
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:69
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:56
abs
#define abs(x)
Definition: datatypes.h:17
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::IMUFactor::accel
const Vector3 & accel() const
Definition: IMUFactor.h:75
x2
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:41