Skip to main content

Physics Simulation: Gravity and Collisions

Learning Objectives

After completing this chapter, you will be able to:

  • Configure physics engines and parameters in Gazebo
  • Set up realistic gravity and collision properties
  • Fine-tune physics parameters for humanoid robots
  • Debug physics-related simulation issues

Introduction

Physics simulation forms the foundation of realistic robotic simulation, enabling robots to interact with their environment in ways that closely mirror real-world behavior. In the context of Physical AI & Humanoid Robotics, accurate physics simulation is especially critical due to the complex multi-body dynamics involved in humanoid locomotion and interaction. Properly configured physics parameters ensure that behaviors learned in simulation can transfer effectively to real-world robots.

Gazebo supports multiple physics engines (ODE, Bullet, DART) and provides extensive control over physical parameters such as gravity, friction, damping, and collision behavior. For humanoid robots with many degrees of freedom, careful tuning of these parameters is essential to achieve stable, realistic movement patterns that will translate well to physical hardware.

Core Concepts

Physics simulation in Gazebo involves modeling the fundamental forces and interactions that govern how objects move and interact. The accuracy of this simulation directly impacts the validity of results obtained from simulation-based development and testing.

Physics Engines

Gazebo supports three primary physics engines:

  • ODE (Open Dynamics Engine): Default engine, good for general applications
  • Bullet: Known for robust collision detection and realistic physics
  • DART: Advanced engine with articulated body handling, good for complex robots

Gravity and World Physics

Gravity is a fundamental force in physics simulation, and its setting affects all objects in the simulation. By default, Gazebo simulates Earth gravity (9.8 m/s²), but this can be adjusted for different environments or testing scenarios.

Collision Detection

Collision detection algorithms determine when and how objects in the simulation interact. Proper collision geometry is critical for realistic interactions while maintaining simulation performance. For humanoid robots, this is particularly important for tasks like walking, grasping, and navigating.

Hands-on Examples

Let's configure physics parameters for realistic humanoid simulation:

<?xml version="1.0"?>
<sdf version="1.7">
<world name="humanoid_physics_world">
<!-- Physics engine configuration -->
<physics type="ode">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
<real_time_update_rate>1000</real_time_update_rate>
<gravity>0 0 -9.8</gravity>

<!-- ODE-specific parameters -->
<ode>
<solver>
<type>quick</type>
<iters>10</iters>
<sor>1.0</sor>
</solver>
<constraints>
<cfm>0.0</cfm>
<erp>0.2</erp>
<contact_max_correcting_vel>100.0</contact_max_correcting_vel>
<contact_surface_layer>0.001</contact_surface_layer>
</constraints>
</ode>
</physics>

<!-- Include a ground plane -->
<include>
<uri>model://ground_plane</uri>
</include>

<!-- Include the sun -->
<include>
<uri>model://sun</uri>
</include>

<!-- Humanoid robot with custom physics properties -->
<model name="simple_humanoid">
<pose>0 0 1.0 0 0 0</pose>

<!-- Torso with realistic mass and inertia -->
<link name="torso">
<pose>0 0 0 0 0 0</pose>
<inertial>
<mass>15.0</mass>
<inertia>
<ixx>0.2</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.3</iyy>
<iyz>0.0</iyz>
<izz>0.1</izz>
</inertia>
</inertial>

<!-- Visual and collision geometry -->
<visual name="visual">
<geometry>
<box>
<size>0.3 0.2 0.5</size>
</box>
</geometry>
</visual>

<collision name="collision">
<geometry>
<box>
<size>0.3 0.2 0.5</size>
</box>
</geometry>
<surface>
<friction>
<ode>
<mu>0.5</mu>
<mu2>0.5</mu2>
<fdir1>0 0 0</fdir1>
<slip1>0.0</slip1>
<slip2>0.0</slip2>
</ode>
</friction>
<bounce>
<restitution_coefficient>0.1</restitution_coefficient>
<threshold>100000</threshold>
</bounce>
<contact>
<ode>
<soft_cfm>0.0</soft_cfm>
<soft_erp>0.2</soft_erp>
<kp>1000000000000.0</kp>
<kd>1.0</kd>
<max_vel>100.0</max_vel>
<min_depth>0.001</min_depth>
</ode>
</contact>
</surface>
</collision>
</link>

