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

Divide by zero error when FIFO is disabled for MPU9250, calibrateMPU9250 doesn't work. #250

Open
playztag opened this issue Jun 20, 2021 · 1 comment

Comments

@playztag
Copy link

Following the code examples, if I run IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); to calibrate the bias, my program will crash with a divide-by-zero error. Upon further investigation, I found that

readBytes(MPU9250_ADDRESS, FIFO_COUNTH, 2, &data[0]); // read FIFO sample count fifo_count = ((uint16_t)data[0] << 8) | data[1];

returns 0 and thus the lines 258-260 on MPU9250.cpp below will crash:
accel_bias[0] /= (int32_t) packet_count; // Normalize sums to get average count biases accel_bias[1] /= (int32_t) packet_count; accel_bias[2] /= (int32_t) packet_count;

The way I fixed this was simply commenting out line 236 of MPU9250.cpp
//writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable gyro and accelerometer sensors for FIFO
Now, the read operation will return a non-zero value.

playztag added a commit to playztag/M5Stack that referenced this issue Jun 20, 2021
Resolving issue 250, divide-by-zero error when calibrating IMU
m5stack#250
@Tinyu-Zhao
Copy link
Collaborator

The M5Stack host uses MPU6886 instead of MPU9250

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

No branches or pull requests

2 participants