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

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

About: https://www.youtube.com/c/hardwareai My channel about robotics with ROS and machine learning!

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.

Since Debian Buster was officially released just a few weeks ago(as of moment of writing this article), there are no pre-built ROS packages to install with apt-get, which is a preferred method of installation. Hence we will need to build it from source. Trust me, it's not that scary as it sounds. The process is described in this official tutorial, but to build ROS Melodic on Raspberry Pi we will need to make a few modifications.

In case you are still scared, here is a funny picture that *might* help you relax. Please do provide feedback if the level of relaxation provided was sufficient. If not, it will be replaced with picture of a funny cat.

January 2020 EDIT: Since it has been half a year since I posted this article there might have been some changes to ROS or Buster. I have made an image for Raspberry Pi 4 a while ago, after writing this tutorial. A contributor has uploaded it to Google Drive
https://drive.google.com/file/d/1lcPBYgdFG7EuaIV23...

April 2020 EDIT: I have found time recently to redo ROS Melodic installation on the newest Raspbian image from official Raspberry Pi site.I have edited this instructable accordingly. I also created and shared clean, compressed images:

Raspbian Buster Lite 2020-02-13 Release with ROS Melodic Bare-bones Need 8 GB SD card

Raspbian Buster with desktop 2020-02-13 Release with ROS Melodic Desktop Need 16 GB SD card

It might be the fastest way to get your system up and running. If you wish to compile ROS yourself, keep reading the article.

Step 1: Installing Bootstrap Dependencies and Download the Packages

Let's start by 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

Then initialize rosdep and update it

sudo rosdep init
rosdep update

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

Now you have two choices:

ROS-Comm: (Bare Bones) installation - install this one if you are familiar with ROS and know what you are doing and what packages you will need. If you need packages not included in ROS-Comm, you will need to compile from source as well.

Desktop Install: includes GUI tools, such as rqt, rviz, and robot-generic libraries. Might be better choice for beginners to ROS.

I'll go with installing Desktop Install here.

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

wstool init -j8 src melodic-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 -j4 -t src

Step 2: Fix the Issues

April 2020 EDIT: Skip this step, it seems all the issues have been fixed now.

Let's install the compatible version of Assimp (Open Asset Import Library) to fix collada_urdf dependency problem.

mkdir -p ~/ros_catkin_ws/external_src 

cd ~/ros_catkin_ws/external_src
wget <a href="http://sourceforge.net/projects/assimp/files/assimp-3.1/assimp-3.1.1_no_test_models.zip/download" rel="nofollow"> http://sourceforge.net/projects/assimp/files/assi...</a> -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

Let's also install OGRE for rviz

sudo apt-get install  libogre-1.9-dev

January 2020 UPDATE: The issues with libbost already has been fixed by ROS developers, you can skip this part

/// skip /// Finally we'll need to fix the issues with libboost. I'm using the solution from this post on stackoverflow:

"The errors during compilation are caused by the 'boost::posix_time::milliseconds' function which
in newer boost versions accepts only an integer argument, but the actionlib package in ROS, gives it a float on several places. You can list all files using that function (!in ros_catkin_ws folder!):

find -type f -print0 | xargs -0 grep 'boost::posix_time::milliseconds' | cut -d: -f1 | sort -u

Open them in your text editor and search for the
'boost::posix_time::milliseconds' function call.

and replace calls like this:

boost::posix_time::milliseconds(loop_duration.toSec() * 1000.0f));

with:

boost::posix_time::milliseconds(int(loop_duration.toSec() * 1000.0f)));

and these:

boost::posix_time::milliseconds(1000.0f)

with:

boost::posix_time::milliseconds(1000)

I recommend you use nano text editor, which is simpler than VIM ;) Ctrl+O is saving, Ctrl+X is exiting and Ctrl+W is searching.

///continue_from_here///

Step 3: Build and Source the Installation

