How to Create a 2D Map of Your Room With LiDAR

Because of the precision required in various fields such as agriculture, archaeology, and transportation, lasers are widely used for purposes such as obstacle avoidance, mapping, or even autonomous navigation.

Let’s look at LiDARs, how they work, and how you can use them to create a 2D map of your space.

Things you need to scan your room

Below are the requirements to create a 2D map of your space:

  • A laptop or PC running Ubuntu Server
  • ROS installation
  • A LiDAR

What is LiDAR?

LiDAR or Light Detection and Ranging, can also be found under another name, LADAR (Laser Detection and Ranging) an active remote sensing technology that measures distances using light in the form of a pulsed laser. The technology works by directing an optical pulse at a target and measuring the properties of the reflected return signal.

The system measures the time it takes for the beam to return. In general it is a range finder. The width of the optical pulse can range from a few nanoseconds to several microseconds and can target a wide variety of materials.

System connection and laser data acquisition

In this case, RPLIDAR A1 is used, a low-cost LiDAR sensor suitable for indoor robotic applications. It has a 360 degree scanning field, a rotation frequency of 5.5 Hz/10 Hz and a range of 8 meters. The LiDAR has a range scanner system, a motor system and a communication interface (serial interface/USB).

The system measures distance data more than 2000 times per second and with high-resolution distance output. Consequently, it requires the use of multiple tools to process and visualize the data. For example, you can use the SlamTech RoboStudio tool or the package provided by ROS.

Why ROS?

ROS (Robot Operating System) is software used by a global open source community of robotics hobbyists dedicated to improving and making robots available to all. It was originally developed by Eric Berger and Keenan Wyrobek at Stanford University. ROS also lets you visualize sensor data, create interfaces, and use tools like Rviz and the gazebo simulation engine.

With ROS, you can easily break your code into packages that contain small programs called nodes. These nodes are connected via topics through which they send and receive messages.

In this project, you will use rplidar_ros, a ROS package specifically designed for LiDAR data collection. The hector_slam package will later be used for map creation.

Step 1: ROS installation

After installing Ubuntu Server, open your terminal and run the following command to ensure your Debian package index is up to date. The difference between update and upgrade has already been covered.

sudo apt update

The next step is to install ROS.

sudo apt install ros-noetic-desktop-full

You can test ROS by using the Roscoreserving as proof of proper installation.

roscore 

Step 2: Get your first scan

First, run the following command to get the rplidar_ros Package:

sudo apt-get install ros-noetic-rplidar-ros 

That rplidar_ros The package contains the scripts and startup files needed to retrieve and visualize LiDAR scan data.

When you have finished your software, connect your LiDAR to your PC via the USB port. The LiDAR will start spinning but will not emit a laser unless you run the following command which will call a ROS boot file.

roslaunch rplidar_ros rplidar.launch 

By running this command, you can see the reflected distances, which will be published in a topic called /scan.

rostopic echo /scan 

You should see a representation of the unprocessed laser scan data in your terminal:

To visualize this data, open another terminal, be careful not to close the other running terminal that is getting data from the laser scanner, and start it Rvizthe visualization tool.

rosrun rviz rviz

change that fixed frame to laserthen click Add button in the lower left corner of the window and select laser scan. Finally set up the LaserScan theme /Scanand you can see your real-time LiDAR scan.

If you’re having trouble getting your first scan, it may be because your device isn’t authorized to transmit data over the serial port. To fix this, run the following command and then continue with the previous steps.

sudo chmod 777 /dev/ttyUSB0

Step 3: Start mapping

After you have tested your LiDAR and confirmed that it is working properly, the next step is to start scanning your area of ​​interest. To do this, you need an add-on package called Hector Slam (where “Slam” stands for “Simultaneous localization and mapping”).

As before, run the following command to install this package:

sudo apt-get install ros-noetic-hector-slam 

Before running the scan, change some parameters as shown below. Find tutorial.launch in the hector_slam package by typing the roscd Command.

roscd hector_slam_launch

The command nano lets you open and edit your file.

nano tutorial.launch

You may encounter a Linux file permission error, which can be fixed with this command:

sudo chmod 777 tutorial.launch

Here is an example of execution:

The next step is to change the lines as shown below:

The last step is to run this line.

roslaunch hector_slam tutorial.launch 

For best results, start by moving your LiDAR slowly through your room, as creating maps is most effective when moving slowly. You can turn on your trajectory and experiment with the laser scan settings.

You can use indoor SLAM to scan the entire house with a laptop and a LiDAR as shown in the video below. The results can be improved by integrating additional sensors and then combining the data from both sources.

Step 4: Save and edit your card

Run the following command when you’re done scanning to save the map:

rostopic pub syscommand std_msgs/String "savegeotiff"

In this scenario, imagemagick can be used to convert the map to a PNG image file, run these two commands to complete the installation and the conversion.

sudo apt-get install imagemagick
convert scannedMap.pgm MyPngMap.png

Get more value from LiDAR

With a LiDAR and a PC you could do a 2D scan. You can improve your scan by adding a depth camera like Kinect and integrating the two types of data captured.

The same technology may be found in some high-end iPhone and iPad models, where the LiDAR is integrated into the camera module on the back of the device, enabling the development of 3D maps, distance measurements and augmented reality applications.

Leave a Reply

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