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):
If the
ROS2_WEBOTS_HOME
environment variable is set, ROS 2 will use the Webots in this folder, regardless of its version.If the
WEBOTS_HOME
environment variable is set, ROS 2 will use the Webots in this folder, regardless of its version.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
.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-rolling-webots-ros2
Create a ROS 2 workspace with its src
directory.
mkdir -p ~/ros2_ws/src
Source the ROS 2 environment.
source /opt/ros/rolling/setup.bash
Retrieve the sources from Github.
cd ~/ros2_ws
git clone --recurse-submodules https://github.com/cyberbotics/webots_ros2.git src/webots_ros2
Install the package dependencies.
sudo apt install python3-pip python3-rosdep python3-colcon-common-extensions
sudo rosdep init && rosdep update
rosdep install --from-paths src --ignore-src --rosdistro rolling
Build the package using colcon
.
colcon build
Source this workspace.
source install/local_setup.bash
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/rolling/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-rolling-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
For older versions of WSL, the following steps can be followed:
Install VcXsrv.
Launch VcXsrv. You can leave most of the parameters default, except the
Extra settings
page, where you must setClipboard
,Primary Selection
andDisable access control
and unsetNative opengl
.You can save the configuration for future launches.
Click on
Finish
, you will see that the X11 server is running in the icon tray.In your WSL environment, export the
DISPLAY
variable.export DISPLAY=$(ip route list default | awk '{print }'):0
You can add this to your
.bashrc
, so that it is set for every future WSL environment.echo "export DISPLAY=$(ip route list default | awk '{print }'):0" >> ~/.bashrc