Skip to main content

A Python library to calibrate 6 DOF IMUs

Project description

imucal - A Python library to calibrate 6 DOF IMUs

Test and Lint codecov Documentation Status Code style: black PyPI PyPI - Downloads status

This package provides methods to calculate and apply calibrations for 6 DOF IMUs based on multiple different methods.

So far supported are:

For more information check the quickstart guide below and the documentation.

Installation

pip install imucal

To use the included calibration GUI you also need matplotlib (version >2.2). You can install it using:

pip install imucal[calplot]

Supported Python versions and Platforms

imucal is officially tested on Python 3.7, 3.8, 3.9 and 3.10. It should further work with all major operating systems. However, you might run into some issues on ARM based MacBooks, as hd5py does not seem to be properly supported yet. However, as hd5py is only an optional dependency, you can still use imucal without it, if you do not need support for HDF5 import or export of calibration files.

Quickstart

This package implements the IMU-infield calibration based on Ferraris1995. This calibration method requires the IMU data from 6 static positions (3 axes parallel and antiparallel to the gravitation vector) for calibrating the accelerometer and 3 rotations around the 3 main axes for calibrating the gyroscope. In this implementation, these parts are referred to as {acc,gyr}_{x,y,z}_{p,a} for the static regions and {acc,gyr}_{x,y,z}_rot for the rotations. As example, acc_y_a would be the 3D-acceleration data measured during a static phase, where the y-axis was oriented antiparallel to the gravitation vector. For more information on how to perform the calibration check our guide.

For the calibration, you need to separate your data into these individual sections. If you already recorded them separately or know where each section starts and ends in a continuous recording, you can use ferraris_regions_from_df and ferraris_regions_from_section_list, respectively to convert the data into the correct format for the calibration (section_data in the snippet below).

If you don't have that information yet, we recommend to use the included GUI to annotate the data. To annotate a Ferraris calibration session that was recorded in a single go, you can use the following code snippet.
Note: This will open an interactive Tkinter plot. Therefore, this will only work on your local PC and not on a server or remote hosted Jupyter instance.

from imucal import ferraris_regions_from_interactive_plot

# Your data as a 6 column dataframe
data = ...

section_data, section_list = ferraris_regions_from_interactive_plot(
    data, acc_cols=["acc_x", "acc_y", "acc_z"], gyr_cols=["gyr_x", "gyr_y", "gyr_z"]
)
# Save the section list as reference for the future
section_list.to_csv('./calibration_sections.csv')  # This is optional, but recommended

Independent of how you obtained the section_data in the correct format, you can now calculate the calibration parameters:

from imucal import FerrarisCalibration

sampling_rate = 100 #Hz 
cal = FerrarisCalibration()
cal_mat = cal.compute(section_data, sampling_rate, from_acc_unit="m/s^2", from_gyr_unit="deg/s")
# `cal_mat` is your final calibration matrix object you can use to calibrate data
cal_mat.to_json_file('./calibration.json')

Applying a calibration:

from imucal.management import load_calibration_info

cal_mat = load_calibration_info('./calibration.json')
new_data = pd.DataFrame(...)
calibrated_data = cal_mat.calibrate_df(new_data, acc_unit="m/s^2", gyr_unit="deg/s")

For further information on how to perform a calibration check the User Guides or the Examples.

Further Calibration Methods

At the moment, this package only implements calibration methods based on Ferraris1994/95, because this is what we use to calibrate our IMUs. We are aware that various other methods exist and would love to add them to this package as well. Unfortunately, at the moment we can not justify the time investment.

Still, we think that this package provides a suitable framework to implement other calibration methods with relative ease. If you would like to contribute such a method, let us know via GitHub Issue, and we will try to help you as good as possible.

Citation

If you are using imucal in your scientific work, we would appreciate if you would cite our JOSS paper or link the project.

Küderle, Arne, Nils Roth, Robert Richer, and Bjoern M. Eskofier. 
“Imucal - A Python Library to Calibrate 6 DOF IMUs.”
Journal of Open Source Software 7, no. 73 (May 26, 2022): 4338. https://doi.org/10.21105/joss.04338.

Contributing

All project management and development happens through this GitHub project. If you have any issues, ideas, or any comments at all, just open a new issue. We are always happy when people are interested to use our work and would like to support you in this process. In particular, we want to welcome contributions of new calibration algorithms, to make this package even more useful for a wider audience.

Dev Setup

We use poetry to manage our dependencies. Therefore, you need to first install Poetry locally on you machine.

Then you can run the following command to install a local development version of this library in a dedicated venv.

poetry install -E calplot -E h5py

To run tests/the linter/... we use doit. You can see all available commands by running:

poetry run doit list

and execute any command by running

poetry run doit <command-name>

Updating dependencies

If you update or add dependencies using (poetry add or poetry update) you will see that the pyproject.toml and the poetry.lock files are both updated. This might take a while (>10 min) depending on the dependency you updated. Unfortunately, we can not do anything about that at the moment. Make sure you commit the changes to both files. Otherwise, wrong versions of dependencies will be used in the CI and by other developers.

In case you update dependencies by directly editing the pyproject.toml file, you need to be very careful and make sure, you run poetry lock [--no-update] afterwards. Otherwise, the lock file will be out of date.

In general, it is a good idea to just run poetry update from time to time. This will install the latest version of all dependencies that are still allowed by the version constrains in the pyproject.toml. This allows to check, if everything still works well with the newest versions of all libraries.

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

imucal-2.3.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

imucal-2.3.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file imucal-2.3.1.tar.gz.

File metadata

  • Download URL: imucal-2.3.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Linux/5.15.0-1020-azure

File hashes

Hashes for imucal-2.3.1.tar.gz
Algorithm Hash digest
SHA256 ef6b6a35bd9f4fff9919b65191c18581104eeb867942049a08a8ffa6cf921605
MD5 e2b0e35c2b13700362023e7f8d9792d1
BLAKE2b-256 191567836c485f0d6f5bce7bfcf56b323e2ce37261c3d9aeb19f8d6f3c15b554

See more details on using hashes here.

File details

Details for the file imucal-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: imucal-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Linux/5.15.0-1020-azure

File hashes

Hashes for imucal-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2a4641efee6c7b1e592217c52150844c280fb3d9efd66636f09dfcc5d0dc622
MD5 9d3eee5ab26e14ac0d3a7774ae647e69
BLAKE2b-256 54537aa3062f44162d60f5f1f167ae41903a3b0df70bf73ab0733cb1df100235

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