Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

Getting Started with the Low-Cost RPLIDAR Using NVIDIA Jetson Nano

4 min read

Are you interested in building your own robot or autonomous vehicle? Are you looking for a cost-effective and efficient way to incorporate laser-based distance sensing into your project? If so, then you’re in luck! In this blog post, we will explore how to get started with low-code RPlidar on the Jetson Nano, a powerful single-board computer from NVIDIA that is popular for AI and robotics applications.

What is RPlidar?

Image1
Source ~ https://robu.in/product/rp-lidar-a1m8-360-degrees-laser-range-finder/

RPlidar is a brand of inexpensive and lightweight laser range finders that use a rotating laser scanner to measure distances and create a 2D point cloud of the environment. It is commonly used in robotics, drones, and other autonomous systems for obstacle detection, mapping, and navigation. RPlidar provides accurate and reliable distance measurements with a wide field of view and a long range, making it a popular choice for many robotics enthusiasts and professionals.

Key Use Cases:

  • Home service /cleaning robot navigation and localization.
  • General robot navigation and localization.
  • Smart toy localization and obstacle avoidance.
  • Environment scanning and 3D re-modeling.
  • General simultaneous localization and mapping

Image4

What is Jetson Nano?

Jetson Nano is a single-board computer (SBC) developed by NVIDIA, specifically designed for AI and robotics applications. It features a powerful NVIDIA GPU with CUDA cores for accelerated computing, a quad-core ARM Cortex-A57 CPU, and ample memory and storage options. Jetson Nano runs on a Linux-based operating system and supports a wide range of programming languages, making it ideal for developing AI-powered robotics projects.

Getting Started

Step 1. Hardware Requirements

  • 1x RPLiDAR A1M8 360 Degree Laser Range Finder – 6m (Radius Range) – Special Thanks to Seeed Studio for sponsoring for these hardware equipments.

Image11

  • 1 x Interfacing Controller and Connecting Cable.

Image10

  • 1x Jetson Nano

Image13

  • 1x Wifi USB Adapter for Keyboard and Mouse

Image15

  • 1x Tenda W311MI Wireless N150 USB Adapter Nano

Image14

  • 1x HDMI cable

Step 2. Assemble the Hardware Components

First, you will need to assemble the hardware components required for using RPlidar with Jetson Nano. You will need a USB cable to connect the RPlidar to the Jetson Nano. Make sure to use a high-quality USB cable to ensure reliable data transmission.

Connect the RPlidar to the Jetson Nano: Plug one end of the USB cable into the RPlidar and the other end into one of the USB ports on the Jetson Nano.

Please Note: The Grove Hat Sensor Expansion board is not required for the project. 

Power Up the Jetson Nano: Connect the power supply to the Jetson Nano and power it up. Wait for the Jetson Nano to boot up and complete the initialization process.

Image7

Once you have assembled all the hardware components, you’re ready to move on to the next step.

Step 3: Install the RPlidar Driver

Next, you will need to install the RPlidar driver on your Jetson Nano. The RPlidar driver provides the necessary software interface for communication between the RPlidar unit and the Jetson Nano. Here’s how you can do it:

Open a terminal window on the Jetson Nano and run the following commands to install the RPlidar driver:

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

Step 4. Add a new apt key

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

Step 5. Install ros-melodic

sudo apt install ros-melodic-desktop
sudo rosdep init

Step 6. Update Rosdep

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

Step 7. Check the version

rosversion -d

Step 8. Install catkin

clearros

Step 9. Create the catkin root and source folders

mkdir -p ~/catkin_ws/src
  • In your terminal, run:
cd ~/catkin_ws/src

Step 10. Clone the github repository of RPLIDAR ROS package

git clone  https://github.com/robopeak/rplidar_ros.git
cd ..

Step 11. Run catkin_make to compile your catkin workspace

catkin_make

Step 12. Run to source the environment with your current terminal. Don’t close the terminal.

source devel/setup.bash

Step 13. Open a new terminal, run the following command – DO NOT CLOSE THE FIRST TERMINAL

roscore

Step 14. Launch the RPlidar Node

After the installation is complete, you can launch the RPlidar node by running the following command in the terminal:

roslaunch rplidar_ros view_rplidar.launch

This will start the RPlidar node and establish communication between the RPlidar unit and the Jetson Nano. An instance of Rviz will then open with a map of the RPLIDAR’s surroundings.

Step 15. View RPlidar Data in ROS

Image122

Running the ROS inside a Docker Container

FROM ros:melodic-robot-bionic

WORKDIR /root
SHELL [ "bash", "-c"]
ENV ROS_WS /ros

RUN apt-get update \
&& apt-get install -y \
   git \
   vim \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p ${ROS_WS}/src \
&&  cd ${ROS_WS}/src \
&&  git clone https://github.com/Slamtec/rplidar_ros.git

COPY b2_rplidar /ros/src/b2_rplidar

RUN source /opt/ros/${ROS_DISTRO}/setup.bash \
&& cd ${ROS_WS}/src \
&& catkin_init_workspace \
&& cd ${ROS_WS} \
&& catkin_make 

COPY ./entrypoint.sh /
RUN echo "source /entrypoint.sh" >> .bashrc
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "bash" ]

This Dockerfile sets up a Docker image based on the ROS Melodic image with additional packages and configurations for using RPlidar. It installs Git and Vim, and then creates a workspace for ROS by setting the ROS_WS environment variable to /ros and creating a source directory in ${ROS_WS}/src.

Next, it clones the RPlidar ROS package from Slamtec into the ROS workspace source directory using Git. It also copies the b2_rplidar package into the /ros/src directory.

The Dockerfile then sources the ROS setup script, initializes the ROS workspace source directory with catkin_init_workspace, and builds the workspace with catkin_make. Finally, it copies an entrypoint script into the root directory, adds a command to source the script to the .bashrc file, and sets the entrypoint to the script.

In nutshell, this Dockerfile sets up a Docker image with the necessary packages and configurations for working with RPlidar in ROS, and provides a convenient entrypoint script for launching the image.

Creating the Entrypoint.sh File

#!/bin/bash

source "/opt/ros/$ROS_DISTRO/setup.bash"
source "${ROS_WS}/devel/setup.bash"
exec "$@"

Building the Docker Image

docker build -t ajeetraina/rplidar .

Running the ROS driver container

docker run -d --rm \
--name container_name \
--label ${LABEL} \
--net host \
--privileged \
--env DISPLAY \
--env ROS_MASTER_URI \
--mount type=bind,source=$PROJ_DIR/b2-rplidar/b2_rplidar,target=/ros/src/b2_rplidar \
--mount type=bind,source=${DOWNLOADS_DIR},target=/root/Downloads \
$DOCKER_IMAGE roslaunch b2_rplidar b2_rplidar.launch

You can find the working code in this repository.

Conclusion

Getting started with low-code RPlidar with Jetson Nano is an exciting journey that can open up a wide range of possibilities for building robotics projects. In this blog post, we covered the basic steps to get started with low-code RPlidar with Jetson Nano, including setting up ROS, installing the RPlidar driver and viewing RPlidar data in ROS using RViz. By following these steps and exploring the possibilities of RPlidar, you can create innovative and exciting robotics projects with the Jetson Nano platform. In our next blog post, we will see how one can save time in building the entire software stack using Docker containers.

So, grab your Jetson Nano and RPlidar unit, start experimenting, and unleash the power of low-code robotics!  Stay tuned! Happy coding!

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index