testAttitudeFactor.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 #include <functional>
25 
26 #include "gtsam/base/Matrix.h"
27 
28 using namespace std::placeholders;
29 using namespace std;
30 using namespace gtsam;
31 
32 // *************************************************************************
33 TEST(Rot3AttitudeFactor, Constructor) {
34  // Example: pitch and roll of aircraft in an ENU Cartesian frame.
35  // If pitch and roll are zero for an aerospace frame,
36  // that means Z is pointing down, i.e., direction of Z = (0,0,-1)
37  Unit3 bMeasured(0, 0, 1); // measured direction is body Z axis
38  Unit3 nDown(0, 0, -1); // down, in ENU navigation frame, is "reference"
39 
40  // Factor
41  Key key(1);
42  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
43  Rot3AttitudeFactor factor0(key, nDown, model);
44  Rot3AttitudeFactor factor(key, nDown, model, bMeasured);
45  EXPECT(assert_equal(factor0, factor, 1e-5));
46 
47  // Create a linearization point at the zero-error point
48  Rot3 nRb;
50 
51  auto err_fn = [&factor](const Rot3& r) {
52  return factor.evaluateError(r, OptionalNone);
53  };
54  // Calculate numerical derivatives
55  Matrix expectedH = numericalDerivative11<Vector, Rot3>(err_fn, nRb);
56 
57  // Use the factor to calculate the derivative
58  Matrix actualH;
59  factor.evaluateError(nRb, actualH);
60 
61  // Verify we get the expected error
62  EXPECT(assert_equal(expectedH, actualH, 1e-8));
63 }
64 
65 /* ************************************************************************* */
66 TEST(Rot3AttitudeFactor, CopyAndMove) {
67  Unit3 nDown(0, 0, -1);
68  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
69  Rot3AttitudeFactor factor(0, nDown, model);
70 
71  // Copy assignable.
73  Rot3AttitudeFactor factor_copied = factor;
74  EXPECT(assert_equal(factor, factor_copied));
75 
76  // Move assignable.
78  Rot3AttitudeFactor factor_moved = std::move(factor_copied);
79  EXPECT(assert_equal(factor, factor_moved));
80 }
81 
82 // *************************************************************************
83 TEST(Pose3AttitudeFactor, Constructor) {
84  // Example: pitch and roll of aircraft in an ENU Cartesian frame.
85  // If pitch and roll are zero for an aerospace frame,
86  // that means Z is pointing down, i.e., direction of Z = (0,0,-1)
87  Unit3 bMeasured(0, 0, 1); // measured direction is body Z axis
88  Unit3 nDown(0, 0, -1); // down, in ENU navigation frame, is "reference"
89 
90  // Factor
91  Key key(1);
92  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
93  Pose3AttitudeFactor factor0(key, nDown, model);
94  Pose3AttitudeFactor factor(key, nDown, model, bMeasured);
95  EXPECT(assert_equal(factor0, factor, 1e-5));
96 
97  // Create a linearization point at the zero-error point
98  Pose3 T(Rot3(), Point3(-5.0, 8.0, -11.0));
100 
101  Matrix actualH1;
102 
103  auto err_fn = [&factor](const Pose3& p) {
104  return factor.evaluateError(p, OptionalNone);
105  };
106  // Calculate numerical derivatives
107  Matrix expectedH = numericalDerivative11<Vector, Pose3>(err_fn, T);
108 
109  // Use the factor to calculate the derivative
110  Matrix actualH;
111  factor.evaluateError(T, actualH);
112 
113  // Verify we get the expected error
114  EXPECT(assert_equal(expectedH, actualH, 1e-8));
115 }
116 
117 /* ************************************************************************* */
118 TEST(Pose3AttitudeFactor, CopyAndMove) {
119  Unit3 nDown(0, 0, -1);
120  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
121  Pose3AttitudeFactor factor(0, nDown, model);
122 
123  // Copy assignable.
125  Pose3AttitudeFactor factor_copied = factor;
126  EXPECT(assert_equal(factor, factor_copied));
127 
128  // Move assignable.
130  Pose3AttitudeFactor factor_moved = std::move(factor_copied);
131  EXPECT(assert_equal(factor, factor_moved));
132 }
133 
134 // *************************************************************************
135 int main() {
136  TestResult tr;
137  return TestRegistry::runAllTests(tr);
138 }
139 // *************************************************************************
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
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
TestHarness.h
Matrix.h
typedef and functions to augment Eigen's MatrixXd
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
initial::nRb
const Rot3 nRb
Definition: testScenarioRunner.cpp:149
main
int main()
Definition: testAttitudeFactor.cpp:135
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
AttitudeFactor.h
Header file for Attitude factor.
numericalDerivative.h
Some functions to compute numerical derivatives.
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::Pose3
Definition: Pose3.h:37
gtsam::Rot3AttitudeFactor
Definition: AttitudeFactor.h:91
gtsam::Pose3AttitudeFactor
Definition: AttitudeFactor.h:167
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
Eigen::Triplet< double >
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::Pose3AttitudeFactor::evaluateError
Vector evaluateError(const Pose3 &nTb, OptionalMatrixType H) const override
Definition: AttitudeFactor.h:212
gtsam
traits
Definition: SFMdata.h:40
std
Definition: BFloat16.h:88
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::Z_2x1
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
Definition: Vector.h:45
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
gtsam::Unit3
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
TEST
TEST(Rot3AttitudeFactor, Constructor)
Definition: testAttitudeFactor.cpp:33
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
test_callbacks.value
value
Definition: test_callbacks.py:160
gtsam::Rot3AttitudeFactor::evaluateError
Vector evaluateError(const Rot3 &nRb, OptionalMatrixType H) const override
Definition: AttitudeFactor.h:136


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