Learning Gazebo and ROS simulation for robotics beginners is one of the smartest investments you can make as a robotics developer. Instead of risking your physical robot on untested code, simulation lets you develop, test, and debug algorithms in a safe virtual environment. A simulation crash costs nothing; a real robot crash can cost thousands of rupees and hours of repair. This guide walks you through setting up Gazebo, integrating it with ROS2, and running your first simulated robot.
Table of Contents
- Why Simulate Before Building?
- Installing Gazebo & ROS2 Integration
- Creating a Robot URDF for Simulation
- Running Your First Simulation
- Adding Simulated Sensors
- Simulating Navigation with Nav2
- Frequently Asked Questions
Why Simulate Before Building?
Simulation is standard practice at every professional robotics company — Boston Dynamics, Amazon Robotics, and every autonomous vehicle company test in simulation for thousands of hours before deploying physical robots. For Indian students and hobbyists, simulation offers additional compelling benefits:
- Cost savings: Test navigation algorithms without risking your ₹8,000 robot chassis. Simulate motor driver bugs before they burn out your ₹1,500 L298N.
- Speed: Debug 10 runs in the time a physical test takes 1. Simulation can run faster than real-time on a modern laptop.
- Repeatability: Every simulation run starts from exactly the same state. Impossible with physical robots.
- No physical hardware needed: Students can learn robotics on any laptop without purchasing hardware. This democratises robotics education across India.
- Safety: Test emergency stop algorithms, collision avoidance, and edge cases that would be dangerous with a real robot.
Installing Gazebo & ROS2 Integration
There are two Gazebo versions to know about: Gazebo Classic (versions 1-11, now called “Gazebo Classic”) and Gazebo Sim (formerly Gazebo Ignition, versions Fortress onwards). For ROS2 Humble, use Gazebo Fortress or Harmonic.
# Install ROS2 Humble (if not already done)
# See our ROS2 installation guide
# Install Gazebo Harmonic (recommended for new projects)
sudo apt install -y ros-humble-ros-gz
# OR install Gazebo Classic (if following older tutorials)
sudo apt install -y ros-humble-gazebo-ros-pkgs
# Verify Gazebo installation
gz sim --version
# Should output: Gazebo Sim, version X.X.X
# Test basic Gazebo launch
gz sim shapes.sdf
System Requirements: Gazebo is GPU-accelerated for rendering. A dedicated GPU (even an older Nvidia GTX 1050 or AMD RX 570) significantly improves simulation performance. On Raspberry Pi 4, Gazebo Sim runs slowly — use your laptop for simulation and deploy algorithms to the Pi.
Creating a Robot URDF for Simulation
URDF (Unified Robot Description Format) is an XML format that describes your robot’s structure, physics, and visual appearance. It is used by both ROS and Gazebo.
<!-- simple_robot.urdf -->
<?xml version="1.0"?>
<robot name="simple_robot">
<!-- Base link -->
<link name="base_link">
<visual>
<geometry>
<box size="0.3 0.2 0.05"/> <!-- 30cm x 20cm x 5cm -->
</geometry>
<material name="grey">
<color rgba="0.5 0.5 0.5 1"/>
</material>
</visual>
<collision>
<geometry>
<box size="0.3 0.2 0.05"/>
</geometry>
</collision>
<inertial>
<mass value="1.5"/> <!-- kg -->
<inertia ixx="0.01" ixy="0" ixz="0"
iyy="0.01" iyz="0" izz="0.02"/>
</inertial>
</link>
<!-- Left wheel -->
<link name="left_wheel">
<visual>
<geometry><cylinder radius="0.05" length="0.03"/></geometry>
<material name="black"><color rgba="0.1 0.1 0.1 1"/></material>
</visual>
<collision>
<geometry><cylinder radius="0.05" length="0.03"/></geometry>
</collision>
<inertial>
<mass value="0.2"/>
<inertia ixx="0.0001" ixy="0" ixz="0"
iyy="0.0001" iyz="0" izz="0.0002"/>
</inertial>
</link>
<!-- Left wheel joint -->
<joint name="left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<origin xyz="-0.1 0.12 0" rpy="1.5708 0 0"/> <!-- rotated 90° -->
<axis xyz="0 0 1"/>
</joint>
<!-- Repeat for right wheel... -->
<!-- Differential drive Gazebo plugin -->
<gazebo>
<plugin filename="libgazebo_ros_diff_drive.so"
name="differential_drive_controller">
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<wheel_separation>0.24</wheel_separation>
<wheel_diameter>0.1</wheel_diameter>
<command_topic>/cmd_vel</command_topic>
<odometry_topic>/odom</odometry_topic>
</plugin>
</gazebo>
</robot>
Running Your First Simulation
# Create a ROS2 package for your robot
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_cmake my_robot_sim
# Create directories
mkdir -p my_robot_sim/urdf my_robot_sim/launch my_robot_sim/worlds
# Copy your URDF to urdf/ directory
# Create a basic flat world SDF file
cat > my_robot_sim/worlds/simple_world.sdf << 'EOF'
<?xml version="1.0"?>
<sdf version="1.8">
<world name="simple">
<plugin filename="libgz-sim-physics-system.so" name="gz::sim::systems::Physics"/>
<plugin filename="libgz-sim-sensors-system.so" name="gz::sim::systems::Sensors"/>
<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<direction>-0.5 0.1 -0.9</direction>
</light>
<model name="ground_plane">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry><plane><normal>0 0 1</normal></plane></geometry>
</collision>
</link>
</model>
</world>
</sdf>
EOF
# Build the package
cd ~/ros2_ws && colcon build
source install/setup.bash
# Launch Gazebo with your robot
gz sim my_robot_sim/worlds/simple_world.sdf
Adding Simulated Sensors
Simulated sensors generate realistic sensor data using the physics engine and ray-casting. Add them to your URDF:
<!-- LiDAR sensor plugin (add inside <robot> tag) -->
<link name="lidar_link">
<visual>
<geometry><cylinder radius="0.025" length="0.05"/></geometry>
</visual>
</link>
<joint name="lidar_joint" type="fixed">
<parent link="base_link"/>
<child link="lidar_link"/>
<origin xyz="0 0 0.05"/>
</joint>
<gazebo reference="lidar_link">
<sensor type="ray" name="lidar">
<ray>
<scan>
<horizontal>
<samples>360</samples>
<min_angle>-3.14159</min_angle>
<max_angle>3.14159</max_angle>
</horizontal>
</scan>
<range><min>0.1</min><max>10.0</max></range>
</ray>
<plugin name="gazebo_ros_lidar" filename="libgazebo_ros_ray_sensor.so">
<ros><remapping>~/out:=/scan</remapping></ros>
<output_type>sensor_msgs/LaserScan</output_type>
</plugin>
</sensor>
</gazebo>
Simulating Navigation with Nav2
# Install Nav2 for ROS2 Humble
sudo apt install -y ros-humble-navigation2 ros-humble-nav2-bringup
ros-humble-turtlebot3-gazebo
# Launch TurtleBot3 simulation with navigation
export TURTLEBOT3_MODEL=waffle
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py &
# Launch Nav2 navigation stack
ros2 launch turtlebot3_navigation2 navigation2.launch.py
map:=$HOME/map.yaml &
# Launch RViz2 to send navigation goals
ros2 launch turtlebot3_bringup rviz2.launch.py
In RViz2, use the “Nav2 Goal” tool to click a destination on the map. Watch the robot plan a path around obstacles and navigate autonomously in simulation.
Frequently Asked Questions
Gazebo is running very slowly on my laptop — how do I speed it up?
Reduce rendering quality: open Gazebo GUI, Edit → GUI Settings, reduce visual quality. Disable shadows in world SDF. Use a simpler world (fewer objects). Enable GPU acceleration — check that your GPU drivers are installed correctly. Also consider using Gazebo in headless mode (no GUI) when running experiments that don’t need visual output: gz sim -s world.sdf (server only).
How realistic is Gazebo physics compared to real-world behaviour?
Gazebo physics is reasonably accurate for most robotics applications but has known limitations. Wheel odometry in Gazebo is more accurate than real wheels (no slip, consistent friction). Contact physics and grasping are notoriously difficult to simulate accurately. The “sim-to-real gap” means algorithms that work perfectly in simulation often need tuning on real hardware. Use simulation for algorithm development and structure, then tune parameters on real hardware.
Can I import a 3D-printed robot design from Fusion 360 into Gazebo?
Yes! Export your Fusion 360 design as STL or COLLADA (.dae) file. Reference these mesh files in your URDF visual and collision elements. For accurate physics, also specify inertial properties (mass, inertia tensor) either manually or use Gazebo’s inertia calculation from mesh. The URDF builder plugin in Fusion 360 can automate much of this process.
Is there a cloud-based Gazebo option for students without powerful laptops?
The ROS Development Studio (theconstructsim.com) provides browser-based ROS and Gazebo simulations. This is excellent for Indian students with older laptops or limited internet bandwidth to download large simulation packages. Free tier available, paid tiers for more compute.
Add comment