kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.03k stars 472 forks source link

Is the singularity going from Quaternion to Tait-Bryan angles dealt with? #93

Open gjwo opened 7 years ago

gjwo commented 7 years ago

Kris, in you code around line 625, do you deal with the singularity at +-90% pitch as described in your reference here http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles? if not dealt with this could explain the glitches I am getting, I am guessing this isn't normally an issue with flying model planes or quadcopters as they shouldn't be pointing straight up or down! I am trying to get a cube to mimic the orientation of the sensor, so this is an issue for me.

UnTraDe commented 7 years ago

I experience the exact same problem using the latest code for Arduino with the MPU-9250. I tried looking both directly at the values that the Arduino code outputs (yaw, pitch and roll) and using the quaternion directly to rotate a 3D cube in OpenGL. In both cases when Pitch gets to around -90/90 degrees the Yaw flips. Have you managed to find any solution to this issue?

gjwo commented 7 years ago

@UnTraDe thanks for commenting, I was beginning to think it was something I had done in translatng the code to java, but if you are getting the same to the original code it can't be that. If you are driving a cube directly off the quaternion, then it has to be the inputs to the caculation or the calculation itself not the Tait-Bryan conversion. Can you post a plot of yaw pitch and roll against time when doing a 360 degree rotation on pitch, to compare with mine?

UnTraDe commented 7 years ago

@gjwo I recorded 3 graphs, each with a 360 degrees rotation around different axis: Sorry for the graphs quality didn't have enough time to fine tune everything...

graph Y axis is degress graph X axis is sample count (I send sample over the com port each 20 ms (50 Hz) so the time is in units of 20 ms)

BLUE - pitch GREEN - yaw RED - roll

Pitch: pitch-rot

Yaw: yaw-rot

Roll: roll-rot

gjwo commented 7 years ago

@UnTraDe see my graphs on #90 (near the bottom), I would have expected yaw rotate and roll rotate to show a one sawtooth and two stable lines, with the pitch one one showing a sawtooth with a problem on yaw. So your yaw rotation above looks a bit odd. I got a clean one by rotating on the desk.

UnTraDe commented 7 years ago

@gjwo Oh I see. Your graph also using 0 to 360 degrees and mine -180 to 180. But I think there is still something wrong with mine, let me try a few things and I'll post new graphs.

gjwo commented 7 years ago

@UnTraDe I have 360 for yaw because I also have a compass display.

UnTraDe commented 7 years ago

@gjwo Better graphs:

BLUE - pitch GREEN - yaw RED - roll

Here you can see I got the exact same result as yours

Pitch: pitch

Yaw: yaw

Roll: roll

kriswiner commented 7 years ago

If you want to avoid these "discontinuities you need to manage the transitions in software. The yaw goes from -180 to +180, so if you want 0 to 360 like a compass with a smooth transition you have to construct this in the sketch. This is what I do. These curves all look normal to me.

On Thu, Jan 12, 2017 at 9:03 AM, Tomer notifications@github.com wrote:

Better graphs:

BLUE - pitch GREEN - yaw RED - roll

Here you can see I got the exact same result as yours

Pitch: [image: pitch] https://cloud.githubusercontent.com/assets/920831/21899636/9e9dccaa-d8f9-11e6-97b1-0b504ef05d29.png

Yaw: [image: yaw] https://cloud.githubusercontent.com/assets/920831/21899642/a4c16ad8-d8f9-11e6-966a-72449a55872c.png

Roll: [image: roll] https://cloud.githubusercontent.com/assets/920831/21899647/ab584754-d8f9-11e6-8384-2e5cbdea7cf7.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU-9250/issues/93#issuecomment-272220482, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpIsp68dFl0izVCPtMKbNFShmbi1ks5rRlzNgaJpZM4LASxj .

UnTraDe commented 7 years ago

@kriswiner The Yaw and Roll graphs are ok, they are very precise and responsive. The problem is with the Pitch (the first graph). The pitch angle (the blue line) rotatets between +90 to -90, while the in the others (yaw, roll) rotates from +180 to -180 (as seen in the second and third graphs. And it also changes direction instead of rolling around like yaw and roll do (it looks more like sinus instead of a saw-tooth).

But the bigger problem is that the pitch rotation affects yaw and roll heavily (like the example in the first graph).

Any idea why it happens?

kriswiner commented 7 years ago

Yes, you will see this kind of cross talk when you are not feeding the Madgwick filter the sensor data properly. It expects the data in a NED format.

As far as pitch going from -90 to +90, this is what the asin does. If you want some other values you will have to manage this in the sketch. For example, if you wan it to go from 0 to 180 instead, you will have to add the 90 degree delta appropriately. But it can only span 180 degrees.

On Thu, Jan 12, 2017 at 10:05 AM, Tomer notifications@github.com wrote:

@kriswiner https://github.com/kriswiner The Yaw and Roll graphs are ok, they are very precise and responsive. The problem is with the Pitch (the first graph). The pitch angle (the blue line) rotatets between +90 to -90, while the in the others (yaw, roll) rotates from +180 to -180 (as seen in the second and third graphs. And it also changes direction instead of rolling around like yaw and roll do.

But the bigger problem is that the pitch rotation affects yaw and roll heavily (like the example in the first graph).

Is there any reason for this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU-9250/issues/93#issuecomment-272236668, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qg9eKl7EiZMVffUOdHmh5O2-xXi2ks5rRmtwgaJpZM4LASxj .

gjwo commented 7 years ago

@UnTraDe am I right in thinking you are using Kris's sketch?

UnTraDe commented 7 years ago

@gjwo Yes, I'm using the latest code from the master branch

gjwo commented 7 years ago

@kriswiner Kris, does this mean your code is not feeding the Madgwick filter the sensor data properly?

kriswiner commented 7 years ago

Depends on which sketch, but in general I wouldn't assume so. The sensors values have to passed into the Madgwick or Mahony function in a NED configuration, this will change depending on the delais of your sensor breakout board and specific application.

On Fri, Jan 13, 2017 at 4:45 AM, Graham Wood notifications@github.com wrote:

@kriswiner https://github.com/kriswiner Kris, does this mean your code is not feeding the Madgeick filter the sensor data properly?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU-9250/issues/93#issuecomment-272435269, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qp-a6BP92qYDQB7rIORs2mCBMlN3ks5rR3H1gaJpZM4LASxj .