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.
Image Credit: Jeremie Deray |
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
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
Installing VSCode
Use Code:
cd ~/micro_ros_ws/src/micro_ros_raspberrypi_pico_sdk
mkdir .vscode
touch .vscode/settings.json
vi .vscode/settings.json
{
"cmake.configureEnvironment": {
"PICO_SDK_PATH": "/home/$USER/micro_ros_ws/src/pico-sdk",
},
}
code .
Uploading to a Raspberry Pi Pico
Simply connect the board to a computer via USB connection while pushing the little white button labelled BOOTSEL to upload it. The Pi Pico will then mount as a flash drive, allowing us to copy/paste the.uf2 file with ease. Go to a computer terminal and type,
cp build/pico_micro_ros_example.uf2 /media/$USER/RPI-RP2
Micro-ros-agent installation
Snap is already pre-installed and ready to use if you're running Ubuntu 16.04 or later. If you're using a different operating system, you may either instal snap or use the Docker image. Type, to instal the micro-ros-agent snap.
sudo snap install micro-ros-agent
sudo snap set core experimental.hotplug=true
sudo systemctl restart snapd
$ snap interface serial-port
name: serial-port
summary: allows accessing a specific serial port
plugs:
- micro-ros-agent
slots:
- snapd:pico (allows accessing a specific serial port)
snap connect micro-ros-agent:serial-port snapd:pico
We'll start the micro-ros-agent with the Pi Pico connected via USB as follows:
micro-ros-agent serial --dev /dev/ttyACM0 baudrate=115200
$ source /opt/ros/dashing/setup.bash
$ ros2 topic echo /pico_publisher
data: 41
---
data: 42
---
$ ros2 node list
/pico_node
Posts You May like:
- LED Tricks Using The Raspberry Pi Pico
- The RP2040 Raspberry Pi Pico Meets LoRa
- Pico supports SD cards and FatFS
- How to connect a Raspberry Pi Pico to LoRaWAN
- 50 Raspberry Pi Hacks & Tips You Should Know
- How to Install Wi-Fi and Internet on a Raspberry Pi Pico
- Easiest Way to to Run DC Motor with Raspberry Pi Pico
- Drag-and-Drop Programming For The Raspberry Pi Pico
- Make Pico DIY Project Without Any Soldering or Breadboard
- Detailed Comparison of Arduino Nano RP2040 Connect Vs Raspberry Pi Pico
- Make a USB Microphone Using the Raspberry Pi Pico
- The RP2040 is Now Available for $1
- Pico LoRa Expansion is Finally Out! Supports 868MHz
- CircuitPython 6.3.0 is Now Available with Improvement & Fixes
- Pico DIY Projects! Must Try 17 Different Pico HATs & Expansions