You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Jazzy.

Installation (Windows)

Goal: Install the webots_ros2 package and run simulation examples on Windows.

Tutorial level: Advanced

Time: 10 minutes

Background

The webots_ros2 package provides an interface between ROS 2 and Webots. It includes several sub-packages, including webots_ros2_driver, which allows ROS nodes to communicate with Webots. Other sub-packages are mainly examples that show multiple possible implementations using the interface. In this tutorial, you are going to install the package and learn how to run one of these examples.

Prerequisites

It is recommended to understand basic ROS principles covered in the beginner Tutorials. In particular, Creating a workspace and Creating a package are useful prerequisites.

Webots is a prerequisite to use the webots_ros2 package. You can follow the installation procedure or build it from sources.

Alternatively, you can also let webots_ros2 download Webots automatically. This option appears when you launch an example of the package and no Webots installation is found.

Multiple Installations of Webots

If you have more than one installation of Webots, ROS 2 will look for Webots at the following locations (in this order):

  1. If the ROS2_WEBOTS_HOME environment variable is set, ROS 2 will use the Webots in this folder, regardless of its version.

  2. If the WEBOTS_HOME environment variable is set, ROS 2 will use the Webots in this folder, regardless of its version.

  3. If none of the previous points is set/installed ROS 2 will look for Webots in the default installation paths for a compatible version: C:\Program Files\Webots.

  4. If Webots couldn’t be found, webots_ros2 will show a window and offer automatic Webots installation of the last compatible version.

Tasks

1 Install WSL2

On Windows, WSL (Windows Subsystem for Linux) improves the user experience with ROS 2 compared to native Windows installation, as it runs on a Linux platform. Install WSL with an Ubuntu version which is compatible with your ROS distribution and upgrade to WSL2 following the official Microsoft tutorial.

2 Install ROS 2 in WSL

Install ROS 2 inside Ubuntu WSL, following Ubuntu (deb packages).

3 Install webots_ros2

You can then either install webots_ros2 from the official released package, or install it from the latest up-to-date sources from Github.

The following commands must be run inside the WSL environment.

Run the following command in a terminal.

sudo apt-get install ros-iron-webots-ros2

4 Launch the webots_ros2_universal_robot example

WSL doesn’t support hardware acceleration (yet). Therefore, Webots should be started on Windows, while the ROS part is running inside WSL. To do so, the following commands must be run inside the WSL environment.

First source the ROS 2 environment, if not done already.

source /opt/ros/iron/setup.bash

Setting the WEBOTS_HOME environment variable allows you to start a specific Webots installation (e.g. C:\Program Files\Webots). Use the mount point “/mnt” to refer to a path on native Windows.

export WEBOTS_HOME=/mnt/c/Program\ Files/Webots

If installed from sources, source your ROS 2 workspace, if not done already.

cd ~/ros2_ws
source install/local_setup.bash

Use the ROS 2 launch command to start demo packages (e.g. webots_ros2_universal_robot).

ros2 launch webots_ros2_universal_robot multirobot_launch.py

5 RViz troubleshooting

With recent versions of WSL2, RViz should work out of the box.

You can check if it works correctly by running any example that uses RViz, for example:

sudo apt install ros-iron-slam-toolbox
ros2 launch webots_ros2_tiago robot_launch.py rviz:=true slam:=true

The Tiago robot can be controlled using:

ros2 run teleop_twist_keyboard teleop_twist_keyboard

With older WSL versions, RViz2 may not work directly, as no display is available. To use RViz, you can either upgrade WSL or enable X11 forwarding.

In a Windows shell:

wsl --update