Mayitzin / ahrs

Attitude and Heading Reference Systems in Python
https://ahrs.readthedocs.io/
MIT License
568 stars 91 forks source link

Initializing Madgwick from accelerometer and mag alone #10

Closed jpiat closed 4 years ago

jpiat commented 4 years ago

Hi,

i'm trying to use this package to estimate heading of a UGV from mag, acc and gyro. The issue i'm having is with the initialization of the filter from mag data and acc data alone assuming tha te UGV is not moving. This filter initialization requires gyro and accelerometer data to be available (with mag in my case). This results in the filter to take a lot of time to converge since the gyro data shows no movement but the mag data is not aligned with initial quaternion. The initialization should allow to use accelerometer and mag data alone. The other option is to compute the initial quaternion from ag and acc data alone, but it would be much simpler to make this part of the filter initialization.

Mayitzin commented 4 years ago

Hi, the newest version (0.3) includes new estimators that can be used to compute the initial quaternion without needing the gyroscope.

You can try, for example, with the class Tilt that computes the attitude from accelerator and, if available, with magnetometer too. It can be used like:

>>> from ahrs.filters import Tilt
>>> tilt = Tilt()
>>> tilt.estimate(acc=acc_data, mag=mag_data)
array([0.09867706 0.33683592 0.52706394 0.77395607])

Check its documentation (https://ahrs.readthedocs.io/en/latest/filters/tilt.html) for more examples.

Soon version 0.3 will be available in pypi too.