<!-- Hip link with specific physics properties -->
<link name="hip">
<pose>-0.1 0 -0.25 0 0 0</pose>
<inertial>
<mass>3.0</mass>
<inertia>
<ixx>0.01</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.01</iyy>
<iyz>0.0</iyz>
<izz>0.005</izz>
</inertia>
</inertial>

<visual name="visual">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.15</length>
</cylinder>
</geometry>
</visual>

<collision name="collision">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.15</length>
</cylinder>
</geometry>
<surface>
<friction>
<ode>
<mu>0.8</mu>
<mu2>0.8</mu2>
</ode>
</friction>
<contact>
<ode>
<soft_cfm>0.0</soft_cfm>
<soft_erp>0.2</soft_erp>
<kp>1000000000000.0</kp>
<kd>1.0</kd>
</ode>
</contact>
</surface>
</collision>
</link>

<!-- Joint with actuation parameters -->
<joint name="torso_to_hip" type="revolute">
<parent>torso</parent>
<child>hip</child>
<pose>-0.1 0 -0.25 0 0 0</pose>
<axis>
<xyz>0 0 1</xyz>
<limit>
<lower>-1.57</lower>
<upper>1.57</upper>
<effort>50.0</effort>
<velocity>2.0</velocity>
</limit>
<dynamics>
<damping>2.0</damping>
<friction>1.0</friction>
</dynamics>
</axis>
</joint>

<!-- Add plugin for ROS control -->
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<robotNamespace>/simple_humanoid</robotNamespace>
</plugin>
</model>
</world>
</sdf>

Expected Output:

[INFO] [1678882844.123456789] [physics_configurator]: Physics configurator initialized
[INFO] [1678882844.123456789] [physics_configurator]: Current gravity: x: 0.0, y: 0.0, z: -9.8
[INFO] [1678882844.123456789] [physics_configurator]: Current step size: 0.001
[INFO] [1678882844.123456789] [physics_configurator]: Physics properties updated successfully
[INFO] [1678882844.123456789] [physics_configurator]: New time step: 0.001
[INFO] [1678882844.123456789] [physics_configurator]: New max update rate: 1000.0

[INFO] [1678882845.123456789] [humanoid_physics_tuner]: Humanoid Physics Tuner initialized
[INFO] [1678882845.223456789] [humanoid_physics_tuner]: Stability: 0.12, Z variance: 0.0005, X variance: 0.0007
[INFO] [1678882845.323456789] [humanoid_physics_tuner]: Stability: 0.11, Z variance: 0.0004, X variance: 0.0007

Exercises

Complete the following exercises to reinforce your understanding:

  1. Stability Tuning: Adjust physics parameters to improve robot stability

    • Modify damping values to reduce oscillations
    • Adjust friction coefficients to prevent slipping
    • Test how different values affect robot locomotion
    • Find optimal values for your specific robot model
  2. Collision Detection: Configure collision properties for a complex robot

    • Set up collision geometry for all robot links
    • Test collision behavior with different objects
    • Adjust collision parameters to prevent interpenetration
    • Validate that collisions are detected and handled properly

Common Pitfalls and Solutions

  • Pitfall 1: Simulation instability - Robot behaving erratically or exploding
    • Solution: Reduce time step, increase iterations, or add damping to joints
  • Pitfall 2: Performance issues - Slow simulation with complex physics
    • Solution: Simplify collision meshes, reduce update rate, or adjust solver parameters
  • Pitfall 3: Unrealistic behavior - Robot moving unlike real hardware
    • Solution: Fine-tune mass properties, friction, and damping values
  • Pitfall 4: Interpenetration - Objects passing through each other
    • Solution: Increase contact stiffness, reduce time step, or improve collision geometry

Summary

  • Physics engines govern how objects interact in simulation
  • Gravity, friction, and damping are critical for realistic behavior
  • Proper mass and inertia properties ensure accurate dynamics
  • Physics parameters must be tuned for humanoid robots specifically
  • Realistic physics is essential for sim-to-real transfer

Further Reading