Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

  1. Blog
  2. Article

gbeuzeboc
on 8 July 2022


Recently, we announced the beta release of the Gazebo snap to help you install Gazebo for ROS 2. The gazebo snap is easy to install on dozens of Linux distributions and comes bundled with all the dependencies and the ROS 2 integration. It currently supports Gazebo Citadel and thus ROS 2 Foxy.

For the sake of clarity, when talking about Gazebo we are referring to the “new” Gazebo (formerly Ignition Gazebo). 

Let’s see how to install Gazebo for ROS 2 using the Gazebo snap!

How to install Gazebo for ROS 2 using the Gazebo snap

Since Gazebo snap is in beta as of the time of writing, to install it we will specify the channel:

With the option --channel, we are explicitly using the track (citadel) and the risk (beta). We will automatically get updates from this channel. If your Linux distribution of choice doesn’t currently support snap, get more details on the installing snapd documentation.

sudo snap install gazebo --channel=citadel/beta

After installation, we can execute the freshly installed Gazebo with the command gazebo.gz gazebo.

What can the Gazebo snap do?

Let’s test the Gazebo snap with a simple example:

gazebo.gz gazebo shapes.sdf

We now see the ‘shapes’ demo and are able to interact with it:

This is a neat little demo to make sure everything is working fine. Let’s try a more compelling example.

Load worlds in Gazebo

Gazebo allows us to load a world for the simulation. The world file could be our own or one of the many publicly available. In this section, we will explore how to load worlds into our simulation.

Load worlds from Fuel

Gazebo Fuel is an online database that lets one share and access tons of worlds and models. We will make use of it to find an interesting demo and run it.

From the worlds section, we can select the example we want. Let’s settle on using the world tugbot_depot from MovAI. Copy the world URL by clicking on the chevrons icon.

We will paste this URL directly in Gazebo, so it’s automatically downloaded and launched. Let’s close our previous demo and re-open Gazebo with the new one. Be patient, the download can take some time:

gazebo.gz gazebo "https://fuel.gazebosim.org/1.0/MovAi/worlds/tugbot_depot"

After a few seconds, you should see the depot world as well as a robot, as pictured below.

Take a couple of minutes to explore the warehouse and contemplate how detailed this demo is!

Load worlds from host

We can also load an SDF file from our host directly with a locally available world. Let’s try the Nao joint control demo by downloading the world on the host:

gazebo.gz fuel download -u https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/NAO%20joint%20control

If you want to learn more about the Fuel command line, checkout their documentation.

Now we can launch it with:

gazebo.gz gazebo -r ~/snap/gazebo/current/.ignition/fuel/fuel.ignitionrobotics.org/openrobotics/worlds/nao%20joint%20control/1/nao_world.sdf

Note how the demo was downloaded to the ‘~/snap/gazebo/’ folder. This folder and its content are preserved across updates and rollbacks. Read more on the documentation page.

The “-r” option is added to start the simulation at launch. With the simulation being started, we can play with the joint position controller!

Now that we have explored how to load worlds into our Gazebo snap. Let’s see how to bring ROS 2 into the equation!

Run the Gazebo ROS 2 controllers

For this section, we need a system with ROS 2  Foxy installed on an Ubuntu 20.04 (or a container running ROS2 foxy). The gz_snap_ros2_control_demos is a ROS 2 package containing launchfiles and configurations similar to gz_ros2_control_demos. The major difference comes from the launchfiles executing Gazebo snap applications. Everything that is Gazebo related will happen from the snap. We need to create a ROS 2 workspace and clone the  gz_snap_ros2_control_demos:

. /opt/ros/foxy/setup.bash
mkdir -p ~/r2_ws/src
cd ~/r2_ws/src
git clone https://github.com/Guillaumebeuzeboc/gz_snap_ros2_control_demos -b foxy
cd ~/r2_ws
rosdep install --from-paths src/gz_snap_ros2_control_demos/ --rosdistro=foxy -i -y
colcon build
. install/local_setup.bash

Now, we are ready to run a demo:

ros2 launch gz_snap_ros2_control_demos diff_drive_example.launch.py

And in another terminal we can run the example code interacting with it:

. ~/r2_ws/install/setup.bash
ros2 run gz_snap_ros2_control_demos example_diff_drive

We now see the robot moving:

There are three other demos from this package that we can try. Take a few minutes to give them a try.

Use the ROS Ign bridge

To exchange messages between ROS 2 and Gazebo, we can use the ros-ign-bridge. Here again we are going to assume that the Gazebo snap is installed and that we are on a machine running Ubuntu 20.04 with ROS 2 foxy installed.

This time we will need three terminals. One for the Gazebo snap, one for the ros-ign-bridge from the Gazebo snap, and one to visualise the result.

In the first terminal, launch Gazebo:

gazebo.gz gazebo "https://fuel.gazebosim.org/1.0/MovAi/worlds/tugbot_depot"

In the second terminal, we run the ros-ign-bridge. We bridge the Gazebo topic, /model/tugbot/pose (to list Gazebo topic with gazebo.gz topic -l) with the command:

gazebo.ros-gz-bridge parameter_bridge /model/tugbot/pose@geometry_msgs/msg/[email protected]

And finally, in the last terminal, we can “echo” this bridged topic (don’t forget to press the “play” button in the simulation GUI):

. /opt/ros/foxy/setup.bash
ros2 topic echo /model/tugbot/pose

Congratulations, you successfully got the robot pose from Gazebo to ROS 2.

Known limitations

Gazebo snap comes with known limitations we are still working out, notably:

  • No access to the host system path (e.g. /opt/ros). Make sure that your files, such as robot models, are located in the $HOME directory.
  • Custom plugins are not supported yet.

Install Gazebo for ROS 2 summary

We have explored how to install Gazebo for ROS 2, use and interact with the Gazebo snap. This allows you to easily install Gazebo to simulate your robot and its environment. With the Gazebo ROS 2 controllers embedded in the snap, you can easily set up your simulation with your favourite robotics simulator. 

We are planning to release a ROS2 Humble Gazebo Fortress snap soon, so stay tuned!

If you have any other feedback or ideas regarding the Gazebo snap, please join our forum and let us know what you think. Furthermore, have a look at the developer guide if you want to learn how to snap your robotics application.

Related posts


gbeuzeboc
27 April 2023

Optimise your ROS snap – Part 6

Robotics Article

Welcome to Part 6 of our “Optimise your ROS snap” blog series. Make sure to check Part 5. This sixth and final part will  summarise every optimisation that we did. We will provide a critique for every optimisation that we tried along this series of blogs. Finally, we have reached the last part of this ...


gbeuzeboc
21 April 2023

Optimise your ROS snap – Part 4

Robotics Article

Welcome to Part 4 of our “optimise your ROS snap” blog series. Make sure to check Part 3 before. This fourth part is going to explain what dynamic library caching is. We will present how to use it to optimise ROS snaps, along with the different points to be careful about. Finally, we will apply ...


gbeuzeboc
17 April 2023

Optimise your ROS snap – Part 3

Robotics Article

Welcome to Part 3 of our “optimise your ROS snap” blog series. Make sure to check Part 2. This third part is going to present safe optimisations consisting of removing duplicates and unnecessary files. We will present three different methods as well as their cumulative benefits for the performance of ROS snaps. When snaps are ...