ScenarioRunner.h
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 
18 #pragma once
21 #include <gtsam/linear/Sampler.h>
22 
23 namespace gtsam {
24 
25 // Convert covariance to diagonal noise model, if possible, otherwise throw
27  bool smart = true;
28  auto model = noiseModel::Gaussian::Covariance(covariance, smart);
29  auto diagonal = boost::dynamic_pointer_cast<noiseModel::Diagonal>(model);
30  if (!diagonal)
31  throw std::invalid_argument("ScenarioRunner::Diagonal: not a diagonal");
32  return diagonal;
33 }
34 
35 /*
36  * Simple class to test navigation scenarios.
37  * Takes a trajectory scenario as input, and can generate IMU measurements
38  */
39 class GTSAM_EXPORT ScenarioRunner {
40  public:
42  typedef boost::shared_ptr<PreintegrationParams> SharedParams;
43 
44  private:
46  const SharedParams p_;
47  const double imuSampleTime_, sqrt_dt_;
48  const Bias estimatedBias_;
49 
50  // Create two samplers for acceleration and omega noise
51  Sampler gyroSampler_, accSampler_;
52 
53  public:
54  ScenarioRunner(const Scenario& scenario, const SharedParams& p,
55  double imuSampleTime = 1.0 / 100.0, const Bias& bias = Bias())
56  : scenario_(scenario),
57  p_(p),
58  imuSampleTime_(imuSampleTime),
59  sqrt_dt_(std::sqrt(imuSampleTime)),
60  estimatedBias_(bias),
61  // NOTE(duy): random seeds that work well:
62  gyroSampler_(Diagonal(p->gyroscopeCovariance), 10),
63  accSampler_(Diagonal(p->accelerometerCovariance), 29284) {}
64 
65  // NOTE(frank): hardcoded for now with Z up (gravity points in negative Z)
66  // also, uses g=10 for easy debugging
67  const Vector3& gravity_n() const { return p_->n_gravity; }
68 
69  // A gyro simply measures angular velocity in body frame
71  return scenario_.omega_b(t);
72  }
73 
74  // An accelerometer measures acceleration in body, but not gravity
75  Vector3 actualSpecificForce(double t) const {
76  Rot3 bRn(scenario_.rotation(t).transpose());
77  return scenario_.acceleration_b(t) - bRn * gravity_n();
78  }
79 
80  // versions corrupted by bias and noise
82  return actualAngularVelocity(t) + estimatedBias_.gyroscope() +
83  gyroSampler_.sample() / sqrt_dt_;
84  }
86  return actualSpecificForce(t) + estimatedBias_.accelerometer() +
87  accSampler_.sample() / sqrt_dt_;
88  }
89 
90  const double& imuSampleTime() const { return imuSampleTime_; }
91 
93  PreintegratedImuMeasurements integrate(double T,
94  const Bias& estimatedBias = Bias(),
95  bool corrupted = false) const;
96 
98  NavState predict(const PreintegratedImuMeasurements& pim,
99  const Bias& estimatedBias = Bias()) const;
100 
102  Matrix9 estimateCovariance(double T, size_t N = 1000,
103  const Bias& estimatedBias = Bias()) const;
104 
106  Matrix6 estimateNoiseCovariance(size_t N = 1000) const;
107 };
108 
109 } // namespace gtsam
Simple class to test navigation scenarios.
virtual Vector3 omega_b(double t) const =0
angular velocity in body frame
imuBias::ConstantBias Bias
ScenarioRunner(const Scenario &scenario, const SharedParams &p, double imuSampleTime=1.0/100.0, const Bias &bias=Bias())
const double & imuSampleTime() const
Vector3 actualSpecificForce(double t) const
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
Definition: NoiseModel.cpp:116
const Vector3 & gravity_n() const
Eigen::Vector3d Vector3
Definition: Vector.h:43
noiseModel::Diagonal::shared_ptr model
Vector3 acceleration_b(double t) const
Definition: Scenario.h:47
void diagonal(const MatrixType &m)
Definition: diagonal.cpp:12
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
const Vector3 & accelerometer() const
Definition: ImuBias.h:59
Definition: Half.h:150
Vector3 measuredSpecificForce(double t) const
#define N
Definition: gksort.c:12
Vector3 measuredAngularVelocity(double t) const
const Scenario & scenario_
sampling from a NoiseModel
ConstantTwistScenario scenario(Z_3x1, Vector3(v, 0, 0))
Point3 bias(10,-10, 50)
boost::shared_ptr< Diagonal > shared_ptr
Definition: NoiseModel.h:301
Simple trajectory simulator.
Definition: Scenario.h:25
const Vector3 & gyroscope() const
Definition: ImuBias.h:64
Matrix3 transpose() const
Definition: Rot3M.cpp:144
traits
Definition: chartTesting.h:28
Vector3 actualAngularVelocity(double t) const
boost::shared_ptr< PreintegrationParams > SharedParams
const SharedParams p_
imuBias::ConstantBias Bias
float * p
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
Rot3 rotation(double t) const
Definition: Scenario.h:39
Point2 t(10, 10)
Vector sample() const
sample from distribution
Definition: Sampler.cpp:51


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