CodeTheRobot

ROS 2 Lyrical lab 07 ยท 2 hours

tf2, URDF and xacro

Describe a small arm, publish its state and verify every coordinate frame.

Practice this lab in your browser: Compose a transform chain

Understand before building

How this part of ROS 2 works

URDF describes links and joints; tf2 tracks how coordinate frames relate over time. A connected tree lets data be transformed into the frame where a decision is made.

Origins use metres and radians. A plausible-looking model can still be wrong, so inspect numeric transforms as well as RViz.

Before you start

  • Lab 06 complete
  • Radians and coordinate frames

Files you will touch

  • src/training_arm_description/urdf/training_arm.urdf.xacro
  • src/training_arm_description/launch/display.launch.py

Step 1

Set up

sudo apt install ros-lyrical-tf2-tools ros-lyrical-robot-state-publisher ros-lyrical-joint-state-publisher-gui ros-lyrical-rviz2

Step 2

Create the file

<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="training_arm">
  <link name="base_link">
    <visual><geometry><box size="0.3 0.3 0.1"/></geometry></visual>
    <collision><geometry><box size="0.3 0.3 0.1"/></geometry></collision>
  </link>
  <link name="tool0">
    <visual><geometry><cylinder radius="0.03" length="0.4"/></geometry></visual>
    <collision><geometry><cylinder radius="0.03" length="0.4"/></geometry></collision>
  </link>
  <joint name="tool_joint" type="fixed">
    <parent link="base_link"/><child link="tool0"/>
    <origin xyz="0 0 0.25" rpy="0 0 0"/>
  </joint>
</robot>

What each part does

  1. 1.Two links are connected by one fixed joint, making base_link the parent of tool0.
  2. 2.The origin places tool0 half a metre above the base with no rotation.

Step 3

Build, run and inspect

ros2 launch training_arm_description display.launch.py
ros2 run tf2_ros tf2_echo base_link tool0
ros2 run tf2_tools view_frames

Proof that it works

  • RViz shows the model without TF errors
  • tf2_echo reports the 0.5 m transform
  • view_frames creates a connected frame tree

Recovery notes

  • Every non-root link must have exactly one parent joint.
  • Use SI units: metres, kilograms, seconds and radians.
ROS 2 URDF tutorials