Webots: ROSbot 2R + SLAM Toolbox
About​
Webots is a popular simulation engine for ROS 2 projects. In this guide we show how to run the ROSbot simulation in Webots and create a map of the unknown world thanks to Slam Toolbox. The end result looks like that:
Quick Start​
Prerequisites
Install Docker Enginer (+ 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-mapping
cd rosbot-mapping
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 is here https://github.com/husarion/rosbot-mapping and it allows you to start SLAM Toolbox on ROSbot in the following configurations:
Configuration | Compose Files | Additional Requirements |
---|---|---|
Physical robot and PC in the same LAN | compose.rosbot.yaml + compose.pc.yaml | - |
Physical robot and PC in different networks (VPN) | compose.rosbot.yaml + compose.pc.yaml | Husarnet VPN configuread on ROSbot and PC and DDS_CONFIG environment variable set to HUSARNET_SIMPLE_AUTO |
Webots simulation | compose.sim.webots.yaml | - |
Let's focus on the Webots simulation:
services:
rviz:
image: husarion/rviz2:humble-22-12-20
runtime: nvidia
container_name: rviz
network_mode: host
ipc: host
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ./config/rosbot.rviz:/root/.rviz2/default.rviz
environment:
- DDS_CONFIG
- RMW_IMPLEMENTATION
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
rosbot:
image: husarion/webots:galactic
runtime: nvidia
network_mode: host
ipc: host
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
environment:
- DDS_CONFIG
- RMW_IMPLEMENTATION
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
command: ros2 launch webots_ros2_husarion robot_launch.py
mapping:
image: husarion/slam-toolbox:humble-22-12-07
network_mode: host
ipc: host
volumes:
- ./config/slam_toolbox_params_webots.yaml:/slam_params.yaml
environment:
- DDS_CONFIG
- RMW_IMPLEMENTATION
command: >
ros2 launch slam_toolbox online_sync_launch.py
slam_params_file:=/slam_params.yaml
use_sim_time:=True
map-saver:
image: husarion/nav2-map-server:humble-22-12-07
network_mode: host
ipc: host
volumes:
- ./maps:/maps
environment:
- DDS_CONFIG
- RMW_IMPLEMENTATION
command: bash -c "while true; do ros2 run nav2_map_server map_saver_cli --free 0.15 --fmt png -f /maps/map; sleep 5; done"
There are 3 Docker services:
rviz
that starts the RViz2 ROS 2 Visualisation tool. The source code for building that Docker image is hererosbot
that starts the ROSbot 2R Webots simulation in the Husarion world. The source code for building that Docker image is heremapping
it's 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 thats all! If you would like to run your own ROS 2 code with Webots, all you need to do is building 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.