gtsam
Loading...
Searching...
No Matches
InvariantEKF.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
25
26#pragma once
27
28#include <gtsam/base/Lie.h> // For traits (needed for AdjointMap, Expmap)
29#include <gtsam/navigation/LeftLinearEKF.h> // Include the base class
30
31namespace gtsam {
32
56template <typename G>
57class InvariantEKF : public LeftLinearEKF<G> {
58 public:
59 using Base = LeftLinearEKF<G>;
60 static constexpr int Dim = Base::Dim;
61 using TangentVector = typename Base::TangentVector;
64 using Jacobian = typename Base::Jacobian;
66 using Covariance = typename Base::Covariance;
67
73 InvariantEKF(const G& X0, const Covariance& P0) : Base(X0, P0) {}
74
79 static G Dynamics(const G& X, const G& U, OptionalJacobian<Dim, Dim> A = {}) {
80 if (A) {
81 const G U_inv = traits<G>::Inverse(U);
82 *A = traits<G>::AdjointMap(U_inv);
83 }
84 return traits<G>::Compose(X, U);
85 }
86
87 // We hide state-dependent predict methods from LeftLinearEKF by only
88 // providing the invariant predict methods below.
89
99 void predict(const G& U, const Covariance& Q) {
100 this->X_ = traits<G>::Compose(this->X_, U);
101 const G U_inv = traits<G>::Inverse(U);
102 const Jacobian A = traits<G>::AdjointMap(U_inv);
103 // P_ is Covariance. A is Jacobian. Q is Covariance.
104 // All are Eigen::Matrix<double,Dim,Dim>.
105 this->P_ = A * this->P_ * A.transpose() + Q;
106 }
107
117 void predict(const TangentVector& u, double dt, const Covariance& Q) {
118 G U;
119 if constexpr (std::is_same_v<G, Matrix>) {
120 // Specialize to Matrix case as its Expmap is not defined.
121 const Matrix& X = static_cast<const Matrix&>(this->X_);
122 U.resize(X.rows(), X.cols());
123 Eigen::Map<Vector>(static_cast<Matrix&>(U).data(), U.size()) = u * dt;
124 } else {
125 U = traits<G>::Expmap(u * dt);
126 }
127 predict(U, Q * dt); // Q interpreted as continuous-time; discretize with dt
128 }
129
134 static G Dynamics(const G& W, const G& X, const G& U,
136 return traits<G>::Compose(W, Dynamics(X, U, A)); // A is independent of W
137 }
138
150 void predict(const G& W, const G& U, const Covariance& Q) {
151 predict(U, Q); // First apply U
152 // Then apply W on the left
153 this->X_ = traits<G>::Compose(W, this->X_);
154 }
155
156}; // InvariantEKF
157
158} // namespace gtsam
Base class and basic functions for Lie types.
EKF on a Lie group with a general left–linear prediction model.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
void predict(const G &W, const G &U, const Covariance &Q)
Predict step via left and right group composition (Left-Invariant): X_{k+1} = W * X_k * U P_{k+1}...
Definition InvariantEKF.h:150
void predict(const TangentVector &u, double dt, const Covariance &Q)
Predict step via tangent control vector: U = Expmap(u * dt) Then calls predict(U, Q).
Definition InvariantEKF.h:117
typename Base::Jacobian Jacobian
Definition InvariantEKF.h:64
LeftLinearEKF< Gal3 > Base
Definition InvariantEKF.h:59
typename Base::TangentVector TangentVector
Definition InvariantEKF.h:61
static G Dynamics(const G &W, const G &X, const G &U, OptionalJacobian< Dim, Dim > A={})
General dynamics.
Definition InvariantEKF.h:134
static constexpr int Dim
Definition InvariantEKF.h:60
InvariantEKF(const G &X0, const Covariance &P0)
Constructor: forwards to LeftLinearEKF constructor.
Definition InvariantEKF.h:73
void predict(const G &U, const Covariance &Q)
Predict step via group composition (Left-Invariant): X_{k+1} = X_k * U P_{k+1} = Ad_{U^{-1}...
Definition InvariantEKF.h:99
typename Base::Covariance Covariance
Definition InvariantEKF.h:66
static G Dynamics(const G &X, const G &U, OptionalJacobian< Dim, Dim > A={})
Dynamics with W=I.
Definition InvariantEKF.h:79
static constexpr int Dim
Compile-time dimension of G.
Definition LeftLinearEKF.h:46
G X_
Definition ManifoldEKF.h:284
Covariance P_
Definition ManifoldEKF.h:285