Peter: Lets have another look at converting roll/pitch/yaw angles to a rotation matrix. We use the function that we introduced a moment ago; rpy2r, and I’m going to parse in a roll angle of 0.3 radians, a pitch radians of pi/2 radians, and a yaw angle of 0.5 radians. And as before we have an orthonormal rotation matrix.
Now I’m going to convert that back to roll/pitch/yaw angles. To do that I use the inverse function tr2rpy and I parse in the rotation matrix that we just computed, and here are the roll/pitch/yaw angles. You’ll notice they are quite different to those that we parsed in. The middle angle, the pitch angle is the same, its pi/2. The roll angle has changed from 0.3 to 0, and the yaw angle has changed form 0.5 to 0.8.
If you are sharp you’ll have noticed that 0.8 is the sum of 0.3 and 0.5. So one of our angles has got 0, and the yaw angle has gone to the sum of the original roll and yaw angles. What’s going on here?
This is a condition known as singularity, and it occurs in any three-angle sequence representation of an orientation. It occurs for roll/pitch/yaw angles, it occurs for Euler angles. It always occurs when the middle angle takes on a particular value, and for roll/pitch /yaw angles the pitch angle is equal to pi/2, leads to the singularity condition.
This condition is also known by the rather unusual name of gimbal lock. If you’ve ever seen the movie Apollo 13 you will have heard that term used.
Apollo 13 is actually one of my favourite movies. It’s a dramatisation of the very famous Apollo 13 mission to the moon back in 1970.
Astronaut: Ok Houston we’ve had a problem here.
Ground Controller: This is Houston, say again please.
Astronaut: Alright Houston we’ve had a problem. We’ve had a Main B Bus undervolt.
Peter: There was a faulty component built into the spacecraft and eventually caused a massive explosion. The moon landing was aborted and the astronauts were really lucky to get back to earth alive.
The explosion presented the astronauts and NASA ground staff with all kinds of problems; saving the crew’s oxygen, removing excess carbon dioxide, dealing with power shortage, and devising a strategy for getting the astronauts safely back to Earth.
A rather more obscure element of this dramatic crisis is gimbal lock. It is a pretty esoteric term. It’s a very geeky term, and I'm pretty sure it's also the first and perhaps the last time it will ever be mentioned in a Hollywood movie!
The problem first of all was picked up by the ground controllers, as they monitor the crew onboard trying to stabilise the stricken spacecraft.
Ground Controller: 13, Houston. We see you getting close to gimbal lock there. We’d like you to bring up all Quad C’s on Main A. Quad C1, C2, C3 and C4 on Main A, and also bring B3 and B4 up on Main A.
Peter: The pilot was trying desperately to keep it away from the Gimbal lock condition.
Ground Controller: 13, Houston. Do you read?
Astronaut: Yeah we got it.
Peter: The Apollo spacecraft’s flying controls were something like those seen in this NASA testbed.
This gimbal lock condition is related to the example that we were looking at in MATLAB a moment ago but in this case, in the NASA case, they were dealing with real physical gimbals. So let's have a look at physical gimbals and how they work.
A Gimbal is a simple mechanism that's used to keep a delicate instrument like a compass or a clock, level when it's mounted on a vehicle or a vessel that's undergoing considerable motion. And the first example here is a compass in we call a two axis Gimbal, so the compass can rotate around this particular axis and then that whole assembly rotates around this axis. Or if the base of the compass was mounted on the ship and the ship is rolling and pitching then the compass is going to remain level. The same for this clock indicated here, its first free to rotate around this axis and then it's free to rotate around this axis. If I place this box on the table in my cabin on board a sailing ship then the clock is going to remain level even though the ship is undergoing quite considerable motion. This last example is a little bit more complex it contains what we call a three axis Gimbal. In the first case then, the compass is free to rotate around this axis and then that whole assembly is free to rotate around this axis and finally all that inner assembly is free to rotate around this axis.
Gimbals are widely used in engineering systems and this is a schematic of a gimbal that was part of the navigation system for the Apollo lunar module that was referred to earlier in the movie. The key component is what's called the stabilized platform and it consists of three gyroscopes spinning quickly and they keep this particular assembly shown here in blue at a fixed orientation with respect to the universe. Now because the vehicle in which it's mounted is going to be rotating and translating, then we need some way to mechanically connect the space craft to the stable platform but in such a way that the motion of the space craft does not introduce any torque or force on the stable platform. So the way to do that is to use a series of gimbals so the first gimbal is a rotation around this axis here and then that whole assembly is free to rotate around this axis and then finally all that assembly is free to rotate around this axis. What this allows is really important, if we measure the angles of the shaft in each of the gimbals then that tells us the orientation of the vehicle with respect to the stable platform. And that's how this vehicle is able to determine it's orientation in space. The problem occurs when the angle of the second gimbal approaches plus or minus 90 degrees and that's the condition referred to as Gimbal Lock which was mentioned in the movie clip.
For space craft navigation it works something like this, we have this inner element which is referred to as a stable platform, it's got three orthogonal gyroscopes on it and what that means is that the platform maintains a constant orientation with respect to the universe. It's a very impressive thing, the space craft then is attached to the other side of the gimbal mechanism. So as the space craft's orientation changes over time by reading the gimbal angles we can determine the orientation of the space craft with respect to the stable platform whose orientation is a constant.
Let's consider the case where the orientation of the vehicle is expressed in terms of roll, pitch, yaw angles. We write this as a sequence of elementary rotations, a rotation around the X axis by the roll angle, rotation around the Y axis by the pitch angle and a rotation around the Z axis by the yaw angle. Now let's consider what happens when the pitch angle equals 90 degrees or pi on 2 radians. We can write the expression like this, now the pitch angle is equal to pi on 2 and with some well known identities I can rewrite it in this form. Now what we have is 2 consecutive rotations around the X axis so I can write this now as a single rotation around the X axis. The amount of the rotation is R+Y, it's the sum of the roll angle and the yaw angle and there's a final constant rotation. What this indicates is that now roll and yaw are equivalent we can't tell one from another. Another way to think about this mechanical way in terms of the Gimbal mechanism itself is to think that the axis of the first gimbal and the third gimbal and now parallel to each other and aligned. This is a mathematical representation of the Gimbal lock phenomenon. And it occurs when the angle of the middle gimbal approaches pi on 2. This is the condition that they were concerned about in the Apollo 13 clip.
So what this means is when you define your coordinate system for any particular vehicle and if you want to describe it's orientation in terms of roll, pitch and yaw angles it's important that the pitch angle is around 0 for the nominal configuration of your vehicle. So if it's an aircraft then the pitch angle would be 0 when it is in default horizontal configuration or as if it was a rocket you would want to make sure that the 0 pitch angle corresponded to the condition of going straight up. You need to ensure that the situation with the pitch angle equals plus or minus 2 does not occur during normal operating conditions.
A problem arises when using three-angle sequences and particular values of the middle angle leads to a condition called a singularity. This mathematical phenomena is related to a problem that occurs in the physical world with mechanical gimbal systems.
This content assumes high school level mathematics and requires an understanding of undergraduate-level mathematics; for example, linear algebra - matrices, vectors, complex numbers, vector calculus and MATLAB programming.