IEKF_SE2Example.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 
34 #include <gtsam/geometry/Pose2.h>
36 
37 #include <iostream>
38 
39 using namespace std;
40 using namespace gtsam;
41 
42 // Create a 2D GPS measurement function that returns the predicted measurement h
43 // and Jacobian H. The predicted measurement h is the translation of the state
44 // X.
46  return X.translation(H);
47 }
48 
49 // Define a InvariantEKF class that uses the Pose2 Lie group as the state and
50 // the Vector2 measurement type.
51 int main() {
52  // // Initialize the filter's state, covariance, and time interval values.
53  Pose2 X0(0.0, 0.0, 0.0);
54  Matrix3 P0 = Matrix3::Identity() * 0.1;
55 
56  // Create the filter with the initial state, covariance, and measurement
57  // function.
58  InvariantEKF<Pose2> ekf(X0, P0);
59 
60  // Define the process covariance and measurement covariance matrices Q and R.
61  Matrix3 Q = (Vector3(0.05, 0.05, 0.001)).asDiagonal();
62  Matrix2 R = I_2x2 * 0.01;
63 
64  // Define odometry movements.
65  // U1: Move 1 unit in X, 1 unit in Y, 0.5 radians in theta.
66  // U2: Move 1 unit in X, 1 unit in Y, 0 radians in theta.
67  Pose2 U1(1.0, 1.0, 0.5), U2(1.0, 1.0, 0.0);
68 
69  // Create GPS measurements.
70  // z1: Measure robot at (1, 0)
71  // z2: Measure robot at (1, 1)
72  Vector2 z1, z2;
73  z1 << 1.0, 0.0;
74  z2 << 1.0, 1.0;
75 
76  // Define a transformation matrix to convert the covariance into (theta, x, y)
77  // form. The paper and data mentioned above uses a (theta, x, y) notation,
78  // whereas GTSAM uses (x, y, theta). The transformation matrix is used to
79  // directly compare results of the covariance matrix.
80  Matrix3 TransformP;
81  TransformP << 0, 0, 1, 1, 0, 0, 0, 1, 0;
82 
83  // Propagating/updating the filter
84  // Initial state and covariance
85  cout << "\nInitialization:\n";
86  cout << "X0: " << ekf.state() << endl;
87  cout << "P0: " << TransformP * ekf.covariance() * TransformP.transpose()
88  << endl;
89 
90  // First prediction stage
91  ekf.predict(U1, Q);
92  cout << "\nFirst Prediction:\n";
93  cout << "X: " << ekf.state() << endl;
94  cout << "P: " << TransformP * ekf.covariance() * TransformP.transpose()
95  << endl;
96 
97  // First update stage
98  ekf.update(h_gps, z1, R);
99  cout << "\nFirst Update:\n";
100  cout << "X: " << ekf.state() << endl;
101  cout << "P: " << TransformP * ekf.covariance() * TransformP.transpose()
102  << endl;
103 
104  // Second prediction stage
105  ekf.predict(U2, Q);
106  cout << "\nSecond Prediction:\n";
107  cout << "X: " << ekf.state() << endl;
108  cout << "P: " << TransformP * ekf.covariance() * TransformP.transpose()
109  << endl;
110 
111  // Second update stage
112  ekf.update(h_gps, z2, R);
113  cout << "\nSecond Update:\n";
114  cout << "X: " << ekf.state() << endl;
115  cout << "P: " << TransformP * ekf.covariance() * TransformP.transpose()
116  << endl;
117 
118  return 0;
119 }
H
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 set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Definition: gnuplot_common_settings.hh:74
Pose2.h
2D Pose
z1
Point2 z1
Definition: testTriangulationFactor.cpp:45
X
#define X
Definition: icosphere.cpp:20
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:44
gtsam::ManifoldEKF< G >::covariance
const Covariance & covariance() const
Definition: ManifoldEKF.h:111
gtsam::ManifoldEKF< G >::state
const G & state() const
Definition: ManifoldEKF.h:108
Vector2
Definition: test_operator_overloading.cpp:18
gtsam::ManifoldEKF< G >::update
void update(const Measurement &prediction, const Eigen::Matrix< double, traits< Measurement >::dimension, Dim > &H, const Measurement &z, const Eigen::Matrix< double, traits< Measurement >::dimension, traits< Measurement >::dimension > &R)
Definition: ManifoldEKF.h:152
gtsam::InvariantEKF
Left-Invariant Extended Kalman Filter on a Lie group G.
Definition: InvariantEKF.h:50
Eigen::Quaternion
The quaternion class used to represent 3D orientations and rotations.
Definition: ForwardDeclarations.h:293
gtsam
traits
Definition: ABC.h:17
InvariantEKF.h
Left-Invariant Extended Kalman Filter implementation.
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
h_gps
Vector2 h_gps(const Pose2 &X, OptionalJacobian< 2, 3 > H={})
Definition: IEKF_SE2Example.cpp:45
std
Definition: BFloat16.h:88
main
int main()
Definition: IEKF_SE2Example.cpp:51
P0
static double P0[5]
Definition: ndtri.c:59
gtsam::InvariantEKF::predict
void predict(const G &U, const Covariance &Q)
Definition: InvariantEKF.h:79
R
Rot2 R(Rot2::fromAngle(0.1))
gtsam::Pose2
Definition: Pose2.h:39
z2
static const Unit3 z2
Definition: testRotateFactor.cpp:46


gtsam
Author(s):
autogenerated on Wed May 28 2025 03:01:26