Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate AHRS acc2q into zscilib as zsl_quat_from_accel #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deganii
Copy link

@deganii deganii commented Sep 13, 2024

Currently, the zscilib's Madgwick orientation filter starts with an orientation of <1, 0, 0, 0> regardless of the physical IMU's orientation.

The filter then begins the slow/painful process of converging to the correct orientation which can take nearly a minute. For an IMU running at 120Hz, the worst-case Madgwick convergence time is about 47 seconds (β * Dt = 0.033 * 1/120Hz). This is far too long for a warm-up; a Madgwick filter that has not yet converged will output spurious and confusing orientations and result in a bad user experience.

A python implementation of Magwick, called AHRS, solves this bootstrapping problem with a non-iterative algorithm called acc2q (acceleration => quat)

AHRS Implementation:
https://github.com/Mayitzin/ahrs/blob/595ab9877c77f5960e39b352c0ef551d2d2efcb9/ahrs/common/orientation.py#L970
Reference:
([Trimpe et al] https://idsc.ethz.ch/content/dam/ethz/special-interest/mavt/dynamic-systems-n-control/idsc-dam/Research_DAndrea/Balancing%20Cube/ICRA10_1597_web.pdf

This algorithm that relies only on the current accelerometer sample. The integration of the acc2q algorithm is highlighted in the below flow diagram (dotted red block).

diagram

Computing q0 and feeding this into Madgwick results in a very reasonable q0 orientation and a much better overall experience.

@microbuilder
Copy link
Member

As per the comment in #62, can you create a PR in Zephyr that references this commit so that it can go through the normal test suite before being merged? Thanks for the changes, though ... much appreciated.

@microbuilder
Copy link
Member

Please also add some details in the commit messages and add a signed-off-by to make sure you get the proper credit for the work.

@deganii deganii force-pushed the zsl_quat_from_accel branch from f10cdd0 to 1ce505d Compare September 17, 2024 16:37
Add zsl_quat_from_accel header to quaternions.h

Incorporate AHRS acc2q into zscilib as zsl_quat_from_accel

Currently, the zscilib's Madgwick orientation filter starts with an orientation of <1, 0, 0, 0> regardless of the physical IMU's orientation.

The filter then begins the slow/painful process of converging to the correct orientation which can take literally minutes. For an IMU running at 120Hz, the worst-case Madgwick convergence time is about 47 seconds (β * Dt = 0.033 * 1/120Hz). This is far too long for a warm-up; a Madgwick filter that has not yet converged will output spurious and confusing orientations and result in a bad user experience.

A python implementation of Magwick, called AHRS, solves this bootstrapping problem with a non-iterative algorithm called acc2q (acceleration => quat)

AHRS Implementation:
https://github.com/Mayitzin/ahrs/blob/595ab9877c77f5960e39b352c0ef551d2d2efcb9/ahrs/common/orientation.py#L970
Reference:
([Trimpe et al] https://idsc.ethz.ch/content/dam/ethz/special-interest/mavt/dynamic-systems-n-control/idsc-dam/Research_DAndrea/Balancing%20Cube/ICRA10_1597_web.pdf

This algorithm that relies only on the current accelerometer sample. The integration of the acc2q algorithm is highlighted in the below flow diagram (dotted red block).

![diagram](https://github.com/user-attachments/assets/6a32fe55-2233-4b40-bec4-85e4af0750a3)

Computing q0 and feeing this into Madgwick results in a very reasonable q0 orientation and a much better overall experience.

Signed-off-by: Ismail Degani <[email protected]>
@deganii deganii force-pushed the zsl_quat_from_accel branch from 1ce505d to 925d63c Compare September 17, 2024 17:52
deganii added a commit to deganii/zephyr that referenced this pull request Sep 17, 2024
zscilib: fix computational errors

This diff adds a top-level Zephyr PR for the zscilib enhancements described in detail here:
zephyrproject-rtos/zscilib#63

Signed-off-by: Ismail Degani <[email protected]>
@deganii
Copy link
Author

deganii commented Sep 17, 2024

Thanks for the review. Please see my updates:

  • I've modified to a single commit which has all the details of the fixes made
  • I've added the signoff requested
  • I've fixed all of the comment / lint issues
    I've raised a top-level commit which refers to this pull request in the submanifest optional.yaml :

zephyrproject-rtos/zephyr#78596

@kartben
Copy link

kartben commented Nov 22, 2024

Ping @microbuilder

@microbuilder
Copy link
Member

Ping @microbuilder

As per some comments in the discord there are still quite a few issues with this preventing it from being it from being mergable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants