Zenoh Installation and Introduction
About Zenoh
Zenoh is a lightweight protocol that integrates pub/sub (data in motion) and distributed query (data at rest) features into a single place. Its elegance lies in the amount of flexibility and efficiency it provides in return for its minimal overhead.
Zenoh can be deployed in a wide range of scenarios. However, my goal is to use it for robotics. It will allow different components within a robotic system to communicate with each other. For example, a sensor and a controller.
This post will cover the installation of the zenoh-cpp library, which is a header-only binding around the zenoh-c API (or zenoh-pico, but that has a more niche use-case). Since most code samples out there are written in Rust, the language zenoh was originally built in, I thought it'd be nice to write a more complete introduction to zenoh-cpp, and shine a light on it. With that said, this will be a more beginner-friendly tutorial. Seasoned veterans may want to skip ahead to some code samples.
Installation
Windows
Prerequisites
Besides installing it on Windows itself, you have the option of using WSL for development and installation instead. You run into a lot less errors there because there's often less uncertainty with development on Linux.
Building from Source and Installation
In order to install zenoh-cpp, we first need to build and install zenoh-c (since zenoh-cpp is a binding around zenoh-c as mentioned above). So crack open a terminal, and run these commands!
- Run
rustup-update - Clone the zenoh-c repo into a new workspace folder of your choice
git clone https://github.com/eclipse-zenoh/zenoh-c.git
- We will build zenoh-c in a dedicated build directory, which will be kept separate from the source directory.
mkdir -p build && cd buildcmake ../zenoh-ccmake --build . --config Release
- Install the library into our system
cmake --build . --target install- On Windows, our default installation path is
C:/Program Files/${INSTALLATION}, so you will find it there. If you want to install it into a dedicated local directory, run:cmake ../zenoh-c -DCMAKE_INSTALL_PREFIX="path/to/installation"-
Do note that you will then have to point your CMake to the library accordingly
Now that we've built zenoh-c, we can begin building zenoh-cpp.
- Create a fresh new folder for zenoh-cpp, just to keep things organised.
- Clone the zenoh-cpp repository directly into that folder.
git clone https://github.com/eclipse-zenoh/zenoh-cpp.git
- Install zenoh-cpp with a very similar procedure
mkdir -p build && cd buildcmake ../zenoh-cppcmake .. -DCMAKE_PREFIX_PATH="C:/Program Files/${INSTALLATION}"CMAKE_PREFIX_PATHshould be where your zenoh-c installation is. By default,C:/Program Files/zenohc
cmake --install . --config Release
To get a deeper breakdown of the build process here, you may refer to this optional article.
Next Step: Project Setup
Now that we've installed zenoh-cpp into our system, we can start to dive into setting up a project and writing our first few lines of code. You will find this in the next article.
Glossary
Pub/Sub (publication and subscription)
- This is a messaging pattern in which components or nodes within a network are split into two categories: publisher and subscriber (not mutually exclusive).
- When a publisher publishes a message (e.g. a node running on a sensor publishes its readings), a list of nodes that are subscribed to it (subscriber nodes), are able to receive those messages, and perform some corresponding operation.
- Different protocols implement this pattern differently, but a defining property of this property is the decoupling between the publisher and subscriber, making them independent.
Distributed Query
- Unlike pub/sub, instead of waiting for data to arrive, nodes can perform queries to actively find specific data upon demand. A query is made, and a response is returned.
Binding
- Some code that acts as an interface for calling some other code. It aims to cover/translate the same functionality for the code it binds to, but with a different language. Note that it doesn't "port" the functionality over, i.e. rewrite the original code in its entirety.