URDF Robot Model + RViz Visualisation

Concept

URDF (Unified Robot Description Format) is an XML file describing your robot's geometry, joints, and links. RViz is ROS 2's 3D visualisation tool. The robot_state_publisher node reads the URDF and broadcasts transforms.

Install Dependencies

sudo apt install ros-humble-urdf-tutorial ros-humble-joint-state-publisher-gui -y

Create the URDF File

Save as ~/ROBOT/src/robot_pkg/robot_pkg/my_robot.urdf:

<?xml version="1.0"?>
<robot name="simple_robot">

  <!-- Base link (blue box) -->
  <link name="base_link">
    <visual>
      <geometry>
        <box size="0.5 0.3 0.1"/>
      </geometry>
      <material name="blue">
        <color rgba="0 0 1 1"/>
      </material>
    </visual>
  </link>

  <!-- Left Wheel (black cylinder) -->
  <link name="left_wheel">
    <visual>
      <geometry>
        <cylinder radius="0.05" length="0.04"/>
      </geometry>
      <material name="black">
        <color rgba="0 0 0 1"/>
      </material>
    </visual>
  </link>

  <!-- Right Wheel (black cylinder) -->
  <link name="right_wheel">
    <visual>
      <geometry>
        <cylinder radius="0.05" length="0.04"/>
      </geometry>
      <material name="black">
        <color rgba="0 0 0 1"/>
      </material>
    </visual>
  </link>

  <!-- Left Wheel Joint -->
  <joint name="left_wheel_joint" type="continuous">
    <parent link="base_link"/>
    <child  link="left_wheel"/>
    <origin xyz="0.15 0.17 0" rpy="1.5707 0 0"/>
    <axis xyz="0 0 1"/>
  </joint>

  <!-- Right Wheel Joint -->
  <joint name="right_wheel_joint" type="continuous">
    <parent link="base_link"/>
    <child  link="right_wheel"/>
    <origin xyz="0.15 -0.17 0" rpy="1.5707 0 0"/>
    <axis xyz="0 0 1"/>
  </joint>

</robot>

Visualise in RViz

Terminal 1 — Publish robot description

ros2 run robot_state_publisher robot_state_publisher   --ros-args -p robot_description:="$(cat ~/ROBOT/src/robot_pkg/robot_pkg/my_robot.urdf)"

Terminal 2 — Joint state publisher GUI (spin the wheels)

ros2 run joint_state_publisher_gui joint_state_publisher_gui

Terminal 3 — Open RViz

rviz2

RViz Configuration Steps

  1. In the Global Options panel, set Fixed Frame to base_link
  2. Click Add (bottom left)
  3. Select RobotModel from the list
  4. In the RobotModel panel, set the Description Topic to /robot_description

Expected Result

RViz will show a blue rectangular box (the base) with two black cylinders (the wheels) attached at its sides. The Joint State Publisher GUI lets you rotate the wheels interactively.

URDF Quick Reference

ElementPurpose
<link>A rigid body part of the robot
<joint>Connects two links; defines motion type
<visual>What the link looks like in RViz
<geometry>Shape: box, cylinder, sphere, mesh
<origin>Position & orientation (xyz rpy)