You refer to the forward kinematics problem: given three angles, one specific orientation results.
Gimbal lock however is related to the inverse kinematics problem: "Given an orientation, which are the angles that realise it?". For certain orientations, two of the axes become parallel, so there is no single solution. I.e. the angles become dependent: you need to make an arbitrary choice for one of both angles, in order to calculate the other one.
EDIT:
For a nice explanation see this answer on Mathematics Stack Exchange and especially this video which is mentioned in that answer.
EDIT 2:
Reply to the comments:
Can you please elaborate on what you "Gimbal lock however is related to the inverse kinematics problem". You mean that my assumption about representing any orientation of a 3D body is correct?
Given a choice for a representation (e.g. ZYX Euler angles, or ZXZ, or Roll-Pitch-Yaw, etc.), then pick whatever set of 3 values for those angles and this unambiguously defines an orientation. But some sets (with different values), yield the same orientation. So the inverse relation is not true: given a random orientation, it is not always possible to calculate three unique values for the angles.
So why use 3 angles than instead of e.g. a rotation matrix, which does not have this issue? Well, it depends on the use case, e.g.:
- If bandwidth is limited, it is less costly to transfer three angles instead of 9 values of a matrix,
- For a user interface, it is more intuitive to specify angles, instead of a matrix,
- Etc.
Regarding the video, it definitely explains gimble lock. But my confusion is that, in the video they model a real physical gimble. On the other hand I can forget about existance of a physical gimble.
As soon as you choose to represent orientation by three angles, you are using a mathematical representation that corresponds to a gimble. This irrespective of whether your mechanism has a physical gimble or not.
I can now calculate it with a matrix T = R(Δx)*R(Δy)*R(Δz)
This is the forward kinematics problem: "Given Δx, Δy and Δz, what is T". You can simply do the rotation matrix multiplications and any Δx, Δy and Δz will unambiguously yield a matrix T.
The inverse however: "Given a T, what are the corresponding values for Δx, Δy and Δz?" does not always have a unique solution.
Wrt the following:
But if you rotate in the body frame only, body frame axes are always orthogonal and they cannot become parallel to one another, no matter how you rotate the object.
Yes this is definitely possible! If you do not care about your reference frame, rotating from incrementing reference frames will not result in gimbal lock.
I don't really understand what is meant by that; in any case: each minimal representation for orientations (i.e. representing orientation by only 3 values) has singularities, i.e. orientations for which one cannot calculate one unique set of three values. But each set of three values defines a distinct orientation.
Is this what gimbal lock is about mathematically? If yes can you please say why it is a problem? I mean if there are multiple angles that yield the same orientation I can still just randomly choose one of them and be able to solve my inverse kinematics problem, right?
I guess, that it has something to do with interpolation - when I want to build a trajectory through multiple poses, in cartesian space, the fact that I have multiple euler angles for some orientation may mess up some calculations. Am I thinking in the right direction?
Mathematically, gimbal lock is a singularity, no different than other singularities of a robot manipulator (except that robot singularities are related to the physical state of the robot, whereas for gimbal lock there typically is no physical gimbal, it is just a choice of a representation).
E.g. consider a 6-joint serial industrial manipulator, that is velocity-controlled (i.e. you need to calculate joint velocities). You can relate end effector twist $\mathbf{t}$ (i.e. 6D 'velocity') to the joint velocities $\mathbf{\dot q}$ by the Jacobian: $$\mathbf{t} = \mathbf{J} \cdot \mathbf{\dot q}$$ To send joint velocities to your robot, you need to calculate them using the inverse relation: $$\mathbf{\dot q} = \mathbf{J}^{-1} \cdot \mathbf{t}$$ In a singular position, the Jacobian $\mathbf{J}$ is rank deficient and its inverse does not exist. It is important to realize that this is due to the physical state of that robot, i.e. the robot physically looses a degree of freedom in that position (i.e. only a 5D subset of the 6D twists is possible in that position, other twists are physically impossible).
Now let's say you want to specify trajectory poses in terms of cartesian coordinates and ZYX Euler angles. Consider the finite displacement $\mathbf{d}$ between to poses a and b:
$$ \mathbf{d}^b_a = [\begin{matrix}x & y & z & \phi & \theta & \psi\end{matrix}]^T $$
From your trajectory specification (and/or your control loop), you get values for the time derivitive of this displacement twist (i.e. cartesian velocities and the angular velocities expressed as Euler angle velocities): $$\mathbf{\dot d} = [\begin{matrix}\dot x & \dot y & \dot z & \dot \phi & \dot \theta & \dot \psi\end{matrix}]^T$$ For your robot control, you still need to calculate the joint velocities from these. The relation for this, is given by:
$$\mathbf{\dot d} = \left[ \begin{array}{cc} \mathbf{I}_{3x3} & \mathbf{0}_{3x3} \\ \mathbf{0}_{3x3} & \mathbf{E}^{-1} \end{array} \right] \cdot \mathbf{t} = \left[ \begin{array}{cc} \mathbf{I}_{3x3} & \mathbf{0}_{3x3} \\ \mathbf{0}_{3x3} & \mathbf{E}^{-1} \end{array} \right] \cdot \mathbf{J} \cdot \mathbf{\dot q}$$
with $$ \mathbf{E} = \left[ \begin{array}{ccc} 0 & -\sin \phi & \cos \theta \cos \phi\\ 0 & \cos \phi & \cos \theta \sin \phi\\ 1 & 0 & -\sin \phi \end{array}\right], $$ and $$ \mathbf{E}^{-1} = \left[ \begin{array}{ccc} \frac{\cos \phi \sin \theta}{\cos \theta} & \frac{\sin \phi \sin \theta}{\cos \theta} & 1\\ -\sin \phi & \cos\phi & 0\\ \frac{\cos \phi}{\cos \theta} & \frac{\sin \phi}{\cos \theta} & 0 \end{array}\right]$$
So there's no solution if $cos(\theta) = 0$, for these values we have a singularity (i.e. gimbal lock).
It is important to realize that this is purely a singularity of the chosen representation for the orientation. There is not necessarily also a physical singularity of the robot. So theoretically you could just switch to another representation. But that does not come for free: you need extra code to detect the gimbal lock and somehow deal with it.