20#include <gtsam/config.h>
22#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
42 typedef NoiseModelFactorT<Vector6, POSE, POSE> Base;
43 typedef IMUFactor<POSE> This;
48 Vector3 accel_, gyro_;
54 using Base::evaluateError;
57 IMUFactor(
const Vector3& accel,
const Vector3& gyro,
58 double dt,
const Key& key1,
const Key& key2,
const SharedNoiseModel& model)
59 : Base(model, key1, key2), accel_(accel), gyro_(gyro), dt_(dt) {}
62 IMUFactor(
const Vector6& imu_vector,
63 double dt,
const Key& key1,
const Key& key2,
const SharedNoiseModel& model)
64 : Base(model, key1, key2), accel_(imu_vector.head(3)), gyro_(imu_vector.tail(3)), dt_(dt) {}
66 ~IMUFactor()
override {}
69 gtsam::NonlinearFactor::shared_ptr clone()
const override {
70 return std::static_pointer_cast<gtsam::NonlinearFactor>(
71 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
74 bool equals(
const NonlinearFactor& e,
double tol = 1e-9)
const override {
75 const This*
const f =
dynamic_cast<const This*
>(&e);
76 return f && Base::equals(e) &&
79 std::abs(dt_ - f->dt_) < tol;
83 std::string a =
"IMUFactor: " + s;
84 Base::print(a, formatter);
87 std::cout <<
"dt: " << dt_ << std::endl;
91 const Vector3& gyro()
const {
return gyro_; }
92 const Vector3& accel()
const {
return accel_; }
93 Vector6 z()
const {
return (Vector6() << accel_, gyro_).finished(); }
99 Vector6 evaluateError(
const PoseRTV& x1,
const PoseRTV& x2,
100 OptionalMatrixType H1,
101 OptionalMatrixType H2)
const override {
102 const Vector6 meas = z();
103 if (H1) *H1 = numericalDerivative21<Vector6, PoseRTV, PoseRTV>(
104 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
105 if (H2) *H2 = numericalDerivative22<Vector6, PoseRTV, PoseRTV>(
106 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
107 return predict_proxy(x1, x2, dt_, meas);
111 virtual Vector evaluateError(
const Pose3& x1,
const Pose3& x2,
112 OptionalMatrixType H1, OptionalMatrixType H2)
const {
114 return Vector6::Zero();
119 static Vector6 predict_proxy(
const PoseRTV& x1,
const PoseRTV& x2,
120 double dt,
const Vector6& meas) {
121 Vector6 hx = x1.imuPrediction(x2, dt);
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