Welcome to ROSMASTER R2 repository
11.6 gmapping mapping
6. gmapping mapping algorithm
6. gmapping mapping algorithm6.1. Introduction6.2. Use6.2.1. Start6.2.2. Controlling the robot6.2.3. Map saving6.2. Topics and services6.3. Configuration parameters6.4, TF transformation
Gmapping: http://wiki.ros.org/gmapping/
map_server: https://wiki.ros.org/map_server
6.1. Introduction
gmapping is only applicable to points where the number of two-dimensional laser points in a single frame is less than 1440. If the number of laser points in a single frame is greater than 1440, then problems such as [[mapping-4] process has died] will occur.
Gmapping is a commonly used open source SLAM algorithm based on the filtered SLAM framework.
Gmapping is based on the RBpf particle filter algorithm, which separates the real-time positioning and mapping processes. Positioning is performed first and then mapping is performed.
Gmapping has made two major improvements on the RBpf algorithm: improved proposal distribution and selective resampling.
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 when building 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.

6.2. Use
Note: When building a map, the slower the speed, the better the effect (note that the rotation speed should be slower). If the speed is too fast, the effect will be poor.
According to different models, you only need to set the purchased model in [.bashrc], X1 (normal four-wheel drive) X3 (Mailun) Take X3 as an example
xxxxxxxxxx#Raspberry Pi 5 master needs to enter docker first, please perform this step#If running the script into docker fails, please refer to ROS/07, Docker tutorial~/run_docker.shOpen the [.bashrc] file
xxxxxxxxxxsudo vim .bashrc
Find the [ROBOT_TYPE] parameters and modify the corresponding car model
xxxxxxxxxxexport ROBOT_TYPE=X3 # ROBOT_TYPE: X1 X3 X3plus R2 X76.2.1. Start
Start the command (robot side). For the convenience of operation, this section takes [mono + laser + yahboomcar] as an example.
xxxxxxxxxxroslaunch yahboomcar_nav laser_bringup.launch # laser + yahboomcarroslaunch yahboomcar_nav laser_usb_bringup.launch # mono + laser + yahboomcarroslaunch yahboomcar_nav laser_astrapro_bringup.launch # Astra + laser + yahboomcar<PI5 needs to open another terminal to enter the same docker container

Mapping command (robot side)
xxxxxxxxxxroslaunch yahboomcar_nav yahboomcar_map.launch use_rviz:=false map_type:=gmapping[use_rviz] parameter: whether to enable rviz visualization.
[map_type] parameter: Set the mapping algorithm [gmapping].
Turn on the visual interface (virtual machine side)
xxxxxxxxxxroslaunch yahboomcar_nav view_map.launch

The gap at the back of the robot is due to the obstruction caused by the installation position of the display screen, so a certain range of radar data is blocked. The shielding range can be adjusted, or it can not be blocked according to the actual situation. For specific operations, see [01. Radar Basic Course].
6.2.2. Controlling the robot
Keyboard controls robot movement
xxxxxxxxxxrosrun teleop_twist_keyboard teleop_twist_keyboard.py # System integrationroslaunch yahboomcar_ctrl yahboom_keyboard.launch # CustomControl the robot movement with the handle
Make the robot cover the area to be mapped and the map should be as closed as possible.
There may be some scattered points during the mapping process. If the mapping environment is well closed, relatively regular, and the movement is slow, the scattering phenomenon will be much smaller.
6.2.3. Map saving
xxxxxxxxxxrosrun map_server map_saver -f ~/yahboomcar_ws/src/yahboomcar_nav/maps/my_map # The first waybash ~/yahboomcar_ws/src/yahboomcar_nav/maps/map.sh # The second wayThe map will be saved to the ~/yahboomcar_ws/src/yahboomcar_nav/maps/ folder, a pgm image and a yaml file.
map.yaml
xxxxxxxxxx