Mayitzin / ahrs

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

Complementary filter implementation-documentation discrepancies #84

Open KomaGR opened 2 years ago

KomaGR commented 2 years ago

The documentation: https://ahrs.readthedocs.io/en/latest/filters/complementary.html

Attitude propagation

The following line adds a sign that seems to contradict the documentation. Why is that? https://github.com/Mayitzin/ahrs/blob/9e02c5d8efe6c2fcb96ce6d4b0b20370d5d2c5f8/ahrs/filters/complementary.py#L247-L253

Filter

Negate q_am in some cases? Why? https://github.com/Mayitzin/ahrs/blob/9e02c5d8efe6c2fcb96ce6d4b0b20370d5d2c5f8/ahrs/filters/complementary.py#L315-L319

However, the filter seems to work OK...

Mayitzin commented 1 year ago

Hi, yes, there have been some discrepancies between the implementation and the documentation due to different reference frames being used, and weren't changed in the documentation. The negation of the signs were to ensure the right angle (and not its opposite) was being estimated.

Most of these troubles came from its implementation with Quaternions. However, a new implementation of the Complementary Filter has been done with roll-pitch-yaw angles, which is a more widespread version in practice.

These angles are then converted to Quaternions, Rotation Matrices, etc.

I think it is a much simpler and clearer approach. I'll update the documentation and its unit tests, so that we can have a Complementary Filter working as expected, and properly explained too.