Running micro-ROS on Raspberry Pi Pico

In this post, we'll look at how the Raspberry Pi Pico can communicate with a ROS2 graph natively via micro-ROS. In VSCode, we'll create a project, build it, and upload it to the microcontroller. As a result, we'll presume you're comfortable with ROS2 development using VSCode.

Running ROS2 on RP2040 microcontrollers.

The Raspberry Pi Pico with RP2040 chip is totally open-hardware and created by the Pi's developers. At only $4, it is extraordinarily inexpensive, as is typical of the Pi foundation.

The board's specifications, the distinctions between a microprocessor and a microcontroller, the 101 on how to get started, and what the Pi Pico can accomplish are all outside the scope of this article. But, whether you're familiar with microcontrollers or not, I strongly advise you to have a look for yourself.

micro-ROS

Microcontrollers have long been treated as second-class citizens in the ROS (1) world. They can't communicate with the ROS graph directly, therefore developers must rely on libraries like rosserial. However, ROS2 is a completely new universe, and things are evolving all the time.

 micro-ROS instals ROS 2 on microcontrollers, allowing them to participate in the ROS 2 ecosystem as first-class citizens.

The micro-ROS project is led by huge industry names like Bosch, eProsima, Fiware Foundation, and a slew of partners and collaborators, including Amazon and Canonical, as well as the OFERA H2020 project.

So, what exactly is it? It's simply a thin wrapper (see its design paper) on top of DDS for eXtremely Resource Constrained Environments (DDS-XRCE) that runs on a real-time OS and allows microcontrollers to communicate with a ROS2 graph (the standard talker/listener) using an optimised subset of the DDS protocol. It's a mouthful. It uses a ‘bridged' communication architecture with the ‘micro-ROS Agent‘ as a ‘broker.' The agent is responsible for bridging the gap between the ROS2 graph and one or more micro-ROS devices.

More information, including how it compares/differs from rosserial, may be found on the micro-ROS website (see here and here).

So, now that we've explained a few terminology, let's get started with the official micro-ROS on Raspberry Pi Pico example available on github, step by step. Note that I'm using Ubuntu 20.04 with the VSCode snap for this lesson.

If you haven't yet upgraded to Ubuntu 20.04, you might want to consider utilising an LXD container. To get started setting up the container, refer to our earlier piece ‘ROS Development with LXC.'

Dependencies are being installed.

Let's begin by installing the required prerequisites.

sudo apt install build-essential cmake gcc-arm-none-eabi libnewlib-arm-none-eabi doxygen git python3

Obtaining the Information

We'll now establish a workspace and gather all of the necessary information.

mkdir -p ~/micro_ros_ws/src
cd ~/micro_ros_ws/src
git clone --recurse-submodules https://github.com/raspberrypi/pico-sdk.git
git clone https://github.com/micro-ROS/micro_ros_raspberrypi_pico_sdk.git

The Pi Pico SDK, offered by the Pi Foundation, is the initial repository. The second includes a precompiled micro-ROS stack as well as a hello-world-style example.

Installing VSCode

Let's open the example in VSCode and configure it. You'll need two VSCode additions to follow along, both of which are ubiquitous in C++ programming. For VSCode, these extensions are the C++ extension and the CMake tools. After installing them, we'll create a CMake tools configuration file and specify a variable to tell our project where to look for the Pi Pico SDK.

Use Code:

cd ~/micro_ros_ws/src/micro_ros_raspberrypi_pico_sdk
mkdir .vscode
touch .vscode/settings.json

Use your preferred editor to open the newly produced file.

vi .vscode/settings.json

plus the following,

{
    "cmake.configureEnvironment": {        "PICO_SDK_PATH": "/home/$USER/micro_ros_ws/src/pico-sdk",
 },
...
Read more »