-
Before applying Loop Closure
-
After applying Loop Closure
The light blue line shows the driving trajectory displayed on RViz. When driving using only FAST-LIO-ROS2, slight position estimation errors can accumulate, causing the trajectory to shift when returning to the starting point. Applying Loop Closure can correct this shift using information about previously traveled locations.
This article describes how to create a 3D point cloud map using FAST-LIO-ROS2 with Livox MID-360S and ROS2 Jazzy, and then correct the driving trajectory using Simple Loop Closure. We will explain the process step-by-step, from environment setup, configuration, code modification, and Loop Closure adjustments to saving the corrected map as map.pcd.
This content will be useful for those who want to start creating 3D LiDAR maps with ROS2, or those who want to improve map inaccuracies that occur during long-distance driving.
While FAST-LIO is suitable for fast and smooth self-localization, during long-distance travel or when circling the same location and returning, small estimation errors can accumulate, causing maps to appear double, such as walls or pathways.
On the other hand, Loop Closure checks whether it's possible to return to a previously visited location and uses that information to correct any deviations in the entire movement trajectory. The process of reviewing the entire trajectory together is called Pose Graph Optimization.
This paper explains the process of "inputting point cloud and IMU data → estimating position and map using FAST-LIO-ROS2 → correcting for discrepancies using Loop Closure → saving the corrected map" on ROS2, following the steps of configuration, introduction, setup, execution, and verification.
Target: Ubuntu 24.04, ROS2: Jazzy
Prerequisites: Livox-SDK2 and livox_ros_driver2 must be installed.
The main terms used in this article are: a point cloud is a large number of 3D points acquired by LiDAR; an IMU is a device that measures the movement and rotation of a sensor; odometry is the estimated result of the current position and orientation; a keyframe is representative data used for map correction; and ICP is the process of overlaying two point clouds.
What are FAST-LIO-ROS2 and Loop Closure? Their roles and drift correction mechanisms.
To create a map using 3D LiDAR, it's necessary to align and overlay point clouds acquired while moving at the same reference point. To achieve this, the sensor's location and orientation are continuously estimated. This process is called LiDAR odometry.
FAST-LIO-ROS2 estimates position and orientation by combining LiDAR point cloud data and IMU motion information. This calculation uses a technique called "iterative extended Kalman FILTERS," which updates position and orientation while combining LiDAR and IMU information.
Furthermore, the time at which each point was acquired is used to correct for distortion of the point cloud that occurs during movement.
However, even with highly accurate position estimations for each individual movement, it's impossible to completely eliminate small errors. As the distance traveled increases, these errors accumulate, and when returning to the starting point, the same wall or floor may be drawn in a different location. This discrepancy is called drift. Simple Loop Closure checks for representative historical data (keyframes) near the current position, and if the current and past point clouds overlap sufficiently, it uses that information to correct the drift of the entire movement trajectory.
Even with non-repetitive scanning 3D LiDARs like the MID-360S, it's possible to create maps while correcting for point cloud distortion caused by sensor movement by using the time each point was acquired.
| Functionality | Main role | Output in this configuration |
|---|---|---|
| FAST-LIO-ROS2 | Estimation of current position and orientation using LiDAR and IMU, and creation of a point cloud map. | Location and orientation information (Odometry), point cloud converted to map coordinates, movement trajectory |
| Simple Loop Closure | Searching for previously visited locations, overlaying point clouds (ICP), and correcting the entire travel trajectory. | Corrected movement trajectory, corrected point cloud map (map.pcd) |
| RViz/CloudCompare | Visually check the map during processing and after saving. | Map overlaps, walls, closed loop shapes |
point
Loop Closure is not a function that creates maps in place of FAST-LIO. FAST-LIO estimates the current location and map in real time, and Loop Closure then corrects the overall discrepancy that accumulates during travel.
System configuration: MID-360S + FAST-LIO-ROS2 + Loop Closure
The point cloud output from the MID-360S and the data from the built-in IMU are distributed as a ROS2 topic via livox_ros_driver2. FAST-LIO-ROS2 correlates the point cloud data with the IMU timestamps, corrects for point cloud distortion caused by sensor movement, and generates a point cloud for the current position and orientation, as well as a map.
Simple Loop Closure takes the point cloud "/cloud_registered" (converted to the map coordinate system output by FAST-LIO-ROS2) and position/orientation information "/Odometry" as input. Loop Closure saves representative data (Keyframes) that serve as the basis for map correction at every certain distance of movement or rotation. If it is determined that the current point cloud matches a previously saved Keyframe, it uses GTSAM, a library that performs position and orientation optimization calculations, to review the entire movement trajectory up to that point. This process is called Pose Graph Optimization. The point clouds are then rearranged according to the corrected position and orientation, and the final map.pcd is created.
The structure assumed in this paper is as follows.
Please replace the topic name with the one that matches the launch file and settings you are using.
| 1 | MID-360S | Point cloud CustomMsg + built-in IMU |
|---|---|---|
| ▼ | ||
| 2 | livox_ros_driver2 | Distributed as a ROS2 topic |
| ▼ | ||
| 3 | FAST-LIO-ROS2 | Point cloud distortion correction, position and orientation estimation, and point cloud converted to map coordinates. |
| ▼ | ||
| 4 | Simple Loop Closure | Searching for past locations, overlaying point clouds, and correcting the entire movement trajectory. |
| ▼ | ||
| 5 | Save map | Output the corrected map.pcd. |
Operating environment and prerequisites for ROS2 Jazzy
This article confirms operation with Ubuntu 24.04 and ROS2 Jazzy. Note that the FAST-LIO-ROS2 README targets ROS2 Foxy and later, and recommends Humble. FAST-LIO-ROS2 and Simple Loop Closure use multiple external libraries for map processing and point cloud processing. Before building, install the necessary libraries with rosdep and confirm that GTSAM, PCL, and Eigen are correctly recognized. GTSAM is used to correct the entire movement trajectory, so if it is not installed or the version is incompatible, Simple Loop Closure cannot be built.
Map quality is affected not only by software settings but also by how the sensors are mounted and how the vehicle is driven. The MID-360S should be securely fixed to the vehicle to prevent vibrations and changes in mounting angle during driving. Rapid acceleration, sharp turns, areas with many glass surfaces, and long corridors with few distinguishing features such as walls and pillars may make it difficult to correctly overlay the point cloud. For the initial check, drive slowly and choose a route that passes through places where shapes are easily distinguishable, such as corners of pillars and walls, to make the check easier.
| Item | Confirmation details |
|---|---|
| LiDAR | MID-360S. Uses an internal IMU. |
| OS/ROS2 | Ubuntu24.04。ROS2 Jazzy。 |
| ROS2 Driver | livox_ros_driver2. A CustomMsg containing time information for each point is used. |
| Major libraries | PCL 1.8 or later, Eigen 3.3.4 or later, GTSAM 4.x, nanoflann. |
| Time Synchronization | Minimizing the time difference between LiDAR and IMU. Loss of time information for each point reduces the accuracy of motion correction. |
| Included data | Record point cloud data, IMU data, and TF data (if necessary) to rosbag2. Closed-loop evaluation includes a return trip to the starting point. |
Installation and configuration of FAST-LIO-ROS2
FAST-LIO-ROS2 uses the time each point was acquired and the IMU's movement information to correct for distortion of the point cloud that occurred during movement. Then, it compares the current point cloud with a map that has already been created and updates the position and orientation. Therefore, even if the point cloud is received, if the IMU's time, units, coordinate axes, and the relationship between the LiDAR and IMU's mounting position and orientation are incorrect, problems such as the map tilting, the point cloud spreading during rotation, and the trajectory suddenly jumping will occur.
After setup, instead of running Loop Closure simultaneously from the start, first verify that FAST-LIO-ROS2 alone can stably create maps. On RViz, verify that the point cloud does not shake significantly when stopped, that walls do not appear as large doubles when traversing the same location, and that /Odometry and /cloud_registered are continuously output. Connecting Simple Loop Closure afterward makes it easier to pinpoint where problems occur.
An example workspace is shown below.
Please change the actual directory name to match your environment.
mkdir -p ~/FAST_LIO_ROS2/src
cd ~/FAST_LIO_ROS2/src
git clone --recursive https://github.com/Ericsii/FAST_LIO_ROS2.git
cd ..
rosdep install --from-paths src --ignore-src -y
For the MID-360S, check at least the following items:
| Setting items | Confirmation details | Points to note |
|---|---|---|
| lid_topic/imu_topic | Match the point cloud/IMU topics delivered by the driver. | Check with ros2 topic list/hz |
| lidar_type | Set values for MID-360S | Check the default values in the configuration file to be used. |
| extrinsic_T/extrinsic_R | Relationship between the mounting position and orientation of LiDAR and IMU (external parameters) | FRAMES definition can also be checked using the built-in IMU. |
| extrinsic_est_en | Using false is recommended when using known external parameters. | The function that automatically estimates mounting relationships should only be enabled after confirming its necessity. |
| time_sync_en | Consider this only if external synchronization is not possible. | Even if you synchronize the time using software, complete synchronization cannot be guaranteed. |
| pcd_save_en/map_file_path | Whether or not to save FAST-LIO standalone maps and where to save them. | Distinguish it from the map after Loop Closure. |
Implementing Simple Loop Closure and setting up ICP/representative data Keyframes for overlaying point clouds.
Simple Loop Closure does not save all received data; instead, it saves data only when a certain distance has been traveled or when a certain amount of rotation has been performed, as a representative FRAMES. This representative FRAMES is called a Keyframe. By using Keyframes, similar point clouds are not saved unnecessarily, reducing the computational cost of searching for past locations and correcting trajectories.
First, the system searches for past keyframes within the range specified by `search_radius` from the current location as candidates for revisiting. Furthermore, it checks for differences in acquisition time, distance traveled so far, and orientation, and excludes the most recent data or data with clearly different orientations from the candidates. The remaining candidates are then treated with ICP. ICP is a process that finds the positional relationship where the two point clouds best overlap by slightly moving them. If ICP completes successfully and the fitness score, which indicates the magnitude of the misalignment between the two point clouds, is smaller than the set value, that candidate is adopted as information (loop constraint) to be used for map correction. A smaller fitness score indicates that the point clouds overlap well.
Simple Loop Closure receives location information and point cloud data estimated by FAST-LIO-ROS2 and searches for historical data close to the current location.
The current and past point clouds are overlaid using ICP, and the results that meet the conditions are added to GTSAM. GTSAM then uses this information to correct for any deviations in the entire movement trajectory up to that point.
Please change the actual directory name to match your environment.
cd ~/FAST_LIO_ROS2/src
git clone --branch ros2 --recursive https://github.com/ashBabu/simple_loop_closure.git
cd ..
rosdep install --from-paths src --ignore-src -y
Modified the simple_loop_closure code for connecting to FAST-LIO-ROS2.
The publicly available ROS2 branch is a general-purpose configuration that can connect to various LiDAR odometry systems. This time, we will edit the source code to match the topic names and map saving methods of FAST-LIO-ROS2. The following modifications will not only add functionality but also prevent runtime issues such as the handling of distance units, calculations that lead to out-of-bounds references in arrays, and the handling of empty point clouds.
Edit the source code: simple_loop_closure_node.cpp to address the following:
Correction 1: Parameterized to allow connection to FAST-LIO topics.
Originally, the input topics were fixed to /cloud and /odometry.
The revised version declares `cloud_topic` and `odom_topic` as ROS2 parameters, allowing you to specify `/cloud_registered` and `/Odometry` from YAML.
Correction 2: Corrected the confusion in units between the KD-tree search radius and the ICP maximum correspondence distance.
Originally, the search radius, which was set to 15.0, was squared during initialization to change it to 225. This value was used not only for KD-tree searches that require a squared value, but also for ICP, which specifies the normal distance, resulting in a maximum supported distance of 225 × 2 = 450 m for ICP.
In the revised version, search_radius_ is saved as 15 m, and the squared value of 15 m is used only when searching for candidates in the KD-tree. The maximum range of ICP is 15 × 2 = 30 m in the current code.
The KD-tree, used to quickly find nearby past keyframes, uses the square of the search radius, so we pass a value of 15 m × 15 m. On the other hand, the maximum correspondence distance of 30 m for ICP is the value used in this evaluation. Depending on the environment, there is a possibility of incorrectly mapping distant points, so please adjust while checking the overlap of point clouds and Loop Edges on RViz.
Correction 3: Fixed the size_t underflow during target cloud generation.
Originally, the C++ `size_t` type, which cannot handle negative values, was used directly to calculate the starting number for reading past data. For example, if `target_id=7` and `target_frame_num_=50`, the calculation result is -43. However, since `size_t` cannot handle -43, it was converted to a very large positive number, and the past point cloud could not be collected correctly.
The revised version verifies that `target_id` is a valid value before converting it to `size_t`. It also restricts the start position to never be less than 0 and the end position to never exceed the last saved keyframe. If the number of points in the point cloud and the number of corrected poses differ, the smaller number will be used as the valid count.
Correction 4: Do not pass empty source or target point clouds to ICP.
Originally, even if the current point cloud (source cloud) or historical point cloud (target cloud) was empty, it was still passed to ICP. As a result, if the historical point cloud could not be created, errors such as "Invalid or empty point cloud dataset given!" or "No input target dataset was given!" occurred.
The revised version checks at the beginning of tryRegistration() whether the point cloud exists and whether it contains at least one point. If the point cloud is invalid, it does not execute ICP and returns false to indicate processing failure.
Correction 5: Save only map.pcd using /save_req
Originally, saveThread() called saveEachFrames() to save poses.csv and frames/*.pcd, and then saved map.pcd.
The revised version only removes the call to saveEachFrames(). Since the constructPointCloudMap() and map.pcd saving processes remain unchanged, the map generation method that repositions all keyframes with the latest optimized poses is maintained.
You can download the corrected code (simple_loop_closure_node.cpp) from here.
Launch file to start FAST-LIO-ROS2 and Loop Closure simultaneously
This document describes how to create a launch file (mapping_lc.launch.py) that starts FAST_LIO_ROS2 and simple_loop_closure simultaneously. While it's possible to start FAST-LIO-ROS2 and Simple Loop Closure from separate terminals, this document combines them into a single launch file to reduce the chance of errors in specifying the startup order or configuration files. This allows both nodes to be started while sourcing the same workspace, and the RViz settings can be unified to display the evaluation output.
After startup, verify that the fast_lio and simple_loop_closure nodes exist using "ros2 node list", and confirm that input is continuing using "ros2 topic hz /cloud_registered" and "ros2 topic hz /Odometry". If /pgo_map_cloud, /pgo_odom, and /vis_pose_graph are output, the data has been passed to Loop Closure.
from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from launch.substitutions import PathJoinSubstitution
def generate_launch_description():
custom_rviz = PathJoinSubstitution([
FindPackageShare('fast_lio'),
'rviz',
'fastlio_lc.rviz'
])
return LaunchDescription([
ExecuteProcess(
cmd=['ros2', 'launch', 'fast_lio', 'mapping.launch.py',
['rviz_cfg:=', custom_rviz]
],
output='screen'
),
ExecuteProcess(
cmd=['ros2', 'launch', 'simple_loop_closure', 'simple_loop_closure.launch.py'],
output='screen'
),
])
Building and starting a ROS2 workspace
After editing the code, rebuild the entire workspace, including the changed packages. Since previous build results may prevent changes from being reflected, if there are compilation errors or behavioral inconsistencies, delete the build, install, and log directories before rebuilding. Always source the latest install/setup.bash in the startup terminal.
After compilation, start FAST-LIO-ROS2 and Loop Closure.
cd ~/FAST_LIO_ROS2
colcon build --symlink-install
source ./install/setup.bash
ros2 launch fast_lio mapping_lc.launch.py
Save the 3D point cloud map after loop closure correction as map.pcd.
When you send the destination folder to /save_req, Simple Loop Closure retrieves the corrected position and orientation of each keyframe at that point. It moves the point cloud of each keyframe to its corrected position and combines them into a single point cloud to create map.pcd. Therefore, map.pcd is not a direct save of the point cloud accumulated in real time by FAST-LIO-ROS2, but a map recreated using the corrected trajectory by Loop Closure.
After data acquisition and processing are complete, with mapping_lc.launch.py running, execute the following in a separate terminal to save the point cloud map in PCD format. The save request should be executed after rosbag playback or actual vehicle operation is complete and the final Loop Closure process and Pose Graph Optimization are finished. To avoid the possibility of the file being written being incomplete if the node is terminated immediately after saving, wait until "Save completed." is displayed in the terminal and map.pcd has been generated before terminating.
cd ~/FAST_LIO_ROS2
source ./install/setup.bash
ros2 topic pub /save_req std_msgs/msg/String "{data: /home/xxxx/FAST_LIO_ROS2/src/simple_loop_closure/PCD}" --once
Save directory: /home/xxxx/FAST_LIO_ROS2/src/simple_loop_closure/PCD
The map.pcd file will be saved in the specified directory.
*Please create the specified directory in advance.
Main settings and adjustment points for simple_loop_closure
The following are example settings used in this evaluation environment. The optimal values will vary depending on the driving speed, the size of the environment, the density of the point cloud, and the positional shift when returning to the starting point. When making adjustments, first check that the timestamps of the point cloud and the position information are synchronized, and then check that the keyframes are saved correctly. After that, checking in the following order—searching for candidate past locations, overlaying the point cloud using ICP, and displaying RViz—will make it easier to isolate the cause of the problem.
`fitness_score_th` determines whether the results of ICP overlay are used for map correction. A smaller value makes the judgment stricter, making it less likely to adopt incorrect responses, but it also makes it easier to miss correct revisits. A larger value makes it easier to detect revisits, but it may mistakenly identify different locations with similar shapes as the same location. Do not rely solely on the "Loop Detected" log; check the lines indicating loops on RViz together with the corrected map.
The following are the values set in the YAML file for this evaluation. They differ slightly from the default values in the C++ source code.
| category | parameters | Set value | unit | Content |
|---|---|---|---|---|
| Inputs | cloud_topic | /cloud_registered | Topic name | Registered point clouds are input from FAST-LIO. Use sensor_msgs/msg/PointCloud2. |
| Inputs | odom_topic | /Odometry | Topic name | Odometry input from FAST-LIO. Uses nav_msgs/msg/Odometry. Case-sensitive. |
| Inputs | mapped_cloud | true | Boolean | This indicates that the input point cloud has already been converted to map coordinates. Set to true to use /cloud_registered. |
| synchronization | time_stamp_tolerance | 0.01 | s | This is the acceptable time difference when combining point cloud data and positional data as data from the same time. 0.01 seconds is equal to 10 ms. |
| Keyframe | keyframe_dist_th | 0.5 | m | If the movement is more than 0.5 m from the previous keyframe, it will be saved as a new keyframe. |
| Keyframe | keyframe_angular_dist_th | 0.3 | rad | If the rotation is more than approximately 17.2° from the previous keyframe, save it as a new keyframe. |
| Loop Candidate Search | loop_search_time_diff_th | 30.0 | s | Only keyframes saved more than 30 seconds ago will be considered as potential revisit locations. This prevents incorrectly identifying the most recent data as a revisited location. |
| Loop Candidate Search | loop_search_dist_diff_th | 30.0 | m | Only keyframes where the difference in distance traveled so far exceeds 30 meters will be considered for revisiting. This is not based on the straight-line distance from the current location. |
| Loop Candidate Search | loop_search_angular_dist_th | 3.1415 | rad | This is the upper limit of the acceptable difference between the current and past orientations. Since it's set to approximately 180°, it allows for revisits from almost any direction to be considered. |
| Loop Candidate Search | loop_search_frame_interval | 1 | Keyframe | This is the interval for searching for potential return visits. In the implementation, it is set to interval + 1, so with this setting, a search will be performed every 2 keyframes. |
| ICP | search_radius | 15.0 | m | `search_radius` is used as the candidate search radius. It is recommended to parameterize the maximum ICP distance separately; in the current code, it is `search_radius × 2`. |
| ICP | target_frame_num | 50 | Keyframe | The target cloud is constructed using a maximum of 101 keyframes, excluding those outside the loop's boundaries, by combining 50 keyframes before and after the loop candidate keyframe. Near the boundary, its effectiveness is limited to the area within its valid range. |
| ICP | target_voxel_leaf_size | 0.4 | m | This is the interval used to thin out the past point cloud data for comparison with ICP. Increasing the value reduces the number of points and lightens the processing load, but it also causes the loss of fine details in the shape. |
| ICP | source_voxel_leaf_size | 0.4 | m | This is the interval used to thin the current point cloud for comparison using ICP. `source cloud` is the current Keyframe point cloud. |
| ICP judgment | fitness_score_th | 0.4 | Evaluation value | This is the upper limit for adopting the results of the ICP (Intermediate Processing Control) overlay. The result will be adopted only if the ICP completes successfully and the score is less than 0.4. A smaller value indicates a stricter judgment. |
| RViz display | vis_map_voxel_leaf_size | 0.8 | m | This is the interval used to thin out the point cloud displayed in RViz. It is not used in the saved map.pcd file, but is used to lighten the load on the screen. |
| RViz display | vis_map_cloud_frame_interval | 3 | Keyframe | This setting determines the interval between keyframes used when creating the point cloud for RViz display. This setting uses one keyframe every four keyframes to reduce the processing load. |
Please adjust the above parameters depending on your environment.
Comparing 3D point cloud maps before and after applying Loop Closure.
In the evaluation, we compared maps saved before and after applying Loop Closure to the same driving data. During the comparison, we aligned the viewpoint, point size, and display range on CloudCompare to check for overlapping of continuous structures such as walls and floors.
Before applying Loop Closure
After applying Loop Closure
Before applying Loop Closure, the same horizontal structure is displayed separated vertically due to attitude errors accumulated during travel. After applying Loop Closure, constraints obtained from revisited points are reflected throughout the entire trajectory, suppressing the duplication of horizontal sections. This is not the result of moving only a portion of the point cloud, but rather the effect of reconstructing the entire map using the optimized attitude of each keyframe.
Summary: Create a 3D point cloud map with reduced drift using MID-360S
In this configuration, FAST-LIO-ROS2 uses LiDAR and IMU to estimate the current position and map in real time, while Simple Loop Closure uses information about previously traveled locations to correct for deviations accumulated over long-distance travel. By dividing the roles, position estimation can be continued during travel, and a point cloud map with the deviation corrected can be saved after the travel is complete.
However, adding Loop Closure does not guarantee a correct map. If the point cloud input to FAST-LIO-ROS2 does not match the IMU's timestamp, or if the LiDAR and IMU's mounting position and orientation settings are significantly different, the system may fail to find the correct revisited location and treat a different place as the same location. It is important to first confirm that FAST-LIO-ROS2 alone can reliably create a map, and then adjust the Loop Closure's candidate search conditions and ICP judgment values.
By combining Livox MID-360S with FAST-LIO-ROS2, it is possible to build high-speed 3D self-localization and point cloud map generation using LiDAR and IMU on ROS2.
Adding Simple Loop Closure further optimizes the Pose Graph using revisit information from when you return to the starting point, distributing the cumulative error across the entire map.
When implementing the algorithm, it's crucial to verify the consistency of the point cloud data with the IMU's time, topic type, external parameters, and FRAMES before adjusting the algorithm's parameters.
Furthermore, by using the same rosbag and adjusting each candidate search and ICP determination one by one, it becomes easier to isolate the cause.
- FAST-LIO-ROS2: Real-time LiDAR/IMU odometry and local map generation
- Simple Loop Closure: Finds previously traveled locations and corrects map discrepancies accumulated during travel.
- rosbag2: Compare settings by repeatedly using the same driving data.
- map.pcd: Final 3D point cloud map after correction by Loop Closure
Related Info
- FAST-LIO-ROS2
- Simple Loop Closure ROS2 branch
- Livox-SDK2
- livox_ros_driver2
- Livox MID-360S Product Information
- How to use the 3D-LiDAR MID-360 built-in IMU with ROS2
- Creating a 3D map using 3D-LiDAR (Livox: MID-360) "Implementation of FAST-LIO"
- Self-location estimation and movement trajectory acquisition using 3D-LiDAR (Livox: MID-360)
Disclaimer
Please adhere to the licenses, copyright notices, and terms of use for each open-source software.
We use AI generation to assist with some of the code creation. The code provided has been tested on actual devices, but please check the content and thoroughly verify it according to your environment.
Please refer to this disclaimer before using this column.
Inquiry
Link to Related Technical Columns
Materials
- simple_loop_closure_node.cpp


![Making your own CABLES for the Livox MID-360 [Practical Guide]](/uploads/media_files/livox_10_thumbnail-3954867486.jpg)



