Object-oriented Python library for processing Inertial Measurement Unit (IMU) data — covering initial alignment, continuous attitude tracking, and fundamental rotation kinematics.
The core object of inertial navigation is the Direction Cosine Matrix (DCM) b-frame) to the Navigation Frame (n-frame, North-East-Down).
Computes the initial attitude from static accelerometer and gyroscope observations.
Gravity Leveling (Roll & Pitch):
Using the specific force 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 (
Tracks rigid-body orientation over time by compensating for Earth's rotation
The DCM is recursively updated using the Rodrigues' rotation formula (matrix exponential closed-form):
git clone https://github.com/AmrFawzy-NavEng/Python-IMU-Kinematics-AHRS.git
cd Python-IMU-Kinematics-AHRS
pip install -r requirements.txtimport 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)Run python examples/ex01_inertial_navigation.py to process a full IMU recording and generate the attitude history:
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
MIT — see LICENSE for details.
