A URDF model can render cleanly in RViz2 with every coordinate frame properly connected, yet still explode into the sky, sink through the ground plane, or crash with NaN joint velocities the instant you spawn it in a dynamics simulator such as Gazebo, MuJoCo, or Isaac Sim. The reason is simple: RViz2 only reads <visual> and <joint> tags to draw meshes on screen, whereas a physics engine relies exclusively on <collision> (contact geometry) and <inertial> (mass and moment-of-inertia tensors) to solve equations of motion at every millisecond step.
Having completed the kinematic and sensor frame hierarchy through our previous guide on camera coordinate frames and camera_link_optical, we now follow the official ROS 2 Jazzy Physical and Collision Properties Tutorial and the ROS Wiki urdf/XML/link specification to finalize collision simplification, calculate exact analytical inertial tensors for all 14 links of myros_sketch, and verify center-of-mass stability.
Decoupling visual from collision: Rendering Detail vs. Contact Solver Speed
Inside any URDF <link>, the <visual> block tells the rendering engine how the part looks, while the <collision> block defines the geometric boundary that the physics engine’s collision detector tests for contact penetration and normal forces.
| Feature | <visual> Block | <collision> Block |
|---|---|---|
| Primary Purpose | Appearance, color, and CAD detail for human inspection | Contact point detection, normal vectors, and Coulomb friction |
| Recommended Geometry | Detailed .stl or .dae meshes, or clean primitives | Primitive box, cylinder, sphere (or simplified convex hulls) |
| Typical Vertex Count | $10,000$ to $500,000+$ vertices | Analytical closed-form equations ($8$ corners for a box) |
| Execution Frequency | Once per camera render frame ($30 \sim 60\text{ Hz}$ on GPU) | Every physics solver step ($500 \sim 1,000\text{ Hz}$ on CPU) |
Because a physics engine evaluates contact pairs at $1,000\text{ Hz}$ ($1\text{ ms}$ time step), feeding a $200,000$-triangle visual mesh directly into <collision> forces thousands of triangle-triangle intersection checks per millisecond. As noted in our benchmark comparison of robot physics simulators (MuJoCo, Isaac Lab, PyBullet, and Genesis), replacing dense non-convex meshes with analytical primitives reduces contact evaluation from tens of milliseconds to a few microseconds and eliminates high-frequency mesh-chatter vibrations.
<link name="chassis">
<!-- Visual block: detailed CAD mesh or colored box for rendering -->
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="0.20 0.15 0.05"/>
</geometry>
</visual>
<!-- Collision block: fast analytical box primitive for contact solver -->
<collision>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="0.20 0.15 0.05"/>
</geometry>
</collision>
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.45"/>
<inertia ixx="9.375e-4" ixy="0" ixz="0"
iyy="1.594e-3" iyz="0" izz="2.344e-3"/>
</inertial>
</link>
Approximating Complex Brackets with Multiple Primitive <collision> Tags
If an L-shaped sensor mount or stepped sub-assembly cannot be enclosed tightly by a single bounding box, the URDF link XML specification allows you to stack multiple <collision> elements inside a single <link>, each with its own local <origin> offset. Also remember that drive wheels must always use a <cylinder> (or <sphere>) collision shape rather than a <box>, so the wheel rolls smoothly on a continuous circular arc instead of catching on box corners.
<!-- Combining two primitive collision shapes inside a single URDF link -->
<collision>
<origin xyz="0.06 0 0.02" rpy="0 0 0"/>
<geometry><box size="0.05 0.04 0.03"/></geometry>
</collision>
<collision>
<origin xyz="-0.04 0 0.01" rpy="0 0 0"/>
<geometry><cylinder radius="0.02" length="0.04"/></geometry>
</collision>
inertial Physics Constraints and Analytical Moment-of-Inertia Formulas
In 3D rigid-body dynamics, rotational acceleration $\boldsymbol{\alpha}$ under an applied torque $\boldsymbol{\tau}$ is governed by Euler’s equation $\boldsymbol{\tau} = \mathbf{I}\boldsymbol{\alpha} + \boldsymbol{\omega} \times (\mathbf{I}\boldsymbol{\omega})$, where $\mathbf{I}$ is the $3 \times 3$ symmetric inertia tensor defined about the link’s Center of Mass (CoM):
At every integration step, the solver multiplies forces and torques by the inverse mass $m^{-1}$ and inverse inertia matrix $\mathbf{I}^{-1}$. If you enter 0 or an unphysically tiny placeholder such as 1e-9 for mass or any principal moment (ixx, iyy, izz), $\mathbf{I}^{-1}$ blows up by nine orders of magnitude, causing the slightest contact force to accelerate the link to infinite velocity (NaN). Every physically valid inertia tensor must satisfy two mathematical invariants:
- Strict Positive Definiteness: Mass and all three principal moments of inertia must be strictly positive ($m > 0,\ I_{xx} > 0,\ I_{yy} > 0,\ I_{zz} > 0$).
- The Inertia Triangle Inequality: The sum of any two principal moments of inertia must be greater than or equal to the third:
When a uniform primitive shape is centered at its CoM and aligned with the link’s coordinate axes, all off-diagonal products of inertia vanish ($I_{xy} = I_{xz} = I_{yz} = 0$), and the diagonal entries follow closed-form formulas that automatically satisfy both invariants:
| Primitive Shape & Dimensions | $I_{xx}$ ($\text{kg}\cdot\text{m}^2$) | $I_{yy}$ ($\text{kg}\cdot\text{m}^2$) | $I_{zz}$ ($\text{kg}\cdot\text{m}^2$) | Matching myros_sketch Links |
|---|---|---|---|---|
| Solid Box length $l(X)$, width $w(Y)$, height $h(Z)$ | $\dfrac{1}{12} m (w^2 + h^2)$ | $\dfrac{1}{12} m (l^2 + h^2)$ | $\dfrac{1}{12} m (l^2 + w^2)$ | chassis, rpi_base, rpi_frame, esp32s3_frame, imu_link, lidar_base_frame, camera_link |
| Upright Cylinder (Axis along $Z$) radius $r$, length $h$ | $\dfrac{1}{12} m (3r^2 + h^2)$ | $\dfrac{1}{12} m (3r^2 + h^2)$ | $\dfrac{1}{2} m r^2$ | laser_frame (vertical LiDAR turret) |
| Horizontal Wheel Cylinder (Axis along $Y$) radius $r$, width $h$ (rotated $90^\circ$ about $X$) | $\dfrac{1}{12} m (3r^2 + h^2)$ | $\dfrac{1}{2} m r^2$ | $\dfrac{1}{12} m (3r^2 + h^2)$ | wheel_left_link, wheel_right_link |
| Solid Sphere radius $r$ | $\dfrac{2}{5} m r^2$ | $\dfrac{2}{5} m r^2$ | $\dfrac{2}{5} m r^2$ | caster_link |
Pay special attention to the two cylinder rows above. As shown in our guide on modeling differential drive wheels and casters, a wheel cylinder spins around the lateral $Y$ axis (axis xyz="0 1 0"). Consequently, the axial rolling inertia $\frac{1}{2}mr^2$ occupies iyy, while ixx and izz take the transverse formula $\frac{1}{12}m(3r^2+h^2)$.
Complete myros_sketch Inertia Table and Center-of-Mass Stability Analysis
Applying the formulas above to every physical component in myros_sketch yields the complete mass and inertia specification for the robot:
| Link Name | Geometry & Dimensions ($\text{m}$) | Mass $m$ ($\text{kg}$) | $I_{xx}$ ($\text{kg}\cdot\text{m}^2$) | $I_{yy}$ ($\text{kg}\cdot\text{m}^2$) | $I_{zz}$ ($\text{kg}\cdot\text{m}^2$) |
|---|---|---|---|---|---|
chassis | Box $0.200 \times 0.150 \times 0.050$ | $0.450$ | $9.375 \times 10^{-4}$ | $1.594 \times 10^{-3}$ | $2.344 \times 10^{-3}$ |
wheel_left_link | Cylinder $r=0.0325, h=0.026$ (axis $Y$) | $0.050$ | $1.602 \times 10^{-5}$ | $2.641 \times 10^{-5}$ | $1.602 \times 10^{-5}$ |
wheel_right_link | Cylinder $r=0.0325, h=0.026$ (axis $Y$) | $0.050$ | $1.602 \times 10^{-5}$ | $2.641 \times 10^{-5}$ | $1.602 \times 10^{-5}$ |
caster_link | Sphere $r=0.0125$ | $0.020$ | $1.250 \times 10^{-6}$ | $1.250 \times 10^{-6}$ | $1.250 \times 10^{-6}$ |
rpi_base | Box $0.090 \times 0.060 \times 0.005$ | $0.020$ | $6.042 \times 10^{-6}$ | $1.354 \times 10^{-5}$ | $1.950 \times 10^{-5}$ |
rpi_frame | Box $0.085 \times 0.056 \times 0.017$ | $0.050$ | $1.427 \times 10^{-5}$ | $3.131 \times 10^{-5}$ | $4.317 \times 10^{-5}$ |
esp32s3_frame | Box $0.026 \times 0.063 \times 0.008$ | $0.010$ | $3.361 \times 10^{-6}$ | $6.167 \times 10^{-7}$ | $3.871 \times 10^{-6}$ |
imu_link | Box $0.020 \times 0.020 \times 0.003$ | $0.002$ | $6.817 \times 10^{-8}$ | $6.817 \times 10^{-8}$ | $1.333 \times 10^{-7}$ |
lidar_base_frame | Box $0.060 \times 0.060 \times 0.015$ | $0.030$ | $9.563 \times 10^{-6}$ | $9.563 \times 10^{-6}$ | $1.800 \times 10^{-5}$ |
laser_frame | Cylinder $r=0.035, h=0.040$ (axis $Z$) | $0.170$ | $7.473 \times 10^{-5}$ | $7.473 \times 10^{-5}$ | $1.041 \times 10^{-4}$ |
camera_link | Box $0.025 \times 0.030 \times 0.025$ | $0.030$ | $3.813 \times 10^{-6}$ | $3.125 \times 10^{-6}$ | $3.813 \times 10^{-6}$ |
| Total System | 11 physical links (+ 3 virtual frames = 14 links) | $0.912\text{ kg}$ | — | — | — |
(Note: If you build a heavier aluminum-chassis variant weighing roughly $1.99\text{ kg}$—for example with a $1.20\text{ kg}$ chassis, two $0.15\text{ kg}$ wheels, and dual front/rear $0.05\text{ kg}$ casters—simply scale the inertia tensor values linearly with each link’s mass $m$.)
Verifying Center of Mass Against the Support Triangle
Using the link masses $m_i$ and their position vectors $\mathbf{p}i = (x_i, y_i, z_i)$ relative to base_link, we can compute the whole-robot Center of Mass $\mathbf{p}{\text{CoM}} = \frac{\sum m_i \mathbf{p}_i}{\sum m_i}$ before ever launching a simulator:
- Longitudinal balance ($X_{\text{CoM}}$): With the front caster ($x = +0.075\text{ m}$), IMU ($x = +0.065\text{ m}$), and camera ($x = +0.100\text{ m}$) forward of the axle and only the lightweight ESP32-S3 ($x = -0.060\text{ m}$) behind it, the net center of mass sits at $X_{\text{CoM}} \approx +0.004\text{ m}$ ($4\text{ mm}$ ahead of the drive axle).
- Vertical height ($Z_{\text{CoM}}$): Weighted by the elevated LiDAR ($0.170\text{ kg}$ at $z = 0.0875\text{ m}$), the vertical CoM sits at $Z_{\text{CoM}} \approx +0.024\text{ m}$ above
base_link, or $0.0565\text{ m}$ ($5.65\text{ cm}$) above the floor.
The robot’s support triangle is bounded by the left wheel contact point $(0, +0.080)\text{ m}$, the right wheel contact point $(0, -0.080)\text{ m}$, and the front caster contact point $(+0.075, 0)\text{ m}$. Because the ground projection of the CoM $(+0.004, 0)\text{ m}$ lies strictly inside $X \in [0, +0.075]\text{ m}$, the robot rests stably on all three ground contacts without tipping backward. If you later mount a heavy battery pack behind the axle ($X_{\text{CoM}} < 0$), this CoM calculation immediately tells you to add a rear caster link (rear_caster at $x = -0.075\text{ m}$).
Complete myros_sketch Kinematic Tree and 3-Step Simulation Verification
With all structural, controller, sensor, and physics tags in place, the completed myros_sketch URDF tree comprises 14 links connected by 13 joints:
base_footprint (ground-plane projection root frame, massless)
└── [base_footprint_joint: fixed, z = +0.0325 m]
└── base_link (drive-axle center reference frame)
├── [chassis_joint: fixed] ────────────── chassis (0.450 kg)
├── [wheel_left_joint: continuous, Y] ─── wheel_left_link (0.050 kg)
├── [wheel_right_joint: continuous, Y] ── wheel_right_link (0.050 kg)
├── [caster_joint: fixed] ─────────────── caster_link (0.020 kg)
├── [esp32s3_joint: fixed] ────────────── esp32s3_frame (0.010 kg)
├── [imu_joint: fixed] ────────────────── imu_link (0.002 kg)
├── [rpi_base_joint: fixed] ───────────── rpi_base (0.020 kg)
│ └── [rpi_joint: fixed] ────────────── rpi_frame (0.050 kg)
│ └── [lidar_base_joint: fixed] ─── lidar_base_frame (0.030 kg)
│ └── [laser_joint: fixed] ──── laser_frame (0.170 kg)
└── [camera_joint: fixed] ─────────────── camera_link (0.030 kg)
└── [camera_optical_joint: fixed] ─── camera_link_optical (massless optical frame)
Before connecting ros2_control or Nav2, run the following three-step physics verification sequence:
- Validate tree syntax and hierarchy with
check_urdf: Confirm that all 13 joints form a single valid tree rooted atbase_footprintwith no disconnected links or kinematic loops. - Inspect fixed-joint lumping via
gz sdf -p: When Gazebo converts URDF to SDF, it merges all rigidly attached (fixed) child links into their parent dynamic link using the parallel axis theorem. Inspecting the generated SDF verifies that the lumped body mass equals $0.812\text{ kg}$ (plus $2 \times 0.050\text{ kg}$ for the two continuous wheels = $0.912\text{ kg}$ total). - Execute a $2\text{ cm}$ Gazebo Drop Test: Spawn the robot $2\text{ cm}$ ($z = 0.02\text{ m}$) above the ground plane so its collision primitives do not start embedded in the floor, and verify that it settles completely within $1\text{ second}$ without residual jitter.
# Step 1: Validate URDF XML structure and generate a kinematic graph PDF
check_urdf src/myros_sketch/urdf/myros_sketch.urdf
urdf_to_graphviz src/myros_sketch/urdf/myros_sketch.urdf
# Step 2: Check how Gazebo lumps fixed joints and computes composite inertia in SDF
gz sdf -p src/myros_sketch/urdf/myros_sketch.urdf | head -n 45
# Step 3: Spawn the robot in Gazebo and observe the 2 cm drop test
ros2 launch myros_sketch gazebo.launch.py
If the robot exhibits abnormal physical behavior in Gazebo, consult the diagnostic table below:
| Observed Simulation Symptom | Physics Engine Root Cause | Fix |
|---|---|---|
Robot disappears immediately or logs NaN positions | One or more physical links have mass="0" or inertia values near 1e-9 | Populate every physical link with analytical primitive inertia values |
| Robot launches high into the air at the moment of spawn | Spawn height $Z \le 0$ embeds wheel/caster collision shapes inside the ground plane | Pass -z 0.02 ($2\text{ cm}$ elevation) to the Gazebo spawn entity node |
| Robot vibrates or jitters continuously while resting on the floor | Overlapping <collision> boxes between adjacent links or excessive contact stiffness kp | Enable collision visualization in Gazebo (View -> Collisions) and add $1 \sim 2\text{ mm}$ clearance |
| Wheels spin in place or robot accelerates far too slowly | Low surface friction (mu1, mu2) or inflated mass / iyy wheel inertia | Verify total mass ($0.912\text{ kg}$) and confirm iyy uses $\frac{1}{2}mr^2$ |
KDL warning: The root link base_footprint has an inertia | An <inertial> block was mistakenly added to the root link base_footprint | Remove <inertial> from base_footprint; assign mass starting at base_link or chassis |