Apollo 13 movie dramatized the mission to the moon back in 1970. They mentioned about ?Gimbal lock? which caused destabilization of the spacecraft. Apollo guidance computer had an IMU which is basically a gyroscope which is mounted inside 3 nested gimbals.
A gyroscope is a spinning device which maintains its orientation in space. Since the gyroscope is nested within 3 gimbals, it acts as 3 gyros. A slight movement will cause the gyro to move and then the gyro will come back to its orientation. This action of the gyro will be recorded in order to measure the orientation of the spacecraft in space.
While trying to understand Gimbal lock in my study course, I found it very challenging to get a crisp picture about how it happens.
Roll pitch and yaw axis. Source: Wikipedia
In gimbal lock, the outer gimbal moves with the spacecraft to a point where it is parallel to the inner gimbal (pi/2) and in such a case all gimbals will be in the same plane. So, will not be able to re-align itself to the basic plane in order to resume a normal orientation.
In Apollo 13, even after carefully measuring the spacecraft to reach a gimbal lock it still fell into gimbal lock thus causing instability to the spacecraft.
Gimbal lock in Raw pitch and yaw angles. Matlab toolbox by Peter Corke
If you see the image on the left side, then you can see the rpy2r function converts the roll pitch and yaw angles to a rotation matrix and tr2rpy transforms the rotation matrix back to the roll, pitch and yaw angles.
Once we give the pitch angle to 90 degrees, we get a rotation matrix. When we convert it back to rpy, we get a different set of roll pitch and yaw angles. Now, let us see a mathematical representation of gimbal lock.
Gimbal lock ? Mathematical representation
Since the resulting rotation matrix is a combination of alpha and gamma, changing either of them will cause the same effect. The angles apha+gamma can change, but the rotation happens always about the z axis with unexpected results.
We can avoid Gimbal lock by using Euler angles, angle axis representation or either by using Quaternions.
Hope this helped in understanding Gimbal lock clearly!