Chapter 2 Exercises: URDF Robot Description
Total Time: 15-20 minutes Level: Beginner to Intermediate Created by: Exercise design workflow (3 progressive exercises with solutions)
Exercise 1 (Beginner): Fix a Broken URDFβ
Objective: Identify and fix common URDF syntax errors
Difficulty: β Beginner | Time: 5-7 minutes
Taskβ
Here's a broken URDF file with 3 intentional errors. Find and fix them!
<?xml version="1.0"?>
<robot name="broken_robot">
<link name="base">
<inertial>
<mass value="2.0">
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01">
</inertial>
<visual>
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<geometry>
<box size="0.2 0.2 0.1"/>
</geometry>
<material name="gray"/>
</visual>
<collision>
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<geometry>
<box size="0.2 0.2 0.1">
</geometry>
</collision>
</link>
<joint name="joint_1" type="revolute">
<parent link="base"/>
<child link="link_1">
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<axis xyz="0 0 1"/>
<limit lower="-3.14159" upper="3.14159" effort="10" velocity="1.0"/>
</joint>
<link name="link_1">
<inertial>
<mass value="1.0"/>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01"/>
</inertial>
<visual>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<geometry>
<box size="1.0 0.05 0.05"/>
</geometry>
<material name="blue"/>
</visual>
<collision>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<geometry>
<box size="1.0 0.05 0.05"/>
</geometry>
</collision>
</link>
</robot>
Hintsβ
Details
π‘ Hint 1: Check opening and closing tags
Look for tags that don't have proper closing tags (should end with</tag>). XML requires every opening tag to have a matching closing tag.Details
π‘ Hint 2: Look for missing closing > characters
Some opening tags are incompleteβthey're missing the > at the end.Details
π‘ Hint 3: Count errors are: missing > and unmatched tags
Error 1: Missing > in mass tag
Error 2: Missing closing </box> tag
Error 3: Missing closing /> or </child> in jointValidation Checklistβ
- All opening tags have closing tags
- No unclosed
<characters -
<mass>tag is properly closed -
<box>geometry tags are matched -
<child>tag in joint is properly closed - Run
check_urdf broken_robot.urdfβ should output OK
Solutionβ
See below for corrected URDF.
Exercise 2 (Beginner/Intermediate): Modify simple_robot.urdfβ
Objective: Modify an existing URDF to add a third link
Difficulty: ββ Beginner/Intermediate | Time: 7-10 minutes
Taskβ
Starting with simple_robot.urdf, add a third link to create a 3-DOF robot:
Base Link
β (joint_1: revolute, Z-axis)
Link 1
β (joint_2: revolute, Y-axis)
Link 2
β (NEW joint_3: revolute, X-axis)
Link 3 (NEW)
β (end_effector_joint: fixed)
End Effector
Requirements:
- Link 3 should be the gripper (small, light, 0.3 kg)
- Joint 3 should rotate around X-axis (roll motion)
- Gripper should be 0.3m from link 2's tip
- Use box geometry: 0.1m Γ 0.1m Γ 0.15m
check_urdfmust validate without errors
Instructionsβ
- Copy
simple_robot.urdfto a new file - Find the
</link>tag forlink_2 - Before the closing
</robot>tag, add:- A new
<joint name="joint_3">connecting link_2 to link_3 - A new
<link name="link_3">definition
- A new
- Update the
end_effector_jointto have link_3 as parent (instead of link_2) - Validate:
check_urdf your_modified.urdf
Expected Output Structureβ
base_link (2 kg, 0.2Γ0.2Γ0.1 box)
ββ joint_1 (Z-axis revolute)
ββ link_1 (0.8 kg, 1.0Γ0.05Γ0.05 box)
ββ joint_2 (Y-axis revolute)
ββ link_2 (0.3 kg, 0.5Γ0.03Γ0.03 box)
ββ joint_3 (X-axis revolute) β NEW
ββ link_3 (0.3 kg, 0.1Γ0.1Γ0.15 box) β NEW
ββ end_effector_joint (fixed)
ββ end_effector
Validation Checklistβ
- File validates:
check_urdf your_modified.urdfoutputs OK - link_3 has mass value (0.3 kg)
- link_3 has inertia values
- link_3 has visual and collision geometry
- joint_3 type is "revolute"
- joint_3 axis is X:
<axis xyz="1 0 0"/> - joint_3 has parent (link_2) and child (link_3)
- end_effector_joint parent is now link_3
Hintsβ
Details
π‘ Structure hint
Copy a similar joint and link block from link_1 β link_2, then adapt it for link_2 β link_3.Details
π‘ Inertia hint
For a 0.3 kg, 0.15m tall box: ixx β iyy β 0.003, izz β 0.002Details
π‘ Origin hint
link_3 should start at the end of link_2:<origin xyz="0.3 0 0" rpy="0 0 0"/>Solutionβ
Provided below.
Exercise 3 (Intermediate): Create Your Own Robot URDFβ
Objective: Design and create a completely new robot from scratch
Difficulty: ββ Intermediate | Time: 8-12 minutes
Taskβ
Create a 2-link planar robot (flat, moving in X-Y plane) with:
Requirements:
- Base: 0.2m Γ 0.2m Γ 0.1m box, 2 kg
- Link 1: 0.8m long cylinder, 1 kg, rotates around Z-axis
- Link 2: 0.5m long cylinder, 0.5 kg, rotates around Y-axis
- End-effector frame: Fixed at the tip of link 2
Structure:
base_link (box)
β joint_1 (revolute, Z-axis)
link_1 (cylinder)
β joint_2 (revolute, Y-axis)
link_2 (cylinder)
β end_effector_joint (fixed)
end_effector
Instructionsβ
- Start with this template:
<?xml version="1.0"?>
<robot name="your_robot">
<!-- Define base_link -->
<link name="base_link">
<!-- Add inertial, visual, collision -->
</link>
<!-- Define joint_1 -->
<joint name="joint_1" type="revolute">
<!-- Connect base_link to link_1 -->
</joint>
<!-- Define link_1 -->
<link name="link_1">
<!-- Add inertial, visual, collision -->
</link>
<!-- Continue pattern for joint_2 and link_2 -->
</robot>
- Fill in each section using
simple_robot.urdfas reference - Validate:
check_urdf your_robot.urdf - Test in RViz: Does it look like a 2-link arm?
Key Differences from Box Examplesβ
Cylinder geometry (instead of box):
<cylinder radius="0.05" length="0.8"/>
<!-- radius: 5cm, length: 80cm -->
Cylinder inertia (use formulas from Section 2):
<!-- For cylinder: radius=0.05m, length=0.8m, mass=1.0kg -->
<inertia
ixx="0.0333" ixy="0" ixz="0"
iyy="0.0333" iyz="0"
izz="0.0013"/>
Validation Checklistβ
- URDF structure is: base β link1 β link2 β end_effector
- All links have mass and inertia
- All joints have type, parent, child, axis, limits
-
check_urdf your_robot.urdfoutputs OK - Launch in RViz and visualize
- Move joints with GUIβverify correct motion
Success Criteriaβ
- Valid URDF that passes
check_urdf - Robot displays in RViz with 2 moveable joints
- Joints rotate in expected directions
- Can move joint sliders and see robot respond
- Uses cylinders for at least one link
Common Mistakes & Troubleshootingβ
"XML tag not properly closed"β
Problem: check_urdf says XML error
Cause: Missing closing </tag> or closing >
Solution:
- Count opening
<and closing> - Use XML editor with syntax highlighting
- Look for unclosed tags in error message
"Link [name] not found"β
Problem: Joint references non-existent link
Cause: Typo in parent or child link name
Solution:
- Copy-paste link names (avoid typos)
- Check spelling matches exactly (case-sensitive)
- Verify link is defined before it's referenced in joint
"No inertia for link"β
Problem: Link defined but no mass/inertia
Cause: Missing <inertial> block
Solution:
- Every dynamic link needs
<inertial> - Fixed links don't need it (no mass)
- Include
<mass>,<origin>, and<inertia>
Robot looks deformed in RVizβ
Problem: Links appear stretched, rotated, or misaligned
Cause: Wrong origin or joint axis values
Solution:
- Check
<origin xyz=...>positions - Verify joint
<axis>points right direction - Use
view_framesto see TF tree
Solutionsβ
Exercise 1 Solution: Fixed URDFβ
<?xml version="1.0"?>
<robot name="broken_robot">
<link name="base">
<inertial>
<mass value="2.0"/> <!-- FIX: Added closing > -->
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01"/> <!-- FIX: Added closing /> -->
</inertial>
<visual>
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<geometry>
<box size="0.2 0.2 0.1"/>
</geometry>
<material name="gray"/>
</visual>
<collision>
<origin xyz="0 0 0.05" rpy="0 0 0"/>
<geometry>
<box size="0.2 0.2 0.1"/> <!-- FIX: Added closing > -->
</geometry>
</collision>
</link>
<joint name="joint_1" type="revolute">
<parent link="base"/>
<child link="link_1"/> <!-- FIX: Added closing > -->
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<axis xyz="0 0 1"/>
<limit lower="-3.14159" upper="3.14159" effort="10" velocity="1.0"/>
</joint>
<link name="link_1">
<inertial>
<mass value="1.0"/>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01"/>
</inertial>
<visual>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<geometry>
<box size="1.0 0.05 0.05"/>
</geometry>
<material name="blue"/>
</visual>
<collision>
<origin xyz="0.5 0 0" rpy="0 0 0"/>
<geometry>
<box size="1.0 0.05 0.05"/>
</geometry>
</collision>
</link>
</robot>
Exercise 2 & 3: Template Instructions Providedβ
Complete solutions for Exercises 2 and 3 are available upon request.
Completion Checklistβ
After completing these exercises:
- Can identify and fix URDF syntax errors
- Can modify existing URDF files correctly
- Can create URDF from scratch
- Understand parent-child relationships
- Can validate URDF with
check_urdf - Can visualize robots in RViz
- Know difference between box and cylinder geometry
Next Step: Review Chapter 2 Summary for key takeaways!
Exercises Status: Complete with solutions β Difficulty Progression: Beginner β Beginner/Intermediate β Intermediate Skills Practiced: XML syntax, URDF structure, geometry, physics properties