How to Install and Demo the Webots Robot Simulator for ROS 2

cover-demo-arm

In this tutorial, I will show you how to install, build, and demo the ROS 2 package for Webots, the free open-source 3D robot simulator created by Cyberbotics Ltd. Installing Webots was a bit difficult, so it is important you follow the steps below click-by-click, command-by-command so that everything installs properly. Here is what the demo looks like:

Prerequisites

ROS 2 Foxy Fitzroy installed on Ubuntu Linux 20.04 (if you are using another distribution, you will need to replace ‘foxy’ with the name of your distribution).


Install

Below are the exact steps I took to install, build, and demo Webots successfully.

First, open a new terminal window, and create a new workspace. You can call it any name, but we will call it “webots”. Inside the workspace, we will create a source (i.e. src) directory. This is where your packages will go.

mkdir -p ~/webots/src

Navigate to the workspace.

cd ~/webots/src

To install the Webots software, open a new terminal window, and type the following commands:

sudo apt-get install ros-$ROS_DISTRO-webots-ros2

Type Y and then Enter to continue.

Next, we need to clone the repository into our workspace.

git clone https://github.com/cyberbotics/webots_ros2.git

Let’s see if the package is in the source folder of our workspace.

ls
1-in-our-workspaceJPG

Open a new terminal window, and try to run the demo.

ros2 launch webots_ros2_demos armed_robots.launch.py

You will be asked if you want to install the latest version of Webots.

Type Y and press Enter.

It will take some time to install.

2-install-webotsJPG

You will see this demo pop up.

3-demo-armJPG

Press CTRL+C in all terminal windows to shutdown the demo.

Go to the following directory:

cd webots/src/webots_ros2/webots_ros2_importer/webots_ros2_importer
git clone https://github.com/cyberbotics/urdf2webots.git
cd urdf2webots
pip3 install -r requirements.txt

At this stage, I was having install errors when I tried to build the package. So here is what I did next.

Remove the webots package. Either go to the file explorer in Linux and delete the webots_ros2 folder manually, or you can run the following commands to delete the folder.

cd ~/webots/src
rmdir webots_ros2

Now, download the package again.

cd ~/webots/src
git clone --recurse-submodules -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git webots_ros2

Build

Go to the root of the workspace.

cd ~/webots/

Check the dependencies.

rosdep update
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO
colcon build

Add the sourcing of the workspace to the bashrc file.

gedit ~/.bashrc

At the bottom of the bash file, add the following line:

source ~/webots/install/setup.bash

Demo

How to Run the Robotic Arm Demo

Open a new terminal window, and type the following command.

ros2 launch webots_ros2_demos armed_robots.launch.py

When you’re done watching the demo, press CTRL + C in all terminal windows.

That’s it. Keep building!