robocre8
AboutContactSocial
  • robocre8
  • About
  • Contact
  • Social
  • DOCUMENTATIONS
    • MoboBot Documentation
    • EPMC Documentation
    • EIMU Documentation
  • EIMU TUTORIALS
    • How To Calibrate And Setup The EIMU
    • How To Use EIMU With ROS2
    • How To Use EIMU With Arduino
  • EPMC TUTORIALS
    • How To Setup DC Motor PID Speed Control With The EPMC
  • How To Use the EPMC With ROS2
  • How To Use EPMC With Arduino
  • TUTORIALS
    • How To Install ROS2 Humble Desktop On PC (FULL INSTALL)
    • How To Install ROS2 Humble Base On Raspberry Pi 4B (FULL INSTALL)
Powered by GitBook
On this page
  • Prerequisite
  • Installing ROS Humble Base (not Desktop)
  • Setting up colcon for Building ROS2 packages
  • Intializing rosdep
  • Install setuptools For Building ROS2 Python Packages
  • Creating A ROS2 Workspace
  • Test with helloworld package
  • Optional (Install Cyclone DDS)
  1. TUTORIALS

How To Install ROS2 Humble Base On Raspberry Pi 4B (FULL INSTALL)

Learn how to install ros-humble-ros-base on Raspberry pi 4B running Ubuntu 22.04 LTS server

PreviousHow To Install ROS2 Humble Desktop On PC (FULL INSTALL)

Last updated 1 month ago

If you'll be building intelligent robotics applications, chances are you’ll want the power of ROS2 running on a compact, efficient platform like the Raspberry Pi 4B. This guide walks you through the complete process of setting up ROS2 Humble on on a Raspberry Pi running Ubuntu 22.04 Server — from the initial installation to configuring essential tools like colcon and rosdep. By the end, you'll be ready to develop and deploy robust robotics applications on this versatile microcomputer.

Let’s dive in and get your Pi humming with ROS2!

Prerequisite

  • First ensure you have the Ubuntu 22.04 LTS server installed on the Raspberry Pi 4B (2GB, 4GB, or 8GB. The higher, the better)

  • Also, if you did headless installation, you should be able to communicate with the Pi from your Dev PC via SSH.

All we'll be doing in this tutorial assumes you are able to communicate with your Raspberry Pi 4B running Ubuntu 22.04 LTS server with SSH

Installing ROS Humble Base (not Desktop)

Follow the instructions (step by step) to install ros-humble-ros-base (not desktop) on your Raspberry Pi.

This tutorial follows the official ROS humble installation documentation which can be found here

  • Set locale

    locale  # check for UTF-8
    
    sudo apt update && sudo apt install locales
    sudo locale-gen en_US en_US.UTF-8
    sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
    export LANG=en_US.UTF-8
    
    locale  # verify settings

  • Setup sources

    sudo apt install software-properties-common
    sudo add-apt-repository universe
    
    sudo apt update && sudo apt install curl -y
    sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

  • Install ros2 humble (i.e ros-humble-ros-base)

    sudo apt update
    sudo apt upgrade
    
    sudo apt install ros-humble-ros-base

  • Install all the necessary ROS2 development tools - rosdep, colcon, vcs-tool, etc.

    sudo apt install ros-dev-tools

  • Next, add the following command to the .bashrcfile to enable automatic sourcing of the ros humble environment and installed whenever you open a new terminal.

    source /opt/ros/humble/setup.bash
    echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

Setting up colcon for Building ROS2 packages

colcon is a build tool required to build your ROS2 packages created in your ros workspace. It was already installed when you ran the sudo apt install ros-dev-tools command prevoiusly. but you can also install it using sudo apt install python3-colcon-common-extensions But we need to set it up for things like tab completion. Run the following command in your terminal.

  • Setup colcon_cd

    echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
    echo "export _colcon_cd_root=/opt/ros/humble/" >> ~/.bashrc

  • Setup colcon tab completion

    echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

With all the above added to the .bashrc file, the colcon environment and functions will be automatically activated whenever you open a new terminal as well as automatic sourcing of the ros-humble environment.

To learn more about colcon check the link to its documentation here

Intializing rosdep

rosdep is a dependency management utility that can work with packages and external libraries. It is a command line utility for identifying and installing dependencies to build or install a package.

It is most often invoked before before building a package with colcon. It will basiclally download and installing the necessary dependencies a specified in the package.xmlfile so you don't have to manually install each dependencies again.

rosdep was already installed when you ran the sudo apt install ros-dev-tools command previously. but you can also install it using sudo apt install python3-rosdep

To learn more about rosdep check out its documentation here

Follow the instructions below to instialize rosdep:

sudo apt update

sudo rosdep init #NOTE:this might give an error, do not worry, just continue
rosdep update

Install setuptools For Building ROS2 Python Packages

sudo apt install python3-pip

pip3 install setuptools==58.2.0

Creating A ROS2 Workspace

In the root folder of your Raspberry Pi (i.e the home directory)

  • In the root folder of your Raspberry Pi (i.e the home directory), create a ros workspace folder. I would be using this workspace name - ros-ws.

    mkdir -p ~/ros-ws/src

  • change directory into the root ros workspace folder

    cd ~/ros-ws

  • build the ros workspace initially with colcon (while still in the root workspace folder)

    colcon build

    you should now see three other folders - build, install, and log - apart from the src folder already created earlier. Run ls to see them in terminal

  • Let's setup automatic sourcing for the created workspace - ros-ws- in the .bashrc file so that it is automatically sourced whenever you open a new terminal. Run this in terminal:

    echo "source ~/ros-ws/install/setup.bash" >> ~/.bashrc

Test with helloworld package

  • Open a new terminal (to auto source your ros2 environment and workspace) and cd into your ros workspace's src folder

    cd ~/ros-ws/src

  • Clone this ros2 helloworld cpp and python package

    git clone https://github.com/samuko-things/helloworld_ros2.git

  • Change directory into the root ros workspace folder

    cd ~/ros-ws

  • Optionally, run rosdep to install the packge dependencies specified in the package's package.xmlfile

    rosdep install -i --from-path src --rosdistro humble -y

  • Build the package with colcon

    colcon build --symlink-install

  • Open two seperate terminals. In one of the terminals, run a c++ node:

    ros2 run helloworld_ros2 talker

  • In the other terminal, run a python node:

    ros2 run helloworld_ros2 listener.py

Optional (Install Cyclone DDS)

If you would be using ROS2 for navigation and some other high speed data transfer, install and use the Cyclone DDS in place of the default Fast DDS.

sudo apt install ros-humble-rmw-cyclonedds-cpp
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
echo "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp" >> ~/.bashrc