Gmapping mapping

Note: The virtual machine needs to be in the same LAN as the car, and the ROS_DOMAIN_ID needs to be consistent. You can check [Must read before use] to set the IP and ROS_DOMAIN_ID on the board.

1. Introduction to Gmapping

Advantages: Gmapping can construct indoor maps in real time. The amount of calculation required to construct small scene maps is small and the accuracy is high.

Disadvantages: As the scene grows, the number of particles required increases because each particle carries a map, so the amount of memory and computation required to build a large map increases. 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 close the map, it comes at the expense of increased calculations and memory.

 

2. Program function description

Connect the car to the agent and run the program. The mapping interface will be displayed in rviz. Use the keyboard or handle to control the movement of the car until the map is completed. Then run the save map command to save the map.

3. Start and connect to the agent

Taking the supporting virtual machine as an example, enter the following command to start the agent:

image-20240102115728128

Then, turn on the car switch and wait for the car to connect to the agent. The connection is successful, as shown in the figure below.

image-20231218200627187

4. Start the program

First, start the car to process the underlying data program and enter the terminal.

image-20231218200808169

Then, start rviz, visualize the mapping, and enter in the terminal.

image-20231218201237939

The mapping node has not been run yet, so there is no data. Next, run the mapping node and enter in the terminal,

image-20231219105808064

Then run handle control or keyboard control, choose one of the two, terminal input,

Then control the car and slowly walk through the area that needs to be mapped. After the map is completed, enter the following command to save the map and enter it in the terminal.

image-20231219110003776

A map named yahboom_map will be saved. This map is saved in.

Two files will be generated, one is yahboom_map.pgm and the other is yahboom_map.yaml. Take a look at the content of yaml.

5. View the node communication diagram

Terminal input,

image-20231219110115764

If it is not displayed at first, select [Nodes/Topics(all)], and then click the refresh button in the upper left corner.

6. View TF tree

Terminal input,

image-20231219110255739

After the operation is completed, two files will be generated in the terminal directory, namely .gv and .pdf files. The pdf file is the TF tree.

image-20231219110353087

7. Code analysis

Here we only describe map_gmapping_launch.py for mapping. The file path is as follows

map_gmapping_launch.py

A launch file-slam_gmapping_launch and a node for publishing static transformation-base_link_to_laser_tf_node are started here. Take a detailed look at slam_gmapping_launch, the file is as follows

slam_gmapping.launch.py,

The slam_gmapping node is started here, and the slam_gmapping.yaml parameter file is loaded. The file is located (taking the supporting virtual machine as an example),

slam_gmapping.yaml