When a newly assembled differential drive robot veers off course or spins in circles upon receiving a straight-line velocity command, hardware builders often suspect motor wiring or encoder polarity first. In ROS 2 simulation and ros2_control deployments, however, the root cause frequently lies inside the URDF: an inverted joint <axis>, an unrotated cylinder primitive, or a caster Z-offset that lifts the drive tires slightly off the floor. Having established the package layout and elevated base_link to axle height (z = 0.0325 m) in URDF Project Skeleton: Structuring myros_sketch and Aligning base_link, chassis, and base_footprint and reviewed tag syntax in the URDF XML Syntax Guide, we can now attach the drive wheels and caster with physical precision.
This tutorial covers differential drive kinematics, orienting cylinder primitives along the Y-axis, unifying left and right continuous joint axes, calculating rotational inertia and Gazebo contact friction for spherical casters, and matching joint identifiers with diff_drive_controller.
Connecting Differential Drive Kinematics to URDF Geometry
A differential drive platform steers solely by varying the angular velocities of its left and right drive wheels ($\omega_L$ and $\omega_R$). Given a wheel radius $r$ and a wheel separation (track width) $L$ between the left and right tire contact centers, the forward linear velocity $v$ and yaw angular velocity $\omega$ of the robot’s kinematic center (base_link) are governed by forward kinematics:
Conversely, when Nav2 or a teleoperation node publishes a /cmd_vel twist command ($v, \omega$), diff_drive_controller computes the target angular velocities for each motor using the inverse kinematics equations:
In myros_sketch, the physical parameters are $r = 0.0325\text{ m}$ and $L = 0.16\text{ m}$ (with wheels positioned at $y = \pm 0.08\text{ m}$):
- Straight forward motion ($v = 0.2\text{ m/s}, \omega = 0$): $\omega_R = \omega_L = 0.2 / 0.0325 \approx 6.154\text{ rad/s}$ (roughly $58.8\text{ rpm}$).
- In-place counter-clockwise rotation ($v = 0, \omega = 1.0\text{ rad/s}$): $\omega_R = +0.08 / 0.0325 \approx +2.462\text{ rad/s}$ and $\omega_L = -2.462\text{ rad/s}$.
For odometry integration and simulated physics to agree with these equations, the <cylinder radius="0.0325"> geometry and the <origin xyz="0 ±0.08 0"> joint offsets in the URDF must match the controller YAML parameters exactly.
Comparing Wheel and Caster Coordinate Conventions
Across ROS 2 repositories, you will encounter two common conventions for attaching wheels and casters: anchoring them directly to base_link (at axle height) or anchoring them to chassis (when chassis is offset above base_link).
| Design Parameter | Convention A (Parent: base_link, 3-Point Support) | Convention B (Parent: chassis, 4-Point Support) | Integration Rule for ros2_control & TF2 |
|---|---|---|---|
| Wheel Link & Joint Names | wheel_left_link / wheel_left_joint | left_wheel / left_wheel_joint | Whether named wheel_left_link or left_wheel, the joint name in diff_drive_controller YAML must match the URDF <joint name> |
| Wheel Dimensions & Origin | $r=0.0325\text{ m}, w=0.026\text{ m}$, xyz="0 ±0.08 0" from base_link | $r=0.033\text{ m}, w=0.020\text{ m}$, xyz="0 ±0.11 -0.03" from chassis | The wheel axle Z height above base_footprint must equal the wheel radius $r$ |
| Caster Link & Origin | Single front caster_link ($r=0.0125\text{ m}$), xyz="0.075 0 -0.020" | Front & rear front_caster, rear_caster ($r=0.015\text{ m}$), xyz="±0.10 0 -0.045" | The lowest point of the caster sphere must lie on the exact same z=0 plane as the tires |
Notice that whether links are named wheel_left_link/caster_link or left_wheel/front_caster, ros2_control and diff_drive_controller bind hardware interfaces strictly by the URDF <joint name="..."> string. Below, we implement Convention A because placing base_link at the wheel axle height sets the wheel joint Z coordinate cleanly to 0.
Rotating the Cylinder Primitive (rpy) and Aligning Wheel Inertia
In URDF, the default symmetry axis of a <cylinder> primitive points along the Z-axis (vertical). Under REP-0103 coordinate conventions, however, a forward-moving robot (+X) rolls its wheels around the Y-axis (lateral left). If you insert a cylinder without rotating its local origin, the wheel lies flat on its side like a coin.
To lay the cylinder along the Y-axis, apply a 90-degree rotation about the X-axis (rpy="1.5708 0 0", since $\pi / 2 \approx 1.570796\text{ rad}$) inside the <visual> and <collision> origin tags:
<link name="wheel_left_link">
<visual>
<origin xyz="0 0 0" rpy="1.5708 0 0"/>
<geometry>
<cylinder radius="0.0325" length="0.026"/>
</geometry>
<material name="rubber">
<color rgba="0.15 0.15 0.15 1.0"/>
</material>
</visual>
<collision>
<origin xyz="0 0 0" rpy="1.5708 0 0"/>
<geometry>
<cylinder radius="0.0325" length="0.026"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.05"/>
<inertia ixx="1.602e-5" ixy="0.0" ixz="0.0"
iyy="2.641e-5" iyz="0.0" izz="1.602e-5"/>
</inertial>
</link>
As emphasized in the ROS 2 Jazzy physical and collision properties tutorial, rotating the wheel geometry so its axle lies along the Y-axis means the principal moment of inertia about the spinning axle is $I_{yy}$, while $I_{xx}$ and $I_{zz}$ represent the transverse axes:
For a wheel of mass $m = 0.05\text{ kg}$, radius $r = 0.0325\text{ m}$, and width $h = 0.026\text{ m}$, these formulas yield $I_{yy} = 2.641 \times 10^{-5}\text{ kg}\cdot\text{m}^2$ and $I_{xx} = I_{zz} = 1.602 \times 10^{-5}\text{ kg}\cdot\text{m}^2$.
Configuring Continuous Joints and Unifying Left/Right Axis Signs
According to the ROS Wiki URDF joint specification, type="continuous" describes an unbounded hinge joint around a single axis. Below are the left and right wheel joint declarations:
<joint name="wheel_left_joint" type="continuous">
<parent link="base_link"/>
<child link="wheel_left_link"/>
<origin xyz="0 0.08 0" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
<limit effort="1.5" velocity="20.0"/>
<dynamics damping="0.05" friction="0.02"/>
</joint>
<joint name="wheel_right_joint" type="continuous">
<parent link="base_link"/>
<child link="wheel_right_link"/>
<origin xyz="0 -0.08 0" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
<limit effort="1.5" velocity="20.0"/>
<dynamics damping="0.05" friction="0.02"/>
</joint>
Follow these four engineering steps when defining differential wheel joints:
- Set the joint Z coordinate to zero (
z = 0): Becausebase_linkis already elevated toz = 0.0325 mabovebase_footprint, placing the wheel joint atz = 0relative tobase_linkputs the tire contact patch flush on the ground plane (z = 0). - Keep both joint axes identical (
axis xyz="0 1 0"): By the right-hand rule, pointing your thumb along +Y (to the left) curls your fingers in the direction of forward wheel roll. Applying a positive angular velocity (+$\omega$) to0 1 0rolls both the left and right wheels forward. Never flip the right wheel axis to0 -1 0—doing so causes the right wheel to spin backward on a positive command. - Specify physical
<limit>and<dynamics>bounds: Even though acontinuousjoint has no angle limits, specifyingeffort="1.5"(N·m) andvelocity="20.0"(rad/s, equivalent to0.65 m/slinear speed) along with viscousdamping="0.05"prevents simulation controllers from commanding infinite torque spikes. - Encapsulate left/right symmetry in a xacro macro: Passing
prefix(left/right) andy_reflect(1/-1) into<xacro:macro name="wheel" params="prefix y_reflect">lets you computeorigin xyz="0 ${y_reflect * wheel_separation / 2} 0"while keeping<axis xyz="0 1 0"/>invariant.
<xacro:macro name="drive_wheel" params="prefix y_reflect">
<link name="wheel_${prefix}_link">
<visual>
<origin xyz="0 0 0" rpy="1.5708 0 0"/>
<geometry>
<cylinder radius="${wheel_radius}" length="0.026"/>
</geometry>
<material name="rubber"/>
</visual>
<collision>
<origin xyz="0 0 0" rpy="1.5708 0 0"/>
<geometry>
<cylinder radius="${wheel_radius}" length="0.026"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.05"/>
<inertia ixx="1.602e-5" ixy="0.0" ixz="0.0"
iyy="2.641e-5" iyz="0.0" izz="1.602e-5"/>
</inertial>
</link>
<joint name="wheel_${prefix}_joint" type="continuous">
<parent link="base_link"/>
<child link="wheel_${prefix}_link"/>
<origin xyz="0 ${y_reflect * 0.08} 0" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
<limit effort="1.5" velocity="20.0"/>
<dynamics damping="0.05" friction="0.02"/>
</joint>
</xacro:macro>
<xacro:drive_wheel prefix="left" y_reflect="1"/>
<xacro:drive_wheel prefix="right" y_reflect="-1"/>
Using y_reflect solely inside the Y-coordinate expression guarantees that both wheels remain geometrically mirrored across the sagittal (XZ) plane while sharing the exact same positive rotation vector.
Modeling the Spherical Caster, Ground Clearance, and Support Polygon
Two coaxial wheels alone cannot balance a chassis statically; the robot requires a third contact point to form a stable support polygon. Just as bipedal robots must keep their Zero Moment Point (ZMP) and Center of Mass projection inside the foot support polygon (see Humanoid Bipedal Locomotion and Whole-Body Control Fundamentals), a differential drive robot must keep its combined Center of Mass inside the triangle formed by the two drive wheels and the front caster.
Because myros_sketch mounts its Raspberry Pi 5, LiDAR, and camera toward the front, we place a spherical caster of radius $r_c = 0.0125\text{ m}$ at $x = +0.075\text{ m}$:
<joint name="caster_joint" type="fixed">
<parent link="base_link"/>
<child link="caster_link"/>
<origin xyz="0.075 0 -0.020" rpy="0 0 0"/>
</joint>
<link name="caster_link">
<visual>
<geometry>
<sphere radius="0.0125"/>
</geometry>
<material name="nylon">
<color rgba="0.90 0.90 0.85 1.0"/>
</material>
</visual>
<collision>
<geometry>
<sphere radius="0.0125"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.02"/>
<inertia ixx="1.25e-6" ixy="0.0" ixz="0.0"
iyy="1.25e-6" iyz="0.0" izz="1.25e-6"/>
</inertial>
</link>
Look closely at the Z offset of caster_joint: z = -0.020 m.
base_linkelevation above the floor = $+0.0325\text{ m}$- Center height of a sphere with radius $0.0125\text{ m}$ resting on the floor = $+0.0125\text{ m}$
- Relative Z offset from
base_linktocaster_link= $0.0125 - 0.0325 = -0.020\text{ m}$
For a solid sphere of mass $m = 0.02\text{ kg}$ and radius $r_c = 0.0125\text{ m}$, the inertia tensor is isotropic: $I_{xx} = I_{yy} = I_{zz} = \frac{2}{5}mr_c^2 = 1.25 \times 10^{-6}\text{ kg}\cdot\text{m}^2$.
Because caster_joint is fixed, the sphere slides rather than rolls across the floor in Gazebo. If left at Gazebo’s default friction (1.0), lateral scrubbing during turns will cause severe yaw chatter. Configure high traction (mu1 = 0.9) on the rubber drive wheels and near-zero friction (mu1 = 0.01) on the caster:
<gazebo reference="wheel_left_link">
<mu1>0.9</mu1>
<mu2>0.9</mu2>
</gazebo>
<gazebo reference="wheel_right_link">
<mu1>0.9</mu1>
<mu2>0.9</mu2>
</gazebo>
<gazebo reference="caster_link">
<mu1>0.01</mu1>
<mu2>0.01</mu2>
<kp>1000000.0</kp>
<kd>1.0</kd>
</gazebo>
Validating Wheel Transforms and Troubleshooting Drive Faults
Launch the visualization environment and verify the wheel and caster transforms using tf2_echo:
ros2 launch myros_sketch display.launch.py
# In a second terminal, confirm wheel and caster positions
ros2 run tf2_ros tf2_echo base_link wheel_left_link
# Expected Translation: [0.000, 0.080, 0.000]
ros2 run tf2_ros tf2_echo base_footprint caster_link
# Expected Translation: [0.075, 0.000, 0.013] (0.0125 m above floor)
In joint_state_publisher_gui, drag both wheel sliders toward positive values and confirm that both cylinders rotate forward around their Y-axes. If anomalous behavior appears during simulation, consult the diagnostic table below:
| Observed Symptom | Target URDF Element to Inspect | Root Cause and Corrective Action |
|---|---|---|
Robot spins in place on straight /cmd_vel | <axis xyz="..."/> on wheel_right_joint | Right axis was inverted to 0 -1 0 → Set both wheel axes to 0 1 0 |
| Wheels lie flat parallel to the floor | <origin> inside wheel <visual> and <collision> | Cylinder defaults to Z-axis → Add rpy="1.5708 0 0" to rotate 90° about X |
| Drive wheels slip without moving the chassis | Caster joint Z offset and <gazebo> <mu1> tags | Caster Z is too low (< -0.020 m), lifting the drive tires off the ground |
| Chassis stutters or jerks during yaw turns | <mu1> and <mu2> on caster_link | High friction on fixed sphere caster → Lower mu1 and mu2 to 0.0–0.02 |
Wheel sliders missing from joint_state_publisher_gui | type="..." attribute on wheel joints | Joints declared as fixed → Change joint type to continuous |
With the differential drivetrain and three-point support polygon verified, myros_sketch stands level on the ground plane. The next tutorial moves above the chassis deck to mount the onboard compute and microcontroller frames (rpi_base, rpi_frame, and esp32s3_frame).