13#include <boost/bind/bind.hpp>
37 IMUFactor(
const Vector3& accel,
const Vector3& gyro,
44 :
Base(model,
key1, key2),
accel_(imu_vector.head(3)), gyro_(imu_vector.tail(3)), dt_(dt) {}
49 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
50 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
51 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
55 const This*
const f =
dynamic_cast<const This*
>(&e);
59 std::abs(dt_ - f->dt_) < tol;
63 std::string a =
"IMUFactor: " + s;
67 std::cout <<
"dt: " << dt_ << std::endl;
71 const Vector3& gyro()
const {
return gyro_; }
72 const Vector3& accel()
const {
return accel_; }
73 Vector6 z()
const {
return (Vector6() <<
accel_, gyro_).finished(); }
80 boost::optional<Matrix&> H1 = boost::none,
81 boost::optional<Matrix&> H2 = boost::none)
const override {
82 const Vector6 meas = z();
83 if (H1) *H1 = numericalDerivative21<Vector6, PoseRTV, PoseRTV>(
84 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
85 if (H2) *H2 = numericalDerivative22<Vector6, PoseRTV, PoseRTV>(
86 std::bind(This::predict_proxy, std::placeholders::_1, std::placeholders::_2, dt_, meas), x1, x2, 1e-5);
87 return predict_proxy(x1, x2, dt_, meas);
92 boost::optional<Matrix&> H1 = boost::none,
93 boost::optional<Matrix&> H2 = boost::none)
const {
95 return Vector6::Zero();
100 static Vector6 predict_proxy(
const PoseRTV& x1,
const PoseRTV& x2,
101 double dt,
const Vector6& meas) {
Some functions to compute numerical derivatives.
Non-linear factor base classes.
Pose3 with translational velocity.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:736
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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:84
This is the base class for all factor types.
Definition: Factor.h:56
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print.
Definition: NonlinearFactor.cpp:63
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:369
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:401
Class that represents integrating IMU measurements over time for dynamic systems Templated to allow f...
Definition: IMUFactor.h:23
Vector evaluateError(const PoseRTV &x1, const PoseRTV &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Error evaluation with optional derivatives - calculates z - h(x1,x2)
Definition: IMUFactor.h:79
virtual Vector evaluateError(const Pose3 &x1, const Pose3 &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
dummy version that fails for non-dynamic poses
Definition: IMUFactor.h:91
IMUFactor(const Vector3 &accel, const Vector3 &gyro, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
time between measurements
Definition: IMUFactor.h:37
IMUFactor(const Vector6 &imu_vector, double dt, const Key &key1, const Key &key2, const SharedNoiseModel &model)
Full IMU vector specification.
Definition: IMUFactor.h:42
Vector3 accel_
measurements from the IMU
Definition: IMUFactor.h:31
void print(const std::string &s="", const gtsam::KeyFormatter &formatter=gtsam::DefaultKeyFormatter) const override
Print.
Definition: IMUFactor.h:62
bool equals(const NonlinearFactor &e, double tol=1e-9) const override
Check if two factors are equal.
Definition: IMUFactor.h:54
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: IMUFactor.h:49
Robot state for use with IMU measurements.
Definition: PoseRTV.h:23
Vector6 imuPrediction(const PoseRTV &x2, double dt) const
Dynamics predictor for both ground and flying robots, given states at 1 and 2 Always move from time 1...
Definition: PoseRTV.cpp:133