The end result of this tutorial will be the same as in the previous one, but this time all ROS 2 nodes will run in Docker containers.
That means ROS 2 is not needed on the host system at all!
You should be able to run this project even by using a standard OS image provided by manufacturers of Upboard Single Board Computer powering ROSbot PRO (of course you need to install Docker and Docker compose at first).
The goal of this tutorial is to launch navigation2 demo, which will allow the robot to navigate autonomously and avoid obstacles. The ROSbot will be visualized and controlled through Rviz2.
Install ROS2 image on ROSbot
Get a system image
Working on your laptop, visit downloads, find Ubuntu 20.04 + ROS2 Foxy + Docker + Husarnet client and download:
- Tinker Board version for ROSbot 2.0
- UpBoard version for ROSbot 2.0 PRO
Instructions for system installation can be found here.
First ROSbot Configuration
Connecting to Wi-Fi
In the ROSbot 2.0 set there is one USB-Ethernet card.
Turn on the robot and wait until it boots.
Plug in Ethernet adapter (included in set) to USB port in the rear panel
Plug in one end of the Ethernet cable into your computer and other one to the adapter
To connect with ROSbot via ssh, type in terminal application on the computer:
a password is also
To connect to a Wi-Fi network in the terminal type
nmcli d wifi connect <WiFi-SSID> password <WiFi-PASSWORD>
ip ato find your IP address
Reconnect with ssh but this time connect with IP address assigned by WiFi network
Flashing STM32 firmware
If this is your first launch of ROS2 Foxy on ROSbot make sure to upgrade STM32 firmware to one used by docker (pay attention because firmware version for each ROS distribution is different).
STM32 firmware upgrade can be done purely using Docker. Just execute the following line in the Linux terminal of ROSbot:
docker run --privileged --rm husarion/rosbot:latest ./flash_firmware_diff.sh
Setting up your ROSbot
Create folder rosbot-nav2-demo and create file compose.rosbot.yaml in it.
Open this file in your favorite text editor and paste :
# Quick Start (at fist stop ROS Master if working on host)
# $ docker compose -f compose.rosbot.yaml up
# ROS Galactic
command: ros2 launch husarion_nav2 bringup_both.launch.py
# ROS Noetic + ROS 2 Galactic
command: ros2 run ros1_bridge dynamic_bridge
# ROS Master (using custom port in case Master is already running on host OS)
command: stdbuf -o L roscore
# ROS Melodic rosbot hardware layer
- /dev/ttyS4 # must match environment SERIAL_PORT
- SERIAL_PORT=/dev/ttyS4 # default: ttyS1 - rosbot2.0; ttyS4 - rosbot2.0 `pro
command: roslaunch --wait rosbot_description rosbot_docker.launch
# ROS Melodic Rplidar
command: roslaunch --wait rplidar_ros rplidar_a3.launch # For Rosbot 2.0 PRO use roslaunch rplidar_ros rplidar_a3.launch
Save the file and execute in the ROSbot's terminal:
docker compose -f compose.rosbot.yaml pull
To download Docker images specified in
compose.rosbot.yaml from Docker Hub.
Setting up your PC
While your ROSbot is preparing move to your PC. Make sure you have docker and docker compose installed:
$ docker --version
Docker version 20.10.10, build b485636
$ docker compose version
Docker Compose version v2.2.3
If you don't have installed docker follow official installation guide. Do the same in case of lacking docker compose v2. There are also additional steps if you want to skip typing
sudo before each docker command available here.
After making sure you have docker installed just like before create folder with
compose.pc.yaml file and edit it with a text editor.
- CPU only
- GPU acceleration
# Quick Start
# $ xhost local:root
# $ docker compose -f compose.pc.yaml up
# ROS Galactic
# Quick Start
# $ xhost local:root
# $ docker compose -f compose.pc-gpu.yaml up
# ROS Galactic
After that download all Docker Images specified in the
compose.pc.yaml file by using the command:
docker compose -f compose.pc.yaml pull
Launching a demo project
In order to start the demo on your ROSbot make sure you are in the same directory as you were in previous step and start the demo.
docker compose -f compose.rosbot.yaml up
On your PC also make sure to navigate to that directory and start the demo with:
docker compose -f compose.pc.yaml up
remember about executing:
$ xhost local:root
Using a demo
Once ROSbot launched lidar should begin to rotate and logs starts to pop out on terminal.
In Rviz2 add displays you want but for navigation add at least map and select global frame to map.
To add destination use green "2D Goal Pose" arrow in the top bar.
If you want to see rosbot model displayed in rviz2 you will have to select the
rosbot_description/urdf/rosbot.urdf file in RobotModel section.
NOTE Currently dds implementations are heavy on resources so please limit shown displays.
Using many ROS2 devices it the same network (Optional)
ROS2 (DDS) provide a concept of multi cast for machines discovery. As a result every machine running ROS2 can see every nodes/topics on all running machines in the same network.
If you want to limit this behavior change
ROS_DOMAIN_ID in both docker-compose.yaml files this might be number 0-255 (default is 0).
Connecting ROSbot and a laptop over the Internet
You can run the system not only in LAN, but also over the Internet, by adding additional lines to
docker-compose.yml files (both in ROSbot and laptop):
- /var/lib/husarnet # This will persist your Husarnet Client keys, thus IP of the container will be stable/the same between (re)boots
- net.ipv6.conf.all.disable_ipv6=0 # Husarnet is using IPv6 for the internal connections
- ./.env # create .env file in the same folder as Dockerfile and specify HOSTNAME and JOINCODE there
network_mode: service:husarnet in the definitions of other services listed in
It will start an low-latency, P2P VPN network between containers defined in
docker-compose.yml without exposing that network to your host system.
To learn more how to do it, read Connecting Remote Robots Using ROS2, Docker & VPN article from Husarnet's blog.
by Krzysztof Wojciechowski, Adam Krawczyk and Kamil Machoń, Husarion
Do you need any support with completing this tutorial or have any difficulties with software or hardware? Feel free to describe your thoughts on our community forum: https://community.husarion.com/ or to contact with our support: email@example.com