testMagFactor.cpp
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/base/Testable.h>
22 
24 
26 
27 using namespace std;
28 using namespace gtsam;
29 using namespace GeographicLib;
30 
31 // *************************************************************************
32 // Convert from Mag to ENU
33 // ENU Origin is where the plane was in hold next to runway
34 // const double lat0 = 33.86998, lon0 = -84.30626, h0 = 274;
35 
36 // Get field from http://www.ngdc.noaa.gov/geomag-web/#igrfwmm
37 // Declination = -4.94 degrees (West), Inclination = 62.78 degrees Down
38 // As NED vector, in nT:
39 Point3 nM(22653.29982, -1956.83010, 44202.47862);
40 // Let's assume scale factor,
41 double scale = 255.0 / 50000.0;
42 // ...ground truth orientation,
43 Rot3 nRb = Rot3::Yaw(-0.1);
44 Rot2 theta = nRb.yaw();
45 // ...and bias
46 Point3 bias(10, -10, 50);
47 // ... then we measure
49 Point3 measured = nRb.inverse() * (scale * nM) + bias;
50 
51 double s(scale * nM.norm());
52 Unit3 dir(nM);
53 
54 SharedNoiseModel model = noiseModel::Isotropic::Sigma(3, 0.25);
55 
56 using boost::none;
57 
58 // *************************************************************************
60  Matrix H;
61  Point3 expected(22735.5, 314.502, 44202.5);
62  EXPECT( assert_equal(expected, MagFactor::unrotate(theta,nM,H),1e-1));
63  EXPECT( assert_equal(numericalDerivative11<Point3,Rot2> //
64  (boost::bind(&MagFactor::unrotate, _1, nM, none), theta), H, 1e-6));
65 }
66 
67 // *************************************************************************
68 TEST( MagFactor, Factors ) {
69 
70  Matrix H1, H2, H3;
71 
72  // MagFactor
73  MagFactor f(1, measured, s, dir, bias, model);
74  EXPECT( assert_equal(Z_3x1,f.evaluateError(theta,H1),1e-5));
75  EXPECT( assert_equal((Matrix)numericalDerivative11<Vector,Rot2> //
76  (boost::bind(&MagFactor::evaluateError, &f, _1, none), theta), H1, 1e-7));
77 
78 // MagFactor1
79  MagFactor1 f1(1, measured, s, dir, bias, model);
80  EXPECT( assert_equal(Z_3x1,f1.evaluateError(nRb,H1),1e-5));
81  EXPECT( assert_equal(numericalDerivative11<Vector,Rot3> //
82  (boost::bind(&MagFactor1::evaluateError, &f1, _1, none), nRb), H1, 1e-7));
83 
84 // MagFactor2
85  MagFactor2 f2(1, 2, measured, nRb, model);
86  EXPECT( assert_equal(Z_3x1,f2.evaluateError(scaled,bias,H1,H2),1e-5));
87  EXPECT( assert_equal(numericalDerivative11<Vector,Point3> //
88  (boost::bind(&MagFactor2::evaluateError, &f2, _1, bias, none, none), scaled),//
89  H1, 1e-7));
90  EXPECT( assert_equal(numericalDerivative11<Vector,Point3> //
91  (boost::bind(&MagFactor2::evaluateError, &f2, scaled, _1, none, none), bias),//
92  H2, 1e-7));
93 
94 // MagFactor2
95  MagFactor3 f3(1, 2, 3, measured, nRb, model);
96  EXPECT(assert_equal(Z_3x1,f3.evaluateError(s,dir,bias,H1,H2,H3),1e-5));
97  EXPECT(assert_equal((Matrix)numericalDerivative11<Vector,double> //
98  (boost::bind(&MagFactor3::evaluateError, &f3, _1, dir, bias, none, none, none), s),//
99  H1, 1e-7));
100  EXPECT(assert_equal(numericalDerivative11<Vector,Unit3> //
101  (boost::bind(&MagFactor3::evaluateError, &f3, s, _1, bias, none, none, none), dir),//
102  H2, 1e-7));
103  EXPECT(assert_equal(numericalDerivative11<Vector,Point3> //
104  (boost::bind(&MagFactor3::evaluateError, &f3, s, dir, _1, none, none, none), bias),//
105  H3, 1e-7));
106 }
107 
108 // *************************************************************************
109 int main() {
110  TestResult tr;
111  return TestRegistry::runAllTests(tr);
112 }
113 // *************************************************************************
double s(scale *nM.norm())
double yaw(OptionalJacobian< 1, 3 > H=boost::none) const
Definition: Rot3.cpp:219
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Definition: Vector.h:46
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Header for GeographicLib::LocalCartesian class.
Matrix expected
Definition: testMatrix.cpp:974
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
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
Definition: Half.h:150
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
Some functions to compute numerical derivatives.
double f2(const Vector2 &x)
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
Rot2 theta
Rot3 inverse() const
inverse of a rotation
Definition: Rot3.h:311
Unit3 dir(nM)
Point3 nM(22653.29982,-1956.83010, 44202.47862)
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
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 scale
Factors involving magnetometers.
P unrotate(const T &r, const P &pt)
Definition: lieProxies.h:50
#define EXPECT(condition)
Definition: Test.h:151
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Point3 bias(10,-10, 50)
SharedNoiseModel model
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
double f3(double x1, double x2)
Vector3 Point3
Definition: Point3.h:35
Point3 measured
Rot3 nRb
TEST(MagFactor, unrotate)
int main()
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
Point3 scaled


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:48:04