testImuFactorSerialization.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 
26 
27 #include <fstream>
28 
29 using namespace std;
30 using namespace gtsam;
31 using namespace gtsam::serializationTestHelpers;
32 
34  "gtsam_noiseModel_Constrained");
36  "gtsam_noiseModel_Diagonal");
38  "gtsam_noiseModel_Gaussian");
39 BOOST_CLASS_EXPORT_GUID(gtsam::noiseModel::Unit, "gtsam_noiseModel_Unit");
41  "gtsam_noiseModel_Isotropic");
42 BOOST_CLASS_EXPORT_GUID(gtsam::SharedNoiseModel, "gtsam_SharedNoiseModel");
43 BOOST_CLASS_EXPORT_GUID(gtsam::SharedDiagonal, "gtsam_SharedDiagonal");
44 
45 template <typename P>
47  // Create default parameters with Z-down and above noise paramaters
48  auto p = P::Params::MakeSharedD(9.81);
49  p->body_P_sensor = Pose3(Rot3::Ypr(0, 0, M_PI), Point3(0, 0, 0));
50  p->accelerometerCovariance = 1e-7 * I_3x3;
51  p->gyroscopeCovariance = 1e-8 * I_3x3;
52  p->integrationCovariance = 1e-9 * I_3x3;
53 
54  const double deltaT = 0.005;
55 
56  // Biases (acc, rot)
57  const imuBias::ConstantBias priorBias(Vector3(0, 0, 0), Vector3(0, 0.01, 0));
58 
59  P pim(p, priorBias);
60 
61  // measurements are needed for non-inf noise model, otherwise will throw error
62  // when deserialize
63  const Vector3 measuredOmega(0, 0.01, 0);
64  const Vector3 measuredAcc(0, 0, -9.81);
65 
66  for (int j = 0; j < 200; ++j)
67  pim.integrateMeasurement(measuredAcc, measuredOmega, deltaT);
68 
69  return pim;
70 }
71 
72 TEST(ImuFactor, serialization) {
73  auto pim = getPreintegratedMeasurements<PreintegratedImuMeasurements>();
74 
75  EXPECT(equalsObj<PreintegratedImuMeasurements>(pim));
76  EXPECT(equalsXML<PreintegratedImuMeasurements>(pim));
77  EXPECT(equalsBinary<PreintegratedImuMeasurements>(pim));
78 
79  ImuFactor factor(1, 2, 3, 4, 5, pim);
80 
81  EXPECT(equalsObj<ImuFactor>(factor));
82  EXPECT(equalsXML<ImuFactor>(factor));
83  EXPECT(equalsBinary<ImuFactor>(factor));
84 }
85 
86 TEST(ImuFactor2, serialization) {
87  auto pim = getPreintegratedMeasurements<PreintegratedImuMeasurements>();
88 
89  ImuFactor2 factor(1, 2, 3, pim);
90 
91  EXPECT(equalsObj<ImuFactor2>(factor));
92  EXPECT(equalsXML<ImuFactor2>(factor));
93  EXPECT(equalsBinary<ImuFactor2>(factor));
94 }
95 
96 TEST(CombinedImuFactor, Serialization) {
97  auto pim = getPreintegratedMeasurements<PreintegratedCombinedMeasurements>();
98 
99  EXPECT(equalsObj<PreintegratedCombinedMeasurements>(pim));
100  EXPECT(equalsXML<PreintegratedCombinedMeasurements>(pim));
101  EXPECT(equalsBinary<PreintegratedCombinedMeasurements>(pim));
102 
103  const CombinedImuFactor factor(1, 2, 3, 4, 5, 6, pim);
104 
105  EXPECT(equalsObj<CombinedImuFactor>(factor));
106  EXPECT(equalsXML<CombinedImuFactor>(factor));
107  EXPECT(equalsBinary<CombinedImuFactor>(factor));
108 }
109 
110 /* ************************************************************************* */
111 int main() {
112  TestResult tr;
113  return TestRegistry::runAllTests(tr);
114 }
115 /* ************************************************************************* */
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
#define M_PI
Definition: main.h:78
Definition: Half.h:150
TEST(ImuFactor, serialization)
#define EXPECT(condition)
Definition: Test.h:151
static const double deltaT
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const Vector3 measuredAcc
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:736
traits
Definition: chartTesting.h:28
static const Vector3 measuredOmega(w, 0, 0)
P getPreintegratedMeasurements()
float * p
Vector3 Point3
Definition: Point3.h:35
BOOST_CLASS_EXPORT_GUID(gtsam::noiseModel::Constrained,"gtsam_noiseModel_Constrained")
std::ptrdiff_t j
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:47:19