Next we use the rosdep tool for installing all the rest of the dependencies:

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

Once it has completed downloading the packages and resolving the dependencies you are ready to build the catkin packages. (Run this command from ros_catkin_ws folder)

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

If the compilation process freezes(very likely, if you install the desktop version), you need to increase swap space available. By default it's 100 MB, try increasing it to 2048 MB.

Good luck! The whole compilation process takes about 1 hour(less for Bare-bones version), so go make some tea.

Now ROS Melodic should be installed on your Raspberry Pi 4. We'll source the new installation with 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.

Step 4: 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 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

If it doesn't output any errors, do a quick celebration dance(*optional).

Now only the last piece is missing - since you are probably running Raspberry Pi 4 in headless mode, we can't visualize lidar messages. For that we'll need to set-up ROS to run on multiple machines.

Step 5: Set Up ROS to Run on Multiple Machines

For this part you will need a Ubuntu 18.04 computer with ROS Melodic installed. Since it's Ubuntu ROS can be simply installed using apt-get as described in this tutorial.

After you have working ROS installation both on Raspberry Pi and your desktop machine, check the IP addresses of both machines. They need to be on the same network!

Run roscore on your desktop computer and export ROS_MASTER_URI

roscore
export ROS_MASTER_URI=http://[your-desktop-machine-ip]:11311

Next on Raspberry PI execute

export ROS_MASTER_URI=http://[your-desktop-machine-ip]:11311
export ROS_IP=[your-raspberry-pi-ip]

and launch RPILIDAR launch file

roslaunch rplidar_ros rplidar.launch

If it launches successfully, check the topics present on your desktop machine with rostopic list

If you can see / scan mesages, everything works as it supposed to work. Then launch RVIZ on your desktop machine, add Laser Scan messages and choose /scan topic. You will also need to change fixed frame to /laser.

Voila!

Step 6: Done!

This guide can be a first step towards building your ROS robot on top of new Raspberry Pi 4. We have installed ROS Melodic and prepared the installation for running headless and connecting to our desktop machine over wireless network for remote control.

Next steps are dependent on what type of robot you want to build. You can add motors and encoders for odometry, stereo camera for Visual SLAM and all sorts of other exciting and useful things.

The hardware for this article was kindly provided by Seeed studio. Check out Raspberry Pi 4, RPLIDAR A1M8 and other hardware for makers at Seeed studio store!

