Skip to main content

Attitude and Heading Reference Systems.

Project description

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.

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.2.tar.gz (42.2 kB view hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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