AHRS (Attitude and Heading Reference Systems)

repository·master·Indexed 20 days ago

https://github.com/mayitzin/ahrs

A pure Python collection of functions and algorithms for estimating the orientation (attitude) of mobile systems using sensor data. It includes a wide range of attitude estimators based on Wahba's Problem (WP) or Dead Reckoning (DR), such as Madgwick, Mahony, EKF, and QUEST. The library provides tools for handling Rotation Matrices (DCM) and Quaternions, and includes a sensors submodule for generating synthetic Magnetic, Angular Rate, and Gravity (MARG) data for prototyping and testing.

Tokens
19K
Snippets
95
Records
128
Agent score
69%

What's inside AHRS

  1. Overview of the AHRS toolbox

    master
    ahrs is an open source Python toolbox designed for attitude estimation. It provides implementations of well-known algorithms, methods, and resources for fast prototyping, testing, and integration into Python projects. The library is intended for educational and research purposes and is not recommended for commercial use.
  2. Use geodesy utilities in AHRS

    master

    The ahrs.utils.geodesy module provides tools for geodetic calculations. The library includes implementations for specific ellipsoids, magnetic models, and historical geodesy methods.

    Key components include:

    • Ellipsoids: Support for specific reference ellipsoids (e.g., refEllipsoid).
    • Magnetic Models: Implementation of the World Magnetic Model (wmm).
    • Standard Models: Support for wgs84.
    • Historical/Specialized Methods: Support for igf and welmec models.
  3. Understand attitude representations in AHRS

    master

    In AHRS, an attitude describes the orientation of a frame relative to a reference frame. The library provides several mathematical representations to model these orientations, primarily focusing on:

    • Rotation Matrices (DCM): Direction Cosine Matrices used for coordinate transformations.
    • Quaternions: Four-dimensional vectors used to represent rotations without the risk of gimbal lock.

    Depending on your application, you can use specific classes to manage these representations and specialized functions to transform or redefine rotations.

  4. New features in version 0.4

    master

    Version 0.4 introduced several significant updates:

    • New Algorithms: Added FKF (Feedback Kalman Filter) and UKF (Unscented Kalman Filter).
    • New Submodules: Added sensors and geodesy.
    • Enhanced Representations: Added more methods for Quaternion and Direction Cosine Matrix (DCM) representations.
    • Developer Experience: Improved documentation, more examples, and full type hinting for all functions and objects.
  5. Use metrics for SO(3) attitude comparison

    master

    The ahrs.utils.metrics module provides various metrics for evaluating attitude estimation errors in the Special Orthogonal group SO(3). These metrics are used to compare an estimated attitude against a ground truth. Available metrics include:

    • chordal
    • identity_deviation
    • angular_distance
    • qdist
    • qeip
    • qcip
    • qad
  6. Understand Coordinate Frames and Reference Systems

    master

    AHRS uses several standard coordinate frames to define position and orientation. Understanding these is critical for interpreting sensor data and estimator outputs:

    Global/Earth Frames

    • ECEF (Earth-Centered Earth-Fixed): Also called the e-frame. Origin and Z-axis are aligned with the ECI frame, but it rotates with the Earth. Used for positioning elements on or near Earth.
    • ECI (Earth-Centered Inertial): Also called the i-frame. Origin is at Earth's center of mass. X-axis points toward the vernal equinox in the equatorial plane; Z-axis is along Earth's rotation axis.

    Local-Level Frames (LLF)

    Local frames are used for navigation relative to a local origin (often the sensor location). Common LLFs include:

    • NED (North-East-Down): X-axis points North, Y-axis points East, and Z-axis points Down (completing a right-hand system).
    • ENU (East-North-Up): X-axis points East, Y-axis points North, and Z-axis points Up.

    Body Frame

    • Body Frame: Also called the b-frame. Matches the platform sensors are mounted on. The origin is at the center of gravity. The Y-axis points forward, the Z-axis points upwards, and the X-axis completes the right-hand system pointing in the traverse direction.
  7. Use Quaternion and QuaternionArray as NumPy arrays

    master
    In version 0.4, the Quaternion and QuaternionArray classes are derived from numpy.ndarray. This means you can use them directly as regular NumPy arrays while still accessing specialized AHRS methods and properties.
  8. Use the Sensors class for attitude estimation

    master
    The ahrs.utils.sensors.Sensors class provides a unified and flexible way to handle common sensors used in attitude estimation algorithms. Instead of managing individual sensor data streams manually, you can use this class to encapsulate the most frequent sensor types required for AHRS (Attitude and Heading Reference Systems) tasks.
  9. Use DCM and Quaternion classes for attitude modeling

    master

    AHRS provides dedicated classes to handle different mathematical representations of attitude. You can instantiate these classes to perform rotations and coordinate transformations:

    • classDCM: For working with Direction Cosine Matrices.
    • classQuaternion: For working with single quaternion representations.
    • classQuaternionArray: For working with arrays of quaternions (useful for time-series data or multiple orientations).
  10. Understand the difference between instantaneous and recursive attitude estimation

    master

    AHRS provides two main strategies for attitude estimation:

    1. Instantaneous estimation (Static Attitude Determination): Calculates attitude using vectors in two frames (body frame and a known reference frame) at a single point in time. It does not consider system kinematics and is best suited for systems in a quasi-static state.
    2. Recursive estimation (Dynamic Attitude Determination): Uses vectorial observations and takes system dynamics into account to predict behavior. These are more accurate but computationally more demanding. They typically use gyroscope data to integrate angular motion over time, starting from a known initial orientation.

    Sensor Requirements

    Most estimators are designed for low-cost strapdown navigation systems using:

    • Gyroscopes: Measure angular velocity (short-term reliability).
    • Accelerometers: Measure acceleration (long-term reliability).
    • Magnetometers: Measure local magnetic fields (provide heading information).