Add me on LinkedIn if you have any question and subscribe to my YouTube channel to get notified about more interesting projects involving machine learning and robotics.

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    67 Discussions

    0
    shouqqtr13
    shouqqtr13

    Question 3 months ago

    Hello , I got the LaserScan map on rviz using /scan topic. But I have problems in running HectorSLAM or SLAM algorithms in rpi. So is there a contact information ( Email, telegram , or WhatsApp) in order to discuss with u urgent things . Aim Waiting ur reply urgently

    0
    suryarasp
    suryarasp

    4 months ago

    I was struggling couple of days to install ROS on Pi4 , Just I picked up image mentioned in tutorial.Thanks a ton for preparing this as well as updating .Providing image file is great help

    0
    nandahein
    nandahein

    6 months ago

    I found this error when I installed this - sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j2. How can I solve and finish this installation sir? Thanks in advance and looking forward to ur solution for my issues very soon.

    Here is my error---

    CMake Error at CMakeLists.txt:19 (find_package):
    By not providing "Findconsole_bridge.cmake" in CMAKE_MODULE_PATH this
    project has asked CMake to find a package configuration file provided by
    "console_bridge", but CMake did not find one.
    Could not find a package configuration file provided by "console_bridge"
    with any of the following names:
    console_bridgeConfig.cmake
    console_bridge-config.cmake
    Add the installation prefix of "console_bridge" to CMAKE_PREFIX_PATH or set
    "console_bridge_DIR" to a directory containing one of the above files. If
    "console_bridge" provides a separate development package or SDK, be sure it
    has been installed.
    -- Configuring incomplete, errors occurred!
    See also "/home/pi/ros_catkin_ws/build_isolated/class_loader/CMakeFiles/CMakeOutput.log".
    See also "/home/pi/ros_catkin_ws/build_isolated/class_loader/CMakeFiles/CMakeError.log".
    <== Failed to process package 'class_loader':
    Command '['/opt/ros/melodic/env.sh', 'cmake', '/home/pi/ros_catkin_ws/src/class_loader', '-DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/class_loader', '-DCMAKE_INSTALL_PREFIX=/opt/ros/melodic', '-DCMAKE_BUILD_TYPE=Release', '-G', 'Unix Makefiles']' returned non-zero exit status 1
    Reproduce this error by running:
    ==> cd /home/pi/ros_catkin_ws/build_isolated/class_loader && /opt/ros/melodic/env.sh cmake /home/pi/ros_catkin_ws/src/class_loader -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/class_loader -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G 'Unix Makefiles'
    Command failed, exiting.

    error 1.png
    0
    DmitryM8
    DmitryM8

    Reply 6 months ago

    There is a package missing, which is not supposed to happen normally. Can you try re-downloading the packages? In Step 1 :
    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 -j4 -t src
    0
    felipe.n.martins
    felipe.n.martins

    6 months ago

    Thanks a lot for the post. And for the Raspberry Pi image!! It helps a lot!

    0
    DmitryM8
    DmitryM8

    Reply 6 months ago

    Glad that it was helpful!

    0
    jack_kj
    jack_kj

    Question 11 months ago

    I've meet with an error when build the catkin packages.
    After this line of code

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

    This error appeared,
    /usr/bin/ld: cannot find -lcatkin::class_loader::wrapped-linker-option0
    /usr/bin/ld: cannot find -lcatkin::rosconsole::wrapped-linker-option0
    /usr/bin/ld: cannot find -lcatkin::rostime::wrapped-linker-option0
    /usr/bin/ld: cannot find -lcatkin::cpp_common::wrapped-linker-option0
    collect2: error: ld returned 1 exit status
    make[3]: *** [Makefile:38: "/home/pi/ros_catkin_ws/devel_isolated/qt_gui_cpp/lib/python2.7/dist-packages/qt_gui_cpp/libqt_gui_cpp_sip".so] Error 1
    make[2]: *** [src/qt_gui_cpp_sip/CMakeFiles/libqt_gui_cpp_sip.dir/build.make:61: /home/pi/ros_catkin_ws/devel_isolated/qt_gui_cpp/lib/python2.7/dist-packages/qt_gui_cpp/libqt_gui_cpp_sip.so] Error 2
    make[1]: *** [CMakeFiles/Makefile2:566: src/qt_gui_cpp_sip/CMakeFiles/libqt_gui_cpp_sip.dir/all] Error 2
    make: *** [Makefile:141: all] Error 2
    <== Failed to process package 'qt_gui_cpp':
    Command '['/opt/ros/melodic/env.sh', 'make', '-j2']' returned non-zero exit status 2
    Reproduce this error by running:
    ==> cd /home/pi/ros_catkin_ws/build_isolated/qt_gui_cpp && /opt/ros/melodic/env.sh make -j2
    Command failed, exiting.

    I'm currently using raspbian buster on a pi4 4gb
    i tried to install ros kinetic before but i have meet this error as well when building the same package.

    Capture.JPG
    0
    harshitkumawat444
    harshitkumawat444

    Question 1 year ago

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

    after writing the above command , the compilation get struck with error :

    Failed to process package 'bondpy':
    Command '['/opt/ros/melodic/env.sh', 'make', 'cmake_check_build_system']' returned non-zero exit status 2
    Reproduce this error by running:
    ==> cd /home/pi/ros_catkin_ws/build_isolated/bondpy && /opt/ros/melodic/env.sh make cmake_check_build_system
    Command failed, exiting.

    i am new to this so please help me ..


    Screenshot from 2020-01-17 20-21-26.png
    0
    harshitkumawat444
    harshitkumawat444

    Reply 1 year ago

    Thank you for your reply !!!!

    so the image includes ROS Melodic + Buster?

    and can I apply it on Rpi 4b?

    0
    DmitryM8
    DmitryM8

    Reply 1 year ago

    Yes, correct!

    0
    Pix_xel
    Pix_xel

    Tip 1 year ago on Step 2

    Thanks for this great summaryof the requierd fixes.

    Following
    all the commands in Step 2 it seems that the manually fix of the errors
    by (cast floats to int) are not necessary anymore. The downloaded source
    files (today 5 Jan.) already included the necessary casts from float to
    int.

    1
    DmitryM8
    DmitryM8

    Reply 1 year ago

    Thanks! Updated the article just now

    0
    SkyeP2
    SkyeP2

    1 year ago

    Running

    "find -type f -print0 | xargs -0 grep 'boost::posix_time::milliseconds' | cut -d: -f1 | sort -u"

    from ~/ros_catkin_ws returns:

    ./src/ros_comm/roscpp/include/ros/timer_manager.h

    ./src/ros/roslib/test/utest.cpp

    for me. Haven't gotten any further. I'm also running the bare bones installation instead of the desktop one, so perhaps that makes a difference.
    (You might want to add the relevant commands for bare bones installations to that part of the process? Although they're not that hard to find. Also, presumably I won't need Ogre, since there's no rviz.)

    Will comment again to update when and if I make it through tomorrow. (Fingers crossed)

    0
    TheMyG
    TheMyG

    Reply 1 year ago

    It is a great guide DmitryM8, but I could differently use the
    commands for the bare bone installation like SkyeP2 says. The reason is I am
    totally new to ROS and can only figure out that I need to exclude desktop and RVIZ
    stuff, but what else, if anything?

    So if anyone can tell me what I need and don’t need
    for installing the bare bone only, that would be much appreciated?

    0
    SkyeP2
    SkyeP2

    Reply 1 year ago

    Well, that took longer than expected, but I got it to work. Bare bones installation lacks the sensor_msgs package, so I had to install that. I also had issues getting the connectivity to work correctly, for a number of reasons. Virtual box needed to be in Bridged Networking mode, had some DNS issues with one network and IP issues with another. roswtf came in handy there. And then finally I had issues getting rviz to pick up the data properly which were solved by reinstalling rplidar on the master (laptop). Well, it's all worth it. Thank you for the tutorial!

    0
    DmitryM8
    DmitryM8

    Reply 1 year ago

    Perfect! So, you got it to work in VirtualBox?

    0
    SkyeP2
    SkyeP2

    Reply 1 year ago

    Hey, sorry, I was out OOO for a few weeks.

    Yes! I got it to work, but I've forgotten everything over the last month so I'll have to get it up and running again. After that I need odometry and object detection (front-mounted sonar sensor on a servo) and I should be able to get some accurate SLAM/autonomous navigation.

    0
    alessmelino
    alessmelino

    1 year ago

    Hello.

    I followed every single step until build the installation, and in this point I got the following error:

    ==> make -j2 in '/home/pi/ros_catkin_ws/build_isolated/dynamic_reconfigure'
    Scanning dependencies of target dynamic_reconfigure_gencfg
    Scanning dependencies of target dynamic_reconfigure_config_init_mutex
    [ 3%] Building CXX object CMakeFiles/dynamic_reconfigure_config_init_mutex.dir/src/dynamic_reconfigure_config_init_mutex.cpp.o
    [ 3%] Generating dynamic reconfigure files from cfg/Test.cfg: /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/include/dynamic_reconfigure/TestConfig.h /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/lib/python2.7/dist-packages/dynamic_reconfigure/cfg/TestConfig.py
    Traceback (most recent call last):
    File "/home/pi/ros_catkin_ws/src/dynamic_reconfigure/cfg/Test.cfg", line 37, in
    from dynamic_reconfigure.parameter_generator_catkin import *
    File "/home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/lib/python2.7/dist-packages/dynamic_reconfigure/__init__.py", line 35, in
    exec(__fh.read())
    File "", line 38, in
    File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in
    from roslib.launcher import load_manifest
    File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in
    import rospkg
    ImportError: No module named rospkg
    make[2]: *** [CMakeFiles/dynamic_reconfigure_gencfg.dir/build.make:64: /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/include/dynamic_reconfigure/TestConfig.h] Error 1
    make[1]: *** [CMakeFiles/Makefile2:110: CMakeFiles/dynamic_reconfigure_gencfg.dir/all] Error 2
    make[1]: *** Se espera a que terminen otras tareas....
    [ 4%] Linking CXX shared library /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/lib/libdynamic_reconfigure_config_init_mutex.so
    [ 4%] Built target dynamic_reconfigure_config_init_mutex
    make: *** [Makefile:141: all] Error 2
    <== Failed to process package 'dynamic_reconfigure':
    Command '['/opt/ros/melodic/env.sh', 'make', '-j2']' returned non-zero exit status 2
    Reproduce this error by running:
    ==> cd /home/pi/ros_catkin_ws/build_isolated/dynamic_reconfigure && /opt/ros/melodic/env.sh make -j2
    Command failed, exiting.

    Executing the command that it says to me appears the following info:

    [ 4%] Generating dynamic reconfigure files from cfg/Test.cfg: /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/include/dynamic_reconfigure/TestConfig.h /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/lib/python2.7/dist-packages/dynamic_reconfigure/cfg/TestConfig.py
    [ 4%] Built target dynamic_reconfigure_config_init_mutex
    Scanning dependencies of target _dynamic_reconfigure_generate_messages_check_deps_Reconfigure
    CMake Error: Cannot open file for write: /home/pi/ros_catkin_ws/build_isolated/dynamic_reconfigure/CMakeFiles/_dynamic_reconfigure_generate_messages_check_deps_Reconfigure.dir/depend.make.tmp
    CMake Error: : System Error: Permission denied
    Traceback (most recent call last):
    File "/home/pi/ros_catkin_ws/src/dynamic_reconfigure/cfg/Test.cfg", line 37, in <module>
    from dynamic_reconfigure.parameter_generator_catkin import *
    File "/home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/lib/python2.7/dist-packages/dynamic_reconfigure/__init__.py", line 35, in <module>
    exec(__fh.read())
    File "<string>", line 38, in <module>
    File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
    File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
    ImportError: No module named rospkg
    make[2]: *** [CMakeFiles/_dynamic_reconfigure_generate_messages_check_deps_Reconfigure.dir/build.make:74: CMakeFiles/_dynamic_reconfigure_generate_messages_check_deps_Reconfigure.dir/depend] Error 2
    make[1]: *** [CMakeFiles/Makefile2:1480: CMakeFiles/_dynamic_reconfigure_generate_messages_check_deps_Reconfigure.dir/all] Error 2
    make[1]: *** Se espera a que terminen otras tareas....
    make[2]: *** [CMakeFiles/dynamic_reconfigure_gencfg.dir/build.make:64: /home/pi/ros_catkin_ws/devel_isolated/dynamic_reconfigure/include/dynamic_reconfigure/TestConfig.h] Error 1
    make[1]: *** [CMakeFiles/Makefile2:110: CMakeFiles/dynamic_reconfigure_gencfg.dir/all] Error 2
    make: *** [Makefile:141: all] Error 2

    How can I solve it and finish the installation?

    Thanks in advane.

    Best regards.
    Alesandro

    error.PNG