Atlas Robotics
Lesson 3/7 · about 12 min

Watch on YouTube ↗Watch on Facebook ↗

Pose and quaternion: describe position + direction

Open /odom, /amcl_pose or any goal sent to Nav2, you will encounter the same structure: position (x, y, z) and orientation (x, y, z, w). The first part is easy to understand. The following part — quaternion — confuses many people: the robot rotates 90° but why does z: 0.707, w: 0.707 appear? This lesson helps you read and calculate that number yourself.

After this lesson you will

  • Distinguish position, orientation, pose, twist — 4 words that appear everywhere in ROS
  • Toggle between angle yaw and quaternion for robot running on plane, manual and in Python
  • Explain why ROS saves direction using quaternions instead of roll–pitch–yaw angles

4 words to distinguish

WordMeaningmessage type
PositionPosition: x, y, z (meters)geometry_msgs/msg/Point
OrientationDirection (where the robot is facing)geometry_msgs/msg/Quaternion
PosePosition + orientation: "where to stand, where to look"geometry_msgs/msg/Pose; adding header (frame, time) is PoseStamped
TwistVelocity: translation (m/s) + rotation (rad/s)geometry_msgs/msg/Twist — is the type of /cmd_vel

Pose answers "where"; twist answers "how is it moving". /odom contains both (Module 5: Odometry). A pose must always be accompanied by frame — "x = 2 m" compared to what? Compared to odom or map, it can be two places a meter apart. That's why most messages use the Stamped version with header.frame_id.

Orientation on a plane = 1 yaw angle

A 2D mobile robot only rotates around the Z axis (vertical). Its direction is encapsulated in an angle yaw: 0 = viewed along the X axis, positive = rotated left (counterclockwise viewed from above), unit radians (REP-103, lesson 3). The remaining two angles — roll, pitch — are always equal to 0.

With pure yaw, the quaternion has a very compact form:

x = 0,\quad y = 0,\quad z = \sin\frac{\text{yaw}}{2},\quad w = \cos\frac{\text{yaw}}{2}
yawzwRobot looks towards
001+X (front)
90° (π/2)0.7070.707+Y (left)
180° (π)10−X (rear)
−90° (−π/2)−0.7070.707−Y (side right)

Reverse direction — read yaw from quaternion in message:

import math

def yaw_from_quaternion(q):
    # Full formula (correct even when roll/pitch is different from 0); For 2D robots it reduces to 2*atan2(z, w)
    return math.atan2(2.0 * (q.w * q.z + q.x * q.y), 1.0 - 2.0 * (q.y * q.y + q.z * q.z))

def quaternion_from_yaw(yaw):
    return (0.0, 0.0, math.sin(yaw / 2.0), math.cos(yaw / 2.0))   # (x, y, z, w)

Why not save roll–pitch–yaw for easy reading?

  • Gimbal lock: with 3 Euler angles, in some directions (pitch = ±90°) the two rotation axes coincide, losing one degree of freedom, the formula divides by 0. Quaternion has no singularity.
  • No ambiguity about order: "revolves around X then Y then Z" is different from "Z then Y then X" — 3 Euler angles need an ordering convention; quaternions do not.
  • Smooth concatenation and interpolation: concatenation of 2 rotations = multiplication of 2 quaternions; interpolation between two directions (SLERP) for smooth motion. TF2 does this constantly.
  • Continuity: yaw jumps from +180° to −180° when turning to the rear; The quaternion changes continuously.

Humans read angles more easily, computers calculate quaternions more safely. Practical rule: save and transmit using quaternion, change to yaw only when 2D display or calculation is needed. tf2_echo does exactly that: prints both quaternion and RPY.

Two classic mistakes: (1) sending pose with orientation all 0 (0,0,0,0) — that's not "no rotation" but an invalid quaternion (length must be 1), many nodes will reject or behave strangely; "no rotation" is (0,0,0,1). (2) Enter degrees instead of radians.

Try it

# Terminal 1
ros2 launch atlas_bringup bringup.launch.py
# Terminal 2 — let the robot rotate in place
ros2 topic pub --rate 10 /cmd_vel geometry_msgs/msg/Twist "{angular: {z: 0.5}}"
# Terminal 3 — watch the quaternion change, and the RPY already changed by tf2_echo
ros2 run tf2_ros tf2_echo odom base_footprint

Stop the rotation command when tf2_echo reports yaw about 1.57 rad: line Rotation: in Quaternion should be near [0, 0, 0.707, 0.707].

Self-check

How is Pose different from twist?

Pose is position + direction (where to stand, where to look). Twist is linear velocity + rotational velocity (how it is moving).

Quaternion (0, 0, 0.383, 0.924) how many degrees does the robot rotate?

yaw = 2 × atan2(0.383, 0.924) ≈ 0.785 rad ≈ 45°, left rotation.

Want to send a goal to Nav2 with the robot facing −Y direction, what is the orientation?

yaw = −90° = −π/2 → z = \sin(-\pi/4) \approx -0.707, w = \cos(-\pi/4) \approx 0.707: (0, 0, −0.707, 0.707).

Why is orientation (0,0,0,0) an error?

The quaternion representing a rotation must have length 1. (0,0,0,0) represents no rotation; "no rotation" is (0,0,0,1).

Poses and quaternions · Module 2: TF2 & coordinate frames — Atlas Robotics