Skip to main content

Gazebo Setup and Physics Tuning

Estimated Reading Time: 20 minutes Prerequisites: Basic Linux command line Difficulty: Beginner

Introduction​

Simulation is essential for robotics. You need to test before deploying to real robots. Gazebo provides this testing ground.

Gazebo is a 3D robot simulator. It simulates physics. It simulates sensors. It visualizes robots in 3D. Companies like Boston Dynamics use it. Research labs use it. Now you will too.

By the end, you'll have Gazebo running. You'll understand physics configuration. You'll be ready to simulate humanoid robots.

What is Gazebo?​

Gazebo simulates the real world. It calculates forces. It detects collisions. It renders sensors. All in real-time.

Think of it as a video game engine for robots. But instead of entertainment, it tests robot behavior. You can break things safely.

Example 1: Why Simulation Matters​

Type: Scenario

Context: You program a walking gait for your humanoid. You want to test it.

Explanation: Without simulation, you deploy to the real robot. The gait has a bug. The robot falls. It breaks. Repair costs $500. With simulation, you test in Gazebo first. The robot falls in simulation. No damage. You fix the bug. You test again. It walks perfectly. Then you deploy to the real robot. It works. No damage. No repair costs.

Takeaway: Simulation lets you fail safely. Test in the virtual world before the real world.

Gazebo Versions​

Gazebo has two major versions:

Gazebo Classic (old):

  • Version 11 and earlier
  • No longer recommended
  • Limited features

Gazebo (new):

  • Also called Gazebo Harmonic
  • Modern architecture
  • Better physics
  • We use this version

Always use the newest Gazebo. Not Gazebo Classic.

Installation​

Ubuntu 22.04 Setup​

First, update your system:

sudo apt update && sudo apt upgrade -y

This ensures all packages are current.

Add Gazebo Repository​

Gazebo isn't in the default Ubuntu repos. Add it:

# Library: Gazebo Harmonic (osrf/gazebo latest)
# Last updated: 2025-12-05
# Tested on: Ubuntu 22.04

sudo apt-get install lsb-release wget gnupg

sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-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

This adds the official Gazebo repository.

Install Gazebo​

Now install:

sudo apt-get update
sudo apt-get install gz-harmonic -y

This downloads and installs Gazebo. It takes 5-10 minutes.

Verify Installation​

Check it works:

gz sim --version

You should see version information. Something like "Gazebo Harmonic 8.0.0".

Test Launch​

Try launching Gazebo:

gz sim

A window appears. This is Gazebo. You see an empty world. Success!

Close it with Ctrl+C in the terminal.

Understanding Physics Engines​

Gazebo doesn't calculate physics itself. It uses physics engines. Different engines have different strengths.

Available Engines​

ODE (Open Dynamics Engine):

  • Default engine
  • Fast
  • Good enough for most robots
  • Simple to configure

Bullet:

  • Better collision detection
  • Used in games
  • Good for complex environments

DART:

  • Best for humanoid robots
  • Handles contacts well
  • More accurate
  • Slightly slower

Simbody:

  • Very accurate
  • Used for biomechanics
  • Overkill for most projects

Which Engine to Use?​

For humanoid robots, use DART. It handles foot contacts better. It's more stable for walking.

For wheeled robots, use ODE. It's faster.

Example 2: Physics Engine Choice​

Type: Comparison

Context: You're simulating a bipedal walker. It keeps falling over.

Explanation: With ODE, the foot contacts are unstable. The robot jitters. It falls. With DART, contacts are stable. The robot stands firmly. It walks smoothly. DART costs 10% more CPU time. But the accuracy is worth it. Your robot doesn't fall randomly.

Takeaway: Choose the right physics engine for your robot type. Humanoids need DART.

Creating a World File​

Gazebo worlds are defined in SDF files. SDF means Simulation Description Format. It's XML.

Basic World Structure​

Here's a minimal world:

worlds/empty_world.sdf
<!-- Library: Gazebo Harmonic SDF 1.9
Last updated: 2025-12-05
Tested on: Gazebo Harmonic 8.0 -->

<?xml version="1.0"?>
<sdf version="1.9">
<world name="empty_world">

<!-- Physics engine -->
<physics name="physics" type="dart">
<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>
</physics>

<!-- Required plugins -->
<plugin
filename="gz-sim-physics-system"
name="gz::sim::systems::Physics">
</plugin>

<plugin
filename="gz-sim-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>

<plugin
filename="gz-sim-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>

<!-- Lighting -->
<light type="directional" name="sun">
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<direction>-0.5 0.1 -0.9</direction>
</light>

<!-- Ground plane -->
<model name="ground">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<plane>
<normal>0 0 1</normal>
</plane>
</geometry>
</collision>
<visual name="visual">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
</visual>
</link>
</model>

</world>
</sdf>

This creates an empty world. It has physics. It has lighting. It has a ground plane.

Launch Your World​

Save the file. Then launch it:

