This repository demonstrates how to implement the Simultaneous Localization And Mapping (SLAM) algorithm using a series of lidar scans. The primary goal is to build an accurate map of an environment and retrieve the trajectory of a mobile robot.
This example showcases the implementation of the SLAM algorithm with pose graph optimization. The SLAM algorithm incrementally processes lidar scans to build a pose graph linking these scans. The robot recognizes previously-visited places through scan matching and establishes loop closures along its path. The SLAM algorithm uses loop closure information to update the map and adjust the estimated robot trajectory.
-
Clone the repository:
git clone https://github.com/yourusername/slam-lidar.git cd slam-lidar
-
Ensure you have MATLAB installed, as this example relies on MATLAB functions and data structures.
-
Load the provided dataset:
load('offlineSlamData.mat');
Load a down-sampled dataset consisting of laser scans collected from a mobile robot in an indoor environment. The dataset is stored in offlineSlamData.mat
and contains the scans
variable, which holds all the laser scans used in this example.
load('offlineSlamData.mat');
-
Create a
lidarSLAM
object and configure the parameters:maxLidarRange = 8; mapResolution = 20; slamAlg = lidarSLAM(mapResolution, maxLidarRange); slamAlg.LoopClosureThreshold = 210; slamAlg.LoopClosureSearchRadius = 8;
-
Incrementally add scans to the
slamAlg
object:for i = 1:10 [isScanAccepted, loopClosureInfo, optimizationInfo] = addScan(slamAlg, scans{i}); if isScanAccepted fprintf('Added scan %d \n', i); end end figure; show(slamAlg); title({'Map of the Environment', 'Pose Graph for Initial 10 Scans'});
-
Continue to add scans and observe the loop closure process:
firstTimeLCDetected = false; figure; for i = 10:length(scans) [isScanAccepted, loopClosureInfo, optimizationInfo] = addScan(slamAlg, scans{i}); if ~isScanAccepted continue; end if optimizationInfo.IsPerformed && ~firstTimeLCDetected show(slamAlg, 'Poses', 'off'); hold on; show(slamAlg.PoseGraph); hold off; firstTimeLCDetected = true; drawnow end end title('First loop closure');
-
Plot the final built map and the robot's trajectory:
figure; show(slamAlg); title({'Final Built Map of the Environment', 'Trajectory of the Robot'});
Generate an occupancy grid map representing the environment as a probabilistic occupancy grid:
[scans, optimizedPoses] = scansAndPoses(slamAlg);
map = buildMap(scans, optimizedPoses, mapResolution, maxLidarRange);
figure;
show(map);
hold on;
show(slamAlg.PoseGraph, 'IDs', 'off');
hold off;
title('Occupancy Grid Map Built Using Lidar SLAM');
This was created to compare every Lidar scan output and find pattern, for basic analysis. A video is created(in the all 71 plot video folder) for better analysis. Note that this is done because difference between 2 scans cannot be drastic and so, are comparable.
- Incremental SLAM with pose graph optimization
- Loop closure detection and map correction
- Visualization of the mapping process and trajectory
- Generation of an occupancy grid map
- Max Lidar Range: 8 meters (configurable)
- Map Resolution: 20 cells per meter (configurable)
- Loop Closure Threshold: 210 (configurable)
- Loop Closure Search Radius: 8 meters (configurable)
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Push your branch to your forked repository.
- Open a pull request to the main repository.
This project is licensed under the Apache-2.0 License. See the LICENSE
file for details.
For any questions or inquiries, please contact:
- Mail: [email protected]
- GitHub: ChiragMV
- MATLAB
- Research papers(present in the repository)
- https://www.researchgate.net/figure/Multi-line-LiDAR-based-SLAM-system-structure-diagram_fig1_369950490
- https://www.researchgate.net/figure/The-LiDAR-data-preprocessing-includes-three-parts-the-keyframe-selection-a-the_fig3_351731857
- https://ieeexplore.ieee.org/document/10137963
Thank you for using my SLAM with Lidar Scans project! I hope it helps you in your robotics and mapping endeavors.