Categories: BlogCanonicalUbuntu

Install Gazebo for ROS 2 in under a minute

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 is currently supporting Gazebo Citadel and thus ROS 2 Foxy.

Sponsored

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. But let us know 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 to Gazebo, so it is automatically downloaded and launched. So 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.

Sponsored

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. More on this at 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 visualize 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/Pose@ignition.msgs.Pose

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 soon a ROS2 Humble Gazebo Fortress snap, 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 snap documentation if you want to learn more about snaps for robotics applications.

Ubuntu Server Admin

Recent Posts

Building RAG with enterprise open source AI infrastructure

One of the most critical gaps in traditional Large Language Models (LLMs) is that they…

5 hours ago

Life at Canonical: Victoria Antipova’s perspective as a new joiner in Product Marketing

Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…

1 day ago

What is patching automation?

What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…

2 days ago

A beginner’s tutorial for your first Machine Learning project using Charmed Kubeflow

Wouldn’t it be wonderful to wake up one day with a desire to explore AI…

3 days ago

Ubuntu brings comprehensive support to Azure Cobalt 100 VMs

Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…

3 days ago

Ubuntu Weekly Newsletter Issue 870

Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…

4 days ago