Notes related to cross compiling ros2 packages for a Raspiberry Pi 3 B+ running Ubuntu Mate 18.04.
Context: I am trying to work on a DIY “see through wall” application where I mount an IP camera (e.g. Amcrest) in the family room, and view the image stream from the room next door, ideally keeping the perspective consistent across rooms.
The set up I have in mind consists of an IP camera powered by POE. The
ros2_ipcamera node would be running on a raspi in a different room, tasked to retrieve the images from the rtsp uri and publish them for viewing on a monitor or webapp.
The following notes solves the task of getting the
ros2_ipcamera running on a raspi.
Alberto, the engineer that put the work into creating the cross-compile GitHub repo (currently a PR to replace the original as of Oct.14, 2019) was extremely helpful in helping me work through my gaps in understanding of the cross-compile process. Thanks!!!
Preliminary steps to be taken on the target system, in this case the raspi.
- Flash Ubuntu Mate 18.04 onto a mini SD.
- Install ros2-dashing-desktop. Note that base wont work in this particular case as we need some dependencies related to OpenCV.
- Install colcon.
source /opt/ros/dashing/setup.bash. We can quickly test by checking to see if
ros2 topic listworks.
Follow steps outlined here to cross compile.
NOTE: Since I was going to compile
ros2_ipcamera directly on the raspi, I needed to transfer the entire
install directory as opposed to just the
install/lib directory per the example given by Alberto.
vision_opencv depends on OpenCV I needed to include a line to the original dockerfile. The modified dockerfile can be found here. If a reader is aware of an easier way to install opencv please leave me a note below.
For this particular project, the steps modified for my specific use case were as follows.
On host system:
$ git clone https://github.com/alsora/cross_compile/tree/alsora/refactor_cross_compile
$ mkdir -p ~/ros2_ws/src
$ cd ~/ros2_ws
$ wget https://raw.githubusercontent.com/ros2/ros2/dashing/ros2.repos
$ vcs import src < ros2.repos
$ git clone -b ros2 https://github.com/ros-perception/image_common src/ros-perception/image_common
$ git clone -b ros2 https://github.com/ros-perception/vision_opencv src/ros-perception/vision_opencv
$ cd ~/cross_compile
# Build all the docker images contained in the docker_environments directory.
$ bash build.sh
# Specify environment variable (e.g. ubuntu-arm64, raspbian).
$ source env.sh ubuntu-arm64
$ bash get_sysroot.sh
# Script to add COLCON_IGNORE to directories to be ignored and can modify as necessary.
$ bash ignore_pkgs.sh ~/ros2_cc_ws dashing
$ bash cc_workspace.sh ~/ros2_cc_ws
# Transfer install directory to target system.
$ rsync -avz --progress install/* user@address:~/ros2_install
On target system:
$ source ~/ros2_install/install/setup.bash
$ mkdir -p ~/ros2_ws/src
$ cd ~/ros2_ws/src
$ git clone https://github.com/surfertas/ros2_ipcamera.git
$ cd ..
$ colcon build –symlink-install
Overall this was a great exercise to learn more about ros2, cross compiling, IP cameras, POE, and general software development. That said, I am pretty sure that this is not the best set up for the “see through wall” application as a much simpler solution can be considered. Further, despite being able to compile the package on the raspi, the performance of the node is poor, which is more so the result of sub-optimal decisions made by my self.