Skip to content

Preventing Robot Physics Explosions in Gazebo: URDF Collision Simplification and Inertial Tensor Math

Prevent physics explosions in Gazebo by simplifying URDF collision geometries and calculating accurate box, cylinder, and sphere inertial tensors for mobile robots.

Contents

Key takeaways

  1. The primary cause of robots flying off into space or diverging to NaN in physics simulators is not collision geometry, but zero or near-zero (e.g., 1e-9) mass and moment-of-inertia values inside inertial tags.
  2. Using high-polygon visual STL or DAE meshes inside collision tags bottlenecks the physics solver at every 1 ms step; collision geometries should always be approximated with primitive boxes, cylinders, and spheres.
  3. Every link’s principal moments of inertia (ixx, iyy, izz) around its center of mass must be strictly positive and satisfy the triangle inequality (Ixx + Iyy >= Izz), which analytical primitive formulas guarantee automatically.
  4. Across all 14 links and 13 joints, myros_sketch has a total mass of 0.912 kg with a combined center of mass at X = +0.004 m and Z = +0.024 m relative to base_link—safely inside the three-point support triangle formed by the two drive wheels and front caster.

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 PurposeAppearance, color, and CAD detail for human inspectionContact point detection, normal vectors, and Coulomb friction
Recommended GeometryDetailed .stl or .dae meshes, or clean primitivesPrimitive box, cylinder, sphere (or simplified convex hulls)
Typical Vertex Count$10,000$ to $500,000+$ verticesAnalytical closed-form equations ($8$ corners for a box)
Execution FrequencyOnce 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):

I=[IxxIxyIxzIxyIyyIyzIxzIyzIzz]\mathbf{I} = \begin{bmatrix} I_{xx} & I_{xy} & I_{xz} \\ I_{xy} & I_{yy} & I_{yz} \\ I_{xz} & I_{yz} & I_{zz} \end{bmatrix}

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:

  1. 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$).
  2. The Inertia Triangle Inequality: The sum of any two principal moments of inertia must be greater than or equal to the third: Ixx+Iyy≥Izz,Iyy+Izz≥Ixx,Izz+Ixx≥IyyI_{xx} + I_{yy} \ge I_{zz}, \qquad I_{yy} + I_{zz} \ge I_{xx}, \qquad I_{zz} + I_{xx} \ge I_{yy}

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 NameGeometry & 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$)
chassisBox $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_linkCylinder $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_linkCylinder $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_linkSphere $r=0.0125$$0.020$$1.250 \times 10^{-6}$$1.250 \times 10^{-6}$$1.250 \times 10^{-6}$
rpi_baseBox $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_frameBox $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_frameBox $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_linkBox $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_frameBox $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_frameCylinder $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_linkBox $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 System11 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:

  1. Validate tree syntax and hierarchy with check_urdf: Confirm that all 13 joints form a single valid tree rooted at base_footprint with no disconnected links or kinematic loops.
  2. 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).
  3. 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 SymptomPhysics Engine Root CauseFix
Robot disappears immediately or logs NaN positionsOne or more physical links have mass="0" or inertia values near 1e-9Populate every physical link with analytical primitive inertia values
Robot launches high into the air at the moment of spawnSpawn height $Z \le 0$ embeds wheel/caster collision shapes inside the ground planePass -z 0.02 ($2\text{ cm}$ elevation) to the Gazebo spawn entity node
Robot vibrates or jitters continuously while resting on the floorOverlapping <collision> boxes between adjacent links or excessive contact stiffness kpEnable collision visualization in Gazebo (View -> Collisions) and add $1 \sim 2\text{ mm}$ clearance
Wheels spin in place or robot accelerates far too slowlyLow surface friction (mu1, mu2) or inflated mass / iyy wheel inertiaVerify total mass ($0.912\text{ kg}$) and confirm iyy uses $\frac{1}{2}mr^2$
KDL warning: The root link base_footprint has an inertiaAn <inertial> block was mistakenly added to the root link base_footprintRemove <inertial> from base_footprint; assign mass starting at base_link or chassis

Common mistakes

  • Assigning dummy values like mass=1e-9 or inertia=0 to small sensor brackets, causing matrix inversion singularities in the dynamics solver
  • Copying a 200,000-vertex CAD mesh directly from the visual block into the collision block, cutting the simulation Real-Time Factor (RTF) in half
  • Using the Z-axis cylinder inertia formula for a drive wheel rotated 90 degrees onto the Y axis, swapping the rolling moment of inertia (Iyy) with the transverse axes (Ixx, Izz)

Pre-flight checklist

  • Does every physical link (excluding virtual frames like base_footprint and camera_link_optical) define non-zero mass and principal moments of inertia?
  • Do ixx, iyy, and izz satisfy positive definiteness and the triangle inequality (the sum of any two exceeds the third) on every link?
  • Are all collision geometries defined using simple primitives (box, cylinder, sphere), with drive wheels modeled as cylinders rather than boxes?
  • Does the robot pass check_urdf, gz sdf -p inspection, and a 2 cm drop test in Gazebo without jittering or sinking?

Frequently asked questions

Can I just enter arbitrarily large inertia values to make the simulation stable?
Inflating inertia values suppresses numerical explosions, but it ruins physical fidelity. If your wheels or chassis have 10 times their true rotational inertia, acceleration and in-place yaw turns become sluggish, rendering PID and Nav2 controller gains tuned in simulation useless on the real robot. Always compute inertia from actual mass and bounding dimensions.
Why are collision and inertial tags omitted from base_footprint and camera_link_optical?
Both base_footprint and camera_link_optical are virtual coordinate frames with no physical volume. Furthermore, KDL-based parsers emit warnings when the root link of a kinematic tree carries inertia, so keeping base_footprint empty and starting physical mass at base_link or chassis is standard ROS 2 practice.
When should the off-diagonal products of inertia (ixy, ixz, iyz) be non-zero?
For any symmetric primitive shape (box, cylinder, sphere) whose local coordinate axes align with its principal axes of symmetry at the center of mass, all off-diagonal products of inertia are exactly zero. Non-zero off-diagonal terms only arise for asymmetric composite bodies or tilted principal axes, which modular URDF models avoid by splitting components into axis-aligned links.

Sources & verification

  1. ROS 2 Jazzy — Adding physical and collision properties to a URDF model
  2. ROS Wiki — urdf/XML/link
  3. ROS 2 Jazzy — URDF Tutorials
  4. ROS 2 Jazzy — Using Xacro to clean up a URDF file

Last verified: