Skip to content

Zenoh rmw

boxanm edited this page Jan 13, 2025 · 4 revisions

This guide explains how to use Zenoh as an alternative middleware to DDS for ROS 2 communication on norlab robots.

Relevant links

RMW zenoh

Installation and first tests

At the moment of writing this guide ros2-humble-rmw-zenoh-cpp is not yet officially released. Therefore, you will need to enable deb testing repos by following this guide. Then install zenoh rmw with

sudo apt install ros-$ROS_DISTRO-rmw-zenoh-cpp

If an old rmw was already running (you didn't start the robot with all zenoh enabled), kill it with

pkill -9 -f ros && ros2 daemon stop

Open three terminal panes. In one, run the zenoh router. This we will eventually move to systemctl service:

export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 run rmw_zenoh_cpp rmw_zenohd

In the remaining two panes, execute:

export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 run demo_nodes_cpp talker

and

export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 run demo_nodes_cpp listener

You should see now messages going through the network from one node to another.

System setup

We will now create a systemctl service that starts rmw_zenohd automatically on startup. Create a file /etc/systemctl/systemd/launch-zenoh.service with the following content:

[Unit]
Description=Eclipse Zenoh RMW Router
Documentation=https://github.com/ros2/rmw_zenoh
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
WorkingDirectory=/home/robot/
ExecStart=/home/robot/ros2_ws/src/norlab_robot/scripts/startup/launch-zenoh.sh
KillMode=mixed
KillSignal=SIGINT
RestartKillSignal=SIGINT
Restart=on-failure
RestartSec=2
User=robot
StandardOutput=journal
StandardError=journal
SyslogIdentifier=rmw_zenohd

[Install]
WantedBy=default.target

This service launches a file in norlab_robot, which in turns starts rmw_zenohd in screen named zenoh_router:

#! /bin/bash
# service file: /etc/systemd/system/launch-zenoh.service

screen_name="zenoh_router"
screen -S $screen_name -X stuff $'\003'

source /home/robot/ros2_ws/src/norlab_robot/scripts/bash/env.sh
source /opt/ros/humble/setup.bash
source /home/robot/ros2_ws/install/local_setup.bash

sleep 2

echo "Starting Zenoh router.."
export RUST_LOG=zenoh=info
screen -dmS $screen_name ros2 run rmw_zenoh_cpp rmw_zenohd

sleep 2
if screen -list | grep -q $screen_name; then
    echo "Zenoh router started successfully in screen  '$screen_name.'"
else
    echo "ERROR! Failed to start Zenoh router."
fi

If you have any other ROS services running at startup, make sure to add the following lines to their respective service files, in order to only start them after zenoh is running:

[Unit]
...
After=launch_zenoh
Wants=launch_zenoh

Finally, we will need to specify that we want to use zenoh_rmw for all our nodes. This can be done by placing

export RMW_IMPLEMENTATION=rmw_zenoh_cpp

in norlab_robot/scripts/bash/env.sh. Once this is done, sudo reboot and now your computer executes all ROS communication over the Zenoh network!

Custom configuration

With zenoh_rmw, there are two configuration files we need to consider:

  • Router config - started with ros2 run rmw_zenoh_cpp rmw_zenohd
  • Session config - any other ROS 2 node For more info on zenoh_rmw design, check this git page. In our case, the configuration files are located in norlab_robot/scripts/config/zenoh_router.json5 and norlab_robot/scripts/config/zenoh_session.json5. For now on Castor, these look exactly the same as the default files here (router) and here (session). To let zenoh know that we want to use our configuration files, we need to add
export ZENOH_ROUTER_CONFIG_URI=$NORLAB_ROBOT_PATH/config/zenoh_router.json5
export ZENOH_SESSION_CONFIG_URI=$NORLAB_ROBOT_PATH/config/zenoh_session.json5

in norlab_robot/scripts/bash/env.sh.

Connecting with remote computer

If you wanna be able to access the topics and nodes published on Castor's computer, you can again sudo apt install ros-$ROS_DISTRO-rmw-zenoh-cpp. In your zenoh_router.json5, specify Castor computer's IP address:

{
  connect: {
    endpoints: ["tcp/192.168.4.2:7447"],
  },
}

and run zenoh-router with

export RMW_IMPLEMENTATION=rmw_zenoh_cpp
export ZENOH_ROUTER_CONFIG_URI=$HOME/config/zenoh_session.json5
ros2 run rmw_zenoh_cpp rmw_zenohd

❗❗❗While this configuration should be enough to get the comm working, it is unfortunately not the case in the moment. ❗❗❗

Debugging and known issues

Norlab's Robots

Protocols

Templates

Resources

Grants

Datasets

Mapping

Deep Learning

ROS

Ubuntu

Docker (work in progress)

Tips & tricks

Clone this wiki locally