Jérémie Deray Showcases micro-ROS on the Raspberry Pi Pico with a Sonar Sensing Tutorial
Building on part one, Deray's latest shows how to add an ultrasonic sensor and publish its data to a ROS 2 graph.
Robotics software engineer Jérémie Deray has penned a hands-on guide to pulling data from the popular HC-SR04 ultrasonic range sensor and publishing it to a ROS 2 graph using micro-ROS running on the Raspberry Pi Pico.
While the Robot Operating System 2 (ROS 2) is undeniably popular, the real-time operating system (RTOS) is a little heavy for smaller microcontrollers. That's where micro-ROS comes in, designed to offer compatibility with ROS 2 but small enough to run on microcontrollers. Launched late last year, micro-ROS has been slowly expanding its support to more and more platforms — including the Raspberry Pi Pico and its RP2040 microcontroller.
Earlier this year, Canonical's Jérémie Deray offered a step-by-step guide to getting up and running with micro-ROS on the Raspberry Pi Pico. "Let’s break down very briefly what the example does," he wrote at the time. "It sets up a node called pico_node, then a publisher publishing a std_msgs/msg/int32.h message on the topic pico_publisher, a recurring timer and an executor to orchestrate everything. Every 0.1 second, the executor spins. But only every second, the timer will have the publisher publish a message and increase the message data by 1. Simple."
Those eager for more can now have a crack at the follow-up in Deray's series: Adding a physical sensor to the mix, a HC-SR04 ultrasonic range sensor. "These sensors are cheap, fairly simple to use and surprisingly precise under favorable circumstances," Deray explains. "Sonars are used to measure distances. They can therefore be used to detect and locate obstacles, so that a robot can avoid nearby things. It is no mystery why they are so incredibly popular."
"This is a neat little project to approach micro-ROS on the Raspberry Pi Pico and the possibilities it opens. It is really rewarding to see the actual distance between the sensor and an obstacle being readily available on the ROS 2 graph. By taking a step back we can start seeing a slightly larger picture; a picture in which one will be able to easily, effortlessly, add plug and play ROS2-ready hardware modules to existing robots. Plugging a camera and its feed magically appears on the graph. An IMU module could provide a reliable odometry source. A motor ready to spin in a snap (pun intended)."
The full tutorial is now available on the Ubuntu blog.