Installation (Ubuntu)
Goal: Install the webots_ros2
package and run simulation examples on Ubuntu.
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 you to start Webots and communicate with it.
This interface is used in most of the following tutorials, so it is required to install it beforehand.
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.
The Webots software should be installed in order to use the webots_ros2
interface.
You can follow the installation procedure or build it from sources.
Alternatively, you can also let webots_ros2
download and install 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 installed different versions of Webots on your computer, webots_ros2
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 these variables is set,
webots_ros2
will look for Webots in the default installation paths for a compatible version:/usr/local/webots
and/snap/webots/current/usr/share/webots
.If Webots couldn’t be found,
webots_ros2
will show a window offering the automatic installation of the latest compatible version of Webots.
Tasks
1 Install webots_ros2
You can either install the official released package, or install it from the latest up-to-date sources from Github.
Run the following command in a terminal.
sudo apt-get install ros-jazzy-webots-ros2
Create a ROS 2 workspace with its src
directory.
mkdir -p ~/ros2_ws/src
Source the ROS 2 environment.
source /opt/ros/jazzy/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 jazzy
Build the package using colcon
.
colcon build
Source this workspace.
source install/local_setup.bash
2 Launch the webots_ros2_universal_robot
example
The following instructions explain how to start a provided example.
First source the ROS 2 environment, if not done already.
source /opt/ros/jazzy/setup.bash
Setting the WEBOTS_HOME
environment variable allows you to start a specific Webots installation.
export WEBOTS_HOME=/usr/local/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