Welcome to RDK X3 Robot repository
6. gmapping algorithm
6. gmapping graph building algorithm
6. gmapping graph building algorithm6.1 Program function description6.2. Introduction to Gmapping6.3 Program code reference path6.4. Program Startup6.4.1. Build the diagram6.4.2. Map saving6.4.3. View the topic communication node graph6.4.4 View the TF tree
6.1 Program function description
After the programs on the virtual machine and the car are started, the car is controlled by the handle or keyboard. The car uses the lidar scanning data during the moving process, uses gmapping algorithm to build a map, and saves the map after construction. This process is visualized in rviz.
6.2. Introduction to Gmapping
wiki:http://wiki.ros.org/gmapping/
ros2 gmapping:https://github.com/Project-MANAS/slam_gmapping
- Gmapping is only applicable to the point where the number of 2D laser dots in a single frame is less than 1440. If the number of 2D laser dots in a single frame is greater than 1440, the [[mapping-4] process has died] problem will occur.
- Gmapping is based on the RBpf particle filter algorithm. The real-time positioning process is separated from the mapping process. Gmapping makes two major improvements to the RBpf algorithm: improved proposal distribution and selective resampling.
Advantages: Gmapping can build indoor maps in real time, and the calculation required for building small-scene maps is small and the precision is high.
Disadvantages: The number of particles required increases as the scene grows, because each particle carries a map, so the memory and computation required to build a large map increase. Therefore, it is not suitable for building large scene maps. And there is no loop detection, so the map may be misaligned when the loop is closed, although increasing the number of particles can make the map closed, but at the cost of increasing the amount of computation and memory.

6.3 Program code reference path
After SSH connection car, the location of the function source code is located at,
/userdata/yahboomcar_ws/src/yahboomcar_nav/launch/map_gmapping_launch.py
The virtual machine side source code is located at,
xxxxxxxxxx/home/yahboom/dev_ws/src/yahboomcar_rviz/launch/yahboomcar_mapping_launch.py
6.4. Program Startup
6.4.1. Build the diagram
Open the virtual machine terminal and type,
xxxxxxxxxxros2 launch yahboomcar_rviz yahboomcar_mapping_launch.pyAfter SSH connects to the car, terminal input,
xxxxxxxxxxros2 launch yahboomcar_nav map_gmapping_launch.py
Handle [L1] key unlock, control car movement. If you do not use the handle, you can use the keyboard control, the car terminal input,
xxxxxxxxxxros2 run yahboomcar_ctrl yahboom_keyboard
【 Slowly move the cart 】 Start to build the map until the complete map is built.

Note: When building the diagram, the slower the better the effect (especially the rotation speed should be slower), the faster the speed, the effect will be poor.
In addition, the paths of gmapping parameters are,
xxxxxxxxxx/userdata/software/slam_ws/src/slam_gmapping/params/slam_gmapping.yaml
You can modify it according to your needs, compile and run it.
6.4.2. Map saving
Car terminal input,
xxxxxxxxxxros2 launch yahboomcar_nav save_map_launch.py
Map saving path is as follows:,
xxxxxxxxxx/userdata/yahboomcar_ws/src/yahboomcar_nav/maps

Includes a.pGM image and a.YAML file. The.yaml file contains the following contents:
xxxxxxxxxximage/userdata/yahboomcar_ws/src/yahboomcar_nav/maps/yahboom_map.pgmmodetrinaryresolution0.05origin-5.95 -3.26 0negate0occupied_thresh0.65free_thresh0.25Parameter analysis:
- image: indicates the path of the map file. The path can be absolute or relative
- mode: This property can be one of trinary, scale, or raw, depending on the mode selected. trinary is the default mode
- resolution: Map resolution in meters per pixel
- origin: 2D pose (x,y,yaw) in the lower left corner of the map, where yaw is rotated counterclockwise (yaw=0 indicates no rotation). yaw values are currently ignored in many parts of the system.
- negate: Whether to reverse the meanings of white/black, free/occupied (the interpretation of the threshold is not affected)
- occupied_thresh: The occupied_thresh pixel whose occupied_probability is greater than this threshold will be considered as fully occupied.
- free_thresh: Pixels whose occupancy probability is less than this threshold are considered completely free.
6.4.3. View the topic communication node graph
Virtual machine terminal input,
xxxxxxxxxxros2 run rqt_graph rqt_graph

To view gmapping node details, enter,
xxxxxxxxxxros2 node info /slam_gmapping
6.4.4 View the TF tree
Open the virtual machine terminal and type,
xxxxxxxxxx#保存tf树# Save tf treeros2 run tf2_tools view_frames.py#查看tf树# View tf treeevince frames.pdf