Lesson 9.4: URDF with AI
Writing URDF by hand is tedious. Specifying 20 links and 19 joints gets repetitive. Calculating inertia tensors by hand is error-prone. Now that you understand URDF fundamentals, let's leverage AI collaboration to accelerate development and catch errors.
In this lesson, you'll discover how AI excels at URDF generation—fast boilerplate, mathematical accuracy, consistency—while you provide expertise that AI lacks: robot mechanics intuition, project constraints, and error detection.
The Collaboration Pattern
Manual approach (Lessons 9.1-9.3):
- Write URDF by hand
- Slow but forces deep understanding
- Easy to make mistakes (typos, wrong inertia calculations)
AI-accelerated approach (This lesson):
- Describe robot in English
- AI generates URDF quickly
- You evaluate and refine
- Faster development, AI+human synergy
Example: Describing a Robot to AI
Instead of writing URDF directly, describe what you want:
Your description:
I need a mobile robot with:
- Chassis: rectangular body, 40cm long, 25cm wide, 15cm tall, weighs 8kg
- 4 wheels: 6cm radius, 4cm wide, each weighs 0.5kg
- Mounted on the chassis at front, back, left, right
- All wheels powered (continuous joints)
- Camera mounted on top of chassis, looking forward
You ask AI: "Generate a complete URDF file for this robot"
AI produces: A complete, syntactically correct URDF with:
- All link definitions with calculated inertia values
- All joint definitions with correct positioning
- Camera link and fixed joint
- Material definitions for visualization
- Everything properly indented and balanced
This would take you 30 minutes by hand. AI does it in seconds.
Collaborating with AI: First Iteration
Step 1: Prepare Your Specification
Clearly describe your robot. AI needs specifics:
I'm building a robot for package delivery. Requirements:
- Main chassis: 50cm × 30cm × 20cm box, 10kg aluminum
- Drive wheels: 2 wheels, 8cm radius, mounted on sides
- Steering wheel: 1 smaller wheel in front, 4cm radius
- Motor mounts: aluminum brackets on each corner
- Payload platform: 60cm × 40cm flat surface on top
- Sensors: LiDAR on top, two cameras on front
Step 2: Ask AI to Generate URDF
Prompt to AI:
Generate a complete URDF file for this robot:
[your specification from Step 1]
Include:
- All link definitions with realistic mass and inertia
- All joint definitions (type and positioning)
- Material definitions for visualization
- A comment explaining each major section
Step 3: AI Produces Output
AI generates something like this:
<?xml version="1.0"?>
<robot name="delivery_robot">
<!-- Main chassis link -->
<link name="base_link">
<visual>
<geometry>
<box size="0.5 0.3 0.2"/>
</geometry>
<material name="aluminum">
<color rgba="0.8 0.8 0.8 1"/>
</material>
</visual>
<collision>
<geometry>
<box size="0.5 0.3 0.2"/>
</geometry>
</collision>
<inertial>
<mass value="10.0"/>
<inertia ixx="0.0367" ixy="0" ixz="0"
iyy="0.0717" iyz="0"
izz="0.1042"/>
</inertial>
</link>
<!-- Left wheel -->
<link name="left_wheel">
<visual>
<geometry>
<cylinder length="0.04" radius="0.08"/>
</geometry>
<material name="rubber">
<color rgba="0 0 0 1"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.04" radius="0.08"/>
</geometry>
</collision>
<inertial>
<mass value="0.5"/>
<inertia ixx="0.00267" ixy="0" ixz="0"
iyy="0.00267" iyz="0"
izz="0.0016"/>
</inertial>
</link>
<!-- Left wheel joint -->
<joint name="left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<origin xyz="0 0.2 0" rpy="1.5708 0 0"/>
<axis xyz="0 0 1"/>
</joint>
<!-- More links and joints... -->
</robot>
Step 4: Evaluate the Output
Now you review. AI got some things right, maybe some details wrong. Your job:
What AI did well:
- ✅ Correct XML structure (no syntax errors)
- ✅ Calculated realistic inertia values
- ✅ All links and joints properly named
- ✅ Consistent coordinate frames
- ✅ Proper joint positioning
What to check:
- Does the specified mass match? (AI says 10kg, you want 10kg? Yes ✅)
- Are wheel positions correct? (Left wheel at Y=0.2? Left side? Yes ✅)
- Are joint types right? (Wheels are continuous? Yes ✅)
- Is anything missing? (Camera? Payload? Check the spec...)
Issue found: The camera and payload platform are missing from AI's output.
Step 5: Iterate—Ask AI to Fix It
Your feedback to AI:
Good start! I need to add:
1. A payload platform: 60cm × 40cm × 5cm, flat surface on top of chassis
2. A LiDAR sensor: 10cm cylinder on top center
3. Two cameras: mounted on the front, looking forward
Can you:
1. Define links for payload_platform, lidar, and two cameras
2. Create fixed joints to attach them to base_link
3. Position the cameras to look forward (hint: rotate 90 degrees)
AI refines the URDF:
- Adds payload link with correct dimensions and inertia
- Adds LiDAR as a small cylinder fixed to the top
- Adds two camera links with proper rotation for forward-facing view
- Inserts everything in the right place with consistent formatting
Discovering Common URDF Errors
As you review AI-generated URDF, watch for these mistakes that AI sometimes makes:
Error 1: Wrong Joint Type
AI generates:
<joint name="wheel" type="fixed"> <!-- WRONG: should be continuous -->
You notice: A wheel joint should be continuous (spinning), not fixed.
Your correction: Ask AI to change to continuous and explain why.
Error 2: Missing Axis
AI generates:
<joint name="left_wheel" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<!-- Missing <axis> element! -->
</joint>
You notice: The axis is missing, so the wheel won't spin.
Your correction: Request AI add <axis xyz="0 0 1"/>.
Error 3: Inertia Not Centered
AI generates:
<inertial>
<origin xyz="0.1 0 0" rpy="0 0 0"/> <!-- Offset from center -->
<mass value="1.0"/>
<inertia ixx="0.01" ixy="0" ixz="0"
iyy="0.02" iyz="0"
izz="0.03"/>
</inertial>
You notice: Inertia should be relative to the link's origin. AI offset it, which is wrong.
Your correction: Ask AI to remove the <origin> or explain why it's there.
Error 4: Unrealistic Inertia Values
AI generates:
<inertial>
<mass value="0.001"/> <!-- 1 gram? Way too light -->
<inertia ixx="0.000001" ixy="0" ixz="0"
iyy="0.000001" iyz="0"
izz="0.000001"/>
</inertial>
You notice: The mass is unrealistically light. A 1-gram robot isn't realistic for a delivery platform.
Your correction: Ask AI to recalculate with 0.5kg per wheel (matches your spec).
What AI Excels At (And Where You Shine)
AI Excels At:
- Generating syntactically correct XML quickly
- Calculating inertia values accurately from dimensions
- Creating consistent naming conventions
- Maintaining proper indentation
- Writing boilerplate for repetitive structures
You Excel At:
- Knowing robot mechanics: "This wheel type won't work for rough terrain"
- Catching semantic errors: "The camera rotation is backward"
- Understanding constraints: "This configuration violates our payload limit"
- Validating against real-world: "This inertia matches similar robots I've used"
Real Example: Arm Robot
Your description:
A 3-joint robotic arm:
- Base joint: rotates arm left/right (revolute, limited ±90°)
- Shoulder joint: lifts arm up/down (revolute, limited 0-180°)
- Elbow joint: bends arm (revolute, limited 0-180°)
- End effector: simple gripper
Total arm length: 80cm (30cm shoulder + 30cm elbow + 20cm gripper)
Weight: base 2kg, shoulder 1kg, elbow 0.8kg, gripper 0.5kg
AI generates:
- All links with correct masses
- All joints with proper limits:
<limit lower="-1.5708" upper="1.5708"/> - Correct coordinate frames so links chain: base → shoulder → elbow → gripper
- Material definitions for visualization
You review:
- ✅ Link masses match spec
- ✅ Joint limits are in radians (AI converted degrees correctly)
- ✅ Coordinate frames chain properly
- Issue: AI didn't include effort/velocity limits (important for motor simulation)
You ask AI:
The URDF looks good. I need to add effort and velocity limits
to the revolute joints for motor control simulation.
For a small arm, use:
- effort: 10 N⋅m
- velocity: 1.0 rad/s
Can you add these to all revolute joints?
Result: AI adds the missing parameters, your arm URDF is complete.
Exercise: Generate and Refine
- Describe a robot in plain English (3-4 sentences)
- Ask AI to generate complete URDF
- Review output for the 4 common errors above
- Ask AI to fix any issues
- Validate syntax using
check_urdf
Recognizing When to Override AI
AI suggestions aren't always right. Know when to push back.
Example 1: AI suggests low friction
AI: "I recommend friction coefficient 0.3 for fast robot movement"
You: "Actually, this robot operates outdoors on dirt. I need friction 0.8"
Example 2: AI uses default inertia
AI: "Here's inertia using average robot proportions"
You: "My robot is custom—it's much heavier. I calculated custom inertia values"
Example 3: AI generates one solution
AI: "Here's a standard 4-wheel robot configuration"
You: "Actually, I need 6 wheels for rough terrain. Can you generate that instead?"
Always prioritize your domain knowledge over AI default suggestions.
Try With AI
Setup: You've now learned to generate, evaluate, and refine URDF with AI.
Prompt Set:
Prompt 1: "Design a robot for [specific task: delivery, inspection, etc].
Describe what it should look like and what it needs to do.
Then ask an AI: 'Generate a complete URDF for this robot.'"
Prompt 2: "Review the URDF the AI generated. Find one thing that
might be wrong or could be improved. Ask AI to explain that choice.
Is the explanation convincing, or would you change it?"
Prompt 3: "Ask AI: 'If I wanted to add [sensor/attachment], how would
I modify this URDF?' Use the answer to add something to your robot."
Expected Outcomes:
- AI generates working URDF quickly for new designs
- You catch errors AI might miss (constraint violations, unrealistic values)
- You understand why changes matter (mechanics, physics realism)
- You recognize when AI's default choices need overriding
Safety Note: This lesson marks a transition from manual URDF writing to AI-accelerated development. The risk isn't URDF—it's rushing into Gazebo simulation without validating the robot design matches reality. Always:
- Check that robot dimensions make sense
- Verify mass/inertia against similar real robots
- Test in simulation before deploying to real hardware
- Use this AI-human partnership to catch errors early
Optional Stretch: Ask your AI tool: "Show me a complex robot URDF (robot with 10+ links). Walk me through how each part connects. How would I modify it?"