Quaternions for ROS Developers: What x, y, z, w Actually Mean
Every pose in ROS, from a robot's odometry to a camera's mounting angle, stores its orientation as a quaternion: four numbers called x, y, z and w. Most…
Gimbal lock is the reason robotics software stores orientations as quaternions instead of roll, pitch and yaw. It is often described as a mysterious loss of a degree of freedom. It is easier to understand with a concrete example and a few numbers, which is what this guide provides.
When pitch reaches exactly +90° or −90°, the roll axis and the yaw axis line up, so roll and yaw turn the robot about the same axis. Only their difference (or sum) matters. Infinitely many roll/yaw pairs then describe the same orientation, and near that point tiny changes in orientation produce huge swings in the angles.
ROS applies roll about X, then pitch about Y, then yaw about Z, all about fixed axes (see ROS conventions). Take two sets of angles:
They look different. Their rotation matrices are identical:
Pitching by 90° turns the robot's nose straight down onto the original Z axis. After that, a roll about the robot's X axis and a yaw about the world Z axis are rotations about the same line. At pitch +90°, only roll − yaw matters (30 − 0 and 0 − (−30) are both 30). At pitch −90°, only roll + yaw matters.
Exactly 90° is rare in practice. The real damage happens near it. We took an orientation with a given pitch, applied a tiny extra rotation of 1° about the world X axis, and converted the result back to roll, pitch and yaw:
| Starting pitch | Roll afterwards | Yaw afterwards |
|---|---|---|
| 45° | 1.4° | 1.0° |
| 85° | 11.3° | 11.3° |
| 89° | 45.0° | 45.0° |
| 89.9° | 84.3° | 84.3° |
A 1° nudge to the orientation turned into an 84° jump in roll and yaw. A controller that steers on yaw, a filter that averages angles, or a plot of an IMU's angles goes haywire as the device nears vertical, even though nothing dramatic happened physically.
When asked for angles at pitch ±90°, a library has to choose one of the infinitely many answers. A common choice, used by SciPy (which prints "Gimbal lock detected") and by the Quaternion ↔ Euler Converter, is to set yaw to zero and put the whole rotation into roll. So converting roll 10°, pitch 90°, yaw 40° to a quaternion and back gives roll −30°, pitch 90°, yaw 0°: different numbers, same orientation. Code that expects to get its original angles back will be surprised.
atan2(2(wz + xy), 1 − 2(y² + z²)), which is well behaved for robots that stay roughly level.Open the converter and click the "Gimbal lock" example: it sets roll 20°, pitch 90°, yaw 10°, warns about gimbal lock and shows the equivalent answer it picks. Drag the 3D view to see why: the roll and yaw axes coincide. Then read quaternions for ROS developers to get comfortable with the alternative.
Every pose in ROS, from a robot's odometry to a camera's mounting angle, stores its orientation as a quaternion: four numbers called x, y, z and w. Most…
"Roll, pitch and yaw" sounds unambiguous until you compare two libraries and get two different answers. Euler angles depend on which axes the robot uses, the…
Converting between quaternions and roll, pitch, yaw is a few lines of code in any language, and a common source of bugs, because each library has its own…
A robot's sensors only make sense if the software knows where each one is mounted and which way it points. In ROS that knowledge lives in the TF tree as static…
If you have any query or problem
feel free to contact us
email: [email protected]
Comments 0