5. Ok, ROS! (on Raspberry Pi 4). Melodic & Noetic - HaroldSP/Harold GitHub Wiki

ROS Melodic on Raspberry Pi 4[Debian Buster] + RPLIDAR A1M8

This article will cover the process of installing ROS Melodic Morenia on Raspberry Pi 4 running the latest Debian Buster and how to use RPLIDAR A1M8 with our installation. Laconic. The original article is here. There as well one can find the images of the system with ROS, but we are going to build.

1. Installing Bootstrap Dependencies and Download the Packages

1.1. Always update upgrade first!

sudo apt-get update && sudo apt-get upgrade

1.2. Setting up the repositories and installing the necessary dependencies

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://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get update
sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential  cmake

1.3. Then initialize rosdep and update it

sudo rosdep init
rosdep update

1.4. When that's done let's create a dedicated catkin workspace for building ROS and move to that directory

mkdir ~/ros_catkin_ws
cd ~/ros_catkin_ws

1.5. Desktop Install: includes GUI tools, such as rqt, rviz, and robot-generic libraries

One can add extra packages by running:

rosinstall_generator desktop <list_of_packages> --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall

Right now we are going to add the following extra packages: teleop_twist_keyboard, cv_camera

rosinstall_generator desktop teleop_twist_keyboard cv_camera --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall 
wstool init -j8 src melodic-desktop-wet.rosinstall

1.6. If wstool init fails or is interrupted, you can resume the download by running:

 wstool update -j4 -t src

2. Build and Source the Installation

2.1. Rosdep tool for installing all the rest of the dependencies

rosdep install --from-paths src --ignore-src --rosdistro melodic -y

2.2. Once it has completed downloading the packages and resolving the dependencies you are ready to build the catkin packages.

Run this command from the ros_catkin_ws folder. As for me, -j4 worked fine with active cooling. But you can do it with -j2 if you are not sure.

#cd && cd ~/ros_catkin_ws
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j4

If the compilation process freezes, you need to increase swap space available. By default it's 100 Mb, try increasing it to 2048 MB. But make sure that you have enough memory to add and to be left, and make the swap 100 Mb back again or even 0, otherwise your microSD card might die relatively fast.

Good luck! The whole compilation process takes about 1 hour, so go make some tea

2.3. Now ROS Melodic should be installed on your Raspberry Pi 4. We'll source the new installation with the following command:

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

Open a new shell for changes to take effect. Try launching roscore to check if everything was successful

3. Install RPLIDAR ROS Package

Let's create a separate workspace for other packages, that are not part of core ROS. From you home folder do:

mkdir -p ~/catkin_ws/src && cd ~/catkin_ws/
catkin_make

and source it to bashrc:

echo "source $HOME/catkin_ws/devel/setup.bash" >> ~/.bashrc

Okay, we're ready to start installing the RPLIDAR ROS package.

cd src
sudo git clone https://github.com/Slamtec/rplidar_ros.git
cd ..
catkin_make

Wait for the package compilation to finish. Try launching the package to see if the compilation was successful:

roslaunch rplidar_ros rplidar.launch

Noetic. (2021/04/05 edit)

The original article is here

Of course, you are not obliged to do all steps

In step 13 I gave all rights, so it was sudo chmod 777 /dev/ttyUSB0

I have got several errors though in step 14 with the command catkin_init_workspace, so the better order is that one:

cd
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
cd

#source it to bashrc
echo "source $HOME/catkin_ws/devel/setup.bash" >> ~/.bashrc    
source .bashrc

#ready to install RPLIDAR ROS package
cd ~/catkin_ws/src                                             
sudo git clone https://github.com/Slamtec/rplidar_ros.git
cd ..
catkin_make

Wait for the package compilation to finish

Try launching the package to see if the compilation was successful:

roslaunch rplidar_ros rplidar.launch

In my case it wasn't, I got that error

So it turned out that I just did extra:

cd
cd ~/catkin_ws/
cdsource devel/setup.bash

It turned out that simply adding to .bashrc is not enough, you have to source it in terminal with a separate command