Zero to Gazebo: My Journey Learning URDF and Robot Anatomy
Hey everyone! I’m currently diving headfirst into the world of robotics. If you’ve ever wanted to simulate a robot, you quickly realize that before you can make it move, you have to tell the computer what it is.
That’s where URDF (Unified Robot Description Format) comes in.
I’m putting together this reference guide not just to document my own learning process, but to help anyone else out there who wants a clean, top-to-bottom cheat sheet on building robots for ROS and Gazebo. Let’s break down the anatomy of a robot.
1. The Big Picture: A Robot is Just a Tree
At its core, a URDF file is an XML document that describes a robot as a tree of parts. You start with a base and branch out. There are no closed loops allowed in standard URDF (meaning an arm can’t reach back and grab its own base to form a circle).
The two fundamental building blocks are:
- Links: The solid, rigid physical parts (like a forearm, a chassis, or a wheel).
- Joints: The connections between those parts that dictate how they move relative to each other (like an elbow hinge or a wheel axle).
2. The Tag: Demystifying the Bones
Every link in your robot needs three distinct tags to function properly, especially if you plan to simulate it in Gazebo.
Visual, Collision, and Inertial
<visual>: This is purely cosmetic. It dictates what you see on the screen (color, shape, or a 3D mesh like an.stlor.daefile).<collision>: This is the simplified geometry used by the physics engine to calculate when the robot hits a wall or itself. Keep this as a simple shape (box, cylinder, sphere) to save compute power!<inertial>: Do not skip this! Gazebo requires physical properties to simulate gravity and momentum. It needs the link’s mass and its inertia tensor matrix.
Code Example: A Simple Robot Arm Link
<link name="forearm_link">
<visual>
<origin xyz="0 0 0.25" rpy="0 0 0"/>
<geometry>
<cylinder radius="0.05" length="0.5"/>
</geometry>
<material name="blue">
<color rgba="0 0 1 1"/>
</material>
</visual>
<collision>
<origin xyz="0 0 0.25" rpy="0 0 0"/>
<geometry>
<cylinder radius="0.05" length="0.5"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0.25" rpy="0 0 0"/>
<mass value="2.5"/>
<inertia ixx="0.05" ixy="0.0" ixz="0.0" iyy="0.05" iyz="0.0" izz="0.003"/>
</inertial>
</link>A Quick Math Note on Inertia: The
<inertia>tags (ixx,iyy,izz, etc.) represent the 3x3 inertia tensor matrix:
For a solid cylinder of mass
, radius , and height rotating around the x or y-axis, the formula is:
You rarely calculate this by hand; CAD software or online calculators handle it!
3. The Tag: The Muscles and Ligaments
A joint explicitly connects a Parent Link to a Child Link.
The 4 Main Joint Types
| Type | Behavior | Best Used For |
|---|---|---|
| Fixed | Locked rigidly in place. | Sensors (cameras, lidar) mounted to a chassis. |
| Continuous | Spins freely around an axis with no limits. | Wheels or spinning radar domes. |
| Revolute | Spins around an axis, but has hard rotational limits. | Robotic arms, steering columns, hinges. |
| Prismatic | Slides along an axis in a straight line. | Elevators, telescoping poles, grippers. |
Code Example: A Revolute Elbow Joint
<joint name="elbow_joint" type="revolute">
<parent link="upper_arm_link"/>
<child link="forearm_link"/>
<origin xyz="0 0 0.5" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
<limit lower="-1.57" upper="1.57" effort="50.0" velocity="2.0"/>
<dynamics damping="0.5" friction="0.1"/>
</joint>4. Bridging URDF to Gazebo: Transmissions and Plugins
Standard URDF is just a static model. To make it a living, breathing robot in Gazebo simulation, you have to add “motors” and “brains.”
Transmissions
A <transmission> tag tells Gazebo how a motor connects to a joint (e.g., direct drive, or through a gear reduction).
<transmission name="elbow_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="elbow_joint">
<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
</joint>
<actuator name="elbow_motor">
<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>The Gazebo Plugin
Finally, to allow ROS to talk to these transmissions, we inject a Gazebo plugin into the URDF. This acts as the bridge between your code and the simulation physics.
<gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<robotNamespace>/my_robot</robotNamespace>
</plugin>
</gazebo>Wrapping Up
Learning URDF is essentially learning the anatomy of a machine. Once you understand how to string Links together with Joints, assign them physical weights, and wire up Transmissions, you have the foundational skills to build any robot in simulation!