Welcome to Jetson AGX Thor repository
22.ROS2 Gazebo simulation platform
22. ROS2 Gazebo Simulation Platform
1. Introduction to Gazebo
Gazebo is the most widely used 3D physics simulation platform within the ROS ecosystem. It supports physics engines and is capable of high-quality graphical rendering. Beyond merely simulating robots and their surrounding environments, it allows for the incorporation of physical properties such as friction and elasticity coefficients.
For instance, if we were developing a Mars rover, we could simulate the Martian surface environment directly within Gazebo. Similarly, when working with drones—where factors like limited battery life and flight restrictions often prevent frequent experimentation with physical hardware—it is highly practical to utilize Gazebo for initial simulations. Once the algorithms have reached a sufficiently advanced stage of development, they can then be deployed and executed on the actual physical robot.
Consequently, simulation platforms like Gazebo serve as invaluable tools for validating robot algorithms, optimizing robot designs, and testing robot applications within specific scenarios, thereby expanding the possibilities available in robot development.
Note: This chapter is intended solely for informational and learning purposes; the Gazebo environment is not configured within this tutorial, as the development process here relies directly on debugging with physical hardware.
2. Installation and Execution
The Gazebo Harmonic version corresponds to ROS2 Jazzy. Since Gazebo Harmonic is not included in the standard ROS package repositories, you must first add the Gazebo Harmonic download source.
xxxxxxxxxxsudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable noble main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/nullsudo apt update
Proceed to install the Gazebo Harmonic-related plugins.
xxxxxxxxxxsudo apt install -y gz-harmonicsudo apt install -y ros-jazzy-ros-gz
Add the directory path for the turtlebot3_gazebo models to your environment variables.
xxxxxxxxxxecho 'export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/jazzy/share/turtlebot3_gazebo/models' >> ~/.bashrcsource ~/.bashrc
Running Gazebo via the Command Line
Open a terminal and run the shapes.sdf test example.
xxxxxxxxxxgz sim -v -r shapes.sdf
Here, the -v argument stands for "verbose" mode, which prints detailed logs; -r stands for "render," meaning it launches the GUI; and shapes.sdf is a test world included with Gazebo Harmonic, located at the path: /usr/share/gz/gz-sim8/worlds/shapes.sdf.
Executing this command opens the Gazebo simulation interface, which contains a cone, an ellipsoid, a sphere, a cube, a cylinder, and a capsule. When the simulation runs, the ellipsoid will move slightly.

Press Ctrl+C in the terminal to exit Gazebo.
Running Gazebo via ROS
Open a terminal and run the shapes.sdf test example.
xxxxxxxxxxros2 launch ros_gz_sim gz_sim.launch.py gz_args:="-r -v shapes.sdf"
Select the shapes.sdf file from the options on the right side, then click RUN. You may also select other world files to test.


Press Ctrl+C in the terminal to exit Gazebo.