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.

ABC Equivariant Filter Example

Attitude-Bias-Calibration Equivariant Filter¶

This notebook demonstrates the Equivariant Filter (EqF) for attitude estimation with both gyroscope bias and sensor extrinsic calibration, based on the paper:

ā€œOvercoming Bias: Equivariant Filter Design for Biased Attitude Estimation with Online Calibrationā€ by Fornasier et al.

The filter estimates:

  • Attitude (Rotation): The orientation of the body frame relative to a reference frame

  • Bias: Gyroscope bias correction vector (3D)

  • Calibration: Sensor calibration rotation matrices

This demo uses the AbcEquivariantFilter class which provides a clean interface for predict/update operations.

Note: We have hidden verbose loading/plotting functions under cell dropdowns. Feel free to expand to take a closer look.

Try it out in Colab!

Open In Colab

Setup and Imports¶

First, we import all the necessary libraries. We use GTSAM for the filter implementation, NumPy for numerical operations, and Plotly for creating interactive visualizations. The dataclass decorator helps us create clean data structures for organizing measurements and results.

Notebook Cell

Data Structures¶

We define three key data structures:

  1. MeasurementRecord: Stores a single direction measurement with its reference direction, covariance, and calibration index. Each measurement represents an observation of a known direction vector in the body frame.

  2. DataRecord: Contains all information for a single time step, including ground truth state (attitude, bias, calibration), gyroscope measurements, input covariance, and all direction measurements at that timestep.

  3. FilterResults: Aggregates the entire time series of ground truth, estimates, and errors for easy plotting. This allows us to track how the filter performs over the entire trajectory.

Data Loading Functions¶

The CSV file contains simulated IMU and direction measurement data with ground truth. Each row includes quaternion representations of attitude and calibration, gyroscope measurements with noise parameters, and direction observations. The data loader parses this CSV format and converts it into our DataRecord structures, handling normalization of direction vectors and construction of covariance matrices from standard deviations.

Notebook Cell

Filter Processing with Results Tracking¶

This function runs the ABC Equivariant Filter through the entire data sequence. For each time step, it performs a prediction step using gyroscope measurements, then updates with direction observations. The function tracks both the filter estimates and ground truth at each step, computing errors in attitude, bias, and calibration. All results are stored in a FilterResults object for later visualization.

Visualization Functions¶

These functions create interactive Plotly visualizations of the filter results. Each function generates time-series plots comparing ground truth (solid lines) with filter estimates (dashed lines).

Notebook Cell

Load Data¶

Here we locate and load the example dataset (EqFdata.csv). This CSV file contains simulated IMU trajectory data with ground truth, generated from a realistic motion profile. The data includes approximately 12,000 timesteps with gyroscope measurements and direction observations from two sensors (one calibrated, one uncalibrated). If you want to test with your own data, simply provide the path to a CSV file in the same format.

Notebook Cell
ABC-EqF: Attitude-Bias-Calibration Equivariant Filter Demo
==============================================================
Loading data from: /Users/apollo/dev/research/gtsam/build/python/gtsam/Data/EqFdata.csv
Loaded 12001 data points

Initialize and Run Filter¶

Now we create and configure the ABC Equivariant Filter. The initial covariance matrix initial_sigma encodes our uncertainty in the initial state: we’re moderately uncertain about the attitude (0.1 rad²) and calibration (0.1 rad²), but quite confident about the initial bias (0.01 rad²/s²). The filter starts at the identity state (zero attitude, zero bias, identity calibration) and will converge to the true state as it processes measurements. This cell runs the filter through the entire trajectory, which takes a few seconds for 12,000 timesteps.

Processing 12001 data points with EqF...
Progress: ........... Done!

=== Filter Performance Summary ===
Processed measurements: 24002 (valid: 4923)

-- Average Errors --
Attitude: 1.1308383647121234°
Bias: 0.0075498876180193865
Calibration: 0.957466838125976°

-- Final Errors --
Attitude: 3.662018753470247°
Bias: 0.0020652584435729942
Calibration: 0.3643824462229628°

-- Final State vs Ground Truth --
Attitude (RPY) - Estimate: [-13.80445039  -0.64271376  86.74437182] ° | Truth: [-17.40672752  -1.04149482  86.27016675] °
Bias - Estimate: [0.00468984 0.00994432 0.00194401] | Truth: [0.00399696 0.00799933 0.00189684]
Calibration (RPY) - Estimate: [24.81667419  5.05822205 29.67403453] ° | Truth: [25.  5. 30.] °

Filter processing completed successfully!

Visualize Results¶

Attitude Estimation (Roll-Pitch-Yaw)¶

This plot shows how the filter estimates the body’s orientation over time. The three subplots display Roll (rotation about X-axis), Pitch (rotation about Y-axis), and Yaw (rotation about Z-axis). Solid lines represent ground truth, while dashed lines show the filter’s estimates. Notice how closely the estimates track the true values even during dynamic maneuvers. You can zoom into specific time regions and hover over the curves to see exact values at each timestep.

Loading...

Gyroscope Bias Estimation¶

This plot displays the three components of gyroscope bias (systematic errors in angular velocity measurements). The filter must simultaneously estimate the attitude while learning these constant biases. Notice how the bias estimates converge from their initial values (zero) toward the true bias values. The convergence rate depends on the richness of the motion - more diverse rotations provide better observability of the bias. The darker solid lines are ground truth, while lighter dashed lines are the filter’s estimates.

Loading...

Sensor Calibration Estimation¶

These three subplots show the online estimation of sensor calibration parameters, represented as Roll-Pitch-Yaw angles. Calibration represents the fixed rotation between the sensor frame and the body frame, which is unknown at startup. The equivariant filter can estimate this calibration simultaneously with attitude and bias. Watch how the calibration estimates (dashed lines) converge to the true calibration (solid lines) within the first portion of the trajectory, demonstrating the filter’s ability to handle online calibration.

Loading...

Estimation Errors¶

These error plots quantify the filter’s performance by showing the magnitude of estimation errors over time. The red curve shows attitude error (in degrees), while the blue curve shows calibration error. Both errors start high when the filter has little information, then converge to low values as the filter processes more measurements. Temporary spikes may occur during aggressive maneuvers or measurement dropouts. The average errors across the entire trajectory are printed in the summary above.

Loading...

Bias Estimation Error¶

This final plot focuses specifically on the gyroscope bias estimation error. The shaded area under the curve emphasizes the overall error magnitude. Bias estimation typically exhibits a characteristic convergence pattern: starting from the initial uncertainty, the error decreases as the filter observes more motion. The rate of convergence depends on the trajectory’s observability properties. Richer motion (diverse rotations) leads to faster convergence. The final bias error shown in the summary above indicates how accurately the filter has identified the true gyroscope bias.

Loading...