This tutorial is to install ROS melodic on latest (Mon 2020) version of Raspbian.
Hardware
The hardware I use is Raspberry Pi 4
Install Raspbian Buster
Download the latest Raspbian Buster image from the official website and follow the Installation Guide to flash the image into a SD card.
For Windows users, I would recommend using Etcher to do such work. It’s really easy to use and reliable. (I usually use my Windows laptop to flash a SD card, so I don’t know what’s the best approach on other system. Please refer to the official guide and follow the steps carefully).
Headless installation
(Ref Setting up a Raspberry Pi headless)
If you do not have a computer screen for your Pi, you need to setup the wifi beforehand.
Firstly, plug back your SD card reader with the SD card you just flashed to your laptop.
In Windows, you’ll see a disk named “boot” in the navigator of File Explorer. (You’ll also see a popup window saying that you need to format a disk. Be careful NOT to format it, otherwise you’ll need to flash again)
Create a txt file with filename “wpa_supplicant.conf”.
Use some advanced text editor (eg: Visual Studio Code) to open the file, change the EoF sequence from CRLF to LF and insert following content (replace ssid and psk with your wireless network setup)
1 | ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev |
Create a blank txt file with filename “ssh” (no extention)
Eject the SD card from laptop and boot your Pi using modified SD card.
If your setup is correct, you can find your Pi in the local network. (Using IP scanner or whatever you used to find your Pi usually)
Upgrade system and install common software
Run following commands1
2sudo apt update && sudo apt -y dist-upgrade && sudo apt -y upgrade
sudo apt install -y vim curl wget git tmux unzip
Reboot your Pi after installation1
sudo reboot
Install ROS melodic
(Ref Installing ROS Kinetic on the Raspberry Pi, please note that the link is for ROS Kinetic)
Setup ROS Repository
1 | sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' |
Install dependencies
1 | sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake |
Initialize rosdep
1 | sudo rosdep init |
Compile ROS melodic from source code
If you want to try the pre-build install, skip this and go to next section.
Create catkin workspace for compiling and installing ROS melodic
1 | mkdir -p ~/ros_catkin_ws |
Fetch source code by wstool
1 | rosinstall_generator ros_comm --rosdistro melodic --deps --wet-only --tar > melodic-ros_comm-wet.rosinstall |
NOTE
The above is fetching “ros_comm” package which includes basic ROS commnication libs without GUI tools such as rqt, rviz. If you want to install GUI tools, change “ros_comm” to “desktop”. Or you can find more ROS variant hereNOTE
Ifwstool init
got interrupted, you can resume downloading process bywstool update -j4 -t src
Resolve dependencies with rosdep
1 | rosdep install -y --from-paths src --ignore-src --rosdistro melodic -r --os=debian:buster |
Build and install ROS!
1 | sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic |
Add ROS to your bashrc
1 | echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc |
Pre-build workspace
If you already proceed through last section, skip this.
Download pre-build worksapce and unzip it
ros_melodic_raspbian_buster.zip
Upload to your RPi and place in home directory.
Unzip it1
2cd ~
unzip ros_melodic_raspbian_buster.zip
After that, you’ll get a folder called ros_catkin_ws
Resolve dependencies with rosdep
1 | cd ~/ros_catkin_ws |
Install ROS
1 | sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic |
Add ROS to your bashrc
1 | echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc |
About ROS package management on Raspbian
If you use Ubuntu, apt is used to manage ROS packages. However, this approach does not works on RPi currently. We need to build from the source code of the package you want to install.
The process to add new package is as follow
Generate rosinstall file with rosinstall_generator
You may see similar command above somewhere during the installation. This is to generate a list of package source link.1
2cd ~/ros_catkin_ws
rosinstall_generator <package names seperated by space> --rosdistro melodic --deps --wet-only --tar > <custom file name>.rosinstall
Example (to install sensor_msgs)1
rosinstall_generator sensor_msgs --rosdistro melodic --deps --wet-only --tar > melodic-sensor_msgs.rosinstall
Merge and update the workspace
1 | wstool merge -t src <rosinstall file you just generated>.rosinstall |
This will fetch all the source code listed in rosinstall files
Example1
2wstool merge -t src melodic-sensor_msgs.rosinstall
wstool update -t src
Resolve dependency by rosdep
1 | rosdep install --from-paths src --ignore-src --rosdistro melodic -y -r --os=debian:buster |
Rebuild the workspace
1 | sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic |
Conclusion
It’s a bit tedious installing ROS and managing pakcage on RPi and the build time is long. So I wrote this post for memo and future reference.
Next post I’ll talk about how to setup the multi-machine environment and then create a publisher node on RPi.