IEKF_NavstateExample.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/Matrix.h>
20 #include <gtsam/base/VectorSpace.h>
24 
25 #include <iostream>
26 
27 using namespace std;
28 using namespace gtsam;
29 
35 Vector9 dynamics(const Vector6& imu) {
36  auto a = imu.head<3>();
37  auto w = imu.tail<3>();
38  Vector9 xi;
39  xi << w, Vector3::Zero(), a;
40  return xi;
41 }
42 
50  return X.position(H);
51 }
52 
53 int main() {
54  // Initial state & covariances
55  NavState X0; // R=I, v=0, t=0
56  Matrix9 P0 = Matrix9::Identity() * 0.1;
57  InvariantEKF<NavState> ekf(X0, P0);
58 
59  // Noise & timestep
60  double dt = 1.0;
61  Matrix9 Q = Matrix9::Identity() * 0.01;
62  Matrix3 R = Matrix3::Identity() * 0.5;
63 
64  // Two IMU samples [a; ω]
65  Vector6 imu1;
66  imu1 << 0.1, 0, 0, 0, 0.2, 0;
67  Vector6 imu2;
68  imu2 << 0, 0.3, 0, 0.4, 0, 0;
69 
70  // Two GPS fixes
71  Vector3 z1;
72  z1 << 0.3, 0, 0;
73  Vector3 z2;
74  z2 << 0.6, 0, 0;
75 
76  cout << "=== Init ===\nX: " << ekf.state() << "\nP: " << ekf.covariance()
77  << "\n\n";
78 
79  // --- first predict/update ---
80  ekf.predict(dynamics(imu1), dt, Q);
81  cout << "--- After predict 1 ---\nX: " << ekf.state()
82  << "\nP: " << ekf.covariance() << "\n\n";
83  ekf.update(h_gps, z1, R);
84  cout << "--- After update 1 ---\nX: " << ekf.state()
85  << "\nP: " << ekf.covariance() << "\n\n";
86 
87  // --- second predict/update ---
88  ekf.predict(dynamics(imu2), dt, Q);
89  cout << "--- After predict 2 ---\nX: " << ekf.state()
90  << "\nP: " << ekf.covariance() << "\n\n";
91  ekf.update(h_gps, z2, R);
92  cout << "--- After update 2 ---\nX: " << ekf.state()
93  << "\nP: " << ekf.covariance() << "\n";
94 
95  return 0;
96 }
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
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
screwPose2::xi
Vector xi
Definition: testPose2.cpp:169
z1
Point2 z1
Definition: testTriangulationFactor.cpp:45
Matrix.h
typedef and functions to augment Eigen's MatrixXd
dt
const double dt
Definition: testVelocityConstraint.cpp:15
gtsam::NavState
Definition: NavState.h:38
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
dynamics
Vector9 dynamics(const Vector6 &imu)
Left-invariant dynamics for NavState.
Definition: IEKF_NavstateExample.cpp:35
NavState.h
Navigation state composing of attitude, position, and velocity.
OptionalJacobian.h
Special class for optional Jacobian arguments.
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
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: ABC.h:17
h_gps
Vector3 h_gps(const NavState &X, OptionalJacobian< 3, 9 > H={})
GPS measurement model: returns position and its Jacobian.
Definition: IEKF_NavstateExample.cpp:49
InvariantEKF.h
Left-Invariant Extended Kalman Filter implementation.
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
std
Definition: BFloat16.h:88
Eigen::Matrix< double, 9, 9 >
P0
static double P0[5]
Definition: ndtri.c:59
gtsam::InvariantEKF::predict
void predict(const G &U, const Covariance &Q)
Definition: InvariantEKF.h:79
VectorSpace.h
R
Rot2 R(Rot2::fromAngle(0.1))
main
int main()
Definition: IEKF_NavstateExample.cpp:53
z2
static const Unit3 z2
Definition: testRotateFactor.cpp:46


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