A tutorial on how to get microROS and ROS2 working together
In the rapidly evolving world of robotics and embedded systems, microROS is a game-changer. It brings the capabilities of ROS (Robot Operating System) 2 to microcontrollers, facilitating the development of robust and interactive systems. The Raspberry Pi Pico, with its powerful RP2040 chip, provides an excellent platform for such applications.
This tutorial will guide you through setting up and running microROS on the Raspberry Pi Pico. By the end of this tutorial, you’ll be equipped to leverage the power of microROS on your Raspberry Pi Pico
For the corresponding YouTube tutorial, click here.
Install the necessary dependencies with the following command:
sudo apt install cmake g++ gcc-arm-none-eabi doxygen libnewlib-arm-none-eabi git python3 build-essential
Configure the environment:
echo "export PICO_TOOLCHAIN_PATH=..." >> ~/.bashrc
echo "export PICO_SDK_PATH=$HOME/micro_ros_ws/src/pico-sdk" >> ~/.bashrc
source ~/.bashrc
Create the workspace and clone the required repositories:
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/Rotvie/micro_ros_raspberrypi_pico_sdk.git
Compile the microROS code to generate the UF2 file, which will be loaded onto the Raspberry Pi Pico:
cd micro_ros_raspberrypi_pico_sdk
mkdir build
cd build
cmake ..
make
To load the UF2 file, connect the Pico while holding the BOOTSEL button, then run:
cp build/pico_micro_ros_example.uf2 /media/$USER/RPI-RP2
Install and configure the microROS agent:
sudo snap install micro-ros-agent
sudo snap set core experimental.hotplug=true
sudo systemctl restart snapd
snap interface serial-port
snap connect micro-ros-agent:serial-port snapd:pico
To start the microROS node, run:
sudo micro-ros-agent serial --dev /dev/ttyACM0 baudrate=115200
Check the available topics with:
ros2 topic list
For a Raspberry Pi setup, follow the instructions up to the Configuring the microROS agent section. However, if you encounter an error when installing the micro-ros-agent with snap (e.g., error: snap "micro-ros-agent" is not available on stable for this architecture (arm64)
), follow these steps:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir uros_ws && cd uros_ws
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
rosdep update && rosdep install --from-paths src --ignore-src -y
colcon build
source install/local_setup.bash
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh
source install/local_setup.sh
ros2 run micro_ros_agent micro_ros_agent --dev /dev/ttyACM0 baudrate=115200