# MPU6050 - DMP values and Gimbal lock

Hello everyone,

I am actually doing some tests with the MPU6050 in order to get the position and orientation of an object in space (it’s part of my bachelor thesis).

By looking at Jeff Rowberg’s work, i’ve seen that the function “dmpGetQuaternion” is able to directly get the quaternions, which can be transformed to angles (Eulor or Yaw-pitch-roll) with some formulas. It also has a function to get X, Y and Z acceleration components.

My questions are the following :

1. How is it possible that the DMP (Digital Motion Processing) is able to directly give the angle components, while it doesn’t give position nor velocity components, but only acceleration ? From what I understood, the gyro gives velocity components, so there has to be some math done by the DMP in order to get angle components… or am I missing something?

2. Does anybody know how the reference axis behave ? I’m note sure to understand how does Gimbal lock occur inside the MPU6050. I’ve read that it happens when 2 axis align, and it causes the loss of 1 degree of freedom. But how exactly can 2 axis be aligned ? Do they not move together ?

Thank you very very very much to anybody able to help me with those questions.

Cheers !

A gyro, rate gyro, is going to give the rate of precession.

Tilt angle can be had by measuring the acceleration felt and converting that to tilt angle. Also, using the accelerometers one can get velocity.

For gimbal lock, imagine you have a 3 axis counter torqued gimbaled inertial platform and that gimbal is positioned at the north pole with the +X axis sitting on the prime meridian, and the -Y axis pointed at the center of the earth.

I use the MahonyQuaternionUpdate to get quaternions converted to the Euler angles, converted to counter torque values to keep a X/Y platform level. Works great and with some good starting numbers for the Mahony filter and fusion scheme, only gets better as time goes on.

Google "gimbal lock" for many clear explanations.

No consumer grade IMU gives position and velocity information. The sensors are too noisy, and not accurate enough for those calculations. If you want to learn why, see this informative post: http://www.chrobotics.com/library/accel-position-velocity

Gimbal lock does not occur inside the MPU6050. It occurs in your calculations outside the chip.

If I want to tell you to look “exactly there, along this angle I am describing to you” then I might give instructions like “rotate your body to face north, then tilt your head up 30 degrees and lean your head 5 degrees to the left.”

But what if I told you to “tilt” to 90 degrees straight up? Now which direction does “lean” go after that? You are locked with your nose pointed at the sky and can’t lean your head to the side.

MorganS:
Gimbal lock does not occur inside the MPU6050. It occurs in your calculations outside the chip.

If I want to tell you to look "exactly there, along this angle I am describing to you" then I might give instructions like "rotate your body to face north, then tilt your head up 30 degrees and lean your head 5 degrees to the left."

But what if I told you to "tilt" to 90 degrees straight up? Now which direction does "lean" go after that? You are locked with your nose pointed at the sky and can't lean your head to the side.

I am not sure to understand your exemple, if you tilt your head 90° straight up, why would it not be possible to lean to the side? I mean, the XYZ axis do move all togehter right ? If yes, it is always possible to rotate aroudn the 3 axis and they can't be aligned ... or what am I missing ?

Also, how does it occur in the calculation ?

kobeking:
I am not sure to understand your exemple, if you tilt your head 90° straight up, why would it not be possible to lean to the side? I mean, the XYZ axis do move all togehter right ? If yes, it is always possible to rotate aroudn the 3 axis and they can't be aligned ... or what am I missing ?

Also, how does it occur in the calculation ?

You need to play with a gimbal frame, its very illuminating...

MarkT:
You need to play with a gimbal frame, its very illuminating...

I understand that gimbal lock occurs with a gimbal frame, because the gimbals can be aligned... but there is no gimbal frame in the MPU6050, right ? so how does it happen then?

1. How is it possible that the DMP (Digital Motion Processing) is able to directly give the angle components, while it doesn’t give position nor velocity components, but only acceleration ? From what I understood, the gyro gives velocity components, so there has to be some math done by the DMP in order to get angle components… or am I missing something?

according to the documentation the “3 Axis Low Power Quaternions (is a) gyro only quaternions” you can get more accuracy using the “6 Axis Low Power Quaternions – gyro and accel quaternions”
see attached pdf
Z

Unlike most of Wikipedia, that page doesn't explain it in a way that makes sense to me.

Think about my example a bit more. The "turn" axis is fixed to your shoulders and the axis is always vertical. The "tilt" axis is fixed to your head, like it runs out your ears. "Lean" is also fixed to your head and points out the tip of your nose.

There is one simple set of 3 rotations that can point any direction. There is no orientation that is unreachable, even upside-down.

So I can tell you to look left by just "Turn" left. But if you already have your nose pointed straight up, there is no command that can make you look left, not without lowering your nose and swivelling around. And that is not the way things move in real life: you can go from straight-up to left without any other rotation in between.

Unfortunately, thinking about where you point your nose doesn't help to explain why the mathematics fails, and that is clearly explained on the Wikipedia page.

For the batchelor's thesis on position and orientation mentioned in the OP, I assume that some basic understanding of math will be expected, so a review of the relevant trigonometry and elementary rotation operators might be in order.

Thank you guys, I think I might have understood what really happens in the mathematical operations. The exemple on Wikipedia when applying the 3D rotation matrix is very useful to understand the issue. Yet I couldnt find an explanation to the problem when converting quaternions to Euler angles.

The formulas used are the following (found on the internet) :

phi = atan2(2*(q0q1+q2q3), 1-2*(q1^2+q2^2))
theta = asin(2*(q0q2-q3q1))
psi = atan2(2*(q0q3+q1q2), 1-2*(q2^2+q3^2))

With q0, q1, q2 and q3 the components of the quaternion.

Is the gimbal lock associated to the asin() function which can only represent an angle from -pi/2 to pi/2 ?

If not, what causes the gimbal lock ?

If not, what causes the gimbal lock ?

Did you skip over this section of the Wikipedia page? The same problem occurs when you try to convert a quaternion to Euler angles, under certain conditions. When the input values are noisy (and might abruptly change sign), asin() is not well determined when the argument is close to 1 and neither is atan2, when the x value is close to zero.

kobeking:
If not, what causes the gimbal lock ?

I worked on Ships Inertial units for 11 years and never did experience gimbal lock.

jremington:
Did you skip over this section of the Wikipedia page? The same problem occurs when you try to convert a quaternion to Euler angles, under certain conditions. When the input values are noisy (and might abruptly change sign), asin() is not well determined when the argument is close to 1 and neither is atan2, when the x value is close to zero.

I actually read almost the entire wikipedia page, including the exemple you mentionned, and it was very helpful, thank you. What do you mean by "the asin() function is not well determined when the argument is close to 1" ?

Idahowalker:
I worked on Ships Inertial units for 11 years and never did experience gimbal lock.

How is that possible ?

What do you mean by “the asin() function is not well determined when the argument is close to 1” ?

“Not well determined” means that the result of a function can fluctuate wildly or even change sign if the input changes by a small amount.

Quote from: Idahowalker on Today at 08:42 am

I worked on Ships Inertial units for 11 years and never did experience gimbal lock.

How is that possible ?

One guess is that the pitch angle of the ships upon which Idahowalker found him/herself rarely approached 90 degrees.

jremington:
“Not well determined” means that the result of a function can fluctuate wildly or even change sign if the input changes by a small amount.

So you’re saying that the values of the formula inside the atan2() or asin(), for exemple 2*(q0q1+q2q3), 1-2*(q1^2+q2^2), are getting very close to either 0 or 1 when the pitch angle gets close 90° (its this value that leads the 2 other angle values to go crazy).

jremington:
One guess is that the pitch angle of the ships upon which Idahowalker found him/herself rarely approached 90 degrees.

There is a operation in place to prevent the gimbals from locking.

There is a operation in place to prevent the gimbals from locking.

Ahh, so that might explain why you never saw it happen.

jremington:
Ahh, so that might explain why you never saw it happen.

Why would 'you' want gimbal lock in a critical situation when it can be prevented?