Skip to main content

Gazebo: ROSbot XL + SLAM Toolbox

About

In this guide, we will show you how to use Gazebo, a popular simulation engine, to run the ROSbot XL simulation. We will also demonstrate how to use Slam Toolbox to create a map of the unknown world. The final result will look like in the video below.

We will be using Docker to run this project, but you can also run the ROSbot XL simulation directly on your host. You can find the Gazebo simulation model in the official ROSbot XL ROS 2 package repository here: https://github.com/husarion/rosbot_xl_ros. Let's get started!

Quick Start

Prerequisites

Before we begin, there are a few things you'll need to have set up on your computer. First, you'll need to install Docker Engine and Docker Compose by following the official installation guide. This project has been tested on the following setup:

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

Additionally, the compose.sim.gazebo.yaml file in this project uses NVIDIA Container Runtime. So, please make sure that you have an NVIDIA GPU and the NVIDIA Container Toolkit installed on your system before moving forward.

Clone the repository:

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

Start the containers in a new terminal:

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

And in the second terminal start teleop-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

You can access the full source code for this project on GitHub at the following link: https://github.com/husarion/rosbot-xl-mapping. This code will allow you to run the SLAM Toolbox on the ROSbot in a variety of 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
Gazebo simulationcompose.sim.gazebo.yaml-

Let's focus on the Gazebo simulation:

compose.sim.gazebo.yaml
services:

rviz:
image: husarion/rviz2:galactic-8.5.2-20230204-stable
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:
- RMW_IMPLEMENTATION
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all

rosbot-xl:
image: husarion/rosbot-xl-gazebo:humble-0.3.0-20230204
runtime: nvidia
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
network_mode: host
ipc: host
environment:
- RMW_IMPLEMENTATION
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
command: ros2 launch rosbot_xl_gazebo simulation.launch.py mecanum:=${MECANUM:-True}

mapping:
image: husarion/slam-toolbox:humble-2.6.4-20230204-stable
network_mode: host
ipc: host
volumes:
- ./config/slam_toolbox_params.yaml:/slam_params.yaml
environment:
- 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-1.1.5-20230204-stable
network_mode: host
ipc: host
volumes:
- ./maps:/maps
environment:
- 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:

  • The rviz service launches the RViz2 ROS 2 Visualization tool. You can find the source code for building this Docker image here
  • The rosbot-xl service starts the ROSbot XL Gazebo simulation in the Husarion world. The source code for building this Docker image can be found here
  • The mapping service is a Dockerized version of the SLAM Toolbox package.

In addition, configuration files are also included in the project repository and are bind-mounted to the rviz and mapping services.

Summary

That's all there is to it! If you're interested in running your own ROS 2 code with Gazebo, all you need to do is create a minimal Docker image that runs your ROS 2 node. You can easily reuse the husarion/rosbot-xl:humble-simulation Docker image, which includes launch files for Husarion robots. This makes it easy to run your own ROS 2 code with Gazebo and provides a great way to test and debug your code in a simulated environment.

In this project, we used a combination of SLAM Toolbox, Gazebo, and Docker to create a simulation of the ROSbot XL robot and create a map of the unknown world:

  • Gazebo simulation engine is a popular and widely used tool for simulating robots in ROS 2 projects.
  • SLAM Toolbox was great for creating the map because it is a powerful tool that allows for easy implementation of simultaneous localization and mapping (SLAM) algorithms.
  • Finally, Docker was a great choice for this project because it allows for easy deployment and management of the different components of the simulation, such as the RViz2 visualization tool, the ROSbot XL Gazebo simulation, and the SLAM Toolbox package. By using Docker, we were able to easily set up and run the simulation with minimal setup and configuration.

Overall, the use of SLAM Toolbox, Gazebo, and Docker in this project provided a powerful and efficient way to create a simulation of the ROSbot XL robot and generate a map of the unknown world. It's a great example of how these tools can be used together in a real-world application.