MagFactor.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/geometry/Rot2.h>
21 #include <gtsam/geometry/Rot3.h>
22 
23 namespace gtsam {
24 
31 class MagFactor: public NoiseModelFactor1<Rot2> {
32 
33  const Point3 measured_;
34  const Point3 nM_;
35  const Point3 bias_;
36 
37 public:
38 
48  MagFactor(Key key, const Point3& measured, double scale,
49  const Unit3& direction, const Point3& bias,
50  const SharedNoiseModel& model) :
51  NoiseModelFactor1<Rot2>(model, key), //
52  measured_(measured), nM_(scale * direction), bias_(bias) {
53  }
54 
57  return boost::static_pointer_cast<NonlinearFactor>(
59  }
60 
61  static Point3 unrotate(const Rot2& R, const Point3& p,
62  boost::optional<Matrix&> HR = boost::none) {
63  Point3 q = Rot3::Yaw(R.theta()).unrotate(p, HR, boost::none);
64  if (HR) {
65  // assign to temporary first to avoid error in Win-Debug mode
66  Matrix H = HR->col(2);
67  *HR = H;
68  }
69  return q;
70  }
71 
76  boost::optional<Matrix&> H = boost::none) const override {
77  // measured bM = nRb� * nM + b
78  Point3 hx = unrotate(nRb, nM_, H) + bias_;
79  return (hx - measured_);
80  }
81 };
82 
88 class MagFactor1: public NoiseModelFactor1<Rot3> {
89 
90  const Point3 measured_;
91  const Point3 nM_;
92  const Point3 bias_;
93 
94 public:
95 
98  const Unit3& direction, const Point3& bias,
99  const SharedNoiseModel& model) :
100  NoiseModelFactor1<Rot3>(model, key), //
101  measured_(measured), nM_(scale * direction), bias_(bias) {
102  }
103 
106  return boost::static_pointer_cast<NonlinearFactor>(
108  }
109 
114  boost::optional<Matrix&> H = boost::none) const override {
115  // measured bM = nRb� * nM + b
116  Point3 hx = nRb.unrotate(nM_, H, boost::none) + bias_;
117  return (hx - measured_);
118  }
119 };
120 
126 class MagFactor2: public NoiseModelFactor2<Point3, Point3> {
127 
129  const Rot3 bRn_;
130 
131 public:
132 
135  const SharedNoiseModel& model) :
136  NoiseModelFactor2<Point3, Point3>(model, key1, key2), //
137  measured_(measured), bRn_(nRb.inverse()) {
138  }
139 
142  return boost::static_pointer_cast<NonlinearFactor>(
144  }
145 
152  boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
153  boost::none) const override {
154  // measured bM = nRb� * nM + b, where b is unknown bias
155  Point3 hx = bRn_.rotate(nM, boost::none, H1) + bias;
156  if (H2)
157  *H2 = I_3x3;
158  return (hx - measured_);
159  }
160 };
161 
167 class MagFactor3: public NoiseModelFactor3<double, Unit3, Point3> {
168 
170  const Rot3 bRn_;
171 
172 public:
173 
176  const Rot3& nRb, const SharedNoiseModel& model) :
177  NoiseModelFactor3<double, Unit3, Point3>(model, key1, key2, key3), //
178  measured_(measured), bRn_(nRb.inverse()) {
179  }
180 
183  return boost::static_pointer_cast<NonlinearFactor>(
185  }
186 
192  Vector evaluateError(const double& scale, const Unit3& direction,
193  const Point3& bias, boost::optional<Matrix&> H1 = boost::none,
194  boost::optional<Matrix&> H2 = boost::none, boost::optional<Matrix&> H3 =
195  boost::none) const override {
196  // measured bM = nRb� * nM + b, where b is unknown bias
197  Unit3 rotated = bRn_.rotate(direction, boost::none, H2);
198  Point3 hx = scale * rotated.point3() + bias;
199  if (H1)
200  *H1 = rotated.point3();
201  if (H2) // H2 is 2*2, but we need 3*2
202  {
203  Matrix H;
204  rotated.point3(H);
205  *H2 = scale * H * (*H2);
206  }
207  if (H3)
208  *H3 = I_3x3;
209  return (hx - measured_);
210  }
211 };
212 
213 }
214 
const Point3 nM_
Local magnetic field (mag output units)
Definition: MagFactor.h:34
noiseModel::Diagonal::shared_ptr model
MagFactor2(Key key1, Key key2, const Point3 &measured, const Rot3 &nRb, const SharedNoiseModel &model)
Definition: MagFactor.h:134
const Point3 measured_
The measured magnetometer values.
Definition: MagFactor.h:128
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
const Point3 bias_
bias
Definition: MagFactor.h:92
Rot2 R(Rot2::fromAngle(0.1))
Point3 unrotate(const Point3 &p, OptionalJacobian< 3, 3 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
rotate point from world to rotated frame
Definition: Rot3.cpp:136
Vector evaluateError(const Rot3 &nRb, boost::optional< Matrix & > H=boost::none) const override
vector of errors
Definition: MagFactor.h:113
Vector evaluateError(const Rot2 &nRb, boost::optional< Matrix & > H=boost::none) const override
vector of errors
Definition: MagFactor.h:75
const Point3 measured_
The measured magnetometer values.
Definition: MagFactor.h:33
Vector evaluateError(const Point3 &nM, const Point3 &bias, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
vector of errors
Definition: MagFactor.h:151
const Point3 measured_
The measured magnetometer values.
Definition: MagFactor.h:169
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
const Rot3 bRn_
The assumed known rotation from nav to body.
Definition: MagFactor.h:129
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
Definition: Rot3M.cpp:149
const Rot3 bRn_
The assumed known rotation from nav to body.
Definition: MagFactor.h:170
Point3 nM(22653.29982,-1956.83010, 44202.47862)
const Symbol key1('v', 1)
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
static Rot3 Yaw(double t)
Positive yaw is to right (as in aircraft heading). See ypr.
Definition: Rot3.h:177
Eigen::VectorXd Vector
Definition: Vector.h:38
Vector evaluateError(const double &scale, const Unit3 &direction, const Point3 &bias, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
vector of errors
Definition: MagFactor.h:192
double theta() const
Definition: Rot2.h:183
const Point3 bias_
bias
Definition: MagFactor.h:35
boost::shared_ptr< This > shared_ptr
EIGEN_DEVICE_FUNC const Scalar & q
GTSAM_EXPORT Point3 point3(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Point3.
Definition: Unit3.cpp:136
const Point3 nM_
Local magnetic field (mag output units)
Definition: MagFactor.h:91
MagFactor1(Key key, const Point3 &measured, double scale, const Unit3 &direction, const Point3 &bias, const SharedNoiseModel &model)
Definition: MagFactor.h:97
Point3 bias(10,-10, 50)
NonlinearFactor::shared_ptr clone() const override
Definition: MagFactor.h:105
const Point3 measured_
The measured magnetometer values.
Definition: MagFactor.h:90
traits
Definition: chartTesting.h:28
NonlinearFactor::shared_ptr clone() const override
Definition: MagFactor.h:182
Non-linear factor base classes.
const Symbol key3('v', 3)
NonlinearFactor::shared_ptr clone() const override
Definition: MagFactor.h:56
const Symbol key2('v', 2)
static Point3 unrotate(const Rot2 &R, const Point3 &p, boost::optional< Matrix & > HR=boost::none)
Definition: MagFactor.h:61
#define HR
Definition: mincover.c:26
float * p
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
Vector3 Point3
Definition: Point3.h:35
Point3 measured
Rot3 nRb
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
2D rotation
NonlinearFactor::shared_ptr clone() const override
Definition: MagFactor.h:141
MagFactor3(Key key1, Key key2, Key key3, const Point3 &measured, const Rot3 &nRb, const SharedNoiseModel &model)
Definition: MagFactor.h:175
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
3D rotation represented as a rotation matrix or quaternion
MagFactor(Key key, const Point3 &measured, double scale, const Unit3 &direction, const Point3 &bias, const SharedNoiseModel &model)
Definition: MagFactor.h:48


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