When engineers open a Unified Robot Description Format (URDF) file for the first time, XML tags such as <link> and <joint> immediately draw attention. Yet in autonomous navigation and physics simulation, erratic robot behavior rarely stems from XML syntax errors—it almost always traces back to where the reference coordinate frames are anchored. After establishing the compute-to-actuator hierarchy in ROS 2 Robot Hardware Architecture and reviewing tag rules in the URDF XML Syntax Guide, the first practical step in building the myros_sketch mobile robot is setting up a clean package structure and defining its three foundational frames: base_footprint, base_link, and chassis.
This tutorial walks through creating the myros_sketch package on Ubuntu 24.04 with ROS 2 Jazzy, configuring package.xml, CMakeLists.txt, and display.launch.py, and assembling a single-root TF2 hierarchy that keeps wheel odometry, 3D collision boxes, and 2D navigation maps mathematically aligned.
Structuring the myros_sketch Package and Build Rules
A production URDF model never travels as an isolated XML file. It is accompanied by 3D visual meshes (.stl or .dae), RViz2 layout profiles (.rviz), Python launch scripts (.launch.py), and controller configuration files (.yaml). Following the ROS 2 Jazzy package creation documentation, creating an ament_cmake package provides a clean mechanism to install asset directories into the workspace share path.
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_cmake myros_sketch \
--dependencies rclcpp rclpy urdf xacro robot_state_publisher joint_state_publisher joint_state_publisher_gui rviz2
cd ~/ros2_ws/src/myros_sketch
mkdir -p urdf meshes launch rviz config
Organizing files into dedicated subdirectories prevents path clutter as the robot grows from a simple box into a multi-sensor platform:
| Directory Path | File Extensions | Architectural Role and Separation Rationale |
|---|---|---|
urdf/ | .urdf, .xacro | Kinematic tree definitions and modular xacro macros |
meshes/ | .stl, .dae | Detailed 3D visual assets kept separate from primitive collision shapes |
launch/ | .launch.py | Launches robot_state_publisher, joint state GUI, and rviz2 together |
rviz/ | .rviz | Stores Fixed Frame, RobotModel, and TF display settings for reproducible views |
config/ | .yaml | Holds parameters for ros2_control, diff_drive_controller, and Nav2 |
Creating directories in src/myros_sketch is not enough on its own. Without an explicit install(DIRECTORY ...) directive in CMakeLists.txt, running colcon build will leave the install/myros_sketch/share/myros_sketch/ directory empty, and any package://myros_sketch/urdf/... URI lookup will fail at runtime.
cmake_minimum_required(VERSION 3.8)
project(myros_sketch)
find_package(ament_cmake REQUIRED)
install(DIRECTORY urdf meshes launch rviz config
DESTINATION share/${PROJECT_NAME}
)
ament_package()
Next, verify that package.xml declares all execution dependencies so that rosdep install can resolve them automatically across developer machines and CI containers:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>myros_sketch</name>
<version>0.1.0</version>
<description>URDF modeling package for the myros_sketch differential drive robot</description>
<maintainer email="[email protected]">Developer</maintainer>
<license>Apache-2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<exec_depend>robot_state_publisher</exec_depend>
<exec_depend>joint_state_publisher</exec_depend>
<exec_depend>joint_state_publisher_gui</exec_depend>
<exec_depend>rviz2</exec_depend>
<exec_depend>urdf</exec_depend>
<exec_depend>xacro</exec_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Coordinate Conventions (REP-103 and REP-105) and the Three Base Frames
Just as robotic arm kinematics requires a fixed base frame before deriving forward and inverse transforms (see Robot Arm Kinematics and Minimum Math for Pick-and-Place), mobile robot modeling starts by locking down axis directions. The REP-0103 Standard Units of Measure and Coordinate Conventions specification mandates SI units (meters, kilograms, seconds, radians) and a right-handed Cartesian frame where +X points forward, +Y points left, and +Z points up. Violating this convention—for instance, modeling the front of the chassis along +Y—causes the robot to appear sideways in RViz2 and flips laser scan geometry relative to odometry.
| Axis | Linear Direction (REP-103) | Positive Rotation (Right-Hand Rule) | URDF rpy Attribute Slot |
|---|---|---|---|
| X-axis | Forward (Red axis in RViz) | Roll (tilting right side down is negative; left side down is positive) | First value (r) |
| Y-axis | Left (Green axis in RViz) | Pitch (nose up is negative; nose down is positive) | Second value (p) |
| Z-axis | Upward (Blue axis in RViz) | Yaw (counter-clockwise rotation viewed from above is positive) | Third value (y) |
Combining REP-0105 Coordinate Frames for Mobile Platforms with modular URDF design splits the robot body into three distinct frames:
| Frame Name | Z Elevation (Above Floor) | Kinematic and Structural Responsibility | Primary Consumers |
|---|---|---|---|
base_footprint | z = 0.0 m (Ground plane) | 2D planar projection of the robot center on the floor | Nav2, SLAM Toolbox, 2D Costmaps |
base_link | z = 0.0325 m (Wheel axle) | 3D rigid-body kinematic reference and differential rotation center | Wheel joints, odometry integration, TF tree |
chassis | z = 0.0325 m (or offset) | Physical body box carrying visual, collision, and inertia tensors | <visual>, <collision>, <inertial>, upper mounts |
The critical architectural decision here is placing base_link at the drive wheel axle height (z = 0.0325 m) while keeping it completely free of visual geometry. A differential drive robot pivots around the midpoint between its left and right wheel contact patches. When base_link sits directly on that axle axis, in-place rotation produces pure yaw without inducing artificial translational arcs in odometry. Separating chassis into its own child link connected via a fixed joint allows engineers to resize or raise the physical body box later without disturbing the wheel axle origin.
Step-by-Step Implementation: From base_link to the base_footprint Root
Rather than writing an entire robot description in one pass, build and verify the foundational tree in three incremental steps following the ROS 2 Jazzy visual URDF tutorial:
- Declare dimensional properties (
wheel_radius,chassis_length,chassis_width,chassis_height) and the emptybase_linkpivot frame. - Attach the
chassislink viachassis_joint(type="fixed") with complete<visual>,<collision>, and box<inertial>blocks. - Introduce
base_footprintat ground level (z = 0) as the parent ofbase_linkviabase_footprint_joint, refactoring the TF tree root.
Steps 1 and 2: Defining base_link, chassis_joint, and Box Inertia
Create urdf/myros_sketch.urdf and define the core dimensions for myros_sketch: a wheel radius of 0.0325 m (65 mm diameter wheel) and an aluminum chassis measuring 0.20 m long, 0.15 m wide, and 0.05 m thick with a mass of 0.45 kg.
<?xml version="1.0"?>
<robot name="myros_sketch" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- Dimensional constants (meters, kilograms) -->
<xacro:property name="wheel_radius" value="0.0325"/>
<xacro:property name="chassis_length" value="0.20"/>
<xacro:property name="chassis_width" value="0.15"/>
<xacro:property name="chassis_height" value="0.05"/>
<material name="aluminum">
<color rgba="0.70 0.72 0.75 1.0"/>
</material>
<!-- Step 1: Kinematic rotation center at wheel axle height -->
<link name="base_link"/>
<!-- Step 2: Fixed joint attaching the physical chassis box to base_link -->
<joint name="chassis_joint" type="fixed">
<parent link="base_link"/>
<child link="chassis"/>
<origin xyz="0 0 0" rpy="0 0 0"/>
</joint>
<link name="chassis">
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="${chassis_length} ${chassis_width} ${chassis_height}"/>
</geometry>
<material name="aluminum"/>
</visual>
<collision>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="${chassis_length} ${chassis_width} ${chassis_height}"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.45"/>
<inertia ixx="9.375e-4" ixy="0.0" ixz="0.0"
iyy="1.594e-3" iyz="0.0" izz="2.344e-3"/>
</inertial>
</link>
Even though chassis_joint is fixed and has zero degrees of freedom, robot_state_publisher still broadcasts its transform on /tf_static. With base_link at z = 0.0325 m and chassis_joint at origin xyz="0 0 0", the bottom face of the 0.05 m thick chassis sits at $0.0325 - 0.025 = 0.0075\text{ m}$ (7.5 mm ground clearance), and the top deck sits at $0.0325 + 0.025 = 0.0575\text{ m}$ above the floor. On larger platforms—for example, a 0.30 × 0.20 × 0.06 m chassis weighing 1.2 kg mounted above the axle—setting origin xyz="0 0 0.05" on chassis_joint raises the body while preserving base_link as the axle reference.
Physics engines such as Gazebo require positive-definite principal moments of inertia in <inertial>. For a solid rectangular box of mass $m$, length $l$ (along X), width $w$ (along Y), and height $h$ (along Z), the principal moments about its center of mass are:
Substituting $m = 0.45\text{ kg}$, $l = 0.20\text{ m}$, $w = 0.15\text{ m}$, and $h = 0.05\text{ m}$ yields $I_{xx} = 9.375 \times 10^{-4}\text{ kg}\cdot\text{m}^2$, $I_{yy} = 1.594 \times 10^{-3}\text{ kg}\cdot\text{m}^2$, and $I_{zz} = 2.344 \times 10^{-3}\text{ kg}\cdot\text{m}^2$. Leaving inertia values at zero causes numerical singularities that make simulated robots explode or fall through the ground plane.
Step 3: Refactoring the TF Tree Root with base_footprint
To complete urdf/myros_sketch.urdf, add base_footprint and base_footprint_joint. Pay strict attention to the parent-child direction: base_footprint must be the <parent> and base_link must be the <child>.
<!-- Step 3: Ground projection root frame (z = 0) -->
<link name="base_footprint"/>
<joint name="base_footprint_joint" type="fixed">
<parent link="base_footprint"/>
<child link="base_link"/>
<origin xyz="0 0 ${wheel_radius}" rpy="0 0 0"/>
</joint>
</robot>
Adding these seven lines at the bottom of the file performs a structural root refactoring. Whereas base_link was previously the root link, base_footprint now becomes the single root of the entire kinematic tree at z = 0, and base_link is shifted upward by ${wheel_radius} (+0.0325 m). All downstream joints attached to base_link or chassis retain their local relative origins unchanged.
Creating display.launch.py and Verifying Transforms with tf2_echo
To inspect the model in RViz2 and broadcast /tf_static, create launch/display.launch.py. Passing the URDF file through Command(['xacro ', ...]) inside ParameterValue(..., value_type=str) ensures that xacro properties such as ${wheel_radius} are evaluated before robot_state_publisher parses the XML string.
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import Command, LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue
def generate_launch_description():
pkg_share = get_package_share_directory('myros_sketch')
default_model_path = os.path.join(pkg_share, 'urdf', 'myros_sketch.urdf')
return LaunchDescription([
DeclareLaunchArgument(
name='model',
default_value=default_model_path,
description='Absolute path to robot urdf/xacro file'
),
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{
'robot_description': ParameterValue(
Command(['xacro ', LaunchConfiguration('model')]),
value_type=str
)
}]
),
Node(
package='joint_state_publisher_gui',
executable='joint_state_publisher_gui',
name='joint_state_publisher_gui'
),
Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen'
),
])
Build the workspace with --symlink-install and validate both the XML structure and numerical TF broadcasts:
cd ~/ros2_ws
colcon build --symlink-install --packages-select myros_sketch
source install/setup.bash
# 1. Expand xacro macros and validate the URDF tree structure
xacro src/myros_sketch/urdf/myros_sketch.urdf > /tmp/parsed.urdf
check_urdf /tmp/parsed.urdf
# 2. Launch robot_state_publisher and RViz2
ros2 launch myros_sketch display.launch.py
# 3. In a second terminal, verify exact TF translations and generate frames.pdf
ros2 run tf2_ros tf2_echo base_footprint base_link
ros2 run tf2_tools view_frames
Verify the output against the following diagnostic table:
| Verification Check | Expected Output | Fault Diagnosis if Mismatched |
|---|---|---|
check_urdf root link | root Link: base_footprint has 1 child(ren) | Parent/child reversed on base_footprint_joint or disconnected link |
tf2_echo base_footprint base_link | Translation: [0.000, 0.000, 0.033] (0.0325 m) | 0.000 indicates missing Z origin; -0.033 indicates inverted joint direction |
| Chassis bottom clearance in RViz2 | Floats +0.0075 m above the base_footprint grid | Box sinks below grid if chassis_height / 2 exceeds wheel_radius |
/tf_static message inspection | Single transform tree from base_footprint to chassis | Missing robot_description parameter or unexpanded xacro expression |
Architectural Trade-Offs in Base Frame Design
Before moving on to the drivetrain, review the five engineering decisions embedded in this base package skeleton and how they prevent downstream failures in navigation and simulation:
| Architectural Decision | Chosen Configuration | Engineering Rationale and Downstream Impact |
|---|---|---|
| Package build system | ament_cmake with install(DIRECTORY ...) | Ensures urdf/, meshes/, launch/, rviz/, and config/ are portable across machines and Docker builds |
base_link Z elevation | Raised to wheel_radius (0.0325 m) | Aligns the 3D kinematic pivot directly with the differential wheel axle center |
chassis link separation | Separate child link via chassis_joint | Decouples body geometry, center of mass, and deck height from the kinematic axle origin |
base_footprint root | Parent of base_link at z = 0.0 m | Provides a stable 2D planar projection required by SLAM Toolbox and Nav2 costmaps |
| Primitive box collision | <box size="0.20 0.15 0.05"/> | Delivers deterministic contact normals and fast collision checking compared to high-poly STL meshes |
When you later replace the <visual> block of chassis with a textured .stl or .dae mesh exported from CAD, keep the <collision> block as this simple primitive box. Physics engines evaluate collision geometry at every simulation step (typically 500 Hz to 1,000 Hz), and primitive boxes prevent narrow-phase mesh tunneling while keeping CPU usage low.
With the package folder conventions locked in and the three base frames verified, the chassis currently floats 7.5 mm above the floor ready to receive its drivetrain. Continue to Modeling Differential Drive Wheels and Casters in URDF to attach continuous drive wheel joints, orient cylinder primitives along the Y-axis, and configure low-friction spherical casters.