testImuBias.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 
20 
22 #include <boost/bind.hpp>
23 
24 using namespace std;
25 using namespace gtsam;
26 
28 
29 Vector biasAcc1(Vector3(0.2, -0.1, 0));
30 Vector biasGyro1(Vector3(0.1, -0.3, -0.2));
32 
33 Vector biasAcc2(Vector3(0.1, 0.2, 0.04));
34 Vector biasGyro2(Vector3(-0.002, 0.005, 0.03));
36 
37 /* ************************************************************************* */
38 TEST(ImuBias, Constructor) {
39  // Default Constructor
40  Bias bias1;
41 
42  // Acc + Gyro Constructor
44 
45  // Copy Constructor
46  Bias bias3(bias2);
47 }
48 
49 /* ************************************************************************* */
50 TEST(ImuBias, inverse) {
51  Bias biasActual = bias1.inverse();
52  Bias biasExpected = Bias(-biasAcc1, -biasGyro1);
53  EXPECT(assert_equal(biasExpected, biasActual));
54 }
55 
56 /* ************************************************************************* */
57 TEST(ImuBias, compose) {
58  Bias biasActual = bias2.compose(bias1);
59  Bias biasExpected = Bias(biasAcc1 + biasAcc2, biasGyro1 + biasGyro2);
60  EXPECT(assert_equal(biasExpected, biasActual));
61 }
62 
63 /* ************************************************************************* */
64 TEST(ImuBias, between) {
65  // p.between(q) == q - p
66  Bias biasActual = bias2.between(bias1);
67  Bias biasExpected = Bias(biasAcc1 - biasAcc2, biasGyro1 - biasGyro2);
68  EXPECT(assert_equal(biasExpected, biasActual));
69 }
70 
71 /* ************************************************************************* */
72 TEST(ImuBias, localCoordinates) {
73  Vector deltaActual = Vector(bias2.localCoordinates(bias1));
74  Vector deltaExpected =
75  (Bias(biasAcc1 - biasAcc2, biasGyro1 - biasGyro2)).vector();
76  EXPECT(assert_equal(deltaExpected, deltaActual));
77 }
78 
79 /* ************************************************************************* */
80 TEST(ImuBias, retract) {
81  Vector6 delta;
82  delta << 0.1, 0.2, -0.3, 0.1, -0.1, 0.2;
83  Bias biasActual = bias2.retract(delta);
84  Bias biasExpected = Bias(biasAcc2 + delta.block<3, 1>(0, 0),
85  biasGyro2 + delta.block<3, 1>(3, 0));
86  EXPECT(assert_equal(biasExpected, biasActual));
87 }
88 
89 /* ************************************************************************* */
90 TEST(ImuBias, Logmap) {
91  Vector deltaActual = bias2.Logmap(bias1);
92  Vector deltaExpected = bias1.vector();
93  EXPECT(assert_equal(deltaExpected, deltaActual));
94 }
95 
96 /* ************************************************************************* */
97 TEST(ImuBias, Expmap) {
98  Vector6 delta;
99  delta << 0.1, 0.2, -0.3, 0.1, -0.1, 0.2;
100  Bias biasActual = bias2.Expmap(delta);
101  Bias biasExpected = Bias(delta);
102  EXPECT(assert_equal(biasExpected, biasActual));
103 }
104 
105 /* ************************************************************************* */
106 TEST(ImuBias, operatorSub) {
107  Bias biasActual = -bias1;
108  Bias biasExpected(-biasAcc1, -biasGyro1);
109  EXPECT(assert_equal(biasExpected, biasActual));
110 }
111 
112 /* ************************************************************************* */
113 TEST(ImuBias, operatorAdd) {
114  Bias biasActual = bias2 + bias1;
115  Bias biasExpected(biasAcc2 + biasAcc1, biasGyro2 + biasGyro1);
116  EXPECT(assert_equal(biasExpected, biasActual));
117 }
118 
119 /* ************************************************************************* */
120 TEST(ImuBias, operatorSubB) {
121  Bias biasActual = bias2 - bias1;
122  Bias biasExpected(biasAcc2 - biasAcc1, biasGyro2 - biasGyro1);
123  EXPECT(assert_equal(biasExpected, biasActual));
124 }
125 
126 /* ************************************************************************* */
127 TEST(ImuBias, Correct1) {
128  Matrix aH1, aH2;
129  const Vector3 measurement(1, 2, 3);
130  boost::function<Vector3(const Bias&, const Vector3&)> f = boost::bind(
131  &Bias::correctAccelerometer, _1, _2, boost::none, boost::none);
132  bias1.correctAccelerometer(measurement, aH1, aH2);
133  EXPECT(assert_equal(numericalDerivative21(f, bias1, measurement), aH1));
134  EXPECT(assert_equal(numericalDerivative22(f, bias1, measurement), aH2));
135 }
136 
137 /* ************************************************************************* */
138 TEST(ImuBias, Correct2) {
139  Matrix aH1, aH2;
140  const Vector3 measurement(1, 2, 3);
141  boost::function<Vector3(const Bias&, const Vector3&)> f =
142  boost::bind(&Bias::correctGyroscope, _1, _2, boost::none, boost::none);
143  bias1.correctGyroscope(measurement, aH1, aH2);
144  EXPECT(assert_equal(numericalDerivative21(f, bias1, measurement), aH1));
145  EXPECT(assert_equal(numericalDerivative22(f, bias1, measurement), aH2));
146 }
147 
148 /* ************************************************************************* */
149 int main() {
150  TestResult tr;
151  return TestRegistry::runAllTests(tr);
152 }
153 /* ************************************************************************* */
Vector biasGyro2(Vector3(-0.002, 0.005, 0.03))
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
T between(const T &t1, const T &t2)
Definition: lieProxies.h:36
Bias bias2(biasAcc2, biasGyro2)
static Vector6 Logmap(const ConstantBias &p)
Definition: ImuBias.h:151
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Pose2_ Expmap(const Vector3_ &xi)
double measurement(10.0)
Definition: Half.h:150
Some functions to compute numerical derivatives.
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)
ConstantBias compose(const ConstantBias &q)
Definition: ImuBias.h:139
T compose(const T &t1, const T &t2)
Definition: lieProxies.h:39
ConstantBias retract(const Vector6 &v)
Definition: ImuBias.h:148
int main()
Eigen::VectorXd Vector
Definition: Vector.h:38
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
Vector biasAcc2(Vector3(0.1, 0.2, 0.04))
#define EXPECT(condition)
Definition: Test.h:151
Vector3 correctAccelerometer(const Vector3 &measurement, OptionalJacobian< 3, 6 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
Definition: ImuBias.h:69
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Vector6 vector() const
Definition: ImuBias.h:52
Vector6 localCoordinates(const ConstantBias &q)
Definition: ImuBias.h:145
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
imuBias::ConstantBias Bias
Definition: testImuBias.cpp:27
Vector biasAcc1(Vector3(0.2,-0.1, 0))
ConstantBias between(const ConstantBias &q)
Definition: ImuBias.h:142
static ConstantBias Expmap(const Vector6 &v)
Definition: ImuBias.h:154
Vector3 correctGyroscope(const Vector3 &measurement, OptionalJacobian< 3, 6 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
Definition: ImuBias.h:78
ConstantBias inverse()
Definition: ImuBias.h:136
Bias bias1(biasAcc1, biasGyro1)
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Vector biasGyro1(Vector3(0.1,-0.3,-0.2))
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
TEST(ImuBias, Constructor)
Definition: testImuBias.cpp:38


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