gz sim empty_world.sdf

You see your world. An infinite ground plane. Light from above.

Physics Tuning​

Physics parameters affect simulation quality. Wrong parameters cause instability. Right parameters make simulations stable.

Time Step Size​

This is critical. Smaller steps are more accurate. But slower.

<max_step_size>0.001</max_step_size>

This means 1 millisecond per step. 1000 steps per simulated second.

For humanoid robots: Use 0.001 (1ms). Smaller is better.

For wheeled robots: Use 0.005 (5ms). Faster simulation.

Real-Time Factor​

This controls simulation speed:

<real_time_factor>1.0</real_time_factor>

1.0 means real-time. 1 simulated second = 1 real second.

0.5 means half speed. Slower than real-time.

2.0 means double speed. Faster than real-time.

Update Rate​

How often physics calculates:

<real_time_update_rate>1000</real_time_update_rate>

1000 Hz means 1000 updates per second. This matches the 0.001 step size.

Always set this to 1.0 / max_step_size.

Contact Parameters​

Contacts are where objects touch. Feet on ground. Hands on objects. These need careful tuning.

Friction​

Friction prevents sliding:

<friction>
<ode>
<mu>1.0</mu>
<mu2>1.0</mu2>
</ode>
</friction>

mu is friction coefficient. 1.0 is like rubber on concrete. 0.1 is like ice.

For humanoid feet, use 1.0. High friction prevents slipping.

Contact Stiffness​

How "hard" contacts are:

<contact>
<ode>
<kp>1e7</kp>
<kd>1.0</kd>
</ode>
</contact>

kp is stiffness. Higher = harder contacts. Lower = softer.

For rigid robots, use 1e7 (10 million).

kd is damping. It prevents bouncing.

Bounce​

Control how objects bounce:

<bounce>
<restitution_coefficient>0.0</restitution_coefficient>
</bounce>

0.0 = no bounce. Objects stay on ground.

1.0 = perfect bounce. Like a super ball.

For walking robots, use 0.0. No bouncing.

Integration with ROS 2​

Gazebo and ROS 2 need to communicate. Install the bridge:

# Library: ros-gz-bridge (ROS 2 Humble)
# Last updated: 2025-12-05
# Tested on: ROS 2 Humble, Gazebo Harmonic

sudo apt-get install ros-humble-ros-gz -y

This installs ros_gz packages. They bridge Gazebo to ROS 2.

Bridge Topics​

Start the bridge:

ros2 run ros_gz_bridge parameter_bridge /clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock

This bridges the /clock topic. Gazebo time flows to ROS 2.

You can bridge any topic. Sensors. Commands. States.

Testing Your Setup​

Launch Empty World​

gz sim

Gazebo opens. You see the GUI.

Check Performance​

Look at the bottom right. You see "Real Time Factor". It should be close to 1.00.

If it's below 0.5, your computer is slow. Or your world is too complex.

Add a Simple Model​

In Gazebo, click the top menu. Insert → Model. Select "Box".

A box appears. It falls to the ground. Physics works!

Check ROS 2 Integration​

In another terminal:

ros2 topic list

You should see /clock. The bridge works.

Common Issues​

Issue 1: Gazebo Won't Start​

Problem: "Error: cannot open display"

Solutions:

  • Check you're using a graphical environment
  • Not SSH without X forwarding
  • Try: export DISPLAY=:0

Issue 2: Black Screen​

Problem: Gazebo opens but shows black.

Solutions:

  • Update GPU drivers
  • For NVIDIA: sudo ubuntu-drivers autoinstall
  • Reboot after driver update

Issue 3: Very Slow Simulation​

Problem: Real-time factor is 0.1 or lower.

Solutions:

  • Increase max_step_size to 0.005
  • Simplify your robot model
  • Reduce sensor update rates
  • Close other programs

Issue 4: Robot Jitters and Explodes​

Problem: Robot vibrates violently and flies apart.

Solutions:

  • Decrease max_step_size to 0.0005
  • Increase solver iterations
  • Check your URDF for errors
  • Verify mass values are realistic

Best Practices​

Start Simple​

Don't load complex worlds immediately. Start empty. Add objects one by one. Test each addition.

Monitor Performance​

Always check real-time factor. Keep it above 0.8. If it drops, simplify your simulation.

Save Configurations​

Create world files for different scenarios. Testing. Training. Deployment. Each gets its own file.

Use Version Control​

Put your SDF files in git. Track changes. Revert mistakes easily.

Summary​

You've installed Gazebo. You understand physics engines. You can create world files. You've tuned physics parameters. You've integrated with ROS 2.

Key takeaways:

  • Gazebo simulates robots safely
  • DART engine is best for humanoids
  • Time step size affects accuracy
  • Contact parameters prevent instability
  • ROS 2 bridge connects systems

Next Steps​

Now you're ready to add robots to your simulations.

Continue to: Humanoid URDF/SDF

Related topics: