LiDAR integration with ROS Noetic on Raspberry Pi OS

The purpose of this tutorial is to evaluate the performance of the affordable RPLiDAR A1M8 from Slamtec using ROS Noetic on a Raspberry Pi.

ROS is a package of software libraries and tools for the construction and creation of robotic systems and applications. At the current timeframe, ROS Noetic is a version of ROS developed for long-term usage. It is the latest generation of distribution release of Robot Operating System commonly known as ROS1 and it is release number 13. Open Robotics, which spearheads ROS, launched it in the market on 23rd May 2020. Support for the full clinical trial will total 5 years, and the current support is until May 2025. As for the future, all the official efforts will be aimed at the development of ROS 2, which is a rather major redesign of the ROS framework.

ROS Noetic is primarily designed for use on Ubuntu 20.04, making Ubuntu the preferred choice for installing the software. This guide demonstrates the process of installing ROS Noetic on Raspberry Pi OS and connecting your LiDAR to a Raspberry Pi 4 Model B using ROS Noetic middleware. Compiling everything won’t be difficult, but it will be time-consuming.

What’s new in ROS Noetic?

  • Noetic is the sole ROS 1 release that officially provides support for Python 3.

  • Both ROS Melodic and Kinetic originally included OpenCV 3.x, but the upcoming Noetic release will come with version 4.x.

  • ROS Noetic now employs Gazebo 11, while ROS Melodic uses Gazebo 9.

  • The version of CMake in Ubuntu 18.04 has been upgraded from 3.10.2 to 3.16.3.

If you want to compare the version upgrades of each ROS package, please check the following link.

RPLidar A1M8

As you may likely understand, LiDAR stands as a close relative of the ultrasonic distance measuring devices, although the LiDAR operates employing the laser pulses. The major drawback of LiDAR sensors is that they are rather costly. Nevertheless, a growing number of affordable choices are already available for purchase. An instance of this is the RPLiDAR A1M8 created by Slamtec, featuring a 360-degree 2D laser scanner (LIDAR) technology.

RPLIDAR is a low-cost LIDAR sensor suitable for indoor robotic SLAM(Simultaneous localization and mapping) applications. It can be used in other applications such as:

  • General robot navigation and localization
  • Obstacle avoidance
  • Environment scanning and 3D modeling

RPLIDAR A1 Development Kit contains:

  • RPLIDAR A1
  • USB Adapter with communication cable
  • Documentation

The Micro-USB cable does not included.

So, let’s get started.

Prerequisites

Before you get started with this tutorial, you will need the following:

  • Raspberry Pi 4 Model B
  • RPLidar A1M8.
  • Laptop or standalone PC
  • High-performance microSD card: 32GB minimum
  • MicroSD to SD adapter

Step 1 – Preparation of Raspberry Pi

Ensure that you have the most recent Raspbian OS version. You can obtain it from the official Raspberry website.

Once the operating system is installed, we will verify the installation of the most recent drivers using specific commands.

sudo apt-get update

This command updates the list of available packages and their versions.

sudo apt-get upgrade

Once complete, you can reboot your PI by typing the following command.

sudo reboot

After the initial setup, we need to do two things — add swap memory and run in headless mode.

Step 2 – Increasing Raspberry Pi Swap memory

If you are a user of the Raspberry Pi, you must be aware of the fact that its RAM is quite small. I do not expect much of a problem when expanding the SWAP with Raspbian. This suggests that after the Raspberry Pi has used up its RAM, it can use the swap file as more storage space. Raspbian contains a default swap size of 100 MB and I just increased this to 2048 MB.

To stop the operating system from using the current swap file, run the following command.

sudo dphys-swapfile swapoff

Next, we need to modify the swap file configuration file. We can open this file using nano by using the command below.

sudo nano /etc/dphys-swapfile

Within this config file, find the following line of text.

CONF_SWAPSIZE=100

To enable the Raspberry Pi swap file and set it to a size of 2 GB (2044 MB), change the following command:

CONF_SWAPSIZE=2048

Regardless of the size you choose, you need to ensure that the corresponding space is available on your SD card. The Raspberry Pi’s swap file can be reset by executing the following command.

sudo dphys-swapfile setup

You will see the below output:

want /var/swap=2048MByte, checking existing: deleting wrong size file (1073741824), generating swapfile ... of 2048MBytes

To start the operating systems with new swap file, run the following command.

sudo dphys-swapfile swapon

You now have enough SWAP so that it should be no problem if one day the RAM may be overloaded.

Step 3 – Run heedlessly using VNC server

By headless mode, it means that the Raspberry Pi is running without a monitor keyboard and a mouse.

Enable the VNC server on your Raspberry Pi using raspi-config command. Enter sudo raspiconfig in a terminal window.

sudo raspi-config
  • Select Interfacing Options.
  • Navigate to and select SSH.
  • Choose Yes.
  • Select Ok.
  • Choose Finish.

To restart your Raspberry Pi, all you need to do is run the command below.

sudo reboot now

After reboot run connect to your pi via VNC Viewer. You can then verify the amount of memory + swap by issuing the following command:

free -h

The output should look like:

total        used        free      shared  buff/cache   available
Mem: 3.8Gi 192Mi 3.4Gi 60Mi 250Mi 3.5Gi
Swap: 2.0Gi 0B 2.0Gi

Step 4 – Set up ROS Noetic repo on Raspberry Pi 4

Setup your computer to accept software from packages.ros.org.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

If the command succeeds, you won’t see any output. However, you can double check if the repo is added using the cat command:

cat /etc/apt/sources.list.d/ros-latest.list

You will see the following output:

deb http://packages.ros.org/ros/ubuntu buster main

Step 5 – Set up official ROS keys

Afterward, we will install the ROS key to acquire genuine ROS Noetic packages for your Debian Buster system. Including the key is crucial to prevent man-in-the-middle attacks.

By running the following command, we will download the key from Ubuntu’s keyserver into the trusted set of keys:

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

The key is successfully added if you will see output like below, starting with Executing.

Executing: /tmp/apt-key-gpghome.kCZSaT5Kyw/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

gpg: key F42ED6FBAB17C654: public key "Open Robotics <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1

Step 6 – Install build dependencies on Raspberry Pi 4

Now we are finally ready to install Noetic on your Raspberry Pi 4. First, make sure your Debian package index is up-to-date:

sudo apt update

Now pick how much of ROS you would like to install.

  • Desktop-Full Install: : Everything in Desktop plus 2D/3D simulators and 2D/3D perception packages
  • Desktop Install: Everything in ROS-Base plus tools like rqt and rviz
  • ROS-Base: (Bare Bones) ROS packaging, build, and communication libraries. No GUI tools.

There are even more packages available in ROS. You can always install a specific package directly. To find available packages, see ROS Index or use:

apt search ros-noetic

We will first install all dependencies:

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

The ROS-specific tools (rosdep, rosintall_generator, and ws_tool) and essential build tools such as make and cmake are among the dependencies present.

Step 7 – Set up ROS Noetic dependency sources/repos

First, we initialize rosdep, which is a ROS tool for installing dependencies:

sudo rosdep init

You should see the following output after it’s done:

Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

rosdep update

Next we run rosdep update to fetch package information from the repos that are just initialized.

rosdep update

You should see the following output:

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/pi/.ros/rosdep/sources.cache

Step 8 – Install ROS Noetic dependencies

Before we begin, we will need to create a catkin workspace by:

mkdir ~/ros_catkin_ws
cd ~/ros_catkin_ws

Then we use rosinstall_generator to generate a list of Noetic dependencies for different Noetic variants, such as desktop-fulldesktop, and ros_comm. I’ll go with installing Desktop Install here.

rosinstall_generator desktop --rosdistro noetic --deps --wet-only --tar > noetic-desktop-wet.rosinstall

There won’t be any output if it succeeds.

Next, we will use the wstool to fetch all the remote repos:

wstool init src noetic-desktop-wet.rosinstall

The command will take a few minutes to download all of the core ROS packages into the src folder. If wstool init fails or is interrupted, you can resume the download by running:

wstool update -j8 -t src

Then before compiling the packages in the src folder, we install all system dependencies using rosdepinstall:

rosdep install -y --from-paths src --ignore-src --rosdistro noetic -r --os=debian:buster

You should see the following output at the end :

#All required rosdeps installed successfully

Step 9 – Compiling Noetic packages on Raspberry Pi 4

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

sudo src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/noetic -j2 -DPYTHON_EXECUTABLE=/usr/bin/python3

It takes around 1 hour for the compilation process. You should see the following output:

<== Finished processing package [184 of 184]: 'xacro'

Now ROS Noetic should be installed on your Raspberry Pi 4.

Step 10 – Verify Noetic installation on Raspberry Pi 4

First, let’s source the bash.

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

Let’s try some ROS commands to make sure the installation has finished successfully. A simple way to check the functionality of ROS is to use the turtlesim simulator that is part of the ROS installation.

Open a new terminal and run the following command:

roscore

Start a new terminal prompt and run the below command in the terminal:

rosrun turtlesim turtlesim_node

If everything is correct, we will get the following screen:

  • Open up yet another terminal window. Run the following:
rosrun turtlesim turtle_teleop_key
  • Click the mouse in the last container window you created so that it has focus. Use the arrow keys to move the turtle around the screen

If everything goes right, you will obtain the following result on the current terminal:

  • Press Ctrl-C to stop roscore, etc.

Congratulations! We are done with the ROS installation.

Step 11 – Connect your RPLiDAR to Raspberry Pi

Connect your RPLiDAR to Raspberry Pi 4 Model B using a Micro USB Cable. A flashing green light indicates the normal activity of the sensor.

Once you have connected the RPLiDAR to your Raspberry Pi, type the following command line to check the permissions:

Open your terminal and run the following command.

ls -l /dev | grep ttyUSB

The output of the following command must be:

crw-rw----  1 root   dialout 188,   0 Jan  3 14:59 ttyUSB

Run the below command to change permission:

sudo chmod 666 /dev/ttyUSB0

Once the permissions are configured, you have to download and install the RPLIDAR ROS packages.

Step 12 – Install RPLIDAR ROS Package

Let’s create a separate workspace for other packages, that are not part of core ROS.

Create the catkin root and source folders:

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

Configure the Catkin workspace

catkin_init_workspace

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. Go to the source folder of the catkin workspace that you just created:

cd src

Clone the ROS node for the Lidar in the catkin workspace.

sudo git clone  https://github.com/Slamtec/rplidar_ros.git

After that build with catkin.

cd ~/catkin_ws/

Run catkin_make to compile your catkin workspace.

catkin_make

Then run to source the environment with your current terminal. Don’t close the terminal.

source devel/setup.bash

and launch the RPILIDAR launch file

roslaunch rplidar_ros rplidar.launch

An instance of Rviz will then open with a map of the RPLIDAR’s surroundings.

The perspective captured by the laser scanner will be colored in red. Positioned at the grid’s center, the laser scanner has a range from approximately 15cm to 6 meters, allowing visibility of everything within that range on its scanning plane.

ROS is a reliable platform that we utilized to create the map surrounding the RPLIDAR. It is an excellent resource for developing robot software systems that can be beneficial for different hardware platforms, research environments, and runtime needs. This study demonstrated that the affordable RPLiDAR effectively works for integrating SLAM.

That’s it for today! You have ROS Noetic installed and ready to use!

I hope you found this guide useful and thanks for reading. If you have any questions or feedback? Leave a comment below. Stay tuned!

Resources

Source: LiDAR integration with ROS Noetic on Raspberry Pi OS


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top