Attitude estimate using Madgwick filter, in Cython. See the original publication and code.
From the desired python (>=3.6) environment, clone the repository. From the repository's directory, install the requirements and run the compilation and installation pipelines:
$ git clone https://github.com/rfayat/madgwick_imu.git
$ cd madgwick_imu
$ pip install -r requirements.txt
$ python setup.py build_ext --inplace
$ pip install .
The API is taken from the implementation available in the ahrs module. Filtering data can be done as follows:
from madgwick import Madgwick
# Create the filter and compute the quaternions
mf = Madgwick(acc=..., # array of x, y, z accelerometer values (in G)
gyr=..., # array of x, y, z gyroscope values (in radians)
frequency=..., # sampling rate (in Herz)
gain=...) # filter gain (float)
# Rotate [0, 0, 1] by the resulting quaternions
# Return the estimate of the xyz coordinates of gravity
# in the sensor's reference frame
gravity_estimate = mf.gravity_estimate()
A data sample and example script is available in the example folder. To run it, install this package as well as pandas and matplotlib and run:
python -m example.madgwick_imu_example
The script generates the following example of gravity estimate from IMU data: