LESSON

# Singularity in 3D rotation angle sequences

#### Share

#### Transcript

**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.

**Note** that in Robotics, Vision & Control (second edition) and RTB10.x the default definition of roll-pitch-yaw angles has changed from Rx.Ry.Rz to Rz.Ry.Rx. To obtain the same results as shown at 00:22 with RTB10.x use

>> rpy2r(0.3, pi/2, 0.5, 'xyz')

>> tr2rpy(ans, 'xyz')

### Skill level

Undergraduate mathematics

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.

### Rate this lesson

## Check your understanding

## Discussion

## Leave a comment

Please Sign In to leave a comment.

This section quite confusing me!

It’s a difficult topic. Can you be more specific about what confuses you?

Hi! Thank you so much for these awesome lectures,.. however I’m using the MATLAB 2018b version and I installed the robot toolbox addin. It work perfectly for the previous lecture, but the values that I’m getting while following this present lecture using the ‘rpy2r()’ function are different from the ones in the video.

Please can you explain this deviation in results?

Sorry about this. The videos were made using RTB9.x and I changed the default for RTB10.x. If you are using RTB10.x please add the ‘xyz’ flag.

I think Theres a Gimbal in the Movie Event Horizont with Sam Neil too.

Sir, i use matlab 2018b version and RTB10.x, even i changed the commands according to your advice but still i take different values in ‘rpy2r()’ and ‘tr2rpy’.

please can you explain these deviations?

the same problem for me, I discovered that degrees are by default, despite the documentation says radians by default. Convert the angles to degrees and use the flag ‘xyz’ and you’ll get the results of the video.

Your MATLAB setup might be causing these issues. If you are using recent RTB10.x can you please type this command

>> rvccheck

and it will tell you if you have an installation problem. For older versions type

>> which roux

and check if the path includes the word “phased”.

Dr. Corke, I want to thank you (and QUT) for creating and sharing this absolutely phenomenal master class in robotics.

I would greatly appreciate if the “mechanical example” you describe orally at 8:00 could be displayed on screen. As someone with cognitive impairments, starting the visualisation at ~7:30 would help me understand and visualize the formulas you are deriving.

Thank you again for the incredible content.

Hi James, thanks for the kind words about the content. The gimbal itself is described and shown earlier in this lesson, from 6:13. Would it help to have that in another window while listening to the words from 8:00 onward? If you have access to MATLAB you might like to play with my tripleangle graphical app which let’s you play with a virtual gimbal and see firsthand the effect of singularity.

YOU ARE THE BEST!!!!!!

I watched it 4 times before i could satisfactorily say i understood it.

you matlab examples are ideal!!!

you are simply amazing!

Hi Prof.! Could you provide a reference to the identities that you mentioned at around 7:34?

Also, maybe the identities would answer this question, but wouldn’t (10,90,0) and (0,90,10) result in the same final rotation?

If by (x,y,z) you are representing (roll, pitch, yaw) angles in degrees, then absolutely. The roll and yaw rotation axes are aligned so only the sum matters, so (20, 90, -10) would also be the same orientation.

Got it! My confusion was also partly due to the results I was getting in MATLAB using the rpy2r function, and I only noticed later that the angles order ‘xyz’ had to be specified too due to differences in toolbox versions.

But looking at question 4 in this section of the lecture, is (10,90,0) the incorrect option only because of the convention of assigning the sum to the yaw angle?

Correct, it is totally a convention. The problem with conventions is that you often have choice…

I don’t know where these are defined, I derived them by playing with a physical coordinate frame. I’ve listed them in the margin of RVC2 page 39, and also in this paper.

Sir even if I add the flag ‘xyz’ I am getting a completely different answer

>> rpy2r(0.3, pi/2, 0.5, ‘xyz’)

ans =

0.9996 -0.0052 0.0274

0.0055 0.9999 -0.0087

-0.0274 0.0089 0.9996

Most likely an installation problem and clash with another toolbox. See the FAQ page

interchange 0.3 and 0.5 values and see if it works installation might be correct but x and z values are interchanged in toolbox and tr2rpy(ans,’xyz’) will also give z value then y value than x value

So we see here what singularity is mathematically. How does a gimple lock affect the object in an application? What practical problems does it present?

The problem is that the object is unable to rotate about a particular axis in space.

I took this lesson from the book, watched this video, and other videos and unfortunately Gimble Lock is still mysterious to me.

If you have MATLAB, run the tripleangle app, you will either find it in the app panel, or in the App folder. This might make it real for you.