Skip to main content

Webots: ROSbot XL + SLAM Toolbox + Navigation2

About​

Webots is a popular simulation engine for ROS 2 projects. This guide demonstrates how to run the ROSbot XL simulation in Webots, create a map of the unknown world using the Slam Toolbox and deploy autonomous navigation with Navigation2 Stack. 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-xl-autonomy
cd rosbot-xl-autonomy

Start the containers in a new terminal:

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

To direct the robot to explore new areas autonomously and create a map (in the slam mode) or simply to position itself within an existing map, click on the [2D Goal Pose] button in RViz and select the place on the map.

Source code​

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

ConfigurationCompose FilesAdditional Requirements
Physical robot and PC in the same LANcompose.yaml + compose.pc.yaml-
Physical robot and PC in different networks (VPN)compose.yaml + compose.pc.yamlHusarnet VPN configured on ROSbot and PC and FASTRTPS_DEFAULT_PROFILES_FILE environment variable set to /husarnet-fastdds.xml or CYCLONEDDS_URI set to file:///husarnet-cyclonedds.xmldepending on the RMW_IMPLEMENTATION.
Gazebo simulationcompose.sim.gazebo.yaml-
Webots simulationcompose.sim.webots.yaml-

Let's focus on the Webots simulation:

compose.sim.webots.yaml
x-gpu-config:
&gpu-config
runtime: nvidia
environment:
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all

services:

rviz:
image: husarion/rviz2:humble-11.2.6-20230809
<<: *gpu-config
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ./config/rosbot.rviz:/root/.rviz2/default.rviz

rosbot-xl:
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_xl_launch.py

slam:
image: husarion/navigation2:humble-1.1.8-20230809
volumes:
- ./config/${SLAM_MODE:-slam}_webots_params.yaml:/params.yaml
- ./maps:/maps
environment:
- SLAM_MODE=${SLAM_MODE:-slam}
command: >
ros2 launch nav2_bringup ${SLAM_MODE:-slam}_launch.py
params_file:=/params.yaml
map:=/maps/map.yaml
use_sim_time:=True

navigation:
image: husarion/navigation2:humble-1.1.8-20230809
volumes:
- ./config/nav2_params.yaml:/params.yaml
command: >
ros2 launch nav2_bringup navigation_launch.py
params_file:=/params.yaml
use_sim_time:=True

There are 4 Docker services:

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

Additionally, config files are bind mounted to rviz, slam and navigation 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.