Skip to content

URDF Project Skeleton: Structuring myros_sketch and Aligning base_link, chassis, and base_footprint

Structure a ROS 2 Jazzy URDF package with CMakeLists.txt and display.launch.py, then align base_footprint, base_link, and chassis frames for accurate Nav2 TF trees.

Contents

Key takeaways

  1. Separating urdf, meshes, launch, rviz, and config directories inside an ament_cmake package and registering them in CMakeLists.txt prevents missing-resource errors after colcon build.
  2. base_footprint represents the 2D ground-plane projection at z=0, base_link marks the 3D kinematic center of differential rotation at wheel-axle height, and chassis holds the physical box geometry and inertia.
  3. Elevating base_link by the wheel radius (0.0325 m) aligns the URDF reference frame with the differential drive rotation axis so wheel odometry and TF transforms share the exact same origin.
  4. Because a TF2 tree permits only a single root link, base_footprint must be the parent of base_link via a fixed joint rather than the reverse.

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 PathFile ExtensionsArchitectural Role and Separation Rationale
urdf/.urdf, .xacroKinematic tree definitions and modular xacro macros
meshes/.stl, .daeDetailed 3D visual assets kept separate from primitive collision shapes
launch/.launch.pyLaunches robot_state_publisher, joint state GUI, and rviz2 together
rviz/.rvizStores Fixed Frame, RobotModel, and TF display settings for reproducible views
config/.yamlHolds 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.

AxisLinear Direction (REP-103)Positive Rotation (Right-Hand Rule)URDF rpy Attribute Slot
X-axisForward (Red axis in RViz)Roll (tilting right side down is negative; left side down is positive)First value (r)
Y-axisLeft (Green axis in RViz)Pitch (nose up is negative; nose down is positive)Second value (p)
Z-axisUpward (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 NameZ Elevation (Above Floor)Kinematic and Structural ResponsibilityPrimary Consumers
base_footprintz = 0.0 m (Ground plane)2D planar projection of the robot center on the floorNav2, SLAM Toolbox, 2D Costmaps
base_linkz = 0.0325 m (Wheel axle)3D rigid-body kinematic reference and differential rotation centerWheel joints, odometry integration, TF tree
chassisz = 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.

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:

  1. Declare dimensional properties (wheel_radius, chassis_length, chassis_width, chassis_height) and the empty base_link pivot frame.
  2. Attach the chassis link via chassis_joint (type="fixed") with complete <visual>, <collision>, and box <inertial> blocks.
  3. Introduce base_footprint at ground level (z = 0) as the parent of base_link via base_footprint_joint, refactoring the TF tree root.

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:

Ixx=m(w2+h2)12,Iyy=m(l2+h2)12,Izz=m(l2+w2)12I_{xx} = \frac{m(w^2 + h^2)}{12}, \qquad I_{yy} = \frac{m(l^2 + h^2)}{12}, \qquad I_{zz} = \frac{m(l^2 + w^2)}{12}

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 CheckExpected OutputFault Diagnosis if Mismatched
check_urdf root linkroot Link: base_footprint has 1 child(ren)Parent/child reversed on base_footprint_joint or disconnected link
tf2_echo base_footprint base_linkTranslation: [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 RViz2Floats +0.0075 m above the base_footprint gridBox sinks below grid if chassis_height / 2 exceeds wheel_radius
/tf_static message inspectionSingle transform tree from base_footprint to chassisMissing 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 DecisionChosen ConfigurationEngineering Rationale and Downstream Impact
Package build systemament_cmake with install(DIRECTORY ...)Ensures urdf/, meshes/, launch/, rviz/, and config/ are portable across machines and Docker builds
base_link Z elevationRaised to wheel_radius (0.0325 m)Aligns the 3D kinematic pivot directly with the differential wheel axle center
chassis link separationSeparate child link via chassis_jointDecouples body geometry, center of mass, and deck height from the kinematic axle origin
base_footprint rootParent of base_link at z = 0.0 mProvides 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.

Common mistakes

  • Placing base_link directly on the ground plane (z=0) and embedding a large visual mesh inside it, which couples chassis geometry changes to every wheel and sensor offset.
  • Declaring base_footprint as a child of base_link, inverting the TF hierarchy and causing Nav2 costmaps to float above the floor.
  • Creating urdf and launch folders in the source tree without adding an install(DIRECTORY …) rule in CMakeLists.txt, causing ros2 launch to fail with PackageNotFound or file lookup errors.

Pre-flight checklist

  • Are urdf, meshes, launch, rviz, and config directories created in myros_sketch and listed in the CMakeLists.txt install directive?
  • Does package.xml declare runtime dependencies for robot_state_publisher, joint_state_publisher_gui, rviz2, urdf, and xacro?
  • Is base_footprint the single root link at z=0, with base_link positioned at z=0.0325 m (wheel radius)?
  • Does the chassis link define visual, collision, and non-zero box inertial properties computed from mass and dimensions?
  • Do check_urdf and tf2_echo base_footprint base_link confirm a single tree and a +0.0325 m Z translation?

Frequently asked questions

Is base_footprint strictly required, or can a robot operate with base_link alone?
A URDF with only base_link passes check_urdf validation and renders properly in RViz2. However, on mobile platforms where pitch or roll motion occurs during acceleration or uneven floor traversal, a raised base_link shifts vertically relative to the 2D map plane. Providing base_footprint at z=0 gives SLAM and Nav2 a consistent planar pose projection as specified in REP-105.
Should the origin of chassis_joint be set to zero or offset vertically from base_link?
When the geometric center of the chassis box lies at the exact height of the drive wheel axle, the chassis_joint origin is set to xyz=‘0 0 0’. If the chassis plate sits above the motor brackets, a positive Z offset such as +0.02 m to +0.05 m is used. In both cases, verify that the bottom face of the chassis maintains positive ground clearance above z=0.
Do URDF edits require running colcon build every time?
Building the workspace once with colcon build –symlink-install creates symbolic links in the install directory instead of static file copies. Subsequent edits to .urdf or .rviz files take effect immediately upon restarting ros2 launch without recompiling.

Sources & verification

  1. ROS 2 Jazzy — Building a visual robot model with URDF from scratch
  2. REP-0105 — Coordinate Frames for Mobile Platforms
  3. REP-0103 — Standard Units of Measure and Coordinate Conventions
  4. ROS 2 Jazzy — Creating a package

Last verified: