map-based localization.Modified from fast-lio2 and s-fast-lio
just to follow s-fast-lio,I won't go into further detail here.
cd ~/catkin_ws/src
git clone https://github.com/xz00/fast-lio2-map-based-localization.git
cd ../
catkin_make
source ~/catkin_ws/devel/setup.bash
Recommend fast-lio-sam to build a global map.This work utilizes loop detection and point cloud matching, and updates the optimized pose to the front-end, enabling the creation of a high-quality map in a wide range of scenes. Can be used to create global maps based on map localization. a large global map example:
Files that need to be modified is config/velodyne_re.yaml
edit this param: globalmap_dir: "/home/xz/Desktop/catkin_fastlio_slam/data/totalmap.pcd" # starts and ends with "/".
and you should also modify the lidar topic and imu topic.
roslaunch sfast_lio mapping_velodyne_relocalization.launch
rosbag play your-bag.bag
The rough initialization method is the same as LIO-SAM_based_relocalization,complete initialization matching of point clouds by specifying an initialization position and direction in rviz.
Sometimes rough initialization method may not be successful, so it is necessary to use accurate initialization method to do NDT Registration with a better initial value.
In order to provide a better matching initial value, I used a Python script to obtain keyboard input and continuously adjusted this matching initial value, ultimately successfully initializing it in the map. Providing accurate initial values can significantly increase the success rate of initialization.
Open a new terminal in the working directory and execute the following statement:
source devel/setup.bash
rosrun sfast_lio keyboard_catch_local.py
And then in this terminal you can press the corresponding button to adjust the matching initial value:(Here, I have only defined three degrees of freedom: x, y, and yaw. This applies to most initialization situations. If you feel it's not enough, I believe readers can easily make improvements according to the code)
| keyboard input | meaning |
|---|---|
| w | Moving forward |
| s | Moving backward |
| a | Moving left |
| d | Moving right |
| q | rotate left |
| e | rotate right |
| j | increase rototation resolution |
| w | reduce rototation resolution |
| i | increase distance resolution |
| k | reduce distance resolution |
| f | finish, start register |
When you think the matching initial value you adjusted is good enough, you can press “f“ to do NDT Registration.
adjust the matching initial value initialization successful
The green pointcloud is the pointcloud you are adjusting. The red pointcloud is the matched pointcloud after NDT Registration. The yellow pointcloud is the local map.
in the config/velodyne_re.yaml
- init_threshold: 0.15 . The initialization is considered successful only when the score of NDT Registration is lower than this value. You can modify this threshold according to the actual situation.
- ininit_resolution_rot: 1 . This is the resolution of rotation during initialization.You can modify this threshold according to the actual situation or press "j" "l" to dynamically modify this value. The unit of this value is angles.
- ininit_resolution_dis: 0.05 . This is the resolution of distance during initialization.You can modify this threshold according to the actual situation or press "i" "k" to dynamically modify this value. The unit of this value is meters.
note:this code can provide two kind of odometry.
- "/Odometry_relocal",this is just local scan register to local map,so when IMU is not very stable and may drift,this odometry may stable.
- "/Odometry",this is the result of loose coupling between IMU recursive results and point cloud matching results.
The principle is very easy.After the pose is initialized, based on the forward propagation of IMU, when the point cloud is generated, it is registered with the local map, and the results of IMU and point cloud registration are updated through Bayesian rule. You can change some local map's params in the config/velodyne_re.yaml.
5.1 upload the pcd and bag for reader to run an example.
here is an example link example PCD and bag
5.2 record a video to show this code how to use.
here is an old video to show example
you'd better to see this new video to know how to use rough initialization and accurate initialization to finish initialization in a more effective way: new vedio


