Skip to main content

Gazebo Setup: Rigid Body Physics, Gravity & Collisions

Gazebo is a powerful 3D simulation environment that plays a central role in developing Physical AI systems. Its realistic physics engine, gravity simulation, and collision detection capabilities make it ideal for testing humanoid robots before deployment on real hardware. This section covers how to set up Gazebo and configure it for humanoid robotics applications.

Introduction to Gazebo​

Gazebo is a stand-alone application that simulates multi-robot systems in complex indoor and outdoor environments. For Physical AI and humanoid robotics, it provides:

  • Accurate physics simulation using ODE, Bullet, or Dart engines
  • High-quality graphics rendering for visual perception tasks
  • Realistic sensor simulation including cameras, LIDAR, IMU, and more
  • Plugin architecture for extending functionality
  • ROS/ROS2 integration for seamless robot development

Why Gazebo for Humanoid Robotics?​

Gazebo offers specific advantages for humanoid robot simulation:

  1. Dynamic Balance Simulation: Accurately models the physics of bipedal locomotion
  2. Contact Simulation: Realistic handling of feet-ground interactions
  3. Gravity and Inertial Properties: Critical for humanoid stability
  4. Complex Environments: Test navigation and interaction in realistic worlds
  5. Collision Detection: Essential for safe robot operation

Installing Gazebo​

System Requirements​

Before installing, ensure your system meets the requirements:

  • OS: Ubuntu 22.04 LTS (with ROS 2 Humble Hawksbill)
  • CPU: 8-core processor recommended
  • RAM: 16GB minimum, 32GB recommended
  • GPU: Modern GPU with OpenGL 3.3+ support (for visualization)
  • Disk Space: 5+ GB available

Installation via APT​

# Add the Gazebo repository
sudo apt update && sudo apt install -y wget
wget https://packages.osrfoundation.org/gazebo.gpg -O /tmp/gazebo.gpg
sudo cp /tmp/gazebo.gpg /usr/share/keyrings/gazebo-archive-keyring.gpg

# Add the repository to your sources list
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/gazebo-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null

# Update package list
sudo apt update

# Install Gazebo Garden (latest stable)
sudo apt install gz-garden

Install Gazebo Classic (Alternative)​

For projects requiring Gazebo Classic (the previous version):

sudo apt install gazebo libgazebo-dev

Verify Installation​

Test that Gazebo is properly installed:

gz sim --version
# Should output version information

Or for Gazebo Classic:

gazebo --version

Setting Up Your First Gazebo World​

Basic World File Structure​

Gazebo uses SDF (Simulation Description Format) to define simulation environments. Create a simple world file:

<!-- world/simple_humanoid_world.sdf -->
<?xml version="1.0" ?>
<sdf version="1.7">
<world name="simple_humanoid_world">
<!-- Include a ground plane -->
<include>
<uri>model://ground_plane</uri>
</include>

<!-- Include sun for lighting -->
<include>
<uri>model://sun</uri>
</include>

<!-- Optional: Add a grid for visual reference -->
<gui fullscreen="0">
<plugin filename="GzScene3D" name="3D View">
<engine>ogre2</engine>
<scene>scene</scene>
<ambient_light>0.4 0.4 0.4</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<grid>false</grid>
<origin_visual>false</origin_visual>
</plugin>
</gui>
</world>
</sdf>

Run Your World​

Execute the world with:

gz sim -r simple_humanoid_world.sdf

For Gazebo Classic:

gazebo simple_humanoid_world.sdf

Physics Engine Configuration​

Selecting Physics Engine​

Gazebo supports multiple physics engines. Configure your world for humanoid simulation:

<?xml version="1.0" ?>
<sdf version="1.7">
<world name="humanoid_physics_world">
<physics type="ode"> <!-- Options: ode, bullet, dart -->
<!-- Time step for physics simulation -->
<max_step_size>0.001</max_step_size>
<!-- Real time factor (higher means faster simulation) -->
<real_time_factor>1.0</real_time_factor>
<!-- Gravity vector (x, y, z in m/s^2) -->
<gravity>0 0 -9.8</gravity>
</physics>

<!-- Rest of world definition -->
<include>
<uri>model://ground_plane</uri>
</include>

<include>
<uri>model://sun</uri>
</include>
</world>
</sdf>

Physics Parameters for Humanoids​

For humanoid robots, specific physics parameters are crucial:

<physics type="ode">
<!-- For accurate humanoid simulation -->
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
<gravity>0 0 -9.8</gravity>

<!-- ODE-specific settings -->
<ode>
<solver>
<!-- Use quicker but less accurate solver for development -->
<type>quick</type>
<!-- Iterations affect accuracy vs. performance -->
<iters>50</iters>
<!-- Constraint error reduction -->
<sor>1.3</sor>
</solver>

<!-- Contact parameters -->
<constraints>
<!-- ERP: Error reduction parameter (0.2 - 0.8) -->
<cfm>0.000001</cfm>
<erp>0.2</erp>
<!-- Maximum contacts per collision -->
<contact_surface_layer>0.001</contact_surface_layer>
<max_contacts>20</max_contacts>
</constraints>
</ode>
</physics>

Collision Detection for Humanoids​

Collision Geometry Types​

For humanoid robots, selecting appropriate collision geometry is important for both performance and accuracy:

<!-- Different collision geometries -->
<collision name="collision_box">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</collision>

<collision name="collision_cylinder">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.4</length>
</cylinder>
</geometry>
</collision>

<collision name="collision_sphere">
<geometry>
<sphere>
<radius>0.1</radius>
</sphere>
</geometry>
</collision>

<!-- For complex shapes, use meshes -->
<collision name="collision_mesh">
<geometry>
<mesh>
<uri>model://my_robot/meshes/link_collision.dae</uri>
</mesh>
</geometry>
</collision>

Collision Performance Tips​

For humanoid robots with many links:

  1. Use simple geometries where possible (boxes, cylinders, spheres)
  2. Combine multiple colliders into fewer, simpler shapes
  3. Adjust collision bitmasking to avoid unnecessary collision checks
  4. Use per-model collision flags to disable collisions between adjacent links

Gravity Configuration​

Standard Gravity​

For humanoid robotics applications, the standard Earth gravity is typically appropriate:

<gravity>0 0 -9.8</gravity>

Variable Gravity Scenarios​

Gazebo allows simulating different gravitational conditions:

<!-- Moon gravity (~1/6 of Earth) -->
<gravity>0 0 -1.625</gravity>

<!-- Mars gravity (~3/8 of Earth) -->
<gravity>0 0 -3.7</gravity>

<!-- Zero gravity (for testing mechanisms) -->
<gravity>0 0 0</gravity>

Gravity Effects on Humanoids​

Gravity has significant impact on humanoid behavior:

  • Balance control: Essential for bipedal stability
  • Foot-ground contact: Determines walking gait characteristics
  • Energy consumption: Affects efficiency of locomotion
  • Fall behavior: Important for robot safety design

Gazebo Plugins for Humanoid Robotics​

ROS 2 Bridge​

Connect Gazebo to ROS 2 using the gazebo_ros_pkgs:

<model name="simple_humanoid">
<!-- Include ROS 2 control plugin -->
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
<parameters>$(find simple_humanoid_control)/config/humanoid_controllers.yaml</parameters>
</plugin>
</model>

Sensor Plugins​

Simulate various sensors for humanoid robots:

<model name="humanoid_with_sensors">
<!-- IMU sensor -->
<link name="imu_link">
<sensor name="imu_sensor" type="imu">
<always_on>true</always_on>
<update_rate>100</update_rate>
<imu>
<angular_velocity>
<x>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>2e-4</stddev>
</noise>
</x>
<y>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>2e-4</stddev>
</noise>
</y>
<z>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>2e-4</stddev>
</noise>
</z>
</angular_velocity>
<linear_acceleration>
<x>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</x>
<y>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</y>
<z>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</z>
</linear_acceleration>
</imu>
</sensor>
</link>
</model>

Performance Optimization​

Simulation Speed​

For faster simulation, consider these optimizations:

  1. Larger time steps (less accurate but faster)
  2. Fewer physics iterations (less accurate but faster)
  3. Simplified collision meshes
  4. Disabling rendering for headless training: gz sim -s

Visual Quality vs. Performance​

Balance visual quality with simulation performance:

<!-- In the GUI section -->
<plugin filename="GzScene3D" name="3D View">
<engine>ogre2</engine>
<scene>scene</scene>
<ambient_light>0.4 0.4 0.4</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<!-- Disable shadows for better performance -->
<shadows>false</shadows>
<!-- Reduce anti-aliasing -->
<anti_aliasing>0</anti_aliasing>
</plugin>

Common Humanoid Configurations​

Bipedal Robot Example​

Complete SDF definition for a simple bipedal robot:

<?xml version="1.0" ?>
<sdf version="1.7">
<model name="simple_biped">
<!-- Main body -->
<link name="torso">
<pose>0 0 0.75 0 0 0</pose>
<collision name="torso_collision">
<geometry>
<box>
<size>0.3 0.2 0.5</size>
</box>
</geometry>
</collision>
<visual name="torso_visual">
<geometry>
<box>
<size>0.3 0.2 0.5</size>
</box>
</geometry>
</visual>
<inertial>
<mass>10.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.4</izz>
</inertia>
</inertial>
</link>

<!-- Left leg -->
<joint name="left_hip" type="revolute">
<parent>torso</parent>
<child>left_thigh</child>
<axis>
<xyz>0 1 0</xyz>
<limit>
<lower>-1.57</lower>
<upper>1.57</upper>
<effort>100</effort>
<velocity>1.0</velocity>
</limit>
</axis>
<pose>-0.075 0 -0.1 0 0 0</pose>
</joint>

<link name="left_thigh">
<collision name="left_thigh_collision">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.4</length>
</cylinder>
</geometry>
</collision>
<visual name="left_thigh_visual">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.4</length>
</cylinder>
</geometry>
</visual>
<inertial>
<mass>3.0</mass>
<inertia>
<ixx>0.05</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.05</iyy>
<iyz>0.0</iyz>
<izz>0.005</izz>
</inertia>
</inertial>
</link>

<!-- Right leg (similar to left leg) -->
<joint name="right_hip" type="revolute">
<parent>torso</parent>
<child>right_thigh</child>
<axis>
<xyz>0 1 0</xyz>
<limit>
<lower>-1.57</lower>
<upper>1.57</upper>
<effort>100</effort>
<velocity>1.0</velocity>
</limit>
</axis>
<pose>0.075 0 -0.1 0 0 0</pose>
</joint>

<link name="right_thigh">
<collision name="right_thigh_collision">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.4</length>
</cylinder>
</geometry>
</collision>
<visual name="right_thigh_visual">
<geometry>
<cylinder>
<radius>0.05</radius>
<length>0.4</length>
</cylinder>
</geometry>
</visual>
<inertial>
<mass>3.0</mass>
<inertia>
<ixx>0.05</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.05</iyy>
<iyz>0.0</iyz>
<izz>0.005</izz>
</inertia>
</inertial>
</link>

<!-- Hip joint constraints to connect the two legs -->
<joint name="inter_hip" type="fixed">
<parent>left_thigh</parent>
<child>right_thigh</child>
<pose>0 0.15 0 0 0 0</pose>
</joint>
</model>
</sdf>

Troubleshooting Common Issues​

Common Physics Issues​

  1. Objects falling through surfaces

    • Check collision mesh alignment
    • Verify gravity and time step settings
    • Adjust ERP/CFM parameters
  2. Joint oscillation or instability

    • Reduce time step size
    • Increase solver iterations
    • Check joint limits and damping
  3. Slow simulation

    • Simplify collision geometry
    • Increase time step cautiously
    • Reduce number of contacts

Performance Tips​

  1. Use the correct physics engine for your application
  2. Tune parameters for your specific use case
  3. Validate URDF/SDF files before simulation
  4. Monitor simulation statistics to identify bottlenecks

Learning Objectives​

After completing this module, you will be able to:

  • Install and configure Gazebo for humanoid robotics applications
  • Set up physics parameters appropriate for humanoid simulation
  • Configure collision detection and gravity properties
  • Create basic simulation scenarios for humanoid robots
  • Optimize Gazebo performance for complex humanoid models

Hands-On Exercise​

  1. Install Gazebo on your system following the steps above
  2. Create a world file with a humanoid robot model
  3. Configure physics parameters for stable bipedal simulation
  4. Run the simulation and adjust parameters for optimal performance
  5. Experiment with different gravity settings and observe the effects on your humanoid's locomotion

Next Steps​

In the next section, we'll explore how to convert URDF robot descriptions to SDF format for use in Gazebo simulation, and how to configure sensors and actuators for realistic humanoid simulation.