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:
- Dynamic Balance Simulation: Accurately models the physics of bipedal locomotion
- Contact Simulation: Realistic handling of feet-ground interactions
- Gravity and Inertial Properties: Critical for humanoid stability
- Complex Environments: Test navigation and interaction in realistic worlds
- 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>