Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Attitude and Heading Reference Systems.

Project description

AHRS: Attitude and Heading Reference Systems

AHRS is a zoo of functions and objects written in Python helping you to estimate the orientation and position of robotic systems.

Orginally, an AHRS is defined as a set of orthogonal sensors providing attitude information about an aircraft. This field is now expanding to smaller devices, like wearables, automated transportation and all kinds of robots in motion.

The module AHRS is developed with a focus on fast prototyping and easy modularity.

AHRS is compatible with Python 3.6 and above.


AHRS may be installed using pip:

pip install ahrs

Or using the latest version from the repository:

git clone
cd ahrs
python install

AHRS depends on the most distributed packages of Python. If you don't have them, they will be automatically downloaded and installed.

Using AHRS

To play with orientations, for example, we can use the orientation module.

>>> import ahrs
>>> # Rotation matrix of 30.0 degrees around X-axis
... ahrs.common.orientation.rotation('x', 30.0)
array([[ 1.       ,  0.       ,  0.       ],
       [ 0.       ,  0.8660254, -0.5      ],
       [ 0.       ,  0.5      ,  0.8660254]])
>>> # Rotation sequence of the form: R_y(10.0)@R_x(20.0)@R_z(30.0)
... ahrs.common.orientation.rot_seq('yXy', [10.0, 20.0, 30.0])
array([[ 0.77128058,  0.05939117,  0.63371836],
       [ 0.17101007,  0.93969262, -0.29619813],
       [-0.61309202,  0.33682409,  0.71461018]])

It also works nicely with Quaternions.

>>> import numpy as np
>>> q = np.random.random(4)
>>> # It automatically normalizes any given vector
... ahrs.common.orientation.q2R(q)
array([[ 0.76811067,  0.3546719 ,  0.53311709],
       [ 0.55044928,  0.05960693, -0.83273802],
       [-0.32712625,  0.93308888, -0.14944417]])

ahrs also includes a module that simplifies data loading and visualizing

>>> data ="ExampleData.mat")
>>> ahrs.utils.plot_sensors(data.gyr, data.acc, data.mag)

Sensor Plotting

If you want to use the sensor data to estimate the attitude, use the filters module that includes various (more coming) algorithms for it.

>>> madgwick = ahrs.filters.Madgwick()
>>> Q = np.tile([1., 0., 0., 0.], (data.num_samples, 1)) # Allocate an array for all quaternions
>>> d2g = ahrs.common.DEG2RAD   # Constant to convert degrees to radians
>>> for t in range(1, data.num_samples):
...     Q[t] = madgwick.updateMARG(d2g*data.gyr[t], data.acc[t], data.mag[t], Q[t-1])
>>> ahrs.utils.plot_quaternions(Q)

Quaternion Plotting


A comprehensive documentation, with examples, will soon come to Read the Docs.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for AHRS, version 0.1.2.post3
Filename, size File type Python version Upload date Hashes
Filename, size AHRS-0.1.2.post3-py3-none-any.whl (23.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size AHRS-0.1.2.post3.tar.gz (18.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page