ROS2 Dev with Gazebo 11

Ferdinand de Antoni
3 min readMay 3, 2020

I wanted to use the latest development version of ROS2 (currently code name foxy) with Gazebo11. To make this work, I did the following:

Install Ubuntu 20.04 Focal

Download the desktop version of Ubuntu 20.04 LTS and install it. You can keep all the options default (no need to install additional software).

Build ROS2 From Source

Follow the build steps as indicated in Building ROS 2 on Linux. After installing, be sure to test that your installation works correctly using the test example in the guide. If working correctly, add the sourcing of the environment variables to your .bashrc like so:

echo “source ~/ros2_foxy/install/setup.bash” >> ~/.bashrc

Install Gazebo 11

Luckily Gazebo 11 for Focal is now available from the OSRF repo. Add this repo as follows:

$ sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
$ wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt key add -
$ sudo apt update

Now you can install gazebo11:

$ sudo apt install gazebo11 libgazebo11-dev

After installing gazebo11, you can try launching it from the console by simply typing the following:

$ gazebo

If Gazebo launches correctly, then you are all set to add the Gazebo ROS packages.

Note, if you are installing on a VMWare image, it is likely Gazebo will not start and exit with the following error:

VMware: vmw_ioctl_command error Invalid argument.

When this happens you need to set the following before running Gazebo:

$ export SVGA_VGPU10=0

Build Gazebo ROS Packages

To build the Gazebo ROS packages, you can following the steps as indicated in the section Install from source (on Ubuntu) from the Installing gazebo_ros_pkgs (ROS 2) guide. HOWEVER, for step 5 you will need to use the following instead:

$ vcs custom --args checkout gazebo11_foxy

This will give the following output:

$ vcs custom --args checkout gazebo11_foxy
EE.
=== ./src/ros-perception/image_common (git) ===
error: pathspec 'gazebo11_foxy' did not match any file(s) known to git
=== ./src/ros-perception/vision_opencv (git) ===
error: pathspec 'gazebo11_foxy' did not match any file(s) known to git
=== ./src/ros-simulation/gazebo_ros_pkgs (git) ===
Switched to a new branch 'gazebo11_foxy'
Branch 'gazebo11_foxy' set up to track remote branch 'gazebo11_foxy' from 'origin'.

Don’t worry about the errors, the git repo we really wanted to change is the gazebo_ros_pkgs repo. The others are good on their default branches.

Once you have run through all the steps in the guide, also add the sourcing of the environment variables to your .bashrc as follows:

$ echo "source ~/ws/install/setup.bash" >> ~/.bashrc

Open a new terminal (which will now have the appropriate environment variables sourced) and test if everything is working correctly by downloading a world file with a simple robot:

$ wget https://raw.githubusercontent.com/ros-simulation/gazebo_ros_pkgs/ros2/gazebo_plugins/worlds/gazebo_ros_diff_drive_demo.world

Launch Gazebo with this world file:

$ gazebo --verbose gazebo_ros_diff_drive_demo.world

Next, open up another terminal and run the following:

$ ros2 topic pub /demo/cmd_demo geometry_msgs/Twist '{linear: {x: 1.0}}' -1

If all went correctly, you should now see the robot move in Gazebo.

--

--