Skip to content

ROS on Raspberry Pi

Carlos Viescas edited this page Jul 26, 2019 · 11 revisions

2.1. Checking distros.

To check what Raspbian release is installed:

$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

2.2. Installing ROS on Raspberry Pi.

The guide assumes that Stretch is the Raspbian release used and Kinetic is the ROS distro to be installed.

2.2.1. Required software packages.

$ sudo apt-get install dirmngr
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

$ sudo apt-get update
$ sudo apt-get upgrade

$ sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake

$ sudo rosdep init
$ rosdep update

2.2.2. Installation.

If the full ROS distribution is wanted, install rosinstall_generator desktop, otherwise choose rosinstall_generator ros_comm (recommended option for Raspberry Pi). ROS comm only installs the essential packages and communication libraries, avoiding GUI tools that consume a lot of space.

$ mkdir -p ~/ros_catkin_ws
$ cd ~/ros_catkin_ws

$ rosinstall_generator ros_comm --rosdistro kinetic --deps --wet-only --tar > kinetic-ros_comm-wet.rosinstall
$ wstool init src kinetic-ros_comm-wet.rosinstall

2.2.3. Dependencies.

Some dependencies must be built from source.

$ mkdir -p ~/ros_catkin_ws/external_src
$ cd ~/ros_catkin_ws/external_src
$ wget http://sourceforge.net/projects/assimp/files/assimp-3.1/assimp-3.1.1_no_test_models.zip/download -O assimp-3.1.1_no_test_models.zip
$ unzip assimp-3.1.1_no_test_models.zip
$ cd assimp-3.1.1
$ cmake .
$ make
$ sudo make install

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

2.2.4. Building the catkin workspace.

Add swap space to the RPi to increase RAM space and avoid internal compilation error.

$ vim /etc/dphys-swapfile

# Edit the following lines:
CONF_SWAPSIZE=1024

# Uncomment the following line:
CONF_SWAPFILE=/var/swap

Then proceed to build the catkin workspace:

$ cd ~/ros_catkin_ws/
$ sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/kinetic -j2

# After installation, append the source command to the bashrc file:
$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

After the installation, remove the swap memory by changing /etc/dphys-swapfile back to its original form:

$ vim /etc/dphys-swapfile

# Edit the following line:
CONF_SWAPSIZE=100

# Comment the following line:
# CONF_SWAPFILE=/var/swap

2.3. Other packages.

2.3.1. Installing ncurses.

$ sudo apt-get install libncurses5-dev libncursesw5-dev

2.3.2. Installing wiringPi.

Raspbian distros already come with wiringPi installed. If not, just:

$ sudo apt-get install wiringpi

2.3.3. Installing Python requirements.

Python libraries required are Flask (for the web app) and getch (to handle keyboard inputs).

$ sudo python -m pip install --upgrade pip
$ pip install py-getch
$ pip install Flask

2.3.3. Installing gnome-terminal package.

$ sudo apt-get install gnome-terminal