field guide
Quaternion kinematics for the error-state Kalman filter
A working guide to Joan Sola’s quaternion kinematics for the error-state Kalman filter - the reference for fusing IMU data with external corrections in an ESKF/VIO estimator.
The foundational reference for doing orientation estimation with quaternions inside a Kalman filter. Joan Solà’s 2017 paper (arXiv:1711.02508) is the definitive treatment: it derives every formula from first principles, resolves the convention wars, and provides a complete ESKF recipe for fusing IMU data with external corrections (GPS, vision, etc.). If you’re implementing an IMU-driven state estimator that uses quaternions, this is the paper to have open.
Why quaternions for rotation
Rotation matrices (, 9 parameters) over-parameterize orientation. Euler angles (3 parameters) gimbal-lock. Quaternions are the sweet spot: 4 numbers, no singularities, and the algebra handles composition cleanly. A unit quaternion with encodes a rotation of angle around axis :
The half-angle is not a bug — it’s a feature of the double cover of SO(3), which is what makes the quaternion algebra work. and represent the same rotation.
The rotation action on a vector is the double product:
Where is the conjugate (equal to the inverse for unit quaternions). This is equivalent to with given by the quaternion-to-rotation-matrix formula.
Core quaternion algebra
The paper uses Hamilton convention: , with . This is the right-handed convention. Other conventions exist (JPL uses left-handed, some swap real/vector order) — Section 3 of the paper disambiguates all four binary choices.
Quaternion product (): using scalar-vector notation :
The cross product in the vector part makes non-commutative (rotation composition is order-dependent). Product is bilinear and can be expressed as matrix-vector products using left- and right- product matrices and , which will appear throughout the ESKF derivations.
Exponential and logarithmic maps connect the quaternion to the rotation vector (axis-angle) representation:
- — rotation vector → quaternion
- — quaternion → rotation vector
Quaternion-to-rotation-matrix:
Where is the skew-symmetric cross-product matrix.
The four derivative types on SO(3)
Section 4 defines four Jacobian types depending on whether the function domain/codomain is vector space or SO(3). The ones that matter for ESKF:
- Right Jacobian of SO(3): Used for mapping perturbations in the tangent space (rotation vectors) to the manifold (quaternions/rotation matrices):
- For small angles:
Time integration of rotation rates
Given gyroscope readings , the quaternion kinematics are:
Zeroth-order integrator (constant over ):
This is what most implementations use. It preserves unit norm by construction (product of two unit quaternions).
First-order integrator (accounts for via midpoint samples):
The correction term is second-order small ( at 100 Hz) and only matters when the rotation axis changes significantly between samples. For constant rotation axis, the zeroth-order integrator is exact: where .
The ESKF architecture
The error-state Kalman filter decomposes the state into three layers:
| Concept | Meaning | Size |
|---|---|---|
| True state | The actual physical state (unknown) | 18: |
| Nominal state | Large-signal integration of IMU, no noise model | Same 18 |
| Error state | Small-signal difference: | 18: |
The composition is linear addition for vectors (), quaternion product for orientation (, with ), and addition for biases.
Why this decomposition works
- Minimal orientation error: (3 parameters, no redundancy), avoiding singular covariance matrices from over-parameterized constraints.
- Always near origin: The error state is reset to zero after every correction → linearization always valid.
- Second-order products negligible: is small → Jacobians simplify enormously.
- Slow error dynamics: Large-signal motion lives in the nominal state. Error state only changes slowly → corrections can run at lower rate than predictions.
Nominal-state kinematics (continuous time)
These are the noise-free integration equations you’d run at IMU rate (e.g., 200 Hz):
Where are IMU readings, are estimated biases, and . The gravity vector is also estimated — this decouples initial orientation uncertainty from gravity uncertainty (Lupton & Sukkarieh, 2009).
Discrete-time integration (Euler form):
Error-state kinematics — the three key equations
1. Continuous-time error dynamics
The linearized error state evolves as:
The velocity error equation is the critical one — it couples orientation errors into position drift. The term says: an orientation error causes the acceleration vector to be projected slightly wrong, and the resulting position error grows quadratically with time.
2. Discrete-time error Jacobian
The prediction step propagates the error covariance via and :
Notable: the orientation error block uses (a rotation matrix, not a quaternion) — this is the discrete-time equivalent of .
Since is initialized to zero and the prediction equation (268) always returns zero, you skip the mean prediction in code. But the covariance prediction (269) is essential — injects process noise and makes grow continuously.
3. The correction step and injection
When external measurements arrive (GPS position, visual odometry, etc.):
Kalman update:
Observation Jacobian chain rule:
is sensor-specific. is the ESKF-specific mapping from error state to true state, which is identity except for the quaternion block:
Error injection into nominal state:
ESKF reset: After injection, and the covariance is transformed:
Where is identity except for the orientation block: . In practice, most implementations neglect this reset Jacobian () since is tiny. The full expression is provided for high-precision odometry.
Global vs. local angular errors (Section 7)
The classical ESKF defines the orientation error locally: is expressed relative to the nominal orientation . An alternative is to define it globally: is the rotation vector from the nominal to true orientation, expressed in a fixed inertial frame. Li & Mourikis (2012) showed the global formulation has better observability properties. Section 7 derives the full ESKF for global angular errors — the kinematics change but the architecture is identical.
Practical implementation notes
- Mean prediction is a no-op. The error mean starts at zero and the linear equation keeps it there. Skip line (268) but keep the covariance prediction.
- Quaternion normalization. The zeroth-order integrator preserves unit norm. If using first-order integration, re-normalize: .
- Covariance numerical stability. The standard form can lose symmetry/positive-definiteness. The Joseph form is preferred.
- IMU noise parameters. (measurement noise) come from the IMU datasheet. (bias random walk) require experimental calibration. These determine — the process noise covariances that drive growth.
- Earth rotation. rad/s. Negligible for consumer IMUs but measurable with high-end sensors — if your gyro bias stability approaches this, include in the measurement model.
Where the ESKF fits relative to the complementary filter
The complementary-filter is a fixed-gain fusion: one parameter, no covariance, no bias estimation, no position. It gives you roll/pitch at $$200 Hz from a 6-DOF IMU. The ESKF is the full probabilistic version: it estimates position, velocity, orientation, and IMU biases, maintains a full covariance, and fuses external corrections optimally via the Kalman gain. For a drone that needs drift-free navigation in GPS-denied environments, the ESKF is the target state estimator — the complementary filter is a debugging scaffold on the way there.
See also: rotating-coordinate-frames for the frame convention (NED) that feeds the matrices, euler-body-rate-cross-coupling for the gyroscopic terms that the ESKF’s dynamics must account for in aggressive flight, accel-roll-pitch-derivation for the accelerometer angle formulas used in the simpler complementary filter.