FullIMUFactor.h
Go to the documentation of this file.
1 
7 #pragma once
8 
12 
13 namespace gtsam {
14 
22 template<class POSE>
23 class FullIMUFactor : public NoiseModelFactor2<POSE, POSE> {
24 public:
27 
28 protected:
29 
32  double dt_;
33 
34 public:
35 
38  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
39  : Base(model, key1, key2), accel_(accel), gyro_(gyro), dt_(dt) {
40  assert(model->dim() == 9);
41  }
42 
44  FullIMUFactor(const Vector6& imu,
45  double dt, const Key& key1, const Key& key2, const SharedNoiseModel& model)
46  : Base(model, key1, key2), accel_(imu.head(3)), gyro_(imu.tail(3)), dt_(dt) {
47  assert(imu.size() == 6);
48  assert(model->dim() == 9);
49  }
50 
51  ~FullIMUFactor() override {}
52 
55  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
57 
59  bool equals(const NonlinearFactor& e, double tol = 1e-9) const override {
60  const This* const f = dynamic_cast<const This*>(&e);
61  return f && Base::equals(e) &&
62  equal_with_abs_tol(accel_, f->accel_, tol) &&
63  equal_with_abs_tol(gyro_, f->gyro_, tol) &&
64  std::abs(dt_ - f->dt_) < tol;
65  }
66 
67  void print(const std::string& s="", const gtsam::KeyFormatter& formatter = gtsam::DefaultKeyFormatter) const override {
68  std::string a = "FullIMUFactor: " + s;
70  gtsam::print((Vector)accel_, "accel");
71  gtsam::print((Vector)gyro_, "gyro");
72  std::cout << "dt: " << dt_ << std::endl;
73  }
74 
75  // access
76  const Vector3& gyro() const { return gyro_; }
77  const Vector3& accel() const { return accel_; }
78  Vector6 z() const { return (Vector(6) << accel_, gyro_).finished(); }
79 
85  boost::optional<Matrix&> H1 = boost::none,
86  boost::optional<Matrix&> H2 = boost::none) const override {
87  Vector9 z;
88  z.head(3).operator=(accel_); // Strange syntax to work around ambiguous operator error with clang
89  z.segment(3, 3).operator=(gyro_); // Strange syntax to work around ambiguous operator error with clang
90  z.tail(3).operator=(x2.t()); // Strange syntax to work around ambiguous operator error with clang
91  if (H1) *H1 = numericalDerivative21<Vector9, PoseRTV, PoseRTV>(
92  boost::bind(This::predict_proxy, _1, _2, dt_), x1, x2, 1e-5);
93  if (H2) *H2 = numericalDerivative22<Vector9, PoseRTV, PoseRTV>(
94  boost::bind(This::predict_proxy, _1, _2, dt_), x1, x2, 1e-5);
95  return z - predict_proxy(x1, x2, dt_);
96  }
97 
99  virtual Vector evaluateError(const Pose3& x1, const Pose3& x2,
100  boost::optional<Matrix&> H1 = boost::none,
101  boost::optional<Matrix&> H2 = boost::none) const {
102  assert(false);
103  return Vector6::Zero();
104  }
105 
106 private:
107 
109  static Vector9 predict_proxy(const PoseRTV& x1, const PoseRTV& x2, double dt) {
110  Vector9 hx;
111  hx.head(6).operator=(x1.imuPrediction(x2, dt)); // Strange syntax to work around ambiguous operator error with clang
112  hx.tail(3).operator=(x1.translationIntegration(x2, dt)); // Strange syntax to work around ambiguous operator error with clang
113  return hx;
114  }
115 };
116 
117 } // \namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: FullIMUFactor.h:54
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Eigen::Vector3d Vector3
Definition: Vector.h:43
bool equals(const NonlinearFactor &e, double tol=1e-9) const override
Definition: FullIMUFactor.h:59
noiseModel::Diagonal::shared_ptr model
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
This is the const version of tail(Index).
Definition: BlockMethods.h:949
~FullIMUFactor() override
Definition: FullIMUFactor.h:51
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)
FullIMUFactor< POSE > This
Definition: FullIMUFactor.h:26
const Vector3 & accel() const
Definition: FullIMUFactor.h:77
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
Array33i a
const double dt
const Vector3 & gyro() const
Definition: FullIMUFactor.h:76
Eigen::VectorXd Vector
Definition: Vector.h:38
const Point3 & t() const
Definition: PoseRTV.h:58
virtual Vector evaluateError(const Pose3 &x1, const Pose3 &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Definition: FullIMUFactor.h:99
Point3 translationIntegration(const Rot3 &r2, const Velocity3 &v2, double dt) const
Definition: PoseRTV.cpp:161
boost::shared_ptr< This > shared_ptr
void print(const std::string &s="", const gtsam::KeyFormatter &formatter=gtsam::DefaultKeyFormatter) const override
Definition: FullIMUFactor.h:67
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
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
NoiseModelFactor2< POSE, POSE > Base
Definition: FullIMUFactor.h:25
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Non-linear factor base classes.
EIGEN_DEVICE_FUNC SegmentReturnType head(Index n)
This is the const version of head(Index).
Definition: BlockMethods.h:919
static Vector9 predict_proxy(const PoseRTV &x1, const PoseRTV &x2, double dt)
Pose3 x1
Definition: testPose3.cpp:588
Vector6 z() const
Definition: FullIMUFactor.h:78
FullIMUFactor(const Vector6 &imu, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
Definition: FullIMUFactor.h:44
Vector evaluateError(const PoseRTV &x1, const PoseRTV &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Definition: FullIMUFactor.h:84
const G double tol
Definition: Group.h:83
#define abs(x)
Definition: datatypes.h:17
FullIMUFactor(const Vector3 &accel, const Vector3 &gyro, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
time between measurements
Definition: FullIMUFactor.h:37
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734


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