Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

ImuFactorWithGravity Family

Open In Colab

Overview

The standard ImuFactor treats the nav-frame gravity vector as a known constant from PreintegrationParams. The ImuFactorWithGravity family instead makes gravity an optimized variable, for workflows where the navigation frame is not gravity-aligned (eg. LiDAR-odometry map frames), for initialization-free operation, or for online gravity refinement.

Gravity knowledge falls on a spectrum, handled by three factor choices:

  1. Known exactly: use plain ImuFactor (gravity from params). Zero cost.

  2. Known magnitude, unknown direction: ImuFactorWithGravityDirection optimizes a Unit3 direction (2 DOF on S2S^2) scaled by a fixed magnitude given at construction. On Earth, standard gravity is accurate to ~0.3% everywhere, so this is usually the right choice; it removes the magnitude degree of freedom by construction.

  3. Unknown magnitude and direction: ImuFactorWithGravityVector optimizes the free vector g∈R3g \in \mathbb{R}^3 (as a Point3), following Lupton and Sukkarieh (2012). When the magnitude is approximately known, pair it with a single VectorNormFactor on the gravity variable.

CombinedImuFactorWithGravityDirection / ...Vector are the corresponding variants of CombinedImuFactor, adding gravity as a 7th variable while keeping the bias random walk rows (which have a zero gravity Jacobian). ImuFactor2WithGravityDirection / ...Vector are the NavState-based variants, with one combined pose+velocity key per state, as ImuFactor2 is to ImuFactor.

Observability: only the combination RiTgR_i^T g is observed by the accelerometer, so nav-frame gravity and initial attitude are entangled: anchor exactly one of them (a roll/pitch prior or a gravity prior, not both tightly). Gravity magnitude and the accelerometer bias along gravity are only jointly observable under rotation excitation whose axis changes over time (Nemiroff, Chen and Lopez, 2023).

GTSAM Copyright 2010-2022, 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

Mathematical Formulation

Both tangent- and manifold-preintegration accumulate the IMU measurements without gravity; gravity enters only in the PIM’s predict step (the key insight of Lupton and Sukkarieh: gravity can be changed, or estimated, at correction time without re-integrating). With RiR_i the attitude of state ii and Δt\Delta t the preintegration interval, the corrected tangent vector is

ξΔR=ξ~ΔRξΔp=ξ~Δp+Δt RiTvi+12Δt2 RiTgξΔv=ξ~Δv+Δt RiTg\begin{aligned} \xi_{\Delta R} &= \tilde\xi_{\Delta R} \\ \xi_{\Delta p} &= \tilde\xi_{\Delta p} + \Delta t\, R_i^T v_i + \tfrac{1}{2}\Delta t^2\, R_i^T g \\ \xi_{\Delta v} &= \tilde\xi_{\Delta v} + \Delta t\, R_i^T g \end{aligned}

so the Jacobian with respect to the gravity vector is simply

∂ξ∂g=[03×312Δt2RiTΔt RiT]∈R9×3.\frac{\partial \xi}{\partial g} = \begin{bmatrix} 0_{3\times3} \\ \tfrac{1}{2}\Delta t^2 R_i^T \\ \Delta t\, R_i^T \end{bmatrix} \in \mathbb{R}^{9\times3}.

The two parametrizations chain onto this block:

  • Direction: g=m dg = m\,d with d∈S2d \in S^2 a Unit3 and mm fixed, so ∂g/∂δd=mB\partial g / \partial \delta d = m B where B∈R3×2B \in \mathbb{R}^{3\times2} is the tangent basis of dd (Unit3::scaled) — the same scale-times-direction decomposition as MagFactor3.

  • Vector: gg free, ∂g/∂g=I3\partial g / \partial g = I_3; the optional norm pseudo-observation is e=∥g∥−9.81e = \lVert g \rVert - 9.81 with ∂e/∂g=gT/∥g∥\partial e/\partial g = g^T/\lVert g \rVert, added once per gravity variable (never per IMU factor, or the same prior information is counted multiple times).

See the “Gravity as an Optimized Variable” section of doc/ImuFactor.pdf for the full derivation.

After prediction, every factor in this family uses the default SE2(3)SE_2(3) Logmap residual state_j.logmap(predictedState_j).

Usage Example

A stationary IMU in a nav frame whose true gravity is tilted away from the params’ −z-z direction: the accelerometer measures −RTgtrue-R^T g_{true}, so optimizing the gravity variable must recover the true tilted gravity.

true gravity: [ 0.2941  0.4902 -9.7933]
recovered gravity (direction mode): [ 0.2941  0.4902 -9.7933]
direction error: 1.78e-15
recovered gravity (vector mode): [ 0.2941  0.4902 -9.7933]
vector error: 7.85e-17
recovered gravity (NavState mode): [ 0.2941  0.4902 -9.7933]
direction error: 1.78e-15

Key Functionality / API

  • Constructors: same keys as ImuFactor plus a gravity key; the Direction variants accept an optional gravityMagnitude (defaulting to the norm of the params’ gravity vector). gravityMagnitude() returns it.

  • evaluateError(pose_i, vel_i, pose_j, vel_j, bias, gravity) with gravity a Unit3 (Direction) or Point3 (Vector); optional Jacobians follow the usual convention (9×2 or 9×3 for the gravity argument).

  • Merge (tangent preintegration only) merges consecutive factors sharing bias and gravity keys, and rejects mismatched gravity keys or magnitudes.

  • The Combined variants add the second bias key: CombinedImuFactorWithGravity* with keys (pose_i, vel_i, pose_j, vel_j, bias_i, bias_j, gravity) and a 15-dimensional error whose bias rows have a zero gravity Jacobian.

  • ImuFactor2WithGravityDirection / ...Vector are the NavState-based variants (as ImuFactor2 is to ImuFactor), with keys (state_i, state_j, bias, gravity) and the same 9-dimensional error; like ImuFactor2, they provide no Merge.

Source

  • ImuFactorWithGravity.h, CombinedImuFactorWithGravity.h

  • Derivation: doc/ImuFactor.pdf, section “Gravity as an Optimized Variable”

  • T. Lupton and S. Sukkarieh, “Visual-Inertial-Aided Navigation for High-Dynamic Motion in Built Environments Without Initial Conditions”, IEEE T-RO 28(1), 2012.

  • R. Nemiroff, K. Chen and B. T. Lopez, “Joint On-Manifold Gravity and Accelerometer Intrinsics Estimation for Inertially Aligned Mapping”, arXiv:2303.03505, 2023.