Skip to main content

Webots: ROSbot 2R + SLAM Toolbox

About​

Webots is a popular simulation engine for ROS 2 projects. This guide demonstrates how to run the ROSbot simulation in Webots and create a map of the unknown world using the Slam Toolbox. The final result looks like this:

Quick Start​

Prerequisites

Install Docker Engine (+ Compose) by using the official guide. The project was tested on:

$ docker compose version
Docker Compose version v2.12.2
$
$ docker --version
Docker version 20.10.21, build baeda1f

The compose.sim.webots.yaml file uses NVIDIA Container Runtime. Make sure you have NVIDIA GPU and the NVIDIA Container Toolkit installed.

Clone the repository:

git clone https://github.com/husarion/rosbot-autonomy
cd rosbot-autonomy

Start the containers in a new terminal:

xhost +local:docker && \
docker compose -f compose.sim.webots.yaml up

And in the second terminal start telop-twist-keyboard for manual ROSbot XL control:

docker exec -it rviz bash

And inside the running container shell execute:

ros2 run teleop_twist_keyboard teleop_twist_keyboard

Source code​

The full source code can be found here and it allows you to start SLAM Toolbox on ROSbot in the following configurations:

ConfigurationCompose FilesAdditional Requirements
Physical robot and PC in the same LANcompose.rosbot.yaml + compose.pc.yaml-
Physical robot and PC in different networks (VPN)compose.rosbot.yaml + compose.pc.yamlHusarnet VPN configured on ROSbot and PC and DDS_CONFIG environment variable set to HUSARNET_SIMPLE_AUTO
Webots simulationcompose.sim.webots.yaml-

Let's focus on the Webots simulation:

compose.sim.webots.yaml
x-gpu-config:
&gpu-config
runtime: nvidia
env_file: .env.gpu

services:

rosbot:
image: husarion/webots:humble-2023.0.4-20230809-stable
<<: *gpu-config
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
command: ros2 launch webots_ros2_husarion rosbot_launch.py

navigation:
image: husarion/navigation2:humble-1.1.12-20240123
<<: *gpu-config
volumes:
- ./config/nav2_${CONTROLLER:-rpp}_params.yaml:/params.yaml
- ./maps:/maps
environment:
- SAVE_MAP_PERIOD=${SAVE_MAP_PERIOD}
command: >
ros2 launch /husarion_utils/bringup_launch.py
slam:=${SLAM:-True}
params_file:=/params.yaml
map:=/maps/map.yaml
use_sim_time:=True

rviz:
image: husarion/rviz2:humble-11.2.6-20230809
<<: *gpu-config
depends_on:
navigation: { condition: service_healthy }
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ./config/rosbot.rviz:/root/.rviz2/default.rviz

There are 3 Docker services:

  • rviz which starts the RViz2 ROS 2 Visualisation tool. The source code for building that Docker image is here
  • rosbot which starts the ROSbot 2R Webots simulation in the Husarion world. The source code for building that Docker image is here
  • mapping is a Dockerized SLAM Toolbox package.

Additionally, config files are bind mounted to rviz and mapping services that are available in the project repository.

Summary​

And that's all! If you would like to run your own ROS 2 code with Webots, all you need to do is to build your own, minimal Docker image running only your own ROS 2 node. You can simply reuse the husarion/webots Docker image that contains launch files for Husarion robots.