Using ZED and ROS/2 from Docker Container

In the previous tutorial we learned how to build a Docker container with OpenCV. In this tutorial you will learn how to use the ROS framework in a Docker Container. Similar to the tutorial that demonstrated the use of OpenCV in a Docker container, this tutorial also gives an overview of using ROS and ROS2 nodes and packages.

In the next you will learn how to create docker containers with ZED SDK and ROS/ ROS2.

Download and run the Docker image

Pull and run a Docker image with ZED SDK and ROS or ROS2 based on the application you want to build. Similar to the OpenCV containers ROS also requires display support for RVIZ hence making sure that container includes OpenGL support.

$ docker pull <container_tag> #pull a docker container with ZED SDK , ROS or ROS2 and OpenGL support  
$ xhost +si:localuser:root  # allows container to communicate with X server
$ docker run  --gpus all --runtime nvidia --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <container_tag> # run the docker container

#Remember: Replace <container tag> with the tag of your container image

The docker run commands used are detailed in an earlier tutorial. You can find the detailed explanation in Docker documentation

Run a ROS sample example

Assuming that the container you are running has ROS installed and a catkin workspace has been set up, we further go ahead and run a sample example. In the next section you will learn how to create ROS Docker images along with setting up the workspace.

Install zed-ros-wrapper package that lets you use the ZED cameras with ROS right away.

$ cd ~/catkin_ws/src
$ git clone --recursive https://github.com/stereolabs/zed-ros-wrapper.git
$ cd ../
$ rosdep install --from-paths src --ignore-src -r -y
$ catkin_make -DCMAKE_BUILD_TYPE=Release
$ source ./devel/setup.bash

Now, you can simply launch the ZED node using the below commands to run an example, further details can be found in this documentation.

$ roslaunch zed_wrapper zed.launch
$ roslaunch zed_wrapper zedm.launch
$ roslaunch zed_wrapper zed2.launch
$ roslaunch zed_wrapper zed2i.launch

Further, you can explore zed-ros-examples which contains various examples and tutorials including display of ZED data and images, depth display, disparity display and more.

Please refer to the appropriate sections in the ROS documentation for detailed explanation.

Run a ROS2 sample example

For ROS2 users, we can run a ROS2 example supposing that the Docker image supports ROS2 and has a colcon workspace. Install zed-ros2-wrapper which lets you use ZED cameras with ROS2.

$ cd ~/ros2_ws/src/ #use your current ros2 workspace folder
$ git clone  --recursive https://github.com/stereolabs/zed-ros2-wrapper.git
$ cd ..
$ rosdep install --from-paths src --ignore-src -r -y
$ colcon build --symlink-install --cmake-args=-DCMAKE_BUILD_TYPE=Release
$ echo source $(pwd)/install/local_setup.bash >> ~/.bashrc
$ source ~/.bashrc

Now , you can launch the ZED node using the below `ros2 launch commands to run an example, further details about the wrapper can be found in this documentation.

Similar to zed-ros-examples, zed-ros2-examples package contains ROS2 tutorials and example packages for further exploring. Detailed documentation can be found here

Next steps

Now that you are comfortable with using OpenCV and ROS in a Docker container along with the ZED SDK, you can learn Create Docker images with ROS and ROS2.