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

About: 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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Install Dependecies and Download the Packages

Let's start by setting up the repositories and installing the necessary dependencies

sudo sh -c 'echo "deb  $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://' --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 - might be preferred choice for Raspberry Pi, since you probably will be running it headless anyway, if you are using it for a robot. Doesn't include RVIZ, which makes installation process shorter and less hassle.

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

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

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 -O
cd assimp-3.1.1
cmake .
sudo make install

Let's also install OGRE for rviz

sudo apt-get install  libogre-1.9-dev

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));


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

and these:




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.

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

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

Step 3: Build and Source the Installation

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/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, 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

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/

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

cd ..

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

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-desktop-machine-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.


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


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    15 Discussions


    1 day ago

    I seem to be having an issue with the python-catkin-pkg
    any idea?

    The following packages have unmet dependencies:
    python-rosdistro-modules : Depends: python-catkin-pkg-modules but it is not installed
    python-rospkg-modules : Depends: python-catkin-pkg-modules but it is not installed
    E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
    I get this error often

    3 days ago

    Due to the lack of total support from Sipeed and their products, no other way that ask directly to the only person that putted some light in the Maix products.Please, could you give me a clue of how extract data as coordinates of the bboxes from the inference, for example via uart. For what demos of object detection if you cannot send what you detected to a computer,rpi,nano or whatever. I guess that you need program the funcition in maixpy IDE, but Im begginer and no idea from where start. Just a little clue to put me in the way?


    22 days ago


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

    from ~/ros_catkin_ws returns:



    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)

    1 reply

    Reply 15 days 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!


    4 weeks ago

    I am lost at "Try launching roscore to check if everything was successful.", cause I miss the how-to
    and finally in Step 4: "catkin_make", cause there is nothing in the new folder ;)
    And I am interessted to get the Kinect 360 working more than the LIDAR. Any hints?

    4 replies

    Reply 4 weeks ago

    Let's focus on step 3 for now. What's the output of
    sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j2
    Is compilation successful?


    Reply 27 days ago

    There is a lot of output, but no error. Last sentence is: " <== Finished processing package [186 of 186]: 'xacro' "


    Reply 27 days ago

    Nice! So, the compilation is successful, but you can't start roscore. Let's check a couple of things:
    1)/opt/ros/melodic/setup.bash --- is setup.bash present in /opt/ros/melodic/?
    2)Has the following line was added to .bashrc : source /opt/ros/melodic/setup.bash ?
    3) You'll need to open a new terminal or source bash.rc in order for changes to take effect.


    Reply 26 days ago

    1,2 and 3=yes
    And roscore started :] Maybe the full restart of the Pi4 changed something


    Question 6 weeks ago on Step 6

    "find -type f -print0 | xargs -0 grep 'boost::posix_time::milliseconds' | cut -d: -f1 | sort -u"
    Didn't return any results. Also I couldn't find any of the following files:

    And finally when I run sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j2

    I get a "Command not found"

    I'm assuming catkin is not installed properly so i tried to run
    sudo apt-get install ros-melodic-catkin

    This ends up with a "package not found" error. Has something changed since you managed to get this process working before today?

    5 answers

    Answer 4 weeks ago

    The instructable is not complete. Type:
    cd ..
    cd ..
    find -type f -print0 | xargs -0 grep 'boost::posix_time::milliseconds' | cut -d: -f1 | sort -u


    Reply 4 weeks ago

    Right. That command should be executed from ros_catkin_ws. I already added the comment to that part of the tutorial


    Reply 27 days ago

    " already added the comment to that part of the tutorial" - sadly not.
    U are jumping in front of the command:
    cd ~/ros_catkin_ws/external_src
    and cd assimp-3.1.1
    So u have to use cd .. twice or simple: cd ~/ros_catkin_ws
    (And could u pls delete the unneccessary br switches in the code examples?)


    Reply 27 days ago

    "You can list all files using that function(sic) (!in ros_catkin_ws folder!):"
    I added "(!in ros_catkin_ws folder!)
    Because I'm assuming people reading this tutorial have at least basic knowledge of Linux file system :)
    Yes, those br and a tags... Already deleted them.


    Answer 6 weeks ago

    Hi! Very likely the process hasn't changed.
    Where are you running the
    ./src/catkin/bin/catkin_make_isolated command from? It should be run
    from the directory you are building ROS in.
    It is also possible that
    rosinstall_generator hasn't finished downloading all the files. Can you
    try restarting the download with wstool update -j 4 -t src or start