ScenarioRunner.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 
19 #include <gtsam/base/timing.h>
20 
21 #include <boost/assign.hpp>
22 #include <cmath>
23 
24 using namespace std;
25 using namespace boost::assign;
26 
27 namespace gtsam {
28 
29 static double intNoiseVar = 0.0000001;
30 static const Matrix3 kIntegrationErrorCovariance = intNoiseVar * I_3x3;
31 
32 PreintegratedImuMeasurements ScenarioRunner::integrate(
33  double T, const Bias& estimatedBias, bool corrupted) const {
34  gttic_(integrate);
35  PreintegratedImuMeasurements pim(p_, estimatedBias);
36 
37  const double dt = imuSampleTime();
38  const size_t nrSteps = T / dt;
39  double t = 0;
40  for (size_t k = 0; k < nrSteps; k++, t += dt) {
42  corrupted ? measuredAngularVelocity(t) : actualAngularVelocity(t);
44  corrupted ? measuredSpecificForce(t) : actualSpecificForce(t);
45  pim.integrateMeasurement(measuredAcc, measuredOmega, dt);
46  }
47 
48  return pim;
49 }
50 
51 NavState ScenarioRunner::predict(const PreintegratedImuMeasurements& pim,
52  const Bias& estimatedBias) const {
53  const NavState state_i(scenario_.pose(0), scenario_.velocity_n(0));
54  return pim.predict(state_i, estimatedBias);
55 }
56 
57 Matrix9 ScenarioRunner::estimateCovariance(double T, size_t N,
58  const Bias& estimatedBias) const {
59  gttic_(estimateCovariance);
60 
61  // Get predict prediction from ground truth measurements
62  NavState prediction = predict(integrate(T));
63 
64  // Sample !
65  Matrix samples(9, N);
66  Vector9 sum = Vector9::Zero();
67  for (size_t i = 0; i < N; i++) {
68  auto pim = integrate(T, estimatedBias, true);
69  NavState sampled = predict(pim);
70  Vector9 xi = sampled.localCoordinates(prediction);
71  samples.col(i) = xi;
72  sum += xi;
73  }
74 
75  // Compute MC covariance
76  Vector9 sampleMean = sum / N;
77  Matrix9 Q;
78  Q.setZero();
79  for (size_t i = 0; i < N; i++) {
80  Vector9 xi = samples.col(i) - sampleMean;
81  Q += xi * xi.transpose();
82  }
83 
84  return Q / (N - 1);
85 }
86 
87 Matrix6 ScenarioRunner::estimateNoiseCovariance(size_t N) const {
88  Matrix samples(6, N);
89  Vector6 sum = Vector6::Zero();
90  for (size_t i = 0; i < N; i++) {
91  samples.col(i) << accSampler_.sample() / sqrt_dt_,
92  gyroSampler_.sample() / sqrt_dt_;
93  sum += samples.col(i);
94  }
95 
96  // Compute MC covariance
97  Vector6 sampleMean = sum / N;
98  Matrix6 Q;
99  Q.setZero();
100  for (size_t i = 0; i < N; i++) {
101  Vector6 xi = samples.col(i) - sampleMean;
102  Q += xi * xi.transpose();
103  }
104 
105  return Q / (N - 1);
106 }
107 
108 } // namespace gtsam
void integrateMeasurement(const Vector3 &measuredAcc, const Vector3 &measuredOmega, const double dt) override
Definition: ImuFactor.cpp:53
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Quaternion Q
#define gttic_(label)
Definition: timing.h:230
Eigen::Vector3d Vector3
Definition: Vector.h:43
Vector9 localCoordinates(const NavState &g, OptionalJacobian< 9, 9 > H1=boost::none, OptionalJacobian< 9, 9 > H2=boost::none) const
localCoordinates with optional derivatives
Definition: NavState.cpp:135
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Definition: Half.h:150
#define N
Definition: gksort.c:12
static double intNoiseVar
static const Matrix3 kIntegrationErrorCovariance
NavState predict(const NavState &state_i, const imuBias::ConstantBias &bias_i, OptionalJacobian< 9, 9 > H1=boost::none, OptionalJacobian< 9, 6 > H2=boost::none) const
Predict state at time j.
const double dt
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Definition: mpreal.h:2381
static const Vector3 measuredAcc
Vector xi
Definition: testPose2.cpp:150
traits
Definition: chartTesting.h:28
static const Vector3 measuredOmega(w, 0, 0)
Simple class to test navigation scenarios.
Timing utilities.
Point2 t(10, 10)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set samples


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:54