testTangentPreintegration.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 
23 
25 #include <boost/bind.hpp>
26 
27 #include "imuFactorTesting.h"
28 
29 static const double kDt = 0.1;
30 
31 Vector9 f(const Vector9& zeta, const Vector3& a, const Vector3& w) {
32  return TangentPreintegration::UpdatePreintegrated(a, w, kDt, zeta);
33 }
34 
35 namespace testing {
36 // Create default parameters with Z-down and above noise parameters
37 static boost::shared_ptr<PreintegrationParams> Params() {
38  auto p = PreintegrationParams::MakeSharedD(kGravity);
39  p->gyroscopeCovariance = kGyroSigma * kGyroSigma * I_3x3;
40  p->accelerometerCovariance = kAccelSigma * kAccelSigma * I_3x3;
41  p->integrationCovariance = 0.0001 * I_3x3;
42  return p;
43 }
44 }
45 
46 /* ************************************************************************* */
47 TEST(TangentPreintegration, UpdateEstimate1) {
49  const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3);
50  Vector9 zeta;
51  zeta.setZero();
52  Matrix9 aH1;
53  Matrix93 aH2, aH3;
54  pim.UpdatePreintegrated(acc, omega, kDt, zeta, aH1, aH2, aH3);
55  EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-9));
56  EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-9));
57  EXPECT(assert_equal(numericalDerivative33(f, zeta, acc, omega), aH3, 1e-9));
58 }
59 
60 /* ************************************************************************* */
61 TEST(TangentPreintegration, UpdateEstimate2) {
63  const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3);
64  Vector9 zeta;
65  zeta << 0.01, 0.02, 0.03, 100, 200, 300, 10, 5, 3;
66  Matrix9 aH1;
67  Matrix93 aH2, aH3;
68  pim.UpdatePreintegrated(acc, omega, kDt, zeta, aH1, aH2, aH3);
69  // NOTE(frank): tolerance of 1e-3 on H1 because approximate away from 0
70  EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-3));
71  EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-8));
72  EXPECT(assert_equal(numericalDerivative33(f, zeta, acc, omega), aH3, 1e-9));
73 }
74 
75 /* ************************************************************************* */
76 TEST(ImuFactor, BiasCorrectionJacobians) {
77  testing::SomeMeasurements measurements;
78 
79  boost::function<Vector9(const Vector3&, const Vector3&)> preintegrated =
80  [=](const Vector3& a, const Vector3& w) {
82  testing::integrateMeasurements(measurements, &pim);
83  return pim.preintegrated();
84  };
85 
86  // Actual pre-integrated values
88  testing::integrateMeasurements(measurements, &pim);
89 
90  EXPECT(
93  EXPECT(
95  pim.preintegrated_H_biasOmega(), 1e-3));
96 }
97 
98 /* ************************************************************************* */
99 TEST(TangentPreintegration, computeError) {
101  NavState x1, x2;
103  Matrix9 aH1, aH2;
104  Matrix96 aH3;
105  pim.computeError(x1, x2, bias, aH1, aH2, aH3);
106  boost::function<Vector9(const NavState&, const NavState&,
107  const imuBias::ConstantBias&)> f =
108  boost::bind(&TangentPreintegration::computeError, pim, _1, _2, _3,
109  boost::none, boost::none, boost::none);
110  // NOTE(frank): tolerance of 1e-3 on H1 because approximate away from 0
111  EXPECT(assert_equal(numericalDerivative31(f, x1, x2, bias), aH1, 1e-9));
112  EXPECT(assert_equal(numericalDerivative32(f, x1, x2, bias), aH2, 1e-9));
113  EXPECT(assert_equal(numericalDerivative33(f, x1, x2, bias), aH3, 1e-9));
114 }
115 
116 /* ************************************************************************* */
118  testing::SomeMeasurements measurements;
120  testing::integrateMeasurements(measurements, &pim);
121 
122  boost::function<Vector9(const Vector9&, const Vector9&)> f =
123  [pim](const Vector9& zeta01, const Vector9& zeta12) {
124  return TangentPreintegration::Compose(zeta01, zeta12, pim.deltaTij());
125  };
126 
127  // Expected merge result
128  TangentPreintegration expected_pim02(testing::Params());
129  testing::integrateMeasurements(measurements, &expected_pim02);
130  testing::integrateMeasurements(measurements, &expected_pim02);
131 
132  // Actual result
133  Matrix9 H1, H2;
134  TangentPreintegration actual_pim02 = pim;
135  actual_pim02.mergeWith(pim, &H1, &H2);
136 
137  const Vector9 zeta = pim.preintegrated();
138  const Vector9 actual_zeta =
139  TangentPreintegration::Compose(zeta, zeta, pim.deltaTij());
140  EXPECT(assert_equal(expected_pim02.preintegrated(), actual_zeta, 1e-7));
141  EXPECT(assert_equal(numericalDerivative21(f, zeta, zeta), H1, 1e-7));
142  EXPECT(assert_equal(numericalDerivative22(f, zeta, zeta), H2, 1e-7));
143 }
144 
145 /* ************************************************************************* */
146 TEST(TangentPreintegration, MergedBiasDerivatives) {
147  testing::SomeMeasurements measurements;
148 
149  auto f = [=](const Vector3& a, const Vector3& w) {
151  testing::integrateMeasurements(measurements, &pim02);
152  testing::integrateMeasurements(measurements, &pim02);
153  return pim02.preintegrated();
154  };
155 
156  // Expected merge result
157  TangentPreintegration expected_pim02(testing::Params());
158  testing::integrateMeasurements(measurements, &expected_pim02);
159  testing::integrateMeasurements(measurements, &expected_pim02);
160 
161  EXPECT(assert_equal(numericalDerivative21<Vector9, Vector3, Vector3>(f, Z_3x1, Z_3x1),
162  expected_pim02.preintegrated_H_biasAcc()));
163  EXPECT(assert_equal(numericalDerivative22<Vector9, Vector3, Vector3>(f, Z_3x1, Z_3x1),
164  expected_pim02.preintegrated_H_biasOmega(), 1e-7));
165 }
166 
167 /* ************************************************************************* */
168 int main() {
169  TestResult tr;
170  return TestRegistry::runAllTests(tr);
171 }
172 /* ************************************************************************* */
const double kGravity
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Definition: Vector.h:46
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
const CwiseBinaryOp< internal::scalar_zeta_op< Scalar >, const Derived, const DerivedQ > zeta(const EIGEN_CURRENT_STORAGE_BASE_CLASS< DerivedQ > &q) const
TEST(TangentPreintegration, UpdateEstimate1)
void integrateMeasurements(const vector< ImuMeasurement > &measurements, PIM *pim)
internal::FixedSizeMatrix< Y, X3 >::type numericalDerivative33(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative31(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const boost::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
Common testing infrastructure.
Vector9 computeError(const NavState &state_i, const NavState &state_j, const imuBias::ConstantBias &bias_i, OptionalJacobian< 9, 9 > H1, OptionalJacobian< 9, 9 > H2, OptionalJacobian< 9, 6 > H3) const
Calculate error given navStates.
const Matrix93 & preintegrated_H_biasOmega() const
Array33i a
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative32(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
static const double kAccelSigma
Test harness methods for expressions.
#define EXPECT(condition)
Definition: Test.h:151
static Vector9 UpdatePreintegrated(const Vector3 &a_body, const Vector3 &w_body, const double dt, const Vector9 &preintegrated, OptionalJacobian< 9, 9 > A=boost::none, OptionalJacobian< 9, 3 > B=boost::none, OptionalJacobian< 9, 3 > C=boost::none)
static const Vector3 kZero
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static boost::shared_ptr< PreintegratedCombinedMeasurements::Params > Params()
const Matrix93 & preintegrated_H_biasAcc() const
const Vector9 & preintegrated() const
Point3 bias(10,-10, 50)
RowVector3d w
void mergeWith(const TangentPreintegration &pim, Matrix9 *H1, Matrix9 *H2)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
imuBias::ConstantBias Bias
Pose3 x1
Definition: testPose3.cpp:588
float * p
static const double kDt
static const double kGyroSigma
Vector9 f(const Vector9 &zeta, const Vector3 &a, const Vector3 &w)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:57