CodeTheRobot

Ubuntu Linux for Robotics · Lesson 56 of 96

TF2 transforms

Inspecting the transform tree with the Ubuntu tools and publishing static frames.

Estimated time · 45–75 min

Learning goals

What you will understand

  • Explain tf2 transforms in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

TF2 keeps a tree of coordinate frames. From the terminal you can publish a fixed frame with ros2 run tf2_ros static_transform_publisher, read a transform with tf2_echo and draw the whole tree with view_frames (which creates frames.pdf you can open with xdg-open).

Every frame must have exactly one parent and the tree must be connected. The most common mistakes are two publishers for the same frame, a missing map → odom transform and mismatched timestamps (use_sim_time). Check them with tf2_monitor.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the tf2 transforms commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ros2 run tf2_ros static_transform_publisher --x 0.2 --z 0.3 --frame-id base_link --child-frame-id lidar_link
# Publish a fixed lidar mount.
ros2 run tf2_ros tf2_echo base_link lidar_link
# Print the transform between two frames.
ros2 run tf2_tools view_frames
# Draw the whole tree into frames.pdf.
xdg-open frames.pdf
# Open the drawing.
ros2 run tf2_ros tf2_monitor
# Show how often each frame is published.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · Robot arm

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

tip x110 y58ROBOT ARM

Demo for TF2 transforms. Expected result: Translation: [0.200, 0.000, 0.300]

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

ros2 run tf2_ros static_transform_publisher --x 0.2 --z 0.3 --frame-id base_link --child-frame-id lidar_link &
# TODO: print the transform between base_link and lidar_link with tf2_echo

Expected output

Translation: [0.200, 0.000, 0.300]
Stuck? Show the full solution (try it yourself first)
ros2 run tf2_ros static_transform_publisher --x 0.2 --z 0.3 --frame-id base_link --child-frame-id lidar_link &
ros2 run tf2_ros tf2_echo base_link lidar_link

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Publish two static frames, draw the tree, then publish the same child frame from two terminals and observe the flicker in tf2_monitor.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.