Skip to content

Zenoh rmw

boxanm edited this page Jan 15, 2025 · 3 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

ℹ️ It might be a good idea to change ros2 debian repository back to stable from testing at this point.

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: {
/// assuming you are connected to the wifi network castor_norlab
    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_router.json5
export ROS_DOMAIN_ID=4 # 4 is Castor's domain id
ros2 run rmw_zenoh_cpp rmw_zenohd

in a second terminal window, list all available topics on Castor with

export RMW_IMPLEMENTATION=rmw_zenoh_cpp
export ROS_DOMAIN_ID=4 # 4 is Castor's domain id
ros2 topic list

While the above was working on both Ubuntu 22 and 24, we didn't get any messages through with ros2 topic echo on Ubuntu 24. Even though a small message, such as /joy or /chatter, passed on Ubuntu 22, we still weren't able to receive larger ROS messages, such as point clouds. The router config probably needs more tweaking to achieve the desired performance.

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