-
Notifications
You must be signed in to change notification settings - Fork 904
NavState + IMU EKF #2242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
NavState + IMU EKF #2242
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a6d2b46
Navstate specific filter driven by IMU
dellaert 8c93274
Clean up
dellaert 3826d99
Example
dellaert 2eaff9d
Allow custom integration
dellaert bf58dfd
Avoid copy/pasta in test
dellaert 6aaba8a
Wrapping
dellaert 18d352b
Example notebook
dellaert 418229a
Example with update
dellaert 89d1055
remove proffan/robotics tap
dellaert 60ace96
Scale noise by dt
dellaert b5b0c2a
Show stddevs
dellaert fdce7a9
Test Update
dellaert df1b04a
test w Factor Graph "ground truth"
dellaert 1813181
Fix bug in H!
dellaert fff5567
Guidance
dellaert be42e33
Docs
dellaert 735c205
Fix CI
dellaert 1d49721
LeftLinearEKF
dellaert bf1f260
Unit tests
dellaert 0594551
NavState::AutonomousFlow
dellaert 2d138d9
Naming convention
dellaert c67ba83
Now a LeftLinearEKF
dellaert 4d6c820
Wrapper and docs
dellaert 749d394
Psi -> Phi
dellaert 5bcbb6c
Review comments
dellaert e7bdbca
ASV example by Derek
dellaert 3617156
Merge branch 'develop' into feature/navstate_imu
dellaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* ---------------------------------------------------------------------------- | ||
|
|
||
| * GTSAM Copyright 2010, Georgia Tech Research Corporation, | ||
| * Atlanta, Georgia 30332-0415 | ||
| * All Rights Reserved | ||
| * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | ||
|
|
||
| * See LICENSE for the license information | ||
|
|
||
| * -------------------------------------------------------------------------- */ | ||
|
|
||
| /** | ||
| * @file NavStateImuExample.cpp | ||
| * @brief Run the NavStateImuEKF on an orbiting (constant twist) scenario. | ||
| * Uses ScenarioRunner to generate corrupted IMU, de-biases with true | ||
| * biases, feeds the EKF, and compares to Scenario ground truth. | ||
| * | ||
| * @date August 2025 | ||
| * @authors You | ||
| */ | ||
|
|
||
| #include <gtsam/base/Matrix.h> | ||
| #include <gtsam/geometry/Cal3_S2.h> | ||
| #include <gtsam/geometry/PinholeCamera.h> | ||
| #include <gtsam/geometry/Pose3.h> | ||
| #include <gtsam/geometry/Rot3.h> | ||
| #include <gtsam/navigation/NavState.h> | ||
| #include <gtsam/navigation/NavStateImuEKF.h> | ||
| #include <gtsam/navigation/PreintegrationParams.h> | ||
| #include <gtsam/navigation/Scenario.h> | ||
| #include <gtsam/navigation/ScenarioRunner.h> | ||
|
|
||
| #include <cmath> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
| using namespace gtsam; | ||
|
|
||
| static constexpr double kGravity = 9.81; | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| // --- Scenario: camera orbiting a point --- | ||
| const double radius = 30.0; | ||
| const double angular_velocity = M_PI; // rad/sec | ||
| const Vector3 w_b(0, 0, -angular_velocity); | ||
| const Vector3 v_n(radius * angular_velocity, 0, 0); | ||
| ConstantTwistScenario scenario(w_b, v_n); | ||
|
|
||
| // --- Preintegration/IMU parameters --- | ||
| auto params = PreintegrationParams::MakeSharedU(kGravity); | ||
| params->setAccelerometerCovariance(I_3x3 * 0.1); | ||
| params->setGyroscopeCovariance(I_3x3 * 0.1); | ||
| params->setIntegrationCovariance(I_3x3 * 0.1); | ||
| params->setUse2ndOrderCoriolis(false); | ||
| params->setOmegaCoriolis(Vector3::Zero()); | ||
|
|
||
| // True biases used to corrupt measurements in ScenarioRunner | ||
| imuBias::ConstantBias trueBias(Vector3(0.01, -0.005, 0.02), // gyro bias | ||
| Vector3(0.05, 0.03, -0.02)); // accel bias | ||
|
|
||
| // --- Measurement generator --- | ||
| const double dt = 1.0 / 180.0; // 1 degree per step | ||
| ScenarioRunner runner(scenario, params, dt, trueBias); | ||
|
|
||
| // --- Initialize EKF with ground truth | ||
| const double t0 = 0.0; | ||
| NavState X0 = scenario.navState(t0); | ||
| Matrix9 P0 = I_9x9 * 1e-2; // modest initial uncertainty | ||
| NavStateImuEKF ekf(X0, P0, params); | ||
|
|
||
| // --- Run for N steps and compare predictions --- | ||
| const size_t N = 90; | ||
| cout << fixed << setprecision(3); | ||
| cout << "step,t(s),rot_err_deg,pos_err,vel_err\n"; | ||
| double t = t0; | ||
| for (size_t i = 0; i < N; ++i) { | ||
| // Measurements from runner, *not* corrupted by noise | ||
| const Vector3 measuredOmega = runner.actualAngularVelocity(t); | ||
| const Vector3 measuredAcc = runner.actualSpecificForce(t); | ||
|
|
||
| // De-bias using the true (known) biases before feeding EKF | ||
| const Vector3 omega = measuredOmega - trueBias.gyroscope(); | ||
| const Vector3 acc = measuredAcc - trueBias.accelerometer(); | ||
|
|
||
| // Predict one step | ||
| ekf.predict(omega, acc, dt); | ||
|
|
||
| // Ground truth at next time | ||
| t += dt; | ||
| const NavState gt = scenario.navState(t); | ||
|
|
||
| // Print ground truth and EKF state | ||
| // cout << "Ground Truth: " << gt << "\n"; | ||
| // cout << "EKF State: " << ekf.state() << "\n"; | ||
|
|
||
| // Errors | ||
| const Rot3 dR = gt.attitude().between(ekf.state().attitude()); | ||
| const Vector3 rpy = dR.rpy(); | ||
| const double rot_err_deg = | ||
| (Vector3(rpy.cwiseAbs()) * (180.0 / M_PI)).norm(); | ||
| const double pos_err = (gt.position() - ekf.state().position()).norm(); | ||
| const double vel_err = (gt.velocity() - ekf.state().velocity()).norm(); | ||
|
|
||
| cout << i + 1 << ", error: " << t << "," << rot_err_deg << "," << pos_err | ||
| << "," << vel_err << "\n"; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* ---------------------------------------------------------------------------- | ||
|
|
||
| * GTSAM Copyright 2010, Georgia Tech Research Corporation, | ||
| * Atlanta, Georgia 30332-0415 | ||
| * All Rights Reserved | ||
| * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | ||
|
|
||
| * See LICENSE for the license information | ||
|
|
||
| * -------------------------------------------------------------------------- */ | ||
|
|
||
| /** | ||
| * @file LeftLinearEKF.h | ||
| * @brief EKF on a Lie group with a general left–linear prediction model. | ||
| * | ||
| * See Barrau, Axel, and Silvere Bonnabel. "Linear observed systems on groups." | ||
| * Systems & Control Letters 129 (2019): 36-42. | ||
| * Link: https://www.sciencedirect.com/science/article/pii/S0167691119300805 | ||
| * | ||
| * @date August, 2025 | ||
| * @authors Frank Dellaert | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <gtsam/base/Lie.h> // For traits (needed for AdjointMap, Expmap) | ||
| #include <gtsam/navigation/LieGroupEKF.h> // Include the base class | ||
|
|
||
| #include <type_traits> // For std::conjunction, std::is_invocable_r, std::is_same | ||
|
|
||
| namespace gtsam { | ||
|
|
||
| /** | ||
| * @class LeftLinearEKF | ||
| * @brief EKF on a Lie group with a general left–linear prediction model. | ||
| * | ||
| * Discrete step: x⁺ = W · ψ(x) · U, with W,U ∈ G and ψ ∈ Aut(G). | ||
| * For left-invariant error, the state-independent linearization is | ||
| * A = Ad_{U^{-1}} · Φ where Φ := dψ|_e (right-trivialized). The left factor | ||
| * W cancels in A and does not appear there. | ||
| */ | ||
| template <typename G> | ||
| class LeftLinearEKF : public LieGroupEKF<G> { | ||
| public: | ||
| using Base = LieGroupEKF<G>; | ||
| static constexpr int Dim = Base::Dim; ///< Compile-time dimension of G. | ||
| using TangentVector = typename Base::TangentVector; | ||
| using Jacobian = typename Base::Jacobian; | ||
| using Covariance = typename Base::Covariance; | ||
|
|
||
| LeftLinearEKF(const G& X0, const Covariance& P0) : Base(X0, P0) {} | ||
|
|
||
| /** | ||
| * @brief SFINAE template to check if a type satisfies the automorphism | ||
| * concept. Specifically, it checks for the existence of: | ||
| * - G operator()(const G&) const | ||
| * - Jacobian dIdentity() const | ||
| */ | ||
| template <typename Phi> | ||
| struct is_automorphism | ||
| : std::conjunction< | ||
| std::is_invocable_r<G, Phi, const G&>, | ||
| std::is_same<decltype(std::declval<Phi>().dIdentity()), Jacobian>> { | ||
| }; | ||
|
|
||
| /** | ||
| * General left–linear dynamics using a φ functor and its differential at e. | ||
| * Returns W · φ(X) · U, and optional Jacobian A = Ad_{U^{-1}} Φ, Φ := dφ|_e. | ||
| */ | ||
| template <class Phi, typename = std::enable_if_t<is_automorphism<Phi>::value>> | ||
| static G Dynamics(const G& W, const Phi& phi, const G& X, const G& U, | ||
dellaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| OptionalJacobian<Dim, Dim> A = {}) { | ||
| if (A) { | ||
| const G U_inv = traits<G>::Inverse(U); | ||
| *A = traits<G>::AdjointMap(U_inv) * phi.dIdentity(); | ||
| } | ||
| return W * phi(X) * U; | ||
| } | ||
|
|
||
| /** | ||
| * General left–linear predict using a φ functor and its differential at e. | ||
| * Update: X⁺ = W · φ(X) · U | ||
| * Covariance: P⁺ = A P Aᵀ + Q with A = Ad_{U^{-1}} Φ, Φ := dφ|_e. | ||
| */ | ||
| template <class Phi, typename = std::enable_if_t<is_automorphism<Phi>::value>> | ||
| void predict(const G& W, const Phi& phi, const G& U, const Covariance& Q) { | ||
| Jacobian A; | ||
| this->X_ = this->Dynamics(W, phi, this->X_, U, A); | ||
| this->P_ = A * this->P_ * A.transpose() + Q; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace gtsam | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.