32 using Point =
typename POSE::Translation;
33 using Rot =
typename POSE::Rotation;
35 const Point measured_;
38 boost::optional<POSE> body_P_sensor_;
40 static const int MeasDim = Point::RowsAtCompileTime;
45 using shared_ptr = boost::shared_ptr<MagPoseFactor<POSE>>;
48 GTSAM_CONCEPT_TESTABLE_TYPE(POSE)
49 GTSAM_CONCEPT_POSE_TYPE(POSE)
68 const Point& measured,
70 const Point& direction,
73 const boost::optional<POSE>& body_P_sensor)
74 :
Base(model, pose_key),
75 measured_(body_P_sensor ? body_P_sensor->rotation() * measured : measured),
76 nM_(scale * direction.normalized()),
77 bias_(body_P_sensor ? body_P_sensor->rotation() * bias : bias),
78 body_P_sensor_(body_P_sensor) {}
81 NonlinearFactor::shared_ptr
clone()
const override {
82 return boost::static_pointer_cast<NonlinearFactor>(
83 NonlinearFactor::shared_ptr(
new This(*
this)));
89 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
92 gtsam::print(Vector(measured_),
"measured field (bM): ");
98 const This *e =
dynamic_cast<const This*
> (&expected);
111 Vector
evaluateError(
const POSE& nPb, boost::optional<Matrix&> H = boost::none)
const override {
114 Matrix H_rot = Matrix::Zero(MeasDim, RotDim);
115 const Point hx = nPb.rotation().unrotate(nM_, H_rot, boost::none) + bias_;
119 *H = Matrix::Zero(MeasDim, PoseDim);
120 const size_t rot_col0 = nPb.rotationInterval().first;
121 (*H).block(0, rot_col0, MeasDim, RotDim) = H_rot;
124 return (hx - measured_);
130 template<
class ARCHIVE>
131 void serialize(ARCHIVE & ar,
const unsigned int ) {
132 ar & boost::serialization::make_nvp(
"NoiseModelFactor1",
133 boost::serialization::base_object<Base>(*
this));
134 ar & BOOST_SERIALIZATION_NVP(measured_);
135 ar & BOOST_SERIALIZATION_NVP(nM_);
136 ar & BOOST_SERIALIZATION_NVP(bias_);
137 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
Non-linear factor base classes.
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
This is the base class for all factor types.
Definition: Factor.h:56
Factor to estimate rotation of a Pose2 or Pose3 given a magnetometer reading.
Definition: MagPoseFactor.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Implement functions needed for Testable.
Definition: MagPoseFactor.h:89
~MagPoseFactor() override
Concept check by type.
Definition: MagPoseFactor.h:52
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Equals function.
Definition: MagPoseFactor.h:97
NonlinearFactor::shared_ptr clone() const override
Definition: MagPoseFactor.h:81
friend class boost::serialization::access
Serialization function.
Definition: MagPoseFactor.h:129
MagPoseFactor(Key pose_key, const Point &measured, double scale, const Point &direction, const Point &bias, const SharedNoiseModel &model, const boost::optional< POSE > &body_P_sensor)
Construct the factor.
Definition: MagPoseFactor.h:67
Vector evaluateError(const POSE &nPb, boost::optional< Matrix & > H=boost::none) const override
Implement functions needed to derive from Factor.
Definition: MagPoseFactor.h:111
MagPoseFactor()
Default constructor - only use for serialization.
Definition: MagPoseFactor.h:55
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 1 variable.
Definition: NonlinearFactor.h:285
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...