Introducing ROS2 Wrapper for ZED
It’s a little more than a year since the first official release of ROS2 has been released. While the new version of the Robotic Operating System was promising, many features were still under development.
With the release of ROS2 Crystal Clemmys in December 2018, ROS2 has gained a lot of maturities and we felt it was time to add support in ROS2 for the ZED and its 3D computer vision software stack.
One year after Crystal, in December 2019, ROS2 Eloquent Elusor has been released with many changes and improvements on stability.
What’s new in ROS2 respect to ROS1
ROS2 introduces a lot of changes with respect to the ten-year-old ROS1. The official ROS2 design post presents these changes in detail.
The biggest step forward is in the development languages. ROS2 supports Python v3.5, C++11, C++14 and C++17. The “Boost” library is not a dependency anymore.
Also, while ROS1 was created with the PR2 robot in mind, ROS2’s design targets every kind of robot, with an emphasis on robot security, real-time control and distributed control.
Multiple nodes in one process
In ROS1, you can write your code either as a ROS node or as a ROS nodelet. ROS1 nodes are being compiled into executables. ROS1 nodelets on the other hand are being compiled into a shared library which is then being loaded at runtime by a container process.
In ROS2 the concepts of node and nodelet has been unified and each not is now a
Component, very similar to the nodelet in ROS1. In ROS2 a single process can execute more than one node, using Composition, exploiting the intra-process communication feature.
ROS1 communication infrastructure is based on a custom serialization format, a custom transport protocol and a custom central discovery mechanism. ROS1 needs a “master node” running on one of the machines of the robot infrastructure to relay all messages between the different nodes..This means that that if the communication with the “master” node fails, the whole system collapses.
ROS2 has an abstract middleware interface that provides serialization, transport, and discovery. Currently, all implementations of this interface are based on the DDS standard. This enables ROS2 to provide various Quality of Service policies (QoS) which improve communication over different networks. Playing with QoS parameters gives direct control over the reliability, latency and lifespan of each published message. You can reduce the latency of a sensor message that does not need reliability, but guarantee that a message will remain available until it does not reach its destination.
Yuya Maruyama’s “Exploring the Performance of ROS2” provides an excellent analysis about the communication improvements in ROS2.
Components with life cycle
In ROS1, most nodes have their own main functions. In ROS2, components can be subclassed from a life cycle component. The life cycle can be used by tools like roslaunch to start a system composed of many components in a deterministic way, knowing the real state of each node in every moment of its “life”.
Python-based launch system
ROS1 launch files are based on XML tags with very limited capabilities. In ROS2, the launch files are written in Python, which enables more complex logic like conditionals. The Python launch system gives complete control over life cycle components. Users can start each node when a well-defined situation occurs. For example, the file could start the motor control node only when all the sensor nodes are ready to provide information.
Decentralized parameter system
In ROS1, a single global server takes care of all the parameters available in the whole system. Users must instantiate a node-specific dynamic reconfigure server for each node in order to handle real-time changes.
ROS2 eliminates the concept of global parameters. Each node has its own parameter set. When a parameter changes, it notifies the node about the event, which can handle the new value.
Users can’t define the parameters in the launch file like in ROS1. But as they need to provide one or more YAML files, parameter management is still simple and organized.
Future support for real-time
ROS1 does not support writing real-time code, instead relying on external frameworks like Orocos. In ROS2, it will eventually be possible to write real-time nodes when using a proper RTOS.
ROS2 ZED wrapper features
The ZED wrapper for ROS2 exploits many of the new functionalities offered by ROS2. The primary features include:
- Configuration using YAML files: There are four different YAML files that define the node parameters: a common file, a file for the ZED camera, a file for the ZED-M camera, and a file for the ZED2 camera.
- Python launch scripts: the classical “XML” launch file of ROS1 has been replaced by powerful Python launch files that allow starting ROS2 nodes while performing many other operations.
- RGB streams publishing: The plugin publishes left, right RGB and Stereo sync pair streams on their own topics using the image_transport package.
- Depth streams publishing: The plugin publishes the depth map, confidence map, and disparity map on their own topics.
- Pointcloud publishing: The plugin now provides a colored point cloud.
- Positional tracking: The plugin publishes the position of the camera in real-time, relative to its own center.
- 3D Camera models for RVIZ2
- Rviz2 launch Python scripts: We provide pre-configured Python launch files to launch the ZED node, and the RVIZ2 GUI to easily get access to all visual information.
- Dynamically reconfiguring runtime parameters: Users can now change runtime parameters (e.g. gain, exposure, white balance) during node execution using Command Line Instructions.
- Object Detection: The plugin fully supports all the features of the Object Detection module of the ZED SDK
- Rviz2 plugin for Object Detection: to correctly visualize the results of the Object Detection and Tracking processing a new Rviz2 plugin is available to display the bounding boxes of the objects and the skeletons in the case of People Tracking.
The wrapper comes with a complete guide describing all available features, plus C++ tutorials and examples about how to retrieve the main information from a ZED camera connected to the ROS2 network.
A dedicated Github repository is available with many tutorials and examples:
- Installation guide.
- Video subscribing using a global callback function.
- Depth subscribing using manual node composition and node callback.
- Pose and Odometry subscribing using manual node composition and multiple node callbacks.
- BGRA to BGR conversion using the manual composition of multiple nodes.
The current version of the ZED ROS2 Wrapper only supports ROS2 Eloquent Elusor running on Ubuntu 18 machines.