Skip to content

AmrFawzy-NavEng/Python-IMU-Kinematics-AHRS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-IMU-Kinematics-AHRS

Python 3.10+ License: MIT

Object-oriented Python library for processing Inertial Measurement Unit (IMU) data — covering initial alignment, continuous attitude tracking, and fundamental rotation kinematics.

Mathematical Foundation

The core object of inertial navigation is the Direction Cosine Matrix (DCM) $C_b^n$, which maps vectors from the Body Frame (b-frame) to the Navigation Frame (n-frame, North-East-Down).

1. Initial Alignment (InitialAlignment)

Computes the initial attitude from static accelerometer and gyroscope observations.

Gravity Leveling (Roll & Pitch): Using the specific force vector $f_{ib}^b$, roll ($\phi$) and pitch ($\theta$) are extracted from the local gravity vector:

  • $\phi = \arctan2(-f_y, -f_z)$
  • $\theta = \arctan\left(\frac{f_x}{\sqrt{f_y^2 + f_z^2}}\right)$

Gyrocompassing (Yaw): The heading ($\psi$) is determined by projecting Earth's rotation vector $\omega_{ie}^n$ from mean gyro measurements into the leveled frame.

2. Attitude Update (AttitudeComputer)

Tracks rigid-body orientation over time by compensating for Earth's rotation $\omega_{ie}^n$. The rotation vector in the body frame is:

$\Delta\theta_b = \left(\omega_{ib}^b - C_n^b \omega_{in}^n\right) \Delta t$

The DCM is recursively updated using the Rodrigues' rotation formula (matrix exponential closed-form):

$C_{b(k+1)}^n = C_{b(k)}^n \left[ I + \frac{\sin|\Delta\theta|}{|\Delta\theta|} [\Delta\theta\times] + \frac{1-\cos|\Delta\theta|}{|\Delta\theta|^2}[\Delta\theta\times]^2 \right]$

Installation

git clone https://github.com/AmrFawzy-NavEng/Python-IMU-Kinematics-AHRS.git
cd Python-IMU-Kinematics-AHRS
pip install -r requirements.txt

Quick Start

import numpy as np
from imu_kinematics import InitialAlignment, AttitudeComputer

# Compute initial alignment from static IMU readings
aligner = InitialAlignment(
    f_ib_b=np.array([0.01, -0.02, -9.81]),   # Accelerometer [m/s²]
    w_ib_b=np.array([3.7e-5, 0.0, -3.3e-5]), # Gyroscope [rad/s]
    latitude_rad=np.deg2rad(52.0)
)
roll, pitch, yaw = aligner.compute_euler_angles()

# Initialize continuous attitude tracker
tracker = AttitudeComputer(
    initial_c_n_b=aligner.compute_dcm(),
    earth_rate_mag=aligner.earth_rate_mag,
    latitude_rad=np.deg2rad(52.0)
)

# Feed gyro measurements epoch by epoch
euler_angles = tracker.update(w_ib_b=gyro_reading, dt=0.01)

Example Output

Run python examples/ex01_inertial_navigation.py to process a full IMU recording and generate the attitude history:

Attitude Update Demo

Project Structure

Python-IMU-Kinematics-AHRS/
├── imu_kinematics/
│   ├── __init__.py        # Package exports
│   ├── kinematics.py      # Rotation matrices, skew-symmetric, DCM↔Euler
│   ├── alignment.py       # InitialAlignment (gravity leveling + gyrocompassing)
│   └── attitude.py        # AttitudeComputer (continuous DCM update)
├── examples/
│   └── ex01_inertial_navigation.py
├── requirements.txt
└── LICENSE

License

MIT — see LICENSE for details.

About

Python library for IMU processing: Initial alignment (gravity leveling, gyrocompassing), continuous attitude tracking via Rodrigues rotation, and DCM/Euler angle kinematics.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages