A URDF file describes a robot's parts and how they connect. It helps robots understand their shape and move correctly.
Building a simple robot arm URDF in ROS
Start learning this pattern below
Jump into concepts and practice - no test required
<robot name="robot_name"> <link name="link_name"> <!-- Visual, collision, and inertial elements --> </link> <joint name="joint_name" type="joint_type"> <parent link="parent_link"/> <child link="child_link"/> <origin xyz="x y z" rpy="roll pitch yaw"/> <axis xyz="x y z"/> </joint> </robot>
The <robot> tag wraps the whole robot description.
Each <link> is a part of the robot, and <joint> connects two links.
<robot name="simple_arm"> <link name="base_link"/> <link name="arm_link"/> <joint name="base_to_arm" type="revolute"> <parent link="base_link"/> <child link="arm_link"/> <origin xyz="0 0 0.1" rpy="0 0 0"/> <axis xyz="0 0 1"/> </joint> </robot>
<robot name="two_joint_arm"> <link name="base_link"/> <link name="link1"/> <link name="link2"/> <joint name="joint1" type="revolute"> <parent link="base_link"/> <child link="link1"/> <origin xyz="0 0 0.1" rpy="0 0 0"/> <axis xyz="0 0 1"/> </joint> <joint name="joint2" type="revolute"> <parent link="link1"/> <child link="link2"/> <origin xyz="0 0 0.5" rpy="0 0 0"/> <axis xyz="0 1 0"/> </joint> </robot>
This URDF defines a simple robot arm with a base and one arm link connected by a rotating joint. The base is a small box, and the arm is a blue cylinder that can rotate around the base.
<?xml version="1.0"?> <robot name="simple_robot_arm"> <link name="base_link"> <visual> <geometry> <box size="0.2 0.2 0.1"/> </geometry> <material name="gray"> <color rgba="0.5 0.5 0.5 1"/> </material> </visual> </link> <link name="arm_link"> <visual> <geometry> <cylinder length="0.5" radius="0.05"/> </geometry> <material name="blue"> <color rgba="0 0 1 1"/> </material> </visual> </link> <joint name="base_to_arm" type="revolute"> <parent link="base_link"/> <child link="arm_link"/> <origin xyz="0 0 0.05" rpy="0 0 0"/> <axis xyz="0 0 1"/> </joint> </robot>
Always check your URDF in visualization tools like RViz to see if it looks right.
Use clear names for links and joints to avoid confusion.
Define the origin carefully to position parts correctly relative to each other.
A URDF file describes robot parts (links) and how they connect (joints).
Use <link> for parts and <joint> to connect them.
Visualize your URDF to make sure your robot looks and moves as expected.
Practice
Solution
Step 1: Understand URDF role
A URDF file defines the robot's physical structure, including parts and joints.Step 2: Differentiate from other files
Control software, sensor data, and firmware are handled separately, not in URDF.Final Answer:
To describe the robot's parts and how they connect -> Option AQuick Check:
URDF = robot structure description [OK]
- Confusing URDF with control code
- Thinking URDF stores sensor data
- Assuming URDF compiles firmware
Solution
Step 1: Identify correct URDF tag for a link
The <link> tag with a name attribute defines a robot part.Step 2: Check syntax correctness
<link name="arm_link"/> uses correct self-closing tag with name attribute. <link arm_link></link> misses quotes and uses open-close tags unnecessarily. Options A and B use wrong tags.Final Answer:
<link name="arm_link"/> -> Option AQuick Check:
Link tag syntax = <link name="arm_link"/> [OK]
- Using <joint> instead of <link> for parts
- Missing quotes around name
- Using non-existent <part> tag
elbow_joint?
<joint name="elbow_joint" type="revolute"> <parent link="upper_arm"/> <child link="forearm"/> </joint>
Solution
Step 1: Locate parent link in joint tag
The <parent> tag inside the joint defines the parent link connected by the joint.Step 2: Read the parent link attribute
Here, parent link="upper_arm" means the joint connects from upper_arm to forearm.Final Answer:
upper_arm -> Option DQuick Check:
Parent link = upper_arm [OK]
- Confusing parent and child links
- Choosing joint name as parent
- Picking child link as parent
<joint name="wrist_joint" type="fixed"> <parent link="forearm"/> <child link="hand"> </joint>
Solution
Step 1: Check XML tag completeness
The <child> tag is opened but not closed properly.Step 2: Verify joint type and names
Joint type 'fixed' is valid, parent link name looks correct, underscores in names are allowed.Final Answer:
Missing closing tag for <child> -> Option CQuick Check:
Unclosed tag error = Missing closing tag for <child> [OK]
- Ignoring unclosed tags
- Thinking 'fixed' is invalid joint type
- Assuming underscores are disallowed
Solution
Step 1: Confirm joint type and link order
The joint should be revolute, connecting parent 'forearm' to child 'wrist'.Step 2: Check rotation axis
The axis must be around Z axis: xyz="0 0 1".Step 3: Validate options
<joint name="wrist_joint" type="revolute"> <parent link="forearm"/> <child link="wrist"/> <axis xyz="0 0 1"/> </joint> matches all requirements. <joint name="wrist_joint" type="fixed"> <parent link="wrist"/> <child link="forearm"/> <axis xyz="0 0 1"/> </joint> reverses parent and child and uses fixed type. <joint name="wrist_joint" type="revolute"> <parent link="wrist"/> <child link="forearm"/> <axis xyz="1 0 0"/> </joint> reverses links and uses wrong axis. <joint name="wrist_joint" type="continuous"> <parent link="forearm"/> <child link="wrist"/> <axis xyz="0 1 0"/> </joint> uses continuous type and wrong axis.Final Answer:
<joint name="wrist_joint" type="revolute"> <parent link="forearm"/> <child link="wrist"/> <axis xyz="0 0 1"/> </joint> -> Option BQuick Check:
Correct joint type + parent-child + axis = <joint name="wrist_joint" type="revolute"> <parent link="forearm"/> <child link="wrist"/> <axis xyz="0 0 1"/> </joint> [OK]
- Swapping parent and child links
- Using wrong joint type
- Setting axis to wrong vector
