Skip to main content

AHRS: Attitude and Heading Reference Systems

GitHub Workflow Status PyPI - Python Version PyPI - License PyPI PyPI Downloads

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.

Installation

AHRS may be installed using pip:

pip install ahrs

Or directly from the repository:

git clone https://github.com/Mayitzin/ahrs.git
cd ahrs
python setup.py install

AHRS depends on the most distributed packages of scientifc Python environments (NumPy, SciPy and matplotlib). 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.

>>> from ahrs.common import orientation
>>> # Rotation product: R_y(10.0) @ R_x(20.0) @ R_y(30.0)
... Rx = orientation.rotation('x', 10.0)
>>> Ry = orientation.rotation('y', 20.0)
>>> Rz = orientation.rotation('z', 30.0)
>>> Rx@Ry@Rz
array([[ 0.81379768 -0.46984631  0.34202014]
       [ 0.54383814  0.82317294 -0.16317591]
       [-0.20487413  0.31879578  0.92541658]])
>>> # Same rotation sequence but with single call to rot_seq()
... orientation.rot_seq('xyz', [10.0, 20.0, 30.0])
array([[ 0.81379768 -0.46984631  0.34202014]
       [ 0.54383814  0.82317294 -0.16317591]
       [-0.20487413  0.31879578  0.92541658]])

It now includes the class Quaternion to easily handle the orientation estimation with quaternions.

>>> from ahrs import Quaternion
>>> q1 = Quaternion()
>>> str(q1)          # Empty quaternions default to identity quaternion
'(1.0000 +0.0000i +0.0000j +0.0000k)'
>>> q2 = Quaternion([1.0, 2.0, 3.0])
>>> str(q2)          # 3-element vectors build pure quaternions
'(0.0000 +0.2673i +0.5345j +0.8018k)'
>>> q3 = Quaternion([1., 2., 3., 4.])
>>> str(q3)          # All quaternions are normalized
'(0.1826 +0.3651i +0.5477j +0.7303k)'
>>> str(q2+q3)       # Use normal arithmetic operators
'(0.0918 +0.3181i +0.5444j +0.7707k)'
>>> q2.product(q3)   # Quaternion products are supported
array([-0.97590007,  0.        ,  0.19518001,  0.09759001])
>>> str(q2*q3)
'(-0.9759 +0.0000i +0.1952j +0.0976k)'
>>> q2.to_DCM()      # Conversions between representations are also implemented
array([[-0.85714286,  0.28571429,  0.42857143],
       [ 0.28571429, -0.42857143,  0.85714286],
       [ 0.42857143,  0.85714286,  0.28571429]])

And many other quaternion operations, properties and methods are also available.

ahrs includes a sub-module that simplifies data loading and visualization using matplotlib as plot engine.

>>> data = ahrs.utils.io.load("ExampleData.mat")
>>> ahrs.utils.plot_sensors(data.gyr)

Simple Sensor Plotting

It is possible to render more sensors with different subplots, and even titling them.

>>> ahrs.utils.plot_sensors(data.gyr, data.acc, data.mag,
        x_axis=data.time, subtitles=["Gyroscopes", "Accelerometers", "Magnetometers"])

Full Sensor Plotting

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

>>> madgwick = ahrs.filters.Madgwick()    # Madgwick's attitude estimation using default values
>>> 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(Q[t-1], d2g*data.gyr[t], data.acc[t], data.mag[t])
...
>>> ahrs.utils.plot_quaternions(Q)

Quaternion Plotting

Also works by simply passing the data to a desired filter, and it will automatically try to load the sensor information and estimate the quaternions with the given parameters.

>>> orientation = ahrs.filters.Madgwick(data, beta=0.1, frequency=100.0)
>>> orientation.Q.shape
(6959, 4)

Documentation

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.

Source Distribution

AHRS-0.2.2.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

AHRS-0.2.2-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

File details

Details for the file AHRS-0.2.2.tar.gz.

File metadata

  • Download URL: AHRS-0.2.2.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.9

File hashes

Hashes for AHRS-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6ea684dd24d0a4b39fa12cd932f0e1584c72a1ef612a68808e261e3c1a2021ba
MD5 9eb3f1abf84abaf3540f60144038f455
BLAKE2b-256 1df5bbe37faf28aad3786869957402ec74fe4ea31bdfc1a6051335eda4e38ac8

See more details on using hashes here.

File details

Details for the file AHRS-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: AHRS-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 58.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.9

File hashes

Hashes for AHRS-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9cffcd3872d6583f887ec418711b751b64ef5f121166c905d5f45952887dc15d
MD5 e35f5f34b3fd62f02379038a2962de68
BLAKE2b-256 513401fb6b2d188e2943cfa47fad111efda65648e096e20dc06bb4943f8ccb91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page