Skip to content

SamiSonbol/Micro-ROS

Repository files navigation

Description

This repo contains:

This repository easily sets up the environment needed to program and build for Raspberry Pi Pico (especially regarding Micro-ROS and ROS2 Jazzy) by having all stated repos together in a single directory. It includes:

  • Two shell scripts:

    1. build_enviroment.sh – sets all required environment variables by injecting code into the .bashrc file and builds the required repos.
    2. build.sh – cleans and builds individual Micro-ROS projects by removing the old build folder and calling cmake with the correct arguments.
  • CMakeLists.txt example and helper_functions.cmake – contain important functions and lines to help organize and understand the building process easily and cleanly. (The building process of Micro-ROS on Pico is very messy and sometimes obscure.)

  • Multiple organized code folders, each acting as its own library (with src, include folders, and a CMakeLists.txt) to be modularly used in projects. These libraries vary from Micro-ROS management and wrapper classes to code that interacts with and manages sensor modules such as IMU and GPS.

  • apps folder – where Micro-ROS projects can be created for clean organization. Projects do not necessarily have to be in this directory, but this is recommended.


1. Install Dependencies

The official micro_ros_raspberrypi_pico_sdk README also lists git and doxygen as dependencies. Additionally, docker is needed to run the micro-ROS agent.

sudo apt update
sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib pkg-config libusb-1.0-0-dev git doxygen docker.io
sudo systemctl enable docker

2. Configure Environment Variables

Edit the .bashrc file to include environment variables describing the locations of the different directories.

  • Automatic: Run build_enviroment.sh in the root directory (recommended and you wont have to do steps #3 till #5).
  • Manual: Copy the block between the two EOF markers from the script and update the MICROROS_PATH variable to your repo root path.

Notes:

  • Running build_enviroment.sh will overwrite any manually added code between the markers.
  • Make the script executable:
    chmod +x build_enviroment.sh

3. Build pico-sdk

pico-sdk does not need explicit building with cmake or make, since it is compiled automatically when building your executable using its source and include folders.


4. Build picotool

picotool is used to control the Raspberry Pi Pico (load, reboot, etc.) and is important for Micro-ROS.

cd picotool
mkdir build
cd build
cmake ..
make

5. Build micro_ros_raspberrypi_pico_sdk

The static library is precompiled in micro_ros_raspberrypi_pico_sdk/libmicroros. Building will create a demo to verify everything is working.

cd micro_ros_raspberrypi_pico_sdk
mkdir build
cd build
cmake ..
make

6. CMakeLists.txt and helper functions

Inside the pico_w_libraries directory:

  • The example CMakeLists.txt should be read carefully, it can be copied inside every project directory and edited to suit your needs.
  • The first half and the absolute end of the file should barely be changed across projects.
  • The middle sections can be adapted to your coding style.
  • Understanding helper_functions.cmake and at least one library’s CMakeLists.txt is important.

All of this assumes familiarity with CMake.


7. Using build.sh for Micro-ROS Projects

  • Copy build.sh into the root directory of your Micro-ROS project folder.
    • Example: multiple_sensor_publisher/build.sh
  • build.sh deletes the old build folder (with confirmation), runs cmake with the toolchain compiler, then calls make.

Important Notes:

  • Deleting and rebuilding the build folder often resolves old compile issues that otherwise wont be resolved.
  • Make build.sh executable:
    chmod +x build.sh

Notes

  • The environment only needs to be built once unless the repo folder is moved.
  • After building, the generated .uf2 file is needed to flash the Pi Pico. Location depends on your CMakeLists.txt (example: build/bin).
  • Flashing:
    flash_raspberrypi_pico 'path/to/your/file.uf2'
  • After the first environment build, source .bashrc if building apps in the same shell:
    source ~/.bashrc
  • Libraries may have dependencies on each other. Read their CMakeLists.txt carefully.
  • Open and read comments in both build_enviroment.sh and build.sh, they explain very important things in great detail.

About

Micro-ROS directory that contains multiple micro-ros projects for the raspberry pi pico. In addition, this directory contains multiple scripts that automatically set up environment variables, making the directory function as a development environment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors