IMUFactor.h
Go to the documentation of this file.
1 
7 #pragma once
8 
12 
13 namespace gtsam {
14 
20 template<class POSE>
21 class IMUFactor : public NoiseModelFactor2<POSE, POSE> {
22 public:
25 
26 protected:
27 
30  double dt_;
31 
32 public:
33 
36  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
37  : Base(model, key1, key2), accel_(accel), gyro_(gyro), dt_(dt) {}
38 
40  IMUFactor(const Vector6& imu_vector,
41  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
42  : Base(model, key1, key2), accel_(imu_vector.head(3)), gyro_(imu_vector.tail(3)), dt_(dt) {}
43 
44  ~IMUFactor() override {}
45 
48  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
50 
52  bool equals(const NonlinearFactor& e, double tol = 1e-9) const override {
53  const This* const f = dynamic_cast<const This*>(&e);
54  return f && Base::equals(e) &&
55  equal_with_abs_tol(accel_, f->accel_, tol) &&
56  equal_with_abs_tol(gyro_, f->gyro_, tol) &&
57  std::abs(dt_ - f->dt_) < tol;
58  }
59 
60  void print(const std::string& s="", const gtsam::KeyFormatter& formatter = gtsam::DefaultKeyFormatter) const override {
61  std::string a = "IMUFactor: " + s;
63  gtsam::print((Vector)accel_, "accel");
64  gtsam::print((Vector)gyro_, "gyro");
65  std::cout << "dt: " << dt_ << std::endl;
66  }
67 
68  // access
69  const Vector3& gyro() const { return gyro_; }
70  const Vector3& accel() const { return accel_; }
71  Vector6 z() const { return (Vector6() << accel_, gyro_).finished(); }
72 
78  boost::optional<Matrix&> H1 = boost::none,
79  boost::optional<Matrix&> H2 = boost::none) const override {
80  const Vector6 meas = z();
81  if (H1) *H1 = numericalDerivative21<Vector6, PoseRTV, PoseRTV>(
82  boost::bind(This::predict_proxy, _1, _2, dt_, meas), x1, x2, 1e-5);
83  if (H2) *H2 = numericalDerivative22<Vector6, PoseRTV, PoseRTV>(
84  boost::bind(This::predict_proxy, _1, _2, dt_, meas), x1, x2, 1e-5);
85  return predict_proxy(x1, x2, dt_, meas);
86  }
87 
89  virtual Vector evaluateError(const Pose3& x1, const Pose3& x2,
90  boost::optional<Matrix&> H1 = boost::none,
91  boost::optional<Matrix&> H2 = boost::none) const {
92  assert(false); // no corresponding factor here
93  return Vector6::Zero();
94  }
95 
96 private:
98  static Vector6 predict_proxy(const PoseRTV& x1, const PoseRTV& x2,
99  double dt, const Vector6& meas) {
100  Vector6 hx = x1.imuPrediction(x2, dt);
101  return meas - hx;
102  }
103 };
104 
105 } // \namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Vector evaluateError(const PoseRTV &x1, const PoseRTV &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Definition: IMUFactor.h:77
Vector3 accel_
Definition: IMUFactor.h:29
Eigen::Vector3d Vector3
Definition: Vector.h:43
noiseModel::Diagonal::shared_ptr model
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
This is the const version of tail(Index).
Definition: BlockMethods.h:949
static Vector6 predict_proxy(const PoseRTV &x1, const PoseRTV &x2, double dt, const Vector6 &meas)
Definition: IMUFactor.h:98
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: IMUFactor.h:47
IMUFactor< POSE > This
Definition: IMUFactor.h:24
Vector6 imuPrediction(const PoseRTV &x2, double dt) const
Definition: PoseRTV.cpp:133
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
Array33i a
const double dt
const Vector3 & gyro() const
Definition: IMUFactor.h:69
Eigen::VectorXd Vector
Definition: Vector.h:38
void print(const std::string &s="", const gtsam::KeyFormatter &formatter=gtsam::DefaultKeyFormatter) const override
Definition: IMUFactor.h:60
Vector6 z() const
Definition: IMUFactor.h:71
virtual Vector evaluateError(const Pose3 &x1, const Pose3 &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Definition: IMUFactor.h:89
boost::shared_ptr< This > shared_ptr
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
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
~IMUFactor() override
Definition: IMUFactor.h:44
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Definition: base/Matrix.h:84
Pose3 with translational velocity.
traits
Definition: chartTesting.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
bool equals(const NonlinearFactor &e, double tol=1e-9) const override
Definition: IMUFactor.h:52
Non-linear factor base classes.
EIGEN_DEVICE_FUNC SegmentReturnType head(Index n)
This is the const version of head(Index).
Definition: BlockMethods.h:919
NoiseModelFactor2< POSE, POSE > Base
Definition: IMUFactor.h:23
Pose3 x1
Definition: testPose3.cpp:588
const G double tol
Definition: Group.h:83
IMUFactor(const Vector6 &imu_vector, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
Definition: IMUFactor.h:40
#define abs(x)
Definition: datatypes.h:17
const Vector3 & accel() const
Definition: IMUFactor.h:70
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
IMUFactor(const Vector3 &accel, const Vector3 &gyro, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
time between measurements
Definition: IMUFactor.h:35
Vector3 gyro_
Definition: IMUFactor.h:29


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:13