Overview
TF (Transform) is ROS2’s system for managing coordinate frames and transformations between them. Every sensor, link, and map has its own coordinate frame, and TF tracks the spatial relationships between all frames over time.Coordinate Frames
Track position/orientation of sensors relative to robot
Transform Tree
Hierarchical tree of all coordinate transformations
Why TF?
Problem without TF:Coordinate Frames in Mecanum Robot
- map: Global reference frame (fixed, doesn’t drift)
- odom: Odometry frame (smooth but drifts over time)
- base_link: Robot’s center (moves with robot)
- lidar_link, imu_link: Sensor frames (fixed relative to base_link)
TF Broadcasting
Static Transforms (Fixed Relationships)
For sensors mounted on robot (don’t move relative to base_link):static_tf_publisher.py
Dynamic Transforms (Moving Relationships)
For moving frames (e.g., robot position in world):dynamic_tf_publisher.py
TF Listening (Using Transforms)
Example: Transform LiDAR Scan to Map Frame
tf_listener_example.py
TF Tree Visualization
View TF Tree
Monitor TF in Real-Time
Debugging TF Issues
Common TF Patterns
1. Robot Localization (map → odom → base_link)
- odom → base_link: Smooth, continuous (from encoders)
- map → odom: Jumps when robot localizes (from AMCL/SLAM)
- Separation prevents sudden jumps in local planning
2. Sensor Frames (base_link → sensor_link)
launch/sensors_tf.launch.py
Quaternions vs Euler Angles
TF uses quaternions for rotations (avoids gimbal lock):Best Practices
Frame Naming
- Follow REP-105 conventions
- Use descriptive names:
lidar_link, notsensor1 - Suffix with
_linkfor physical links - Suffix with
_framefor virtual frames
Transform Publishing
- Static transforms: Use
static_transform_publisher - Dynamic transforms: Publish at sensor rate (10-50 Hz)
- Always use latest timestamp
- Don’t publish transforms faster than needed
TF Lookup
- Use
lookup_transform()with try-except - Check
canTransform()before lookup - Handle timeouts gracefully
- Use
rclpy.time.Time()for latest transform
Coordinate Systems
- Follow REP-103: X forward, Y left, Z up
- Align sensor frames with physical mounting
- Validate with
view_framestool - Document frame relationships
Troubleshooting
TF lookup failed: frame does not exist
TF lookup failed: frame does not exist
Symptoms:
Could not find transform from 'map' to 'base_link'Solutions:-
Check if frame is being published:
-
View TF tree to find missing link:
-
Verify publisher node is running:
- Check frame names match exactly (case-sensitive)
Transform timeout / extrapolation error
Transform timeout / extrapolation error
Symptoms:
Lookup would require extrapolation into the futureSolutions:-
Use
rclpy.time.Time()instead of specific timestamp: - Increase transform rate (publish more frequently)
-
Add timeout and retry:
TF tree disconnected / multiple roots
TF tree disconnected / multiple roots
Symptoms: Frames appear disconnected in
view_frames.pdfSolutions:- Ensure single root frame (
maporodom) - Check all parent-child relationships
- Verify
robot_state_publisheris running (for URDF frames) - Look for duplicate frame names
Robot jumps/teleports in RViz
Robot jumps/teleports in RViz
Cause: Sudden changes in
map → odom transformSolutions:- This is normal when using AMCL localization
- Separate
map → odom(AMCL) fromodom → base_link(smooth) - Local planning uses
odom, global planning usesmap - Don’t directly publish
map → base_link
Next Steps
URDF/Xacro
Define robot structure with coordinate frames
Localization
EKF sensor fusion and map → odom transform
Navigation
Use TF for path planning and obstacle avoidance
Data Visualization
View TF tree and transforms in RViz