This week I focused on getting ROS Foxy installed via Docker containers on the Raspberry Pi and on Windows 11 (WSL 2).
Firstly, I became familiar with the essentials of ROS by going through their tutorials on their site: ROS Foxy Documentation. Understanding nodes, topics, services, colcon, etc. is essential for setting up a docker image.
The ROS 2 on Raspberry Pi Documentation was also a huge help when it came to choosing the right image for the Pi. Because we’re coding on an arm processor instead of a standard laptop cpu, we need a compatible version of ros. This is denoted in the docker/Dockerfile.pi when we pull from the arm64v8 source. In the dockerfile we include any special libraries that we’ll need for our control scripts.
Creating the first control example script was a matter of looking at the open-source python code that came with the kit. The kit creators included a driver for the servo board named ‘pca9685.py’. This file imports smbus and so I included it in my dockerfile script. The example control script is in src/pi_control/pi_control/servo_node.py. This script sets up a service to set or get a servo position. It leverages the pca9685.py driver file provided in the kit.
ROS definitions for services, msgs, etc. So at first I had the robot_interfaces package within the pi_control package because pi_control was using it. But when I started working on setting up the windows_command installation, I realized it needed the same definitions. So I restructured my packages from:
to:
As you can see, the change forced me to rethink how my docker-compose, and Dockerfile’s needed to be structured. This turned out to be for the best, but required a little refactoring.
Here is a clip of me starting the pi_control node and it initializing the robot servos to 90 degs.
this required a little extra work to set up a virtual bridge because WSL doesn’t automatically make your real ip visible to the virtual machine. Another setup step was preparing the windows_command to render graphics. This setup is done by establishing environment variables DISPLAY and LIBGL_ALWAYS_INDIRECT.
Here is a screenshot of the WSL ROS node launching a command PyQt app that has a slider widget to control a servo position. It also has a view for the upcoming depth streaming.
I can launch both my pi_control, and my windows_command in their respective platforms with docker-compose.