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 // *************************************************************************
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
metersToBaro
double metersToBaro(const double &meters)
Definition: testBarometricFactor.cpp:31
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
BarometricFactor.h
Header file for Barometric factor.
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
pruning_fixture::factor
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
example
Definition: testOrdering.cpp:28
numericalDerivative.h
Some functions to compute numerical derivatives.
key2
const Symbol key2('v', 2)
gtsam::Pose3
Definition: Pose3.h:37
zero
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:296
gtsam::BarometricFactor
Definition: BarometricFactor.h:34
TEST
TEST(BarometricFactor, Constructor)
Definition: testBarometricFactor.cpp:37
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
Eigen::Triplet< double >
ceres::pow
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:570
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
TestResult
Definition: TestResult.h:26
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
error
static double error
Definition: testRot3.cpp:37
std
Definition: BFloat16.h:88
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:41
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
main
int main()
Definition: testBarometricFactor.cpp:115
ceres::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: gtsam/3rdparty/ceres/eigen.h:38


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:16:06