TF Coordinate Transformation in ROS

Introduction

In ROS, robots often have multiple coordinate frames, such as map, odom, base_link, laser, and camera. TF (Transform) is the standard mechanism used to manage relationships between these frames over time.

TF helps us answer questions like:

  • Where is the robot in the map?
  • Where is the camera relative to the robot base?
  • How can sensor data be converted into another frame for planning or visualization?

Why TF Matters

Without TF, each node would need to manually compute coordinate conversions, which is error-prone and hard to maintain. With TF, transformations are published once and reused by all nodes that need them.

This is especially important in:

  • Sensor fusion
  • Navigation and localization
  • Motion planning
  • RViz visualization

Core Concepts

  • Frame: A coordinate system with a name (for example, base_link or camera_link).
  • Transform: The translation and rotation from one frame to another.
  • TF Tree: A tree structure connecting all frames.
  • Static Transform: A fixed relationship between two frames.
  • Dynamic Transform: A time-varying relationship (for example, robot movement).

Minimal Example: Static TF + Verification

This example publishes a static transform from base_link to camera_link, then verifies it in another terminal.

  1. Start ROS core:
bash
roscore
  1. In a new terminal, publish a static transform:
bash
rosrun tf2_ros static_transform_publisher 0.2 0.0 0.3 0 0 0 base_link camera_link

Meaning of the parameters:

  • Translation: x=0.2, y=0.0, z=0.3 (meters)
  • Rotation (RPY): roll=0, pitch=0, yaw=0
  • Parent frame: base_link
  • Child frame: camera_link
  1. In another terminal, verify the transform:
bash
rosrun tf tf_echo base_link camera_link

Expected result:

  • The terminal continuously prints the transform.
  • Translation should stay near (0.2, 0.0, 0.3).
  • Rotation should remain close to zero.

If you also open RViz and set Fixed Frame to base_link, you should see camera_link at the configured offset.

Summary

TF is a foundational part of ROS communication and perception. Once the TF tree is well-defined, modules such as mapping, localization, and control can share a consistent spatial understanding of the robot and its environment.