Skip to main content

Attitude and Heading Reference Systems.

Project description

AHRS: Attitude and Heading Reference Systems

PyPI - Python Version PyPI - License 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 to perform operations on quaternions
'(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.

Project details


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.0.post0.tar.gz (39.6 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.0.post0-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

Details for the file AHRS-0.2.0.post0.tar.gz.

File metadata

  • Download URL: AHRS-0.2.0.post0.tar.gz
  • Upload date:
  • Size: 39.6 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.8

File hashes

Hashes for AHRS-0.2.0.post0.tar.gz
Algorithm Hash digest
SHA256 c8cf2809712cc2ed2891f470f0fb419a229ac8be7b38414af4b28282b9815629
MD5 7624ce3b0874381b8e335d210a6eb864
BLAKE2b-256 15cc1cebbd3359046e1a4f4da81feabf1ba1969822c4d47b310ed7285704ca64

See more details on using hashes here.

File details

Details for the file AHRS-0.2.0.post0-py3-none-any.whl.

File metadata

  • Download URL: AHRS-0.2.0.post0-py3-none-any.whl
  • Upload date:
  • Size: 54.3 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.8

File hashes

Hashes for AHRS-0.2.0.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 d02eca3158df1941f72af28201cadfc2eeb4fbdcd7a3f79ad07bac971cc6b8fc
MD5 c52fecade96b276c837445921bb193fc
BLAKE2b-256 c6536ee76fcc9dc72496487a000f93f15d00f14389c2d5fdfb0f53284b05d6dc

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