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 namespace {
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
48 Point3 scaled = scale * nM;
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 } // namespace
56 
57 // *************************************************************************
59  Matrix H;
60  Point3 expected(22735.5, 314.502, 44202.5);
62  EXPECT(assert_equal(numericalDerivative11<Point3, Rot2> //
63  (std::bind(&MagFactor::unrotate, std::placeholders::_1, nM, OptionalNone), theta), H, 1e-6));
64 }
65 
66 // *************************************************************************
67 TEST( MagFactor, Factors ) {
68 
69  Matrix H1, H2, H3;
70 
71  // MagFactor
72  MagFactor f(1, measured, s, dir, bias, model);
73  EXPECT(assert_equal(Z_3x1,f.evaluateError(theta,H1),1e-5));
74  EXPECT(assert_equal((Matrix)numericalDerivative11<Vector, Rot2>
75  ([&f] (const Rot2& theta) { return f.evaluateError(theta); }, theta), H1, 1e-7));
76 
77  // MagFactor1
78  MagFactor1 f1(1, measured, s, dir, bias, model);
79  EXPECT(assert_equal(Z_3x1,f1.evaluateError(nRb,H1),1e-5));
80  EXPECT(assert_equal(numericalDerivative11<Vector, Rot3>
81  ([&f1] (const Rot3& nRb) { return f1.evaluateError(nRb); }, nRb), H1, 1e-7));
82 
83  // MagFactor2
84  MagFactor2 f2(1, 2, measured, nRb, model);
85  EXPECT(assert_equal(Z_3x1,f2.evaluateError(scaled,bias,H1,H2),1e-5));
86  EXPECT(assert_equal(numericalDerivative11<Vector, Point3> //
87  ([&f2] (const Point3& scaled) { return f2.evaluateError(scaled,bias); }, scaled), H1, 1e-7));
88  EXPECT(assert_equal(numericalDerivative11<Vector, Point3> //
89  ([&f2] (const Point3& bias) { return f2.evaluateError(scaled,bias); }, bias), H2, 1e-7));
90 
91  // MagFactor3
92  MagFactor3 f3(1, 2, 3, measured, nRb, model);
93  EXPECT(assert_equal(Z_3x1,f3.evaluateError(s,dir,bias,H1,H2,H3),1e-5));
94  EXPECT(assert_equal((Matrix)numericalDerivative11<Vector,double> //
95  ([&f3] (double s) { return f3.evaluateError(s,dir,bias); }, s), H1, 1e-7));
96  EXPECT(assert_equal(numericalDerivative11<Vector,Unit3> //
97  ([&f3] (const Unit3& dir) { return f3.evaluateError(s,dir,bias); }, dir), H2, 1e-7));
98  EXPECT(assert_equal(numericalDerivative11<Vector,Point3> //
99  ([&f3] (const Point3& bias) { return f3.evaluateError(s,dir,bias); }, bias), H3, 1e-7));
100 }
101 
102 // *************************************************************************
103 int main() {
104  TestResult tr;
105  return TestRegistry::runAllTests(tr);
106 }
107 // *************************************************************************
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
H
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
Definition: gnuplot_common_settings.hh:74
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
gtsam::Z_3x1
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Definition: Vector.h:46
TestHarness.h
gtsam::MagFactor2
Definition: MagFactor.h:133
biased_x_rotation::bias
const Vector3 bias(1, 2, 3)
f2
double f2(const Vector2 &x)
Definition: testNumericalDerivative.cpp:56
measured
Point2 measured(-17, 30)
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
TEST
TEST(MagFactor, unrotate)
Definition: testMagFactor.cpp:58
initial::nRb
const Rot3 nRb
Definition: testScenarioRunner.cpp:149
gtsam::MagFactor1
Definition: MagFactor.h:92
main
int main()
Definition: testMagFactor.cpp:103
numericalDerivative.h
Some functions to compute numerical derivatives.
scale
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
Definition: gnuplot_common_settings.hh:54
OptionalNone
#define OptionalNone
Definition: NonlinearFactor.h:49
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::MagFactor
Definition: MagFactor.h:33
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::Rot3::yaw
double yaw(OptionalJacobian< 1, 3 > H={}) const
Definition: Rot3.cpp:218
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
gtsam::Rot3::inverse
Rot3 inverse() const
inverse of a rotation
Definition: Rot3.h:308
TestResult
Definition: TestResult.h:26
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::MagFactor3
Definition: MagFactor.h:177
gtsam::Rot2
Definition: Rot2.h:35
gtsam
traits
Definition: SFMdata.h:40
f3
double f3(double x1, double x2)
Definition: testNumericalDerivative.cpp:76
std
Definition: BFloat16.h:88
LocalCartesian.hpp
Header for GeographicLib::LocalCartesian class.
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::testing::unrotate
P unrotate(const T &r, const P &pt)
Definition: lieProxies.h:50
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
gtsam::Unit3
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
MagFactor.h
Factors involving magnetometers.


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:54