SparkFun_MPU-9250-DMP_Arduino_Library icon indicating copy to clipboard operation
SparkFun_MPU-9250-DMP_Arduino_Library copied to clipboard

Quaternion DMP calulation not working on Mega 2560

Open raomin opened this issue 6 years ago • 9 comments

I ran MPU9250_DMP_Quaternion.ino without any problem on an ESP8266. Now I want to use it on a Arduino Mega 2560 and it returns the following:

Q:    INF,    INF,    INF,    INF
R/P/Y:  NAN, 180.00,  NAN
Time: 32761 ms

MPU9250_DMP_Gyro_Cal.ino works correctly on the same Arduino Mega 2560.

I tried DMP_FEATURE_6X_LP_QUAT and DMP_FEATURE_LP_QUAT both gives the same.

Also, dmpBegin returns INV_SUCCESS.

I also tried with Wire.setClock(400000), no success...

Any idea what could cause this issue?

raomin avatar Jul 31 '18 15:07 raomin

I'm actually running into the same exact issue (same mcu, too). Still debugging, but my hunch is that it's the function that converts the quaternion values from integer math to floats. The raw values seem legit, but go to INF after the call to qToFloat()

kolosy avatar Aug 01 '18 04:08 kolosy

Yeah, confirmed. I'll try to get a PR open when I have a minute, but edit MPU9250_DMP::qToFloat and change the integer literals from 1 and 2 to 1L and 2L, respectively. That got it working for me.

kolosy avatar Aug 01 '18 04:08 kolosy

Good spot! It does return some values now... but the values are weird: 0.5847,2.2581,2.6837,2.9126

Values should stay within [-1,1] and it's not just off by +2... Do you observe the same in your setup? seems related to https://github.com/sparkfun/SparkFun_MPU-9250-DMP_Arduino_Library/issues/15

raomin avatar Aug 01 '18 08:08 raomin

I don't see that on mine.. not sure how it's different from yours

kolosy avatar Aug 09 '18 02:08 kolosy

Hello everyone. I am also facing the same issue. DId anyone get the solution

pradeep8892 avatar Aug 10 '18 06:08 pradeep8892

Yeah, confirmed. I'll try to get a PR open when I have a minute, but edit MPU9250_DMP::qToFloat and change the integer literals from 1 and 2 to 1L and 2L, respectively. That got it working for me.

Hey kolosy Just wanted to say thank you. I've been looking for a way to read this IMU for about 1 month now. With your solution everything works. Thank you so much and have a great day ^^

marcoarnold99 avatar May 13 '19 18:05 marcoarnold99

I'll close this issue as @kolosy found a solution for the NAN.

raomin avatar May 14 '19 08:05 raomin

@raomin I'd recommend keeping it open until it's actually fixed in the codebase...

kolosy avatar May 14 '19 14:05 kolosy

good point.

raomin avatar May 14 '19 16:05 raomin