20#include <gtsam/config.h>
22#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
44 typedef NoiseModelFactorT<Vector9, POSE, POSE> Base;
45 typedef FullIMUFactor<POSE> This;
50 Vector3 accel_, gyro_;
56 using Base::evaluateError;
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);
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);
73 ~FullIMUFactor()
override {}
76 gtsam::NonlinearFactor::shared_ptr clone()
const override {
77 return std::static_pointer_cast<gtsam::NonlinearFactor>(
78 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
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) &&
86 std::abs(dt_ - f->dt_) < tol;
90 std::string a =
"FullIMUFactor: " + s;
91 Base::print(a, formatter);
94 std::cout <<
"dt: " << dt_ << std::endl;
98 const Vector3& gyro()
const {
return gyro_; }
99 const Vector3& accel()
const {
return accel_; }
100 Vector6 z()
const {
return (Vector(6) << accel_, gyro_).finished(); }
106 Vector9 evaluateError(
const PoseRTV& x1,
const PoseRTV& x2,
107 OptionalMatrixType H1,
108 OptionalMatrixType H2)
const override {
110 z.head(3).operator=(accel_);
111 z.segment(3, 3).operator=(gyro_);
112 z.tail(3).operator=(x2.t());
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_);
121 virtual Vector evaluateError(
const Pose3& x1,
const Pose3& x2,
122 OptionalMatrixType H1, OptionalMatrixType H2)
const {
124 return Vector6::Zero();
130 static Vector9 predict_proxy(
const PoseRTV& x1,
const PoseRTV& x2,
double dt) {
132 hx.head(6).operator=(x1.imuPrediction(x2, dt));
133 hx.tail(3).operator=(x1.translationIntegration(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