Coordinate Frames and Homogeneous Transforms
Every vector in robotics lives in a frame — get the frame wrong and the maths is perfectly correct and completely useless.
🎯 By the end you'll understand
What a coordinate frame is and why robotics needs more than one. The 4×4 homogeneous transform as the composition primitive of SE(3) — the group of rigid-body motions in 3D space. How to compose two transforms and what happens to a point's coordinates as it passes through the chain. Why frame conventions — especially axis direction, handedness, and sign — must be agreed upon before any data is shared between nodes. And why the "all bugs are frame bugs" heuristic, while an overstatement, is a useful first hypothesis for any unexplained field deviation.
KEY INSIGHTEvery number in robotics is meaningless without its frame
A LIDAR reports a point at (0.0, 1.5, 0.0). Is that 1.5 metres to the left of the sensor? To the left of the robot base? In map coordinates? The number 1.5 tells you nothing until you know which frame it lives in.
Before any algorithm can run, every measurement, every pose estimate, every goal position must be expressed in a coordinate frame — a named, agreed-upon reference in which distances and directions mean something concrete. When two nodes in your system use different frame conventions and nobody notices, the collision avoidance algorithm will steer the robot toward the obstacle it thinks it is avoiding. The maths will be correct. The physics will be catastrophic.
This is an overstatement — but a useful one. In field robotics, a disproportionate share of first-integration bugs trace back to a frame error: a sign flip on the Y axis, an axis permutation between two sensor drivers, a missing frame transform that causes a node to silently operate in the wrong reference. Before debugging any spatial algorithm, ask "are all the frames consistent?" The answer is yes surprisingly rarely on first integration. The heuristic trains you to check frames before rewriting algorithms.
DEFINITIONWhat a coordinate frame is — and why robotics needs a chain of them
A coordinate frame (also called a reference frame) is an origin point plus three mutually perpendicular axes with defined positive directions. Every spatial measurement is a vector expressed relative to one frame. The critical word is relative: the same physical point in space has different coordinate values in different frames.
A mobile robot operating indoors typically involves at least four distinct frames, each serving a specific purpose:
World frame (or map frame) — the fixed global reference
Origin: a fixed point in the environment (often where the robot started). Axes: typically X forward, Y left, Z up (REP 103 convention). This frame does not move. The robot's pose in the world is described as a transform from this frame. In ROS 2, this frame is usually named map and is produced by a SLAM algorithm or a map server.
Robot base frame — moves with the robot body
Origin: the robot's geometric or kinematic center (often the midpoint between the drive wheels for a differential-drive platform). Axes: X forward, Y left, Z up. This frame is attached to the robot and moves with it. In ROS 2, it is named base_link. The transform from map to base_link is the robot's pose estimate — the output of the localization system.
Sensor frame — fixed relative to the sensor's mounting point
Origin: the sensor's optical or acoustic center. Axes: defined by the sensor manufacturer, then re-expressed in REP 103 convention by the driver. For FollowBot's RPLIDAR A2, the convention is X forward, Y left. The transform from base_link to laser is a fixed rigid offset (the mounting height and position of the LIDAR on the chassis) — it does not change while the robot runs. This is called an extrinsic calibration.
Body frame — attached to a moving rigid body (arm link, gripper, etc.)
Origin: a joint center or link center of mass. Axes: defined by the URDF's joint convention. For FollowBot's 6-DOF arm, each link has its own body frame. The transforms between successive arm link frames change as the joints rotate — they are the kinematic state of the arm. This chain of transforms from base to end-effector is forward kinematics, which is Stage 2's subject.
ROS Enhancement Proposal 103 defines the standard axis convention for all ROS-ecosystem frames: X forward, Y left, Z up. This is a right-handed coordinate system. If a sensor driver delivers data in a different convention (some camera drivers use X right, Y down, Z forward) it must re-express that data in REP 103 before publishing to a ROS 2 topic. Frame disagreements between sensor drivers that don't follow REP 103 are one of the most common integration headaches in ROS robotics.
CORE CONCEPTThe 4×4 homogeneous transform — SE(3)'s composition primitive
A rigid-body transform in 3D space — a rotation plus a translation — can be represented as a 4×4 matrix. This is the homogeneous transform, and it is the fundamental primitive of robot geometry. Understanding why it is 4×4 rather than 3×3 + a vector illuminates the whole structure.
The naive approach: represent rotation as a 3×3 matrix R and translation as a 3×1 vector t. To transform a point p, you compute R·p + t. This works for a single transform. But to compose two transforms — "apply transform A, then transform B" — you get B·(A·p + t_A) + t_B = BA·p + (B·t_A + t_B). The translation terms couple with the rotation in an awkward way. You cannot write composition as a single matrix multiply.
The homogeneous trick: represent every 3D point p = (x, y, z) as a 4D vector p̃ = (x, y, z, 1)ᵀ, and represent the transform as:
⎢ r₂₁ r₂₂ r₂₃ tᵧ ⎥
⎢ r₃₁ r₃₂ r₃₃ t_z⎥
⎣ 0 0 0 1 ⎦
where the top-left 3×3 block is a rotation matrix R (orthonormal; det(R) = +1), and the right column is the translation vector t. Now T·p̃ gives a transformed 4D homogeneous vector — and the last element is still 1. More importantly:
If T_A takes points from frame A to frame B, and T_B takes points from frame B to frame C, then the composed transform T_A→C = T_B · T_A. One matrix multiply. No coupling terms. This is why homogeneous transforms are the composition primitive — the entire kinematics of a robot arm is a chain of matrix multiplications, and a TF tree is a graph of these matrices.
The set of all valid 4×4 homogeneous transforms (with R orthonormal and det(R) = +1) is called SE(3) — the Special Euclidean group in 3 dimensions. It is a Lie group: a smooth manifold with a group structure. The "Special" means det(R) = +1 (pure rotations, not reflections). The 6 degrees of freedom of SE(3) correspond to 3 translational DOF (x, y, z) and 3 rotational DOF (which can be parameterized as roll/pitch/yaw, or as a quaternion — covered in Lesson 1.3).
For a differential-drive robot moving on a flat floor — like FollowBot's base — the relevant group is SE(2): x, y, and heading θ. The homogeneous form in 2D is a 3×3 matrix. But even in a 2D base, the sensors are 3D (the LIDAR has a mounting height; the camera has a full 6-DOF pose relative to the base). So in practice you will always work in SE(3) when thinking about FollowBot's full geometry, and use the SE(2) projection only when doing 2D path planning on the floor plane.
A worked example: FollowBot's LIDAR is mounted 0.18 m above and 0.12 m forward of base_link (canonical values from the URDF — see Lesson 1.9). The transform from base_link to laser is:
⎢ 0 1 0 0 ⎥
⎢ 0 0 1 0.18 ⎥
⎣ 0 0 0 1 ⎦
This is a pure translation (identity rotation). The LIDAR detects an obstacle at p_laser = (1.0, 0.3, 0.0) in laser frame. To express that point in base_link frame:
= ⎡ 1 0 0 0.12 ⎤ ⎡ 1.0 ⎤ ⎡ 1.12 ⎤
⎢ 0 1 0 0 ⎥ · ⎢ 0.3 ⎥ = ⎢ 0.3 ⎥
⎢ 0 0 1 0.18 ⎥ ⎢ 0.0 ⎥ ⎢ 0.18 ⎥
⎣ 0 0 0 1 ⎦ ⎣ 1 ⎦ ⎣ 1 ⎦
The obstacle is 1.12 m forward, 0.30 m to the left, and 0.18 m above the robot's base frame origin. This is the data the collision-avoidance planner needs — expressed in a frame relative to the robot's body, not the sensor.
SEE IT2D frame compositor — observe and break the chain
Below is a 2D frame compositor. Frame A is the robot base frame; Frame B is a sensor frame attached to it. Use the sliders to set the position and orientation of each frame, and a point P expressed in Frame B. The compositor chains the transforms and shows you P's coordinates in Frame A (and in the World frame). Then try the sign-error toggle: flip the Y-axis sign convention on Frame B and see what happens to the point.
The key lesson from the widget: a sign error on one axis produces a mirror reflection of all geometry in that axis. The robot's computed point is equidistant from the correct position, on the opposite side. Every downstream algorithm — the costmap, the path planner, the collision checker — receives the reflected position and acts on it correctly. The error is undetectable from inside any individual algorithm. It is only visible by comparing the algorithm's spatial output to the real world.
HOW IT WORKSComposing transforms: the chain rule of robot geometry
The transform chain rule is: to express a point p from frame C in frame A, where the chain is A → B → C, you compute:
p_A = T_A←C · p_C = (T_A←B · T_B←C) · p_C
Note the ordering: right to left. The rightmost transform is applied first. This is standard matrix multiplication convention and a common source of bugs when hand-coding transform chains. Getting the order wrong produces a numerically different result that may still look reasonable — it is not a divide-by-zero crash.
The inverse of a homogeneous transform is not its numerical matrix inverse (which is expensive). For a valid SE(3) transform T = [R | t], the inverse is:
⎣ 0 1 ⎦
This is cheap to compute (matrix transpose + one matrix-vector multiply) and numerically stable. In ROS 2's TF2 library, tf2::Transform::inverse() implements this directly.
There are two common conventions for the subscript on a transform. The convention used here — T_A←B means "a point in frame B, expressed in frame A" — is physically intuitive: the arrow points in the direction of frame re-expression. An equivalent alternative used in some robotics textbooks is T_AB to mean "the pose of frame B described in frame A." Both are common; the danger is mixing them silently. When reading any paper or codebase, establish the convention on page one. In TF2, lookupTransform(target_frame, source_frame, ...) returns the transform that takes a point from source_frame to target_frame — match this precisely.
A concrete composition example for FollowBot: an obstacle is detected at p_laser = (1.0, 0.3) in the laser frame. We want its coordinates in the map frame. The chain is: map ← base_link ← laser.
import rclpy from rclpy.node import Node import tf2_ros import tf2_geometry_msgs from geometry_msgs.msg import PointStamped class PointTransformer(Node): def __init__(self): super().__init__('point_transformer') self.buf = tf2_ros.Buffer() self.listener = tf2_ros.TransformListener(self.buf, self) self.create_timer(1.0, self.run) def run(self): # Point detected by LIDAR in laser frame p = PointStamped() p.header.frame_id = 'laser' p.header.stamp = self.get_clock().now().to_msg() p.point.x, p.point.y, p.point.z = 1.0, 0.3, 0.0 try: # TF2 composes the full chain: laser → base_link → odom → map p_map = self.buf.transform(p, 'map') self.get_logger().info( f'In map frame: ({p_map.point.x:.3f}, {p_map.point.y:.3f})' ) except tf2_ros.LookupException as e: self.get_logger().warn(f'TF lookup failed: {e}')
The critical line is self.buf.transform(p, 'map'). TF2 looks up the transform from laser to map at the timestamp in the header, composing the full chain laser → base_link → odom → map automatically. You never manually multiply the matrices. But you still need to understand the chain to diagnose when it goes wrong — and the most common reason it goes wrong is a missing or mis-named frame in the TF tree.
FOLLOWBOTBuilding FollowBot's TF tree
FollowBot's Stage 1 milestone includes a complete TF tree: map → odom → base_link → laser → camera. Each edge in this tree is a transform broadcast by a specific node. Understanding which node owns which transform is the first architectural decision in robot software design — and getting it wrong means data flowing between nodes will be expressed in inconsistent frames.
robot_state_publisher from the URDF. The arm sub-tree is dashed because its edges are joint-angle-dependent (forward kinematics — Stage 2).The odom frame deserves special attention. It is an intermediate frame that integrates wheel odometry without global corrections — it drifts over time but is continuous (no sudden jumps). The map frame is globally consistent but can jump when the localization system gets a correction (e.g., after loop closure in SLAM). The two-frame design lets the velocity controller operate in the smooth odom frame while the planner operates in the consistent map frame. This is a deliberate architectural decision, not an accident of history.
<!-- base_link → laser: 0.12 m forward, 0.18 m up, no rotation --> <joint name="base_laser_joint" type="fixed"> <parent link="base_link"/> <child link="laser"/> <origin xyz="0.12 0.0 0.18" rpy="0 0 0"/> </joint> <!-- base_link → camera: 0.10 m forward, 0.22 m up, −5° pitch (looking slightly down) --> <joint name="base_camera_joint" type="fixed"> <parent link="base_link"/> <child link="camera_link"/> <origin xyz="0.10 0.0 0.22" rpy="0 -0.0873 0"/> </joint>
The rpy attribute is roll/pitch/yaw in radians. −0.0873 rad ≈ −5°. This static offset is extrinsic calibration — it should be measured from the physical robot, not guessed. A 2° error in camera pitch at 3 m range introduces a ~10 cm vertical error in depth-based person detection. The URDF is the single source of truth for all static transforms. Do not hardcode transform values in node code — read them from the URDF via TF2.
IN PRACTICETF2 in ROS 2: what it does and how to debug it
TF2 is ROS 2's transform library. It maintains a time-indexed tree of transforms and provides an API to look up any transform between any two frames, at any past timestamp (within a configurable buffer window). This is critical: sensor data arrives with timestamps, and you often need to transform a measurement to the frame it was in at the time of measurement, not at the current time.
| TF2 API call | What it does | Common failure |
|---|---|---|
lookupTransform(target, source, time) |
Returns T_target←source at the given time | LookupException if the frame pair doesn't exist |
canTransform(target, source, time) |
Returns True if the transform is available (use before lookup) | Returns False when frames exist but chain is broken |
transform(stamped_msg, target_frame) |
Transforms a stamped geometry message to the target frame | ExtrapolationException if timestamp is too old |
waitForTransform(target, source, time, timeout) |
Blocks until the transform is available, up to timeout | Blocks forever if a frame is never published |
The fastest TF2 debugging command is ros2 run tf2_tools view_frames. It listens for 5 seconds, then outputs a PDF graph of the current TF tree. If a frame is missing or disconnected, you see it immediately. The second most useful command is ros2 run tf2_ros tf2_echo map base_link, which prints the current T_map←base_link transform 10 times per second — the most direct way to verify your localization is publishing something reasonable.
Every message in ROS 2 has a header.stamp. TF2 uses this to select the correct historical transform. If you forget to set the stamp, or set it to time(0) (the epoch), you ask for the transform "at the beginning of time" — which usually fails with an ExtrapolationException. The fix: always set header.stamp = self.get_clock().now().to_msg() before calling transform(). This is mentioned in the ROS 2 documentation but easy to miss in tutorial code where the stamp is implicit.
WEAKNESSWhere frame bugs hide and compound
The most common frame bug is not a wrong translation — it is a wrong axis sign. A sensor driver that reports Y as rightward instead of leftward (or Z as downward instead of upward) produces data that is geometrically plausible but laterally mirrored. The costmap receives mirrored obstacle positions. The planner generates mirrored paths. The robot steers left when it should steer right. No exception is raised. The robot looks like it has "bad PID tuning" or "sensor noise." In reality it has a one-line sign error in the sensor driver's coordinate mapping. Check: ros2 topic echo /scan while pointing the LIDAR at a known object on the left — if the bearing is positive (leftward in REP 103), the sign is correct. If it is negative, the Y axis is flipped.
Depth cameras (Intel RealSense, Azure Kinect) typically report data in optical frame convention: Z forward, X right, Y down. ROS camera drivers are supposed to re-express this in REP 103 (X forward, Y left, Z up), but some do it imperfectly or publish two topics with different conventions. If you subscribe to the raw depth image and use the pixel-to-3D conversion directly, you may get Z-up-becomes-X-forward permuted coordinates. The symptom: obstacles at 2 m depth appear to be 2 m above the robot. The fix: always use the camera_optical_frame → camera_link static transform (usually published by the camera driver) rather than hand-rotating in your node code.
An active transform moves a point; a passive transform re-expresses the same physical point in a different frame. Both use the same 4×4 matrix, but the semantic direction is opposite. T_A←B applied to point p gives p's coordinates in frame A — that is a passive transform (coordinate change). The same matrix applied "the other way" moves a point in frame A to a new position. In robotics the passive (re-expression) interpretation is standard and is what TF2 implements. But if you write code that applies a rotation matrix to "rotate the robot" (active) while TF2 is doing passive lookups elsewhere in the same codebase, you will get sign errors that are extremely hard to debug. Commit to one interpretation and document it at the top of every transform-heavy file.
KEY INSIGHTHow this connects
- What Is a Robot? The Sense-Think-Act Loop (1.1) — the previous lesson established that every node in the loop passes data to the next. This lesson makes precise what that data is: a vector in a frame. The sense→estimate arrow is a LIDAR scan in laser frame; the estimate→plan arrow is a pose in map frame. Coordinate transforms are the grammar that makes those handoffs valid.
- Rotation Representations: Matrices, Euler Angles, and Quaternions (1.3) — the next lesson digs into the 3×3 rotation block inside the 4×4 transform. Euler angles, rotation matrices, and quaternions are all representations of the same SO(3) element; each has different composition properties and different failure modes (gimbal lock, normalization drift). Builds directly on this lesson.
- The TF2 Transform Tree: Frames, Broadcasters, and Listeners (1.5) — the deep treatment of TF2: static vs. dynamic broadcasters, the TF2 buffer, time-travel transforms, and the architecture of a production TF tree. This lesson's brief introduction becomes a full engineering module in 1.5.
Coordinate frames are not a technicality to get through before the real algorithms. They are the foundational data structure of all spatial robotics algorithms. A Kalman filter produces a state estimate in odom frame. A path planner queries the costmap in map frame. A collision checker transforms the obstacle map to base_link frame. Every one of those operations is a transform lookup, and every one of those can fail silently with the wrong convention. The practitioner who internalizes frame conventions before writing algorithms saves ten hours of debugging per month.
GLOSSARYKey terms introduced
- Coordinate frame
- An origin point plus three mutually perpendicular axes with defined positive directions. Every spatial measurement in robotics is a vector expressed relative to a named coordinate frame. Two frames can represent the same physical point with different numerical values.
- Homogeneous transform
- A 4×4 matrix [R | t; 0 | 1] that represents a rigid-body rotation R and translation t in 3D space. The homogeneous representation makes transform composition equivalent to matrix multiplication, eliminating the coupling terms that appear in the naive R·p + t formulation.
- SE(3)
- The Special Euclidean group in three dimensions: the set of all valid rigid-body transforms (rotation + translation) in 3D space, with composition defined by matrix multiplication. "Special" means the rotation matrix has determinant +1 (pure rotation, not reflection). SE(3) has 6 degrees of freedom.
- REP 103
- ROS Enhancement Proposal 103 — the standard axis convention for all ROS-ecosystem coordinate frames: X forward, Y left, Z up (right-handed). All ROS 2 sensor drivers are expected to publish data in this convention. Violations are a primary source of integration bugs.
- TF2
- The ROS 2 transform library. Maintains a time-indexed tree of coordinate frame transforms and provides APIs to look up any transform between any two frames at any past timestamp. The single source of truth for all spatial relationships in a ROS 2 system.
- Extrinsic calibration
- The measured rigid-body transform between two sensor frames (or between a sensor and the robot body). For FollowBot, the URDF defines the extrinsic calibration between base_link, laser, and camera. Errors in extrinsic calibration produce systematic spatial errors in all downstream algorithms.
- Passive transform
- A transform that re-expresses the same physical point in a different coordinate frame (coordinate change), as opposed to an active transform that moves the point to a new physical location. TF2 implements passive transforms. Confusing the two produces sign errors that are difficult to diagnose.
ACTIVE RECALLCheck your understanding
Answer in your own words first, then reveal.
1Why is a 4×4 matrix preferable to a 3×3 rotation matrix plus a 3×1 translation vector when composing multiple transforms?›
The 3×3 + 3×1 representation requires composing two transforms as B·(A·p + t_A) + t_B = BA·p + (B·t_A + t_B). The translation terms couple with the rotation in a way that cannot be written as a single matrix multiply. With the 4×4 homogeneous representation, both transforms become 4×4 matrices and composition is T_composed = T_B · T_A — one matrix multiply with no coupling terms. This makes chain composition of N transforms simply a product of N matrices, which is why the 4×4 form is the composition primitive of all kinematic chains and TF trees.
2FollowBot's LIDAR reports a person at (0.0, −1.0) in laser frame. The team's driver has the Y axis flipped (reports Y as rightward, not leftward). Where does the collision avoidance system think the person is, and what does the robot do?›
With the Y axis flipped, the driver reports the person as being at Y = −1.0, meaning 1.0 m to the right of the sensor. The correct value should be Y = +1.0 (1.0 m to the left). After transformation to base_link and then map frame, the person's map-frame position is mirrored across the X axis relative to the robot's heading. The collision avoidance system builds a costmap with the person on the wrong side. If the robot's goal is to avoid the person (stop at 1 m distance), it will steer away from an empty space on the right while closing in on the real person on the left. No exception is raised. The only symptom is that the robot consistently closes distance with the person instead of maintaining it — which is typically misdiagnosed as a controller tuning problem.
3What is the difference between the odom frame and the map frame in ROS 2, and why do production robots use both?›
The odom frame is produced by integrating wheel odometry (and optionally IMU). It is continuous — no sudden jumps — but drifts over time because odometry integrates noise. The map frame is produced by a SLAM algorithm or localization system and is globally consistent, but can jump when the localization system makes a correction (e.g., recognizes a previously visited place and closes a loop). Production robots use both because the velocity controller needs a smooth, continuous reference (odom) to avoid abrupt motor commands, while the path planner and semantic reasoning need a globally consistent reference (map). The two-frame design cleanly separates these concerns: the controller closes the loop in odom, the planner queries the costmap in map, and TF2 provides the composition T_map←odom when needed for cross-frame queries.
4A teammate writes: "T_laser_to_map = T_base_to_map · T_laser_to_base." Is the matrix multiplication order correct, and how would you verify it?›
The order is correct if "T_A_to_B" means "the matrix that takes a point expressed in A and produces its coordinates in B" (passive convention). To verify: apply T_laser_to_map to a point you know, e.g., the laser's own origin in laser frame, which is (0,0,0). T_laser_to_map · (0,0,0,1)ᵀ should equal the laser's position in map frame (the translation column of T_laser_to_map). Then verify T_laser_to_base · (0,0,0,1)ᵀ equals the laser's position in base_link frame. Check with ros2 run tf2_ros tf2_echo map laser to compare against TF2's own computation. The fastest way to catch a wrong ordering is to check the special case: the identity (p = origin of the source frame) should give exactly the source frame's origin expressed in the target frame.