2
$\begingroup$

I am learning about Euler angles, and read about gimbal lock. I read that representing rotations with Euler angles can always cause gimbal lock. All the examples that I saw on the internet show an example of physical gimbal mechanism. I understand how gimbal lock occurs in that mechanism. For example, if you pitch up along the Y axis 90 degrees, your X axis of rotation is aligned with Z axis or rotation which causes to lose one degree of freedom. I understand all of that in the context of that physical mechanism, however how does it relate to representing orientation of a rigid body with Euler angles in general.

For example, I can always chose my rotations in the body frame (local frame). So three angles - alpha, beta and gamma may represent a sequence of rotations - rotate by angle alpha along X axis of the body, then rotate by angle beta along the Y axis of the body, and finally rotate by angle gamma along the Z axis of the body. In that case even if you happen to rotate initially by 90 degrees and one of the body axis coincides with the global frame axis, it does not matter, because you always rotate along the local body axes, and the body frame will always be orthogonal, so you never lose a degree of freedom, hence gimbal lock never occurs. Same will work vice versa, if you always choose to rotate along global axes which remain static all the time.

Can someone please clarify this confusion. Is gimbal lock indeed only relevant to mechanical gimbal or it may occur under the conditions I described above? And if not why do I see, people talk about the problem of gimbal lock and the need of using quaternions instead. It seems you can just always choose rotations along body or fixed frame, convert these rotations to matrices, and use them instead of quaternions, without a problem of gimbal lock?

Another thing that confuses me is why these gimbal like rotations used in graphics software, like Blender, for example. In virtual environment, like Blender software, you could choose to represent the rotations in the body frame always or in the global frame always, which will again prevent gimbal lock from occurring. So why do they do it that way?

$\endgroup$
1
  • $\begingroup$ I have added two references to my answer, hope this better answers your question. $\endgroup$
    – JRTG
    Commented Apr 22 at 21:11

1 Answer 1

3
+50
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ Thanks for the answer. 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? $\endgroup$ Commented Apr 27 at 6:47
  • $\begingroup$ 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. And just choose my rotations in the local frame. So rotate along x axis of the local frame, then rotate by y axis along of the local frame, and z - of the local frame. I can now calculate it with a matrix T = R(Δx)*R(Δy)*R(Δz). So basically I can always represent any rotation like this no matter how my object is oriented intially, because I always represent my rotations in the local frame. $\endgroup$ Commented Apr 27 at 6:49
  • $\begingroup$ I guess to put it simply - gimbal lock occurs when two axes of rotations become parallel. 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. $\endgroup$ Commented Apr 27 at 7:03
  • $\begingroup$ 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. Maybe this answer by @Chuck goes more in the direction of what you are looking for. Gimbal lock will affect you if you do care about a reference frame (real world in the context of a real gimbal) and you act on/control these angles. $\endgroup$
    – Nyquist
    Commented Apr 27 at 9:53
  • $\begingroup$ See updated answer for the comments. $\endgroup$
    – JRTG
    Commented Apr 27 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.