How to use LiDAR data for 2D mapping in ROS-faral

How to use LiDAR data for 2D mapping in ROS

In today’s world, where robots, autonomous navigators, and service systems in both indoor and outdoor environments are rapidly advancing, precise environmental mapping has become one of the essential infrastructures. One of the sensors that plays a significant role in this area is the 2D LiDAR technology. Unlike camera sensors that may rely on light or visual features, LiDAR provides a direct measurement of distances, enabling realistic mapping. As FARO explains: “SLAM (Simultaneous Localization and Mapping) with the help of LiDAR allows moving devices to simultaneously determine their location and map their surroundings”

Imagine your robot is placed in an indoor environment (e.g., an office center, small factory, or hospital) and needs to create a 2D map of that environment using a 2D LiDAR and ROS, and then use it for navigation. In this blog, we will go through the steps to accomplish this, while also including Faral Tech’s insights on this topic, along with their recommendations, advantages, and challenges. Additionally, this content is optimized for SEO to enhance its visibility in search engines, targeting both technical and business audiences.

Step 1: Choosing and Configuring the 2D LiDAR Hardware

First, we need to select a suitable 2D LiDAR. Key factors include:

Horizontal field of view (e.g., 270° or 360°)

Angular resolution (e.g., 0.25°, 0.5°)

Range (e.g., up to 10 meters)

Scan rate (e.g., 5 Hz or higher)

As mentioned in a review article: “In a paper titled ‘A Review of 2D Lidar SLAM Research,’ it is stated that SLAM algorithms based on 2D LiDAR generally rely on filter-based methods, scan matching, and graph optimization”

After selecting the sensor, it must be physically installed on the robot (or a fixed platform), and we need to ensure that the messages /scan or /laser_scan are correctly published in ROS.

Step 2: Setting Up ROS and Related Packages

In the ROS environment (e.g., ROS Noetic or ROS 2, depending on your choice), the following steps should be taken:

<launch>
  <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
     <!-- Parameters -->
  </node>
  <node pkg="tf" type="static_transform_publisher" name="base_to_laser"/>
  <include file="$(find your_laser_pkg)/launch/laser.launch" />
</launch>

Verify in rviz that the scan messages and transforms (tf) are working correctly.

Step 3: Running Mapping and Generating the 2D Map

Once the sensor and ROS are ready, SLAM begins:

  1. The robot or sensor starts moving around the environment to collect initial data.
  2. The SLAM algorithm estimates the robot’s position relative to the map and gradually generates a 2D map (an ongoing map update).
  3. After sufficient coverage of the environment, the map is saved (e.g., using the command rosrun map_server map_saver -f my_map).

The following table shows some key SLAM parameters for 2D LiDAR:

ParameterDescription
linearUpdateThe forward distance/angle after which a new scan is included
angularUpdateThe angular rotation after which a new scan is included
maxUrangeThe maximum range for scans considered in the mapping
kernelSizeThe kernel size for smoothing the map image
minimumScoreThe minimum score for accepting a scan as an update to the map


Step 4: Improving Map Quality and Usage in ROS

Once the initial map is generated, there are several ways to improve its quality:

For example, an article titled “A 2D‑LiDAR‑based localization method for indoor mobile robots using correlative scan matching” shows that using scan matching methods, the robot’s position can be determined with high accuracy (cambridge.org)

Faral Tech’s Viewpoint

Faral Tech, as an active player in the robotics field, provides specific insights on using 2D LiDAR and ROS, summarized as follows:

1. Smart Spending with 2D LiDAR

Faral believes in the power of smart solutions, especially when it comes to cost efficiency. For many indoor environments—such as service robots, cleaning units, or small-scale industrial applications—2D LiDAR offers a robust and budget-friendly alternative to 3D LiDAR. In these cases, 2D mapping provides everything you need without breaking the bank. Faral recommends starting simple and saving resources while still achieving highly effective results.

2. ROS and Modularity: The Perfect Match

Faral emphasizes that the true strength of building scalable robotic systems lies in modular integration. By leveraging ROS (Robot Operating System) and its open-source ecosystem, you avoid reinventing the wheel. With pre-built packages for 2D mapping, you’ll not only have a system that’s easy to implement but also one that’s easy to maintain and scale. Faral’s key point: modular design is the foundation for flexibility, adaptability, and long-term success.

3. A Map That Lives and Grows

Faral encourages companies to think of their 2D LiDAR maps not as static documents but as evolving assets. The real power of 2D LiDAR mapping lies in its ability to adapt over time to changes in the environment, such as newly introduced obstacles. In Faral’s own words, a map should be continuously updated to reflect the world as it is today, ensuring robots stay reliable and accurate even in dynamic settings.

4. The Efficiency of Reuse

Once a 2D LiDAR map is created, its value doesn’t end there. Faral highlights that security and scalability are built right into the map. A well-designed 2D map can serve as a universal template for various modules within a robot’s architecture—whether it’s navigation, obstacle avoidance, or path planning. This means lower costs and higher efficiency in the long run.

Faral’s Advice for Service Robots

If you’re venturing into the world of service robots or automation, Faral advises:
“Start with 2D LiDAR and ROS for simplicity, and then, if the situation demands more complexity, consider expanding into 3D mapping or additional sensors.”

Advantages, Challenges, and Recommendations

PerspectiveDescription
Smart Spending with 2D LiDARFaral recommends using 2D LiDAR for indoor applications like service robots, cleaning units, and small industrial setups. It’s cost-effective, efficient, and provides everything you need without excessive expense.
ROS and Modularity: The Perfect MatchFaral emphasizes modular integration with ROS, which simplifies system implementation and maintenance. Pre-built 2D mapping packages make the system flexible and scalable.
A Map That Lives and GrowsFaral advocates for viewing 2D maps as evolving assets, constantly updated to account for dynamic changes in the environment like obstacles. This keeps robots accurate and reliable.
The Efficiency of Reuse2D maps offer security and scalability. They can serve as templates for multiple modules within the robot, such as navigation, obstacle avoidance, and path planning, offering long-term cost savings and efficiency.
Faral’s Advice for Service RobotsFaral advises starting with 2D LiDAR and ROS for simplicity. If the environment becomes more complex, consider adding 3D mapping or additional sensors.

Conclusion

In this blog, we reviewed the process of using a 2D LiDAR sensor in the ROS environment for 2D mapping: from selecting hardware and setting up ROS to generating and optimizing the map. We also examined Faral Tech’s viewpoint, which emphasizes cost-effective solutions, ROS integration, and live maps. By following the technical tips and recommendations, you can build an efficient 2D mapping system for your indoor environment.


Can 2D LiDAR be used for outdoor environments?

Yes, but it is generally more suitable for indoor environments with lower speeds.

Do I need to install a special package in ROS for 2D mapping?

Yes, packages like gmapping or cartographer_ros are used for 2D mapping.

Do I need to refine the map after creation?

Yes, typically to remove noise, synchronize with navigation, and keep it updated.