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>
22 
23 #include <functional>
24 #include "gtsam/base/Matrix.h"
26 
27 using namespace std::placeholders;
28 using namespace std;
29 using namespace gtsam;
30 
31 // *************************************************************************
32 TEST( Rot3AttitudeFactor, Constructor ) {
33 
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 bZ(0, 0, 1); // reference direction is body Z axis
38  Unit3 nDown(0, 0, -1); // down, in ENU navigation frame, is "measurement"
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, bZ);
45  EXPECT(assert_equal(factor0,factor,1e-5));
46 
47  // Create a linearization point at the zero-error point
48  Rot3 nRb;
49  EXPECT(assert_equal((Vector) Z_2x1,factor.evaluateError(nRb),1e-5));
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 
85  // Example: pitch and roll of aircraft in an ENU Cartesian frame.
86  // If pitch and roll are zero for an aerospace frame,
87  // that means Z is pointing down, i.e., direction of Z = (0,0,-1)
88  Unit3 bZ(0, 0, 1); // reference direction is body Z axis
89  Unit3 nDown(0, 0, -1); // down, in ENU navigation frame, is "measurement"
90 
91  // Factor
92  Key key(1);
93  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
94  Pose3AttitudeFactor factor0(key, nDown, model);
95  Pose3AttitudeFactor factor(key, nDown, model, bZ);
96  EXPECT(assert_equal(factor0,factor,1e-5));
97 
98  // Create a linearization point at the zero-error point
99  Pose3 T(Rot3(), Point3(-5.0, 8.0, -11.0));
100  EXPECT(assert_equal((Vector) Z_2x1,factor.evaluateError(T),1e-5));
101 
102  Matrix actualH1;
103 
104  auto err_fn = [&factor](const Pose3& p){
105  return factor.evaluateError(p, OptionalNone);
106  };
107  // Calculate numerical derivatives
108  Matrix expectedH = numericalDerivative11<Vector,Pose3>(err_fn, T);
109 
110  // Use the factor to calculate the derivative
111  Matrix actualH;
112  factor.evaluateError(T, actualH);
113 
114  // Verify we get the expected error
115  EXPECT(assert_equal(expectedH, actualH, 1e-8));
116 }
117 
118 /* ************************************************************************* */
119 TEST(Pose3AttitudeFactor, CopyAndMove) {
120  Unit3 nDown(0, 0, -1);
121  SharedNoiseModel model = noiseModel::Isotropic::Sigma(2, 0.25);
122  Pose3AttitudeFactor factor(0, nDown, model);
123 
124  // Copy assignable.
126  Pose3AttitudeFactor factor_copied = factor;
127  EXPECT(assert_equal(factor, factor_copied));
128 
129  // Move assignable.
131  Pose3AttitudeFactor factor_moved = std::move(factor_copied);
132  EXPECT(assert_equal(factor, factor_moved));
133 }
134 
135 // *************************************************************************
136 int main() {
137  TestResult tr;
138  return TestRegistry::runAllTests(tr);
139 }
140 // *************************************************************************
const gtsam::Symbol key('X', 0)
int main()
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Vector evaluateError(const Rot3 &nRb, OptionalMatrixType H) const override
Definition: BFloat16.h:88
Some functions to compute numerical derivatives.
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
#define OptionalNone
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
const Rot3 nRb
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.)
gtsam::Point3 bZ(0, 0, 1)
Vector evaluateError(const Pose3 &nTb, OptionalMatrixType H) const override
Header file for Attitude factor.
traits
Definition: chartTesting.h:28
float * p
Vector3 Point3
Definition: Point3.h:38
TEST(Rot3AttitudeFactor, Constructor)
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
Definition: Vector.h:45
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741


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