TF debug tool
Three tools used throughout every module when working with TF: static_transform_publisher (publish a static transform without writing code), view_frames (draw the entire current TF tree to file), tf2_echo (see the value of a transform in real time).
static_transform_publisher — static publishing without coding
Publish once to /tf_static, suitable for permanently fixed relationships (for example, sensors mounted rigidly on the robot chassis, without moving joints). This is exactly how demo_tf.launch.py produces static_frame:
ros2 run tf2_ros static_transform_publisher \
--x 1.0 --y 0.0 --z 0.5 --frame-id world --child-frame-id static_frame
No need to write TransformBroadcaster by hand for simple static cases like this.
Distinguish between dynamic and static, right on real data
The two commands tf2_echo below run on 2 transforms of demo_tf.launch.py: one dynamic, one static.
view_frames — draw the whole tree to file
Listen to /tf + /tf_static for 5 seconds, export a PDF file drawing the existing TF tree, with the publishing frequency of each frame — useful to detect which frames are "dead" (frequency 0 or not appearing in the tree):
ros2 run tf2_tools view_frames
RViz — the most intuitive way
Display TF in RViz (turn each frame on/off, visually view the XYZ axis) is the most intuitive way to "see" the moving TF tree, instead of reading numbers in the terminal.
Try it
Need 2 terminals (already source install/setup.bash, see Module 0):
# Terminal 1 — keep running; do not close
ros2 launch ros2_basics demo_tf.launch.py
# Terminal 2 — exits after 5 seconds, opens the exported PDF for comparison
ros2 run tf2_tools view_frames
# Terminal 2 — continuously changing data: frame DYNAMIC. Ctrl+C to stop
ros2 run tf2_ros tf2_echo world moving_frame
# Terminal 2 — data will NOT change: frame STATIC. Ctrl+C to stop
ros2 run tf2_ros tf2_echo world static_frame
Example in the Atlas project
From Module 4 onwards, this is the first set of commands to run whenever the robot "is not in the correct place" in RViz or Nav2 reports error TF:
ros2 run tf2_tools view_frames # Does Atlas's real TF tree have enough frames?
ros2 run tf2_ros tf2_echo map base_link # Where is the robot on the map?
ros2 run tf2_ros tf2_echo odom base_link # Are you drifting abnormally?
These commands are not just for practice — I used tf2_echo/view_frames myself to actually debug during the construction of atlas_control/atlas_slam, for example to confirm whether diff_drive_controller published correctly or not odom→base_footprint before suspecting AMCL.