Skip to main content

20-ROS 2 TF2 Coordinate Transformation

1. Introduction to TF2​

Coordinate systems are a fundamental concept in robotics. A complete robotic system often contains many coordinate systems. ROS provides a powerful tool to manage their relationships: TF2.

Reference: tf: The transform library | IEEE


2. Coordinate Systems in Robotics​

In mobile robotics: - base_link represents the robot center - laser_link represents the radar position - odom represents odometry - map represents the global reference

These coordinate relationships can be fixed or dynamic. A reliable coordinate management system is essential.

Coordinate Example

Transformation consists of translation + rotation, represented using a 4×4 matrix. TF2 encapsulates all these calculations.


3. TF Command Line Operations​

This section demonstrates turtle-following using TF2.

note

This demo is recommended to run inside a virtual machine.


3.1 Installing Required Packages​

sudo apt install ros-${ROS_DISTRO}-turtle-tf2-py ros-humble-tf2-tools
sudo pip3 install transforms3d
sudo apt install ros-${ROS_DISTRO}-rqt-tf-tree

Installation


3.2 Starting the Demo​

ros2 launch turtle_tf2_py turtle_tf2_demo.launch.py
ros2 run turtlesim turtle_teleop_key

Turtle Follow


3.3 Viewing the TF Tree​

ros2 run rqt_tf_tree rqt_tf_tree

TF Tree


3.4 Querying Transform Information​

ros2 run tf2_ros tf2_echo turtle2 turtle1

TF Output


3.5 TF Visualization in RViz​

rviz2

Set reference frame to world and add TF plugin.

RViz TF


4. Static Coordinate Transformation​

A static transform defines fixed relations like sensor to base.

4.1 Publishing Static Transform​

ros2 run tf2_ros static_transform_publisher 0 0 3 0 0 3.14 A B

Static TF


4.2 Monitoring Static TF​

ros2 run tf2_ros tf2_echo A B

4.3 Visualizing Static TF​

rviz2

Static TF RViz


5. Case Introduction​

You will: - Implement turtle-follow logic - Implement dynamic TF broadcaster - Implement coordinate monitoring - Apply PID for motion conversion

Advanced: - Time-based TF transformation


6. Turtle Follow Principle​

Principle Diagram

Vectors represent direction and distance between turtles. TF continuously calculates transformations. Velocity is derived from these vectors.


7. Create TF Package​

ros2 pkg create pkg_tf --build-type ament_python --dependencies rclpy --node-name turtle_tf_broadcaster

This generates a TF broadcaster node template.


Maintained by HemiHex​

This documentation is maintained by HemiHex for ROS 2 TF2 workflows.