testImuFactor.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 
21 // #define ENABLE_TIMING // uncomment for timing results
22 
25 #include <gtsam/geometry/Pose3.h>
26 #include <gtsam/nonlinear/Values.h>
28 #include <gtsam/linear/Sampler.h>
31 
33 #include <list>
34 
35 #include "imuFactorTesting.h"
36 
37 namespace testing {
38 // Create default parameters with Z-down and above noise parameters
39 static std::shared_ptr<PreintegrationParams> Params() {
40  auto p = PreintegrationParams::MakeSharedD(kGravity);
41  p->gyroscopeCovariance = kGyroSigma * kGyroSigma * I_3x3;
42  p->accelerometerCovariance = kAccelSigma * kAccelSigma * I_3x3;
43  p->integrationCovariance = 0.0001 * I_3x3;
44  return p;
45 }
46 }
47 
48 /* ************************************************************************* */
49 namespace {
50 // Auxiliary functions to test evaluate error in ImuFactor
51 /* ************************************************************************* */
52 Rot3 evaluateRotationError(const ImuFactor& factor, const Pose3& pose_i,
53  const Vector3& vel_i, const Pose3& pose_j, const Vector3& vel_j,
54  const Bias& bias) {
55  return Rot3::Expmap(
56  factor.evaluateError(pose_i, vel_i, pose_j, vel_j, bias).head(3));
57 }
58 
59 } // namespace
60 
61 /* ************************************************************************* */
62 TEST(ImuFactor, PreintegratedMeasurementsConstruction) {
63  // Actual pre-integrated values
65  EXPECT(assert_equal(Rot3(), actual.deltaRij()));
66  EXPECT(assert_equal(kZero, actual.deltaPij()));
67  EXPECT(assert_equal(kZero, actual.deltaVij()));
68  DOUBLES_EQUAL(0.0, actual.deltaTij(), 1e-9);
69 }
70 
71 /* ************************************************************************* */
72 TEST(ImuFactor, PreintegratedMeasurementsReset) {
73 
74  auto p = testing::Params();
75  // Create a preintegrated measurement struct and integrate
77  Vector3 measuredAcc(0.5, 1.0, 0.5);
78  Vector3 measuredOmega(0.1, 0.3, 0.1);
79  double deltaT = 1.0;
80  pimActual.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
81 
82  // reset and make sure that it is the same as a fresh one
83  pimActual.resetIntegration();
85 
86  // Now create one with a different bias ..
87  Bias nonZeroBias(Vector3(0.2, 0, 0), Vector3(0.1, 0, 0.3));
88  PreintegratedImuMeasurements pimExpected(p, nonZeroBias);
89 
90  // integrate again, then reset to a new bias
91  pimActual.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
92  pimActual.resetIntegrationAndSetBias(nonZeroBias);
93  CHECK(assert_equal(pimActual, pimExpected));
94 }
95 
96 /* ************************************************************************* */
97 TEST(ImuFactor, Accelerating) {
98  const double a = 0.2, v = 50;
99 
100  // Set up body pointing towards y axis, and start at 10,20,0 with velocity going in X
101  // The body itself has Z axis pointing down
102  const Rot3 nRb(Point3(0, 1, 0), Point3(1, 0, 0), Point3(0, 0, -1));
103  const Point3 initial_position(10, 20, 0);
104  const Vector3 initial_velocity(v, 0, 0);
105 
106  const AcceleratingScenario scenario(nRb, initial_position, initial_velocity,
107  Vector3(a, 0, 0));
108 
109  const double T = 3.0; // seconds
110  ScenarioRunner runner(scenario, testing::Params(), T / 10);
111 
112  PreintegratedImuMeasurements pim = runner.integrate(T);
113  EXPECT(assert_equal(scenario.pose(T), runner.predict(pim).pose(), 1e-9));
114 
115  Matrix9 estimatedCov = runner.estimateCovariance(T, 100);
116  EXPECT(assert_equal(estimatedCov, pim.preintMeasCov(), 0.1));
117 }
118 
119 /* ************************************************************************* */
120 TEST(ImuFactor, PreintegratedMeasurements) {
121  // Measurements
122  const double a = 0.1, w = M_PI / 100.0;
123  Vector3 measuredAcc(a, 0.0, 0.0);
124  Vector3 measuredOmega(w, 0.0, 0.0);
125  double deltaT = 0.5;
126 
127  // Expected pre-integrated values
128  Vector3 expectedDeltaR1(w * deltaT, 0.0, 0.0);
129  Vector3 expectedDeltaP1(0.5 * a * deltaT*deltaT, 0, 0);
130  Vector3 expectedDeltaV1(0.05, 0.0, 0.0);
131 
132  // Actual pre-integrated values
134  actual.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
135  EXPECT(assert_equal(Rot3::Expmap(expectedDeltaR1), actual.deltaRij()));
136  EXPECT(assert_equal(expectedDeltaP1, actual.deltaPij()));
137  EXPECT(assert_equal(expectedDeltaV1, actual.deltaVij()));
138  DOUBLES_EQUAL(0.5, actual.deltaTij(), 1e-9);
139 
140  // Check derivatives of computeError
141  Bias bias(Vector3(0.2, 0, 0), Vector3(0.1, 0, 0.3)); // Biases (acc, rot)
142  NavState x1, x2 = actual.predict(x1, bias);
143 
144  {
145  Matrix9 aH1, aH2;
146  Matrix96 aH3;
147  actual.computeError(x1, x2, bias, aH1, aH2, aH3);
148  std::function<Vector9(const NavState&, const NavState&, const Bias&)> f =
149  std::bind(&PreintegrationBase::computeError, actual,
150  std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
151  nullptr, nullptr, nullptr);
152  EXPECT(assert_equal(numericalDerivative31(f, x1, x2, bias), aH1, 1e-9));
153  EXPECT(assert_equal(numericalDerivative32(f, x1, x2, bias), aH2, 1e-9));
154  EXPECT(assert_equal(numericalDerivative33(f, x1, x2, bias), aH3, 1e-9));
155  }
156 
157  // Integrate again
158  Vector3 expectedDeltaR2(2.0 * 0.5 * M_PI / 100.0, 0.0, 0.0);
159  Vector3 expectedDeltaP2(0.025 + expectedDeltaP1(0) + 0.5 * 0.1 * 0.5 * 0.5, 0, 0);
160  Vector3 expectedDeltaV2 = Vector3(0.05, 0.0, 0.0) +
161  Rot3::Expmap(expectedDeltaR1) * measuredAcc * 0.5;
162 
163  // Actual pre-integrated values
164  actual.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
165  EXPECT(assert_equal(Rot3::Expmap(expectedDeltaR2), actual.deltaRij()));
166  EXPECT(assert_equal(expectedDeltaP2, actual.deltaPij()));
167  EXPECT(assert_equal(expectedDeltaV2, actual.deltaVij()));
168  DOUBLES_EQUAL(1.0, actual.deltaTij(), 1e-9);
169 }
170 /* ************************************************************************* */
171 // Common linearization point and measurements for tests
172 namespace common {
173 static const Pose3 x1(Rot3::RzRyRx(M_PI / 12.0, M_PI / 6.0, M_PI / 4.0),
174  Point3(5.0, 1.0, 0));
175 static const Vector3 v1(Vector3(0.5, 0.0, 0.0));
176 static const NavState state1(x1, v1);
177 
178 // Measurements
179 static const double w = M_PI / 100;
180 static const Vector3 measuredOmega(w, 0, 0);
181 static const Vector3 measuredAcc = x1.rotation().unrotate(
182  -kGravityAlongNavZDown);
183 static const double deltaT = 1.0;
184 
185 static const Pose3 x2(Rot3::RzRyRx(M_PI / 12.0 + w, M_PI / 6.0, M_PI / 4.0),
186  Point3(5.5, 1.0, 0));
187 static const Vector3 v2(Vector3(0.5, 0.0, 0.0));
188 static const NavState state2(x2, v2);
189 } // namespace common
190 
191 /* ************************************************************************* */
192 TEST(ImuFactor, PreintegrationBaseMethods) {
193  using namespace common;
194  auto p = testing::Params();
195  p->omegaCoriolis = Vector3(0.02, 0.03, 0.04);
196  p->use2ndOrderCoriolis = true;
197 
198  PreintegratedImuMeasurements pim(p, kZeroBiasHat);
199  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
200  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
201 
202  // biasCorrectedDelta
203  Matrix96 actualH;
204  pim.biasCorrectedDelta(kZeroBias, actualH);
205  Matrix expectedH = numericalDerivative11<Vector9, Bias>(
206  std::bind(&PreintegrationBase::biasCorrectedDelta, pim,
207  std::placeholders::_1, nullptr), kZeroBias);
208  EXPECT(assert_equal(expectedH, actualH));
209 
210  Matrix9 aH1;
211  Matrix96 aH2;
212  NavState predictedState = pim.predict(state1, kZeroBias, aH1, aH2);
213  Matrix eH1 = numericalDerivative11<NavState, NavState>(
214  std::bind(&PreintegrationBase::predict, pim, std::placeholders::_1,
215  kZeroBias, nullptr, nullptr), state1);
216  EXPECT(assert_equal(eH1, aH1));
217  Matrix eH2 = numericalDerivative11<NavState, Bias>(
218  std::bind(&PreintegrationBase::predict, pim, state1,
219  std::placeholders::_1, nullptr, nullptr), kZeroBias);
220  EXPECT(assert_equal(eH2, aH2));
221 }
222 
223 /* ************************************************************************* */
224 TEST(ImuFactor, MultipleMeasurements) {
225  using namespace common;
226 
228  expected.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
229  expected.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
230 
231  Matrix32 acc,gyro;
232  Matrix12 dts;
233  acc << measuredAcc, measuredAcc;
234  gyro << measuredOmega, measuredOmega;
235  dts << deltaT, deltaT;
236  PreintegratedImuMeasurements actual(testing::Params(), kZeroBiasHat);
237  actual.integrateMeasurements(acc,gyro,dts);
238 
239  EXPECT(assert_equal(expected,actual));
240 }
241 
242 /* ************************************************************************* */
243 TEST(ImuFactor, ErrorAndJacobians) {
244  using namespace common;
246 
247  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
248  EXPECT(assert_equal(state2, pim.predict(state1, kZeroBias)));
249 
250  // Create factor
251  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
252 
253  // Expected error
254  Vector expectedError(9);
255  expectedError << 0, 0, 0, 0, 0, 0, 0, 0, 0;
256  EXPECT(
257  assert_equal(expectedError,
258  factor.evaluateError(x1, v1, x2, v2, kZeroBias)));
259 
260  Values values;
261  values.insert(X(1), x1);
262  values.insert(V(1), v1);
263  values.insert(X(2), x2);
264  values.insert(V(2), v2);
265  values.insert(B(1), kZeroBias);
266  EXPECT(assert_equal(expectedError, factor.unwhitenedError(values)));
267 
268  // Make sure linearization is correct
269  double diffDelta = 1e-7;
270  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, diffDelta, 1e-3);
271 
272  // Actual Jacobians
273  Matrix H1a, H2a, H3a, H4a, H5a;
274  (void) factor.evaluateError(x1, v1, x2, v2, kZeroBias, H1a, H2a, H3a, H4a,
275  H5a);
276 
277  // Make sure rotation part is correct when error is interpreted as axis-angle
278  // Jacobians are around zero, so the rotation part is the same as:
279  Matrix H1Rot3 = numericalDerivative11<Rot3, Pose3>(
280  std::bind(&evaluateRotationError, factor, std::placeholders::_1, v1, x2, v2, kZeroBias),
281  x1);
282  EXPECT(assert_equal(H1Rot3, H1a.topRows(3)));
283 
284  Matrix H3Rot3 = numericalDerivative11<Rot3, Pose3>(
285  std::bind(&evaluateRotationError, factor, x1, v1, std::placeholders::_1, v2, kZeroBias),
286  x2);
287  EXPECT(assert_equal(H3Rot3, H3a.topRows(3)));
288 
289  // Evaluate error with wrong values
290  Vector3 v2_wrong = v2 + Vector3(0.1, 0.1, 0.1);
291  values.update(V(2), v2_wrong);
292  expectedError << 0, 0, 0, 0, 0, 0, -0.0724744871, -0.040715657, -0.151952901;
293  EXPECT(
294  assert_equal(expectedError,
295  factor.evaluateError(x1, v1, x2, v2_wrong, kZeroBias), 1e-2));
296  EXPECT(assert_equal(expectedError, factor.unwhitenedError(values), 1e-2));
297 
298  // Make sure the whitening is done correctly
299  Matrix cov = pim.preintMeasCov();
300  Matrix R = RtR(cov.inverse());
301  Vector whitened = R * expectedError;
302  EXPECT(assert_equal(0.5 * whitened.squaredNorm(), factor.error(values), 1e-4));
303 
304  // Make sure linearization is correct
305  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, diffDelta, 1e-3);
306 }
307 
308 /* ************************************************************************* */
309 TEST(ImuFactor, ErrorAndJacobianWithBiases) {
310  using common::x1;
311  using common::v1;
312  using common::v2;
313  Bias bias(Vector3(0.2, 0, 0), Vector3(0.1, 0, 0.3)); // Biases (acc, rot)
314  Pose3 x2(Rot3::Expmap(Vector3(0, 0, M_PI / 10.0 + M_PI / 10.0)),
315  Point3(5.5, 1.0, -50.0));
316 
317  // Measurements
319  measuredOmega << 0, 0, M_PI / 10.0 + 0.3;
320  Vector3 measuredAcc = x1.rotation().unrotate(-kGravityAlongNavZDown)
321  + Vector3(0.2, 0.0, 0.0);
322  double deltaT = 1.0;
323 
324  auto p = testing::Params();
325  p->omegaCoriolis = kNonZeroOmegaCoriolis;
326 
327  Bias biasHat(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.1));
328  PreintegratedImuMeasurements pim(p, biasHat);
329  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
330 
331  // Make sure of biasCorrectedDelta
332  Matrix96 actualH;
333  pim.biasCorrectedDelta(bias, actualH);
334  Matrix expectedH = numericalDerivative11<Vector9, Bias>(
335  std::bind(&PreintegrationBase::biasCorrectedDelta, pim,
336  std::placeholders::_1, nullptr), bias);
337  EXPECT(assert_equal(expectedH, actualH));
338 
339  // Create factor
340  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
341 
342  Values values;
343  values.insert(X(1), x1);
344  values.insert(V(1), v1);
345  values.insert(X(2), x2);
346  values.insert(V(2), v2);
347  values.insert(B(1), bias);
348 
349  // Make sure linearization is correct
350  double diffDelta = 1e-7;
351  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, diffDelta, 1e-3);
352 }
353 
354 /* ************************************************************************* */
355 TEST(ImuFactor, ErrorAndJacobianWith2ndOrderCoriolis) {
356  using common::x1;
357  using common::v1;
358  using common::v2;
359  Bias bias(Vector3(0.2, 0, 0), Vector3(0.1, 0, 0.3)); // Biases (acc, rot)
360  Pose3 x2(Rot3::Expmap(Vector3(0, 0, M_PI / 10.0 + M_PI / 10.0)),
361  Point3(5.5, 1.0, -50.0));
362 
363  // Measurements
365  measuredOmega << 0, 0, M_PI / 10.0 + 0.3;
366  Vector3 measuredAcc = x1.rotation().unrotate(-kGravityAlongNavZDown)
367  + Vector3(0.2, 0.0, 0.0);
368  double deltaT = 1.0;
369 
370  auto p = testing::Params();
371  p->omegaCoriolis = kNonZeroOmegaCoriolis;
372  p->use2ndOrderCoriolis = true;
373 
375  Bias(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.1)));
376  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
377 
378  // Create factor
379  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
380 
381  Values values;
382  values.insert(X(1), x1);
383  values.insert(V(1), v1);
384  values.insert(X(2), x2);
385  values.insert(V(2), v2);
386  values.insert(B(1), bias);
387 
388  // Make sure linearization is correct
389  double diffDelta = 1e-7;
390  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, diffDelta, 1e-3);
391 }
392 
393 /* ************************************************************************* */
394 TEST(ImuFactor, PartialDerivative_wrt_Bias) {
395  // Linearization point
396  Vector3 biasOmega(0, 0, 0); // Current estimate of rotation rate bias
397 
398  // Measurements
399  Vector3 measuredOmega(0.1, 0, 0);
400  double deltaT = 0.5;
401 
402  auto evaluateRotation = [=](const Vector3 biasOmega) {
403  return Rot3::Expmap((measuredOmega - biasOmega) * deltaT);
404  };
405 
406  // Compute numerical derivatives
407  Matrix expectedDelRdelBiasOmega =
408  numericalDerivative11<Rot3, Vector3>(evaluateRotation, biasOmega);
409 
410  const Matrix3 Jr =
411  Rot3::ExpmapDerivative((measuredOmega - biasOmega) * deltaT);
412 
413  Matrix3 actualdelRdelBiasOmega = -Jr * deltaT; // the delta bias appears with the minus sign
414 
415  // Compare Jacobians
416  EXPECT(assert_equal(expectedDelRdelBiasOmega, actualdelRdelBiasOmega, 1e-9));
417 }
418 
419 /* ************************************************************************* */
420 TEST(ImuFactor, PartialDerivativeLogmap) {
421  // Linearization point
422  Vector3 thetahat(0.1, 0.1, 0); // Current estimate of rotation rate bias
423 
424  // Measurements
425  Vector3 deltatheta(0, 0, 0);
426 
427  auto evaluateLogRotation = [=](const Vector3 deltatheta) {
428  return Rot3::Logmap(
429  Rot3::Expmap(thetahat).compose(Rot3::Expmap(deltatheta)));
430  };
431 
432  // Compute numerical derivatives
433  Matrix expectedDelFdeltheta =
434  numericalDerivative11<Vector, Vector3>(evaluateLogRotation, deltatheta);
435 
436  Matrix3 actualDelFdeltheta = Rot3::LogmapDerivative(thetahat);
437 
438  // Compare Jacobians
439  EXPECT(assert_equal(expectedDelFdeltheta, actualDelFdeltheta));
440 }
441 
442 /* ************************************************************************* */
443 TEST(ImuFactor, fistOrderExponential) {
444  // Linearization point
445  Vector3 biasOmega(0, 0, 0); // Current estimate of rotation rate bias
446 
447  // Measurements
448  Vector3 measuredOmega(0.1, 0, 0);
449  double deltaT = 1.0;
450 
451  // change w.r.t. linearization point
452  double alpha = 0.0;
453  Vector3 deltabiasOmega;
454  deltabiasOmega << alpha, alpha, alpha;
455 
456  const Matrix3 Jr = Rot3::ExpmapDerivative(
457  (measuredOmega - biasOmega) * deltaT);
458 
459  Matrix3 delRdelBiasOmega = -Jr * deltaT; // the delta bias appears with the minus sign
460 
461  const Matrix expectedRot = Rot3::Expmap(
462  (measuredOmega - biasOmega - deltabiasOmega) * deltaT).matrix();
463 
464  const Matrix3 hatRot =
465  Rot3::Expmap((measuredOmega - biasOmega) * deltaT).matrix();
466  const Matrix3 actualRot = hatRot
467  * Rot3::Expmap(delRdelBiasOmega * deltabiasOmega).matrix();
468  // hatRot * (I_3x3 + skewSymmetric(delRdelBiasOmega * deltabiasOmega));
469 
470  // This is a first order expansion so the equality is only an approximation
471  EXPECT(assert_equal(expectedRot, actualRot));
472 }
473 
474 /* ************************************************************************* */
476  const Vector3& measuredAcc, const Vector3& measuredOmega) {
477  Vector3 correctedAcc = pim.biasHat().correctAccelerometer(measuredAcc);
478  Vector3 correctedOmega = pim.biasHat().correctGyroscope(measuredOmega);
479  return pim.correctMeasurementsBySensorPose(correctedAcc, correctedOmega).first;
480 }
481 
482 TEST(ImuFactor, ErrorWithBiasesAndSensorBodyDisplacement) {
483  const Rot3 nRb = Rot3::Expmap(Vector3(0, 0, M_PI / 4.0));
484  const Point3 p1(5.0, 1.0, -50.0);
485  const Vector3 v1(0.5, 0.0, 0.0);
486 
487  const Vector3 a = nRb * Vector3(0.2, 0.0, 0.0);
488  const AcceleratingScenario scenario(nRb, p1, v1, a,
489  Vector3(0, 0, M_PI / 10.0 + 0.3));
490 
491  auto p = testing::Params();
492  p->body_P_sensor = Pose3(Rot3::Expmap(Vector3(0, M_PI / 2, 0)),
493  Point3(0.1, 0.05, 0.01));
494  p->omegaCoriolis = kNonZeroOmegaCoriolis;
495 
496  Bias biasHat(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.0));
497 
498  const double T = 3.0; // seconds
499  ScenarioRunner runner(scenario, p, T / 10);
500 
501  // PreintegratedImuMeasurements pim = runner.integrate(T);
502  // EXPECT(assert_equal(scenario.pose(T), runner.predict(pim).pose, 1e-9));
503  //
504  // Matrix6 estimatedCov = runner.estimatePoseCovariance(T);
505  // EXPECT(assert_equal(estimatedCov, runner.poseCovariance(pim), 0.1));
506  //
508  Pose3 x1(nRb, p1);
509 
510  // Measurements
511  Vector3 measuredOmega = runner.actualAngularVelocity(0);
512  Vector3 measuredAcc = runner.actualSpecificForce(0);
513 
514  // Get mean prediction from "ground truth" measurements
515  const Vector3 accNoiseVar2(0.01, 0.02, 0.03);
516  const Vector3 omegaNoiseVar2(0.03, 0.01, 0.02);
517  PreintegratedImuMeasurements pim(p, biasHat);
518 
519  // Check updatedDeltaXij derivatives
520  Matrix3 D_correctedAcc_measuredOmega = Z_3x3;
521  pim.correctMeasurementsBySensorPose(measuredAcc, measuredOmega,
522  nullptr, D_correctedAcc_measuredOmega, nullptr);
523  Matrix3 expectedD = numericalDerivative11<Vector3, Vector3>(
524  std::bind(correctedAcc, pim, measuredAcc, std::placeholders::_1),
525  measuredOmega, 1e-6);
526  EXPECT(assert_equal(expectedD, D_correctedAcc_measuredOmega, 1e-5));
527 
528  double dt = 0.1;
529 
530 // TODO(frank): revive derivative tests
531 // Matrix93 G1, G2;
532 // Vector9 preint =
533 // pim.updatedDeltaXij(measuredAcc, measuredOmega, dt, {}, G1, G2);
534 //
535 // Matrix93 expectedG1 = numericalDerivative21<NavState, Vector3, Vector3>(
536 // std::bind(&PreintegratedImuMeasurements::updatedDeltaXij, pim,
537 // std::placeholders::_1, std::placeholders::_2,
538 // dt, {}, {}, {}), measuredAcc,
539 // measuredOmega, 1e-6);
540 // EXPECT(assert_equal(expectedG1, G1, 1e-5));
541 //
542 // Matrix93 expectedG2 = numericalDerivative22<NavState, Vector3, Vector3>(
543 // std::bind(&PreintegratedImuMeasurements::updatedDeltaXij, pim,
544 // std::placeholders::_1, std::placeholders::_2,
545 // dt, {}, {}, {}), measuredAcc,
546 // measuredOmega, 1e-6);
547 // EXPECT(assert_equal(expectedG2, G2, 1e-5));
548 
549  Bias bias(Vector3(0.2, 0, 0), Vector3(0, 0, 0.3)); // Biases (acc, rot)
550 
551  // integrate at least twice to get position information
552  // otherwise factor cov noise from preint_cov is not positive definite
553  pim.integrateMeasurement(measuredAcc, measuredOmega, dt);
554  pim.integrateMeasurement(measuredAcc, measuredOmega, dt);
555 
556  // Create factor
557  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
558 
559  Pose3 x2(Rot3::Expmap(Vector3(0, 0, M_PI / 4.0 + M_PI / 10.0)),
560  Point3(5.5, 1.0, -50.0));
561  Vector3 v2(Vector3(0.5, 0.0, 0.0));
562 
563  Values values;
564  values.insert(X(1), x1);
565  values.insert(V(1), v1);
566  values.insert(X(2), x2);
567  values.insert(V(2), v2);
568  values.insert(B(1), bias);
569 
570  // Make sure linearization is correct
571  double diffDelta = 1e-8;
572  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, diffDelta, 1e-3);
573 }
574 
575 /* ************************************************************************* */
576 TEST(ImuFactor, PredictPositionAndVelocity) {
577  gttic(PredictPositionAndVelocity);
578  Bias bias(Vector3(0, 0, 0), Vector3(0, 0, 0)); // Biases (acc, rot)
579 
580  // Measurements
582  measuredOmega << 0, 0, 0; // M_PI/10.0+0.3;
584  measuredAcc << 0, 1, -kGravity;
585  double deltaT = 0.001;
586 
588  Bias(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.0)));
589 
590  for (int i = 0; i < 1000; ++i)
591  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
592 
593  // Create factor
594  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
595 
596  // Predict
597  Pose3 x1;
598  Vector3 v1(0, 0.0, 0.0);
599  NavState actual = pim.predict(NavState(x1, v1), bias);
600  NavState expected(Rot3(), Point3(0, 0.5, 0), Vector3(0, 1, 0));
601  EXPECT(assert_equal(expected, actual));
602 }
603 
604 /* ************************************************************************* */
605 TEST(ImuFactor, PredictRotation) {
606  gttic(PredictRotation);
607  Bias bias(Vector3(0, 0, 0), Vector3(0, 0, 0)); // Biases (acc, rot)
608 
609  // Measurements
611  measuredOmega << 0, 0, M_PI / 10; // M_PI/10.0+0.3;
613  measuredAcc << 0, 0, -kGravity;
614  double deltaT = 0.001;
615 
617  Bias(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.0)));
618 
619  for (int i = 0; i < 1000; ++i)
620  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
621 
622  // Create factor
623  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
624 
625  // Predict
626  NavState actual = pim.predict(NavState(), bias);
627  NavState expected(Rot3::Ypr(M_PI / 10, 0, 0), Point3(0,0,0), Z_3x1);
628  EXPECT(assert_equal(expected, actual));
629 }
630 
631 /* ************************************************************************* */
632 TEST(ImuFactor, PredictArbitrary) {
633  gttic(PredictArbitrary);
634  Pose3 x1;
635  const Vector3 v1(0, 0, 0);
636 
638  Vector3(0.1, 0.2, 0), Vector3(M_PI / 10, M_PI / 10, M_PI / 10));
639 
640  const double T = 3.0; // seconds
641  ScenarioRunner runner(scenario, testing::Params(), T / 10);
642  //
643  // PreintegratedImuMeasurements pim = runner.integrate(T);
644  // EXPECT(assert_equal(scenario.pose(T), runner.predict(pim).pose, 1e-9));
645  //
646  // Matrix6 estimatedCov = runner.estimatePoseCovariance(T);
647  // EXPECT(assert_equal(estimatedCov, runner.poseCovariance(pim), 0.1));
649 
650  Bias biasHat(Vector3(0.2, 0.0, 0.0), Vector3(0.0, 0.0, 0.0));
651 
652  // Measurements
654  Vector3 measuredAcc = runner.actualSpecificForce(0);
655 
656  auto p = testing::Params();
657  p->integrationCovariance = Z_3x3; // MonteCarlo does not sample integration noise
658  PreintegratedImuMeasurements pim(p, biasHat);
659  Bias bias(Vector3(0, 0, 0), Vector3(0, 0, 0));
660 // EXPECT(MonteCarlo(pim, NavState(x1, v1), bias, 0.1, {}, measuredAcc, measuredOmega,
661 // Vector3::Constant(accNoiseVar), Vector3::Constant(omegaNoiseVar), 100000));
662 
663  double dt = 0.001;
664  for (int i = 0; i < 1000; ++i)
665  pim.integrateMeasurement(measuredAcc, measuredOmega, dt);
666 
667  // Create factor
668  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
669 
670  // Predict
671  NavState actual = pim.predict(NavState(x1, v1), bias);
672 
673  // Regression test for Imu Refactor
674  Rot3 expectedR( //
675  +0.903715275, -0.250741668, 0.347026393, //
676  +0.347026393, 0.903715275, -0.250741668, //
677  -0.250741668, 0.347026393, 0.903715275);
678  Point3 expectedT(-0.516077031, 0.57842919, 0.0876478403);
679  Vector3 expectedV(-1.62337767, 1.57954409, 0.343833571);
680  NavState expected(expectedR, expectedT, expectedV);
681  EXPECT(assert_equal(expected, actual, 1e-7));
682 }
683 
684 /* ************************************************************************* */
685 TEST(ImuFactor, bodyPSensorNoBias) {
686  gttic(bodyPSensorNoBias);
687  Bias bias(Vector3(0, 0, 0), Vector3(0, 0.1, 0)); // Biases (acc, rot)
688 
689  // Rotate sensor (z-down) to body (same as navigation) i.e. z-up
690  auto p = testing::Params();
691  p->n_gravity = Vector3(0, 0, -kGravity); // z-up nav frame
692  p->body_P_sensor = Pose3(Rot3::Ypr(0, 0, M_PI), Point3(0, 0, 0));
693 
694  // Measurements
695  // Gyroscope measurement is the angular velocity of sensor w.r.t nav frame in sensor frame
696  Vector3 s_omegaMeas_ns(0, 0.1, M_PI / 10);
697  // Acc measurement is acceleration of sensor in the sensor frame, when stationary,
698  // table exerts an equal and opposite force w.r.t gravity
699  Vector3 s_accMeas(0, 0, -kGravity);
700  double dt = 0.001;
701 
702  PreintegratedImuMeasurements pim(p, bias);
703 
704  for (int i = 0; i < 1000; ++i)
705  pim.integrateMeasurement(s_accMeas, s_omegaMeas_ns, dt);
706 
707  // Create factor
708  ImuFactor factor(X(1), V(1), X(2), V(2), B(1), pim);
709 
710  // Predict
711  NavState actual = pim.predict(NavState(), bias);
712 
713  Pose3 expectedPose(Rot3::Ypr(-M_PI / 10, 0, 0), Point3(0, 0, 0));
714  EXPECT(assert_equal(expectedPose, actual.pose()));
715 
716  Vector3 expectedVelocity(0, 0, 0);
717  EXPECT(assert_equal(Vector(expectedVelocity), Vector(actual.velocity())));
718 }
719 
720 /* ************************************************************************* */
725 
726 TEST(ImuFactor, bodyPSensorWithBias) {
727  gttic(bodyPSensorWithBias);
728  using noiseModel::Diagonal;
729  typedef Bias Bias;
730 
731  int numFactors = 10;
732  Vector6 noiseBetweenBiasSigma;
733  noiseBetweenBiasSigma << Vector3(2.0e-5, 2.0e-5, 2.0e-5), Vector3(3.0e-6,
734  3.0e-6, 3.0e-6);
735  SharedDiagonal biasNoiseModel = Diagonal::Sigmas(noiseBetweenBiasSigma);
736 
737  // Measurements
738  // Sensor frame is z-down
739  // Gyroscope measurement is the angular velocity of sensor w.r.t nav frame in sensor frame
740  Vector3 measuredOmega(0, 0.01, 0);
741  // Acc measurement is acceleration of sensor in the sensor frame, when stationary,
742  // table exerts an equal and opposite force w.r.t gravity
743  Vector3 measuredAcc(0, 0, -kGravity);
744 
745  auto p = testing::Params();
746  p->n_gravity = Vector3(0, 0, -kGravity);
747  p->body_P_sensor = Pose3(Rot3::Ypr(0, 0, M_PI), Point3(0,0,0));
748  p->accelerometerCovariance = 1e-7 * I_3x3;
749  p->gyroscopeCovariance = 1e-8 * I_3x3;
750  p->integrationCovariance = 1e-9 * I_3x3;
751  double deltaT = 0.005;
752 
753  // Specify noise values on priors
754  Vector6 priorNoisePoseSigmas(
755  (Vector(6) << 0.001, 0.001, 0.001, 0.01, 0.01, 0.01).finished());
756  Vector3 priorNoiseVelSigmas((Vector(3) << 0.1, 0.1, 0.1).finished());
757  Vector6 priorNoiseBiasSigmas(
758  (Vector(6) << 0.1, 0.1, 0.1, 0.5e-1, 0.5e-1, 0.5e-1).finished());
759  SharedDiagonal priorNoisePose = Diagonal::Sigmas(priorNoisePoseSigmas);
760  SharedDiagonal priorNoiseVel = Diagonal::Sigmas(priorNoiseVelSigmas);
761  SharedDiagonal priorNoiseBias = Diagonal::Sigmas(priorNoiseBiasSigmas);
762  Vector3 zeroVel(0, 0, 0);
763 
764  // Create a factor graph with priors on initial pose, vlocity and bias
766  Values values;
767 
768  graph.addPrior(X(0), Pose3(), priorNoisePose);
769  values.insert(X(0), Pose3());
770 
771  graph.addPrior(V(0), zeroVel, priorNoiseVel);
772  values.insert(V(0), zeroVel);
773 
774  // The key to this test is that we specify the bias, in the sensor frame, as known a priori
775  // We also create factors below that encode our assumption that this bias is constant over time
776  // In theory, after optimization, we should recover that same bias estimate
777  Bias priorBias(Vector3(0, 0, 0), Vector3(0, 0.01, 0)); // Biases (acc, rot)
778  graph.addPrior(B(0), priorBias, priorNoiseBias);
779  values.insert(B(0), priorBias);
780 
781  // Now add IMU factors and bias noise models
782  Bias zeroBias(Vector3(0, 0, 0), Vector3(0, 0, 0));
783  for (int i = 1; i < numFactors; i++) {
785  priorBias);
786  for (int j = 0; j < 200; ++j)
787  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
788 
789  // Create factors
790  graph.emplace_shared<ImuFactor>(X(i - 1), V(i - 1), X(i), V(i), B(i - 1), pim);
791  graph.emplace_shared<BetweenFactor<Bias> >(B(i - 1), B(i), zeroBias, biasNoiseModel);
792 
793  values.insert(X(i), Pose3());
794  values.insert(V(i), zeroVel);
795  values.insert(B(i), priorBias);
796  }
797 
798  // Finally, optimize, and get bias at last time step
800  Bias biasActual = results.at<Bias>(B(numFactors - 1));
801 
802  // And compare it with expected value (our prior)
803  Bias biasExpected(Vector3(0, 0, 0), Vector3(0, 0.01, 0));
804  EXPECT(assert_equal(biasExpected, biasActual, 1e-3));
805 }
806 
807 /* ************************************************************************* */
808 #ifdef GTSAM_TANGENT_PREINTEGRATION
809 static const double kVelocity = 2.0, kAngularVelocity = M_PI / 6;
810 
811 struct ImuFactorMergeTest {
812  std::shared_ptr<PreintegrationParams> p_;
813  const ConstantTwistScenario forward_, loop_;
814 
815  ImuFactorMergeTest()
816  : p_(PreintegrationParams::MakeSharedU(kGravity)),
817  forward_(kZero, Vector3(kVelocity, 0, 0)),
818  loop_(Vector3(0, -kAngularVelocity, 0), Vector3(kVelocity, 0, 0)) {
819  // arbitrary noise values
820  p_->gyroscopeCovariance = I_3x3 * 0.01;
821  p_->accelerometerCovariance = I_3x3 * 0.03;
822  }
823 
824  int TestScenario(TestResult& result_, const std::string& name_,
825  const Scenario& scenario,
826  const Bias& bias01,
827  const Bias& bias12, double tol) {
828  // Test merge by creating a 01, 12, and 02 PreintegratedRotation,
829  // then checking the merge of 01-12 matches 02.
830  PreintegratedImuMeasurements pim01(p_, bias01);
831  PreintegratedImuMeasurements pim12(p_, bias12);
832  PreintegratedImuMeasurements pim02_expected(p_, bias01);
833 
834  double deltaT = 0.01;
835  ScenarioRunner runner(scenario, p_, deltaT);
836  // TODO(frank) can this loop just go into runner ?
837  for (int i = 0; i < 100; i++) {
838  double t = i * deltaT;
839  // integrate the measurements appropriately
840  Vector3 accel_meas = runner.actualSpecificForce(t);
841  Vector3 omega_meas = runner.actualAngularVelocity(t);
842  pim02_expected.integrateMeasurement(accel_meas, omega_meas, deltaT);
843  if (i < 50) {
844  pim01.integrateMeasurement(accel_meas, omega_meas, deltaT);
845  } else {
846  pim12.integrateMeasurement(accel_meas, omega_meas, deltaT);
847  }
848  }
849  auto actual_pim02 = ImuFactor::Merge(pim01, pim12);
850  EXPECT(assert_equal(pim02_expected.preintegrated(),
851  actual_pim02.preintegrated(), tol));
852  EXPECT(assert_equal(pim02_expected, actual_pim02, tol));
853 
854  ImuFactor::shared_ptr factor01 =
855  std::make_shared<ImuFactor>(X(0), V(0), X(1), V(1), B(0), pim01);
856  ImuFactor::shared_ptr factor12 =
857  std::make_shared<ImuFactor>(X(1), V(1), X(2), V(2), B(0), pim12);
858  ImuFactor::shared_ptr factor02_expected = std::make_shared<ImuFactor>(
859  X(0), V(0), X(2), V(2), B(0), pim02_expected);
860 
861  ImuFactor::shared_ptr factor02_merged = ImuFactor::Merge(factor01, factor12);
862  EXPECT(assert_equal(*factor02_expected, *factor02_merged, tol));
863  return result_.getFailureCount();
864  }
865 
866  void TestScenarios(TestResult& result_, const std::string& name_,
867  const Bias& bias01,
868  const Bias& bias12, double tol) {
869  for (auto scenario : {forward_, loop_})
870  TestScenario(result_, name_, scenario, bias01, bias12, tol);
871  }
872 };
873 
874 /* ************************************************************************* */
875 // Test case with zero biases
876 TEST(ImuFactor, MergeZeroBias) {
877  ImuFactorMergeTest mergeTest;
878  mergeTest.TestScenarios(result_, name_, kZeroBias, kZeroBias, 1e-4);
879 }
880 
881 // Test case with identical biases: we expect an exact answer.
882 TEST(ImuFactor, MergeConstantBias) {
883  ImuFactorMergeTest mergeTest;
884  Bias bias(Vector3(0.03, -0.02, 0.01), Vector3(-0.01, 0.02, -0.03));
885  mergeTest.TestScenarios(result_, name_, bias, bias, 1e-4);
886 }
887 
888 // Test case with different biases where we expect there to be some variation.
889 TEST(ImuFactor, MergeChangingBias) {
890  ImuFactorMergeTest mergeTest;
891  mergeTest.TestScenarios(result_, name_,
892  Bias(Vector3(0.03, -0.02, 0.01), Vector3(-0.01, 0.02, -0.03)),
893  Bias(Vector3(0.01, 0.02, 0.03), Vector3(0.03, -0.02, 0.01)), 1e-1);
894 }
895 
896 // Test case with non-zero coriolis
897 TEST(ImuFactor, MergeWithCoriolis) {
898  ImuFactorMergeTest mergeTest;
899  mergeTest.p_->omegaCoriolis = Vector3(0.1, 0.2, -0.1);
900  mergeTest.TestScenarios(result_, name_, kZeroBias, kZeroBias, 1e-4);
901 }
902 #endif
903 
904 /* ************************************************************************* */
905 // Same values as pre-integration test but now testing covariance
906 TEST(ImuFactor, CheckCovariance) {
907  gttic(CheckCovariance);
908  // Measurements
909  Vector3 measuredAcc(0.1, 0.0, 0.0);
910  Vector3 measuredOmega(M_PI / 100.0, 0.0, 0.0);
911  double deltaT = 0.5;
912 
914  actual.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
916  expected << 1.0577e-08, 0, 0, 0, 0, 0, 0, 0, 0, //
917  0, 1.0577e-08, 0, 0, 0, 0, 0, 0, 0, //
918  0, 0, 1.0577e-08, 0, 0, 0, 0, 0, 0, //
919  0, 0, 0, 5.00868e-05, 0, 0, 3.47222e-07, 0, 0, //
920  0, 0, 0, 0, 5.00868e-05, 0, 0, 3.47222e-07, 0, //
921  0, 0, 0, 0, 0, 5.00868e-05, 0, 0, 3.47222e-07, //
922  0, 0, 0, 3.47222e-07, 0, 0, 1.38889e-06, 0, 0, //
923  0, 0, 0, 0, 3.47222e-07, 0, 0, 1.38889e-06, 0, //
924  0, 0, 0, 0, 0, 3.47222e-07, 0, 0, 1.38889e-06;
925  EXPECT(assert_equal(expected, actual.preintMeasCov()));
926 }
927 
928 /* ************************************************************************* */
929 int main() {
930  TestResult tr;
932 #ifdef ENABLE_TIMING
933  tictoc_print_();
934 #endif
935  return result;
936 }
937 /* ************************************************************************* */
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
void integrateMeasurement(const Vector3 &measuredAcc, const Vector3 &measuredOmega, const double dt) override
Definition: ImuFactor.cpp:53
Vector3 actualAngularVelocity(double t) const
const double kGravity
Provides additional testing facilities for common data structures.
Vector3 correctGyroscope(const Vector3 &measurement, OptionalJacobian< 3, 6 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
Definition: ImuBias.h:85
#define CHECK(condition)
Definition: Test.h:108
Vector3 correctedAcc(const PreintegratedImuMeasurements &pim, const Vector3 &measuredAcc, const Vector3 &measuredOmega)
void integrateMeasurements(const Matrix &measuredAccs, const Matrix &measuredOmegas, const Matrix &dts)
Add multiple measurements, in matrix columns.
Definition: ImuFactor.cpp:87
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Definition: Vector.h:46
const Point3 & translation(OptionalJacobian< 3, 6 > Hself={}) const
get translation
Definition: Pose3.cpp:308
virtual const Values & optimize()
Vector9 biasCorrectedDelta(const imuBias::ConstantBias &bias_i, OptionalJacobian< 9, 6 > H={}) const override
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:196
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
A non-templated config holding any types of Manifold-group elements.
Matrix9 estimateCovariance(double T, size_t N=1000, const Bias &estimatedBias=Bias()) const
Compute a Monte Carlo estimate of the predict covariance using N samples.
Vector3f p1
Factor Graph consisting of non-linear factors.
const ValueType at(Key j) const
Definition: Values-inl.h:204
Matrix expected
Definition: testMatrix.cpp:971
#define DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:141
PreintegratedImuMeasurements integrate(double T, const Bias &estimatedBias=Bias(), bool corrupted=false) const
Integrate measurements for T seconds into a PIM.
Vector3 actualSpecificForce(double t) const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
#define M_PI
Definition: main.h:106
Rot2 R(Rot2::fromAngle(0.1))
leaf::MyValues values
void update(Key j, const Value &val)
Definition: Values.cpp:169
Pose2_ Expmap(const Vector3_ &xi)
static const Velocity3 kVelocity(0.4, 0.5, 0.6)
Vector evaluateError(const Pose3 &pose_i, const Vector3 &vel_i, const Pose3 &pose_j, const Vector3 &vel_j, const imuBias::ConstantBias &bias_i, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5) const override
vector of errors
Definition: ImuFactor.cpp:152
Some functions to compute numerical derivatives.
Evaluate derivatives of a nonlinear factor numerically.
static const Vector3 v2(Vector3(0.5, 0.0, 0.0))
Common testing infrastructure.
static const NavState state1(x1, v1)
NonlinearFactorGraph graph
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
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.
Matrix RtR(const Matrix &A)
Definition: Matrix.cpp:528
T compose(const T &t1, const T &t2)
Definition: lieProxies.h:39
Point2 expectedT(-0.0446635, 0.29552)
static const double kAccelSigma
NavState predict(const PreintegratedImuMeasurements &pim, const Bias &estimatedBias=Bias()) const
Predict predict given a PIM.
const double dt
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
#define gttic(label)
Definition: timing.h:295
static const Pose3 x2(Rot3::RzRyRx(M_PI/12.0+w, M_PI/6.0, M_PI/4.0), Point3(5.5, 1.0, 0))
Vector3 deltaPij() const override
static const double w
const Rot3 nRb
internal::FixedSizeMatrix< Y, X3 >::type numericalDerivative33(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Eigen::VectorXd Vector
Definition: Vector.h:38
Point3 unrotate(const Point3 &p, OptionalJacobian< 3, 3 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
rotate point from world to rotated frame
Definition: Rot3.cpp:135
Values result
Vector3 deltaVij() const override
void resetIntegrationAndSetBias(const Bias &biasHat)
static const NavState state2(x2, v2)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative32(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
#define EXPECT(condition)
Definition: Test.h:150
Vector3 correctAccelerometer(const Vector3 &measurement, OptionalJacobian< 3, 6 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
Definition: ImuBias.h:76
Array< int, Dynamic, 1 > v
static const double deltaT
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative31(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
const imuBias::ConstantBias & biasHat() const
RealScalar alpha
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
void tictoc_print_()
Definition: timing.h:268
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const Vector3 measuredAcc
sampling from a NoiseModel
ConstantTwistScenario scenario(Z_3x1, Vector3(v, 0, 0))
Pose3 pose(double t) const override
pose at time t
Definition: Scenario.h:92
Simple trajectory simulator.
Definition: Scenario.h:25
const Velocity3 & velocity(OptionalJacobian< 3, 9 > H={}) const
Definition: NavState.cpp:62
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:743
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
static const Vector kZero
imuBias::ConstantBias Bias
Definition: testImuBias.cpp:27
static const Pose3 x1(Rot3::RzRyRx(M_PI/12.0, M_PI/6.0, M_PI/4.0), Point3(5.0, 1.0, 0))
Rot2 expectedR
Definition: testPose2.cpp:149
static const Vector3 measuredOmega(w, 0, 0)
static const Vector3 v1(Vector3(0.5, 0.0, 0.0))
NavState predict(const NavState &state_i, const imuBias::ConstantBias &bias_i, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 6 > H2={}) const
Predict state at time j.
double error(const Values &c) const override
Simple class to test navigation scenarios.
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
#define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance)
Check the Jacobians produced by a factor against finite differences.
Matrix preintMeasCov() const
Return pre-integrated measurement covariance.
Definition: ImuFactor.h:141
std::pair< Vector3, Vector3 > correctMeasurementsBySensorPose(const Vector3 &unbiasedAcc, const Vector3 &unbiasedOmega, OptionalJacobian< 3, 3 > correctedAcc_H_unbiasedAcc={}, OptionalJacobian< 3, 3 > correctedAcc_H_unbiasedOmega={}, OptionalJacobian< 3, 3 > correctedOmega_H_unbiasedOmega={}) const
float * p
int getFailureCount()
Definition: TestResult.h:35
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
void insert(Key j, const Value &val)
Definition: Values.cpp:155
const Pose3 pose() const
Definition: NavState.h:86
const Rot3 & rotation(OptionalJacobian< 3, 6 > Hself={}) const
get rotation
Definition: Pose3.cpp:315
A class for computing marginals in a NonlinearFactorGraph.
TEST(ImuFactor, PreintegratedMeasurementsConstruction)
const G double tol
Definition: Group.h:86
Vector3 Point3
Definition: Point3.h:38
static std::shared_ptr< PreintegratedCombinedMeasurements::Params > Params(const Matrix3 &biasAccCovariance=Matrix3::Zero(), const Matrix3 &biasOmegaCovariance=Matrix3::Zero(), const Matrix6 &biasAccOmegaInt=Matrix6::Zero())
int main()
#define X
Definition: icosphere.cpp:20
std::shared_ptr< ImuFactor > shared_ptr
Definition: ImuFactor.h:192
3D Pose
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
void resetIntegration() override
Re-initialize PreintegratedIMUMeasurements.
Definition: ImuFactor.cpp:47
Accelerating from an arbitrary initial state, with optional rotation.
Definition: Scenario.h:83
static const double kGyroSigma
std::ptrdiff_t j
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:23