testBarometricFactor.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>
23 
24 using namespace std::placeholders;
25 using namespace std;
26 using namespace gtsam;
27 
28 // *************************************************************************
29 namespace example {}
30 
31 double metersToBaro(const double& meters) {
32  double temp = 15.04 - 0.00649 * meters;
33  return 101.29 * std::pow(((temp + 273.1) / 288.08), 5.256);
34 }
35 
36 // *************************************************************************
37 TEST(BarometricFactor, Constructor) {
38  using namespace example;
39 
40  // meters to barometric.
41 
42  double baroMeasurement = metersToBaro(10.);
43 
44  // Factor
45  Key key(1);
46  Key key2(2);
47  SharedNoiseModel model = noiseModel::Isotropic::Sigma(1, 0.25);
48  BarometricFactor factor(key, key2, baroMeasurement, model);
49 
50  // Create a linearization point at zero error
51  Pose3 T(Rot3::RzRyRx(0., 0., 0.), Point3(0., 0., 10.));
52  double baroBias = 0.;
53  Vector1 zero;
54  zero << 0.;
55  EXPECT(assert_equal(zero, factor.evaluateError(T, baroBias), 1e-5));
56 
57  // Calculate numerical derivatives
58  Matrix expectedH = numericalDerivative21<Vector, Pose3, double>(
59  [&factor](const Pose3& p, const double& d) {return factor.evaluateError(p, d);},
60  T, baroBias);
61 
62  Matrix expectedH2 = numericalDerivative22<Vector, Pose3, double>(
63  [&factor](const Pose3& p, const double& d) {return factor.evaluateError(p, d);},
64  T, baroBias);
65 
66  // Use the factor to calculate the derivative
67  Matrix actualH, actualH2;
68  factor.evaluateError(T, baroBias, actualH, actualH2);
69 
70  // Verify we get the expected error
71  EXPECT(assert_equal(expectedH, actualH, 1e-8));
72  EXPECT(assert_equal(expectedH2, actualH2, 1e-8));
73 }
74 
75 // *************************************************************************
76 
77 //***************************************************************************
79  using namespace example;
80 
81  // meters to barometric.
82 
83  double baroMeasurement = metersToBaro(10.);
84 
85  // Factor
86  Key key(1);
87  Key key2(2);
88  SharedNoiseModel model = noiseModel::Isotropic::Sigma(1, 0.25);
89  BarometricFactor factor(key, key2, baroMeasurement, model);
90 
91  Pose3 T(Rot3::RzRyRx(0.5, 1., 1.), Point3(20., 30., 1.));
92  double baroBias = 5.;
93 
94  // Calculate numerical derivatives
95  Matrix expectedH = numericalDerivative21<Vector, Pose3, double>(
96  [&factor](const Pose3& p, const double& d) {return factor.evaluateError(p, d);},
97  T, baroBias);
98 
99  Matrix expectedH2 = numericalDerivative22<Vector, Pose3, double>(
100  [&factor](const Pose3& p, const double& d) {return factor.evaluateError(p, d);},
101  T, baroBias);
102 
103  // Use the factor to calculate the derivative and the error
104  Matrix actualH, actualH2;
105  Vector error = factor.evaluateError(T, baroBias, actualH, actualH2);
106  Vector actual = (Vector(1) << -4.0).finished();
107 
108  // Verify we get the expected error
109  EXPECT(assert_equal(expectedH, actualH, 1e-8));
110  EXPECT(assert_equal(expectedH2, actualH2, 1e-8));
111  EXPECT(assert_equal(error, actual, 1e-8));
112 }
113 
114 // *************************************************************************
115 int main() {
116  TestResult tr;
117  return TestRegistry::runAllTests(tr);
118 }
119 // *************************************************************************
const gtsam::Symbol key('X', 0)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
TEST(BarometricFactor, Constructor)
noiseModel::Diagonal::shared_ptr model
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:296
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Definition: BFloat16.h:88
Some functions to compute numerical derivatives.
Eigen::VectorXd Vector
Definition: Vector.h:38
#define EXPECT(condition)
Definition: Test.h:150
Eigen::Triplet< double > T
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double metersToBaro(const double &meters)
Vector evaluateError(const Pose3 &p, const double &b, OptionalMatrixType H, OptionalMatrixType H2) const override
vector of errors
int main()
traits
Definition: chartTesting.h:28
Header file for Barometric factor.
float * p
static double error
Definition: testRot3.cpp:37
Vector3 Point3
Definition: Point3.h:38
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:570
The matrix class, also used for vectors and row-vectors.
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
const Symbol key2('v', 2)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:52