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

Initialize using gravity vectors to exclude the influence of the orientation during initialization #79

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Zhaosn
Copy link

@Zhaosn Zhaosn commented Jan 31, 2024

The previous method of subtracting gravity when calibrating accelerometers required that the Z-axis is upward, but now a gravity vector is used.
Now, when I initialize the module with the Z-axis not facing up, the first few returns will be around 0 and then jump to the actual value, instead of the initialized position as ypr=0 (which is what I thought it would be before). And it doesn't have this problem: #77
It's worth to note that my tests show it's maybe better to keep the code unchanged and keep the z-axis calibrated upwards, just make sure the z-axis was calibrated upwards. Now all directions can be just as bad, and the calibration error is related to epsilon.
(fix #78)

…eters required that the Z-axis be exactly parallel to and upward of the direction of gravity, but now a normalized gravity vector is used. This algorithm for obtaining the normalized vector could perhaps be replaced by "Fast Inverse Square Root".
Unit vectors with offsets close to zero are literally monsters!
…ode unchanged and keep the z-axis calibrated upwards, just make sure the z-axis was calibrated upwards. Now all directions can be just as bad, and the calibration error is related to epsilon
@Zhaosn
Copy link
Author

Zhaosn commented Feb 1, 2024

Unfortunately, the bugs in this code don't always recur, causing me to repeat changes, and I apologize for the frequent interruptions.
If the acceleration reading is [0 0 0] at the beginning, it causes the unit vector to return [nan nan nan], which causes the ITerm always be nan, leading to unconvergence
fix: line3439

mpu6050/src/MPU6050.cpp

Lines 3438 to 3443 in fbb3de4

for (int i = 0; i < 3; i++) {
if (isnan(Reading[i])) {Reading[i] = 0;}
Error = -Reading[i];
eSum += abs(Reading[i]);
PTerm = kP * Error;
ITerm[i] += (Error * 0.001) * kI; // Integral term 1000 Calculations a second = 0.001

If the acceleration reading is [0 0 0] at the beginning, it causes the unit vector to return [nan nan nan nan], which causes the ITerm always be nan, leading to unconvergence

Signed-off-by: Zhaosn <[email protected]>
Signed-off-by: Zhaosn <[email protected]>
@xpeqex
Copy link
Member

xpeqex commented Feb 12, 2024

Hi @Zhaosn

Thank you for the contribution. Could you please share more details about the bug you are mentioning? Additionally, is there any setup you can share with us to test this?

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.

2 participants