Python AHRS

Python is, undeniably, the language to prototype (and even build) scientific applications. Highly modular, very well spread and very effective when it comes to get something tangible to show around.

In the field of Robotics there are tons of libraries supporting anything you want, but all of them are centered towards unique cases and there are few instances where they connect or easily interact with other libraries.

Originally Attitude and Heading Reference Systems were intended to be an area for driving and tracking systems in the defense, transportation and communication fields (satellites, planes, rockets, etc.), but it has found a new area with the inclusion of embedded systems everywhere. From autonomous cars to pencils, everything is now connected and most probably containing a tracking system.

However, modern prototyping tools require a huge amount of libraries to prototype, test and/or build applications for it. I personally love ROS and the attention it has gained in the scientific and engineering areas. If anyone wants to jump into the robotic playground, that’s the way to go.

I just don’t like its complicated maneuver to even start with the simplest example. Don’t get me wrong, I love it and still think it’s the best, but is not as fast to grasp as it could be.

So, I made my own AHRS library to make those steps easier for the unexperienced (but also for the advanced) user. I simply called it like that AHRS and it can be found in its Github repository or in the Python Package Index like that.

I chose Python 3, more precisely Python 3.6, because it was already time for me to move on and forget about Python 2, and I also think the world should do that.

There are two ways to install it, either with pip:

pip install ahrs

or from source:

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

With it you have AHRS in your system. This first draft is in constant developing mode, while I’ll keep adding nice tools around it. For now you can load, process and visualize your data with few lines.

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

I’ve included basic Sensor Fusion and tracking algorithms, like Kalman Filters, Attitude estimation, as well as conversion between orientation representations, e.g. Euler angles and Quaternions. All functions, classes and modules have full docstrings, so that it will enable me to build and upload a nice documentation for it.

orientation = ahrs.filters.EKF(data)

And just like that, I have a full estimation of the orientation using the Extended Kalman Filter.

Do you prefer an estimation using Madgwick’s algorithm with a sampling rate equal to 200 Hz? No problem!

orientation = ahrs.filters.Madgwick(data, frequency=200.0)

The object orientation is an instance of Madgwick with the estimated attitude stored in an array of quaternions called Q, which you can also plot with ease.

>>> ahrs.utils.plot_quaternions(orientation.Q)

Many other tools are present to filter signals, fuse sensors and a fairly simple way to plot all data.

For a better glimpse of the package, I would recommend to check the repository in Github.

Future tests and benchmarks of algorithms using this package are planned. I just wanna have more time to do them. We’ll see.