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.
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.
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
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
Create folder rosbot-nav2-demo and create file docker-compse.yaml in it.
mkdir rosbot-nav2-democd /rosbot-nav2-demotouch docker-compose.yaml
Open this file in your favorite text editor and paste :
version: "2.3" services: # ROS Noetic + ROS 2 Foxy bridge: image: ros:foxy-ros1-bridge restart: on-failure network_mode: host ipc: host environment: - "ROS_IP=127.0.0.1" - "ROS_MASTER_URI=http://127.0.0.1:11311" - "ROS_DOMAIN_ID=0" command: ros2 run ros1_bridge dynamic_bridge # ROS Melodic rosbot hardware layer rosbot: image: husarion/rosbot tty: true restart: on-failure network_mode: host environment: - "ROS_IP=127.0.0.1" - "ROS_MASTER_URI=http://127.0.0.1:11311" - "SERIAL_PORT=/dev/ttyS4" # default: ttyS1 - rosbot2.0; ttyS4 - rosbot2.0 `pro privileged: false devices: - "/dev/ttyS4" # must match environment SERIAL_PORT command: roslaunch rosbot_description rosbot_docker.launch # ROS Melodic Rplidar rplidar: image: husarion/rplidar:latest restart: unless-stopped network_mode: host environment: - "ROS_IP=127.0.0.1" - "ROS_MASTER_URI=http://127.0.0.1:11311" devices: - /dev/ttyUSB0 tty: true command: roslaunch 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:
To download Docker images specified in
docker-compose.yml from Docker Hub.
While your ROSbot is preparing move to your PC. Make sure you have docker and docker compose installed:
$ docker --versionDocker version 20.10.5, build 55c4c88 $ docker-compose --versiondocker-compose version 1.25.0, build unknown
If you don't have installed docker follow official installation guide. Do the same in case of lacking docker compose. 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
docker-compose.yaml file and edit it with a text editor.
mkdir rosbot-nav2-democd /rosbot-nav2-demotouch docker-compose.yaml
version: "2.3" services: # ROS Foxy navigation nav2: image: husarion/nav2:foxy tty: true restart: on-failure network_mode: host ipc: host environment: - "ROS_DOMAIN_ID=0" command: ros2 launch husarion_nav2 bringup_both.launch.py # ROS Foxy Rviz2 VNC rviz2: image: husarion/ros2-desktop-vnc:latest restart: on-failure network_mode: host ipc: host enviroment: - "ROS_DOMAIN_ID=0" volumes: - ./rosbot_pro.rviz:/root/.rviz2/default.rviz ports: - 6080:80 shm_size: '512m'
After that download all Docker Images specified in the
docker-compose.yml file by using the command:
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.
On your PC also make sure to navigate to that directory and start the demo with:
Once ROSbot launched lidar should begin to rotate and logs starts to pop out on terminal. At this point to make your ROSbot move or see how map is being created you need to launch rviz2. We also prepared ready to run docker container with configured rviz2 and it was already launched on your PC. You can connect to it from your web browser on address http://127.0.0.1:80/. After logging in to VNC launch new terminal session by clicking on LXTerminal icon and type
ros2 run rviz2 rviz2.
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.
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).
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):
husarnet: image: husarnet/husarnet restart: unless-stopped volumes: - /var/lib/husarnet # This will persist your Husarnet Client keys, thus IP of the container will be stable/the same between (re)boots sysctls: - net.ipv6.conf.all.disable_ipv6=0 # Husarnet is using IPv6 for the internal connections cap_add: - NET_ADMIN devices: - /dev/net/tun env_file: - ./.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: firstname.lastname@example.org