jremington / ICM_20948-AHRS

Mahony Fusion Filter and Tilt compensated compass for ICM_20948
32 stars 7 forks source link

Rotation on an individual axis causes changes in others. #6

Closed chianti-ga closed 9 months ago

chianti-ga commented 9 months ago

Hello, after calibrating the gyroscope and magnetometer using Magneto, I obtain consistent results along the rotation axis. However, the rotation of one axis induces the rotation of another (see attached graph). How can I fix that?

chart

The data on the graph were obtained by performing rotations against a flat surface to eliminate any parasitic movements, except for a fraction of the measurements where the ICM hit the surface, causing the spike in the graph.

Here's the .ino file (in a .txt to avoid blocking by github) ICM_20948_Mahony.ino.txt

jremington commented 9 months ago

I tested your modified code, after replacing the calibration constants and device address appropriate for my sensor, and noticed that you are transmitting data every 10 ms, at 9600 Baud. That won't work, because it takes 1 ms to transmit a single character at 9600 Baud, and the numerical integration fails.

I changed the Baud rate to 115200 and do not observe the interaction between angles that you describe. The code is working as expected. I recommend that you do not transmit data more often than about every 100 ms, at the highest possible Baud rate.

The numerical integration in the update step must be done with the shortest possible loop timing, or the orientation accuracy will be reduced.

chianti-ga commented 9 months ago

Thanks for your help, everything works perfectly now, but is there any way to get the angles more often than every 100ms? Such as offloading the calculation to the PC?

jremington commented 9 months ago

How often you you actually need angle updates?

chianti-ga commented 9 months ago

ideally 60 times per second, but 30 is acceptable, the aim being to use the IMU as a head tracker

jremington commented 9 months ago

Try it and see. The orientation accuracy will degrade, the more often you disrupt the numerical integration timing.