Main Content

Install ROS Melodic on Raspberry Pi

This section shows how to install ROS Melodic on your Raspberry Pi® board with Raspbian Buster as the operating system. Use these installation steps unless a binary package is available for ROS Melodic.

Prerequisites

Verify that your Raspberry Pi hardware board uses Raspbian Buster as the operating system.

Install ROS Melodic

Download and build ROS Melodic on your Raspberry Pi hardware board.

Open the Raspberry Pi terminal and execute these steps.

  1. Install repository key.

    $ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' 
    $ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
  2. Update the Debian package index.

    $ sudo apt-get update
    $ sudo apt-get upgrade
  3. Install bootstrap dependencies.

    $ sudo apt install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake
  4. Initialize rosdep.

    $ sudo rosdep init
    $ rosdep update

Create catkin Workspace

  1. Create a catkin workspace to build the core packages. Run this command on the Raspberry Pi terminal.

    $ mkdir -p ~/ros_catkin_ws
    $ cd ~/ros_catkin_ws
  2. Use the wstool command to fetch the core packages and build them on your Raspberry Pi.

    $ rosinstall_generator ros_comm rosout std_msgs sensor_msgs geometry_msgs tf  --rosdistro melodic --deps --wet-only  --tar > melodic-ros_mw-wet.rosinstall 
    $ wstool init src melodic-ros_mw-wet.rosinstall 

    This command adds all the catkin or wet packages in the specified variant and then downloads the sources into the ~/ros_catkin_ws/src directory. Once you execute this command, the system can take a few minutes to download the core packages into the src folder.

    If the wstool init command fails or is interrupted, you can resume the downloading process by running this command.

    wstool update -j4 -t src

Resolve Dependencies with rosdep

Before you build the catkin workspace, verify that you have resolved all dependencies and installed all packages. Resolve dependencies by running this command on the Raspberry Pi terminal.

$ cd ~/ros_catkin_ws
$ rosdep install -y --from-paths src --ignore-src --rosdistro melodic -r --os=debian:buster

Build catkin Workspace

For Raspberry Pi hardware boards such as Model B+, Model B Rev1, Model B Rev2, Pi 2 Model B, Pi Zero W, you can increase the swap space. Execute this command on the Raspberry Pi terminal to open the swap configuration file.

$ sudo nano /etc/dphys-swapfile

In the Editor window, search for the CONF_SWAPSIZE variable and set it to 500. Save the file. This increase the swap space to 500 MB.

Execute these commands to activate new the swap size.

$ sudo dphys-swapfile setup
$ sudo dphys-swapfile swapon

Build the catkin workspace after you have completed resolving the dependencies and downloading the packages.

Invoke catkin_make_isolated.

$ sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic

Warning

Do not change the default location for installing ROS Melodic.

ROS Melodic is now installed on your Raspberry Pi hardware board.

Source the new installation.

$ source /opt/ros/melodic/setup.bash

Optionally, source setup.bash in the ~/.bashrc to automatically add the ROS environment variables to your bash session every time you launch a new shell.

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

Create Simulink catkin Workspace

To create a Simulink® catkin workspace, execute these steps on the Raspberry Pi terminal.

  1. Source setup script for ROS Melodic.

    source /opt/ros/melodic/setup.bash
    
  2. Initialize ROS user workspace ~/catkin_ws.

    mkdir -p ~/catkin_ws/src
    cd ~/catkin_ws/src
    catkin_init_workspace
    
  3. Build ROS user workspace. This step creates devel and build directories under the ~/catkin_ws workspace.

    cd ~/catkin_ws/
    catkin_make

See Also

Related Topics