8. karto mapping algorithm

karto: http://wiki.ros.org/slam_karto

map_server: https://wiki.ros.org/map_server

8.1. Introduction

Karto is a 2D laser SLAM solution based on a sparse graph optimization method with loop closure detection. The graph optimization method uses the mean value of the graph to represent the map. Each node represents a position point of the robot trajectory and a sensor measurement data set. Each new node is added and the calculation is updated. Karto uses spa (karto_slam) or g2o (nav2d) optimization library, and the front-end and back-end use a single thread.

The ROS version of Karto_SLAM, in which the Spare Pose Adjustment (SPA) used is related to scan matching and loop closure detection. The more landmarks there are, the greater the memory requirements. However, compared with other methods, the graph optimization method has greater advantages in mapping in large environments because it only contains point graphs (robot poses), and the map is obtained after the pose is obtained.

overall program framework

img

8.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

Open the [.bashrc] file

Find the [ROBOT_TYPE] parameters and modify the corresponding car model

Note: Due to the difference in radar laser data between 4ROS radar and A1 radar, you need to modify the karto source code part before it can run normally and modify the file.

Locate line 4165, the source code is,

Need to be changed to,

After saving, switch to the ~/software/library_ws directory and use catkin_make to compile.

8.2.1. Start

Start the command (robot side). For the convenience of operation, this section takes [mono + laser + yahboomcar] as an example.

Mapping command (robot side)

<PI5 needs to open another terminal to enter the same docker container

image-20240408144126098

Turn on the visual interface (virtual machine side)

image-20220224150211979

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].

8.2.1. Controlling the robot

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.

8.2.1. Map saving

The map will be saved to the ~/yahboomcar_ws/src/yahboomcar_nav/maps/ folder, a pgm image and a yaml file.

map.yaml

Parameter analysis:

8.3. Topics and services

Topic SubscriptionTypeDescription
scansensor_msgs/LaserScanDepth data of lidar scan
tftf/tfMessageUsed for conversion between lidar coordinate system, base coordinate system, and odometer coordinate system
Topic PostTypeDescription
map_metadatanav_msgs/MapMetaDataPublish map Meta data
mapnav_msgs/OccupancyGridPublish map raster data
visualization_marker_arrayvisualization_msgs/MarkerArrayPublish pose diagram
ServiceTypeDescription
dynamic_mapnav_msgs/GetMapGet map data

Node view

image-20220224150211979

8.4. Configuration parameters

ParametersTypeDefault valueDescription
~base_framestring"base_link"Robot base coordinate system
~map_framestring"map"Map coordinate system
~odom_framestring"odom"Odometer coordinate system
~throttle_scansint1Process 1 per this many scans (set this to a higher number to skip more scans)
~map_update_intervalfloat5.0The time in seconds between map updates. Lowering this number will update the occupancy grid more frequently, but will increase the computational load.
~resolutionfloat0.05Map resolution (meters per occupied grid block)
~deltafloat0.05Map resolution (meters per occupied grid block). Same as resolution. Defined for compatibility with gmapping parameter names.
~transform_publish_periodfloat0.05The time in seconds between transform publications.
use_scan_matchingbooltrueWhether to use the scan matching algorithm, generally set to true, the mapper algorithm can correct the noise and errors of the odometer and laser. In some simulation environments with accurate sensor data, the scan matching algorithm will achieve worse results (because the use of Gaussian blur reduces the observation confidence of high-precision sensors), and it is recommended to turn it off (just add noise to the simulation environment).
use_scan_barycenterbooltrueDefines the distance between scans using the centroid of the scan endpoints.
minimum_travel_distancedouble0.2Set the minimum travel between scans.
minimum_travel_headingdoubledeg2rad(10)=0.087266461Set the minimum angle between scans.
scan_buffer_sizeint70Set the length of ScanBuffer, approximately equal to scan_buffer_maximum_scan_distance/minimum_travel_distance
scan_buffer_maximum_scan_distancedouble20.0Setting the maximum length of ScanBuffer is similar to Size
link_match_minimum_response_finedouble0.8Set the minimum response threshold for the minimum scans connection
link_scan_minimum_distancedouble10.0Set the maximum distance between scans of two connections. If it is greater than this value, the response threshold of the two will not be considered
loop_search_maximum_distancedouble4.0Maximum distance for loop detection. Scans less than this distance from the current position will be considered matching loop closures.
do_loop_closingbooltrueWhether to enable loop closing detection
loop_match_minimum_chain_sizeint10The lowest chain size for loop detection
loop_match_maximum_variance_coarsedoublemath::Square(0.4)=0.16The maximum covariance value of coarse matching during loop matching. If it is less than this value, it is considered a feasible solution
loop_match_minimum_response_coarsedouble0.8The minimum response for coarse matching during loop matching. A response value greater than this value will start coarse precision loop optimization
loop_match_minimum_response_finedouble0.8The minimum response threshold for loop matching. High accuracy will only start when it is greater than this value
ParametersTypeDefault valueDescription
correlation_search_space_dimensiondouble0.3Set the search range size of Correlation Grid
correlation_search_space_resolutiondouble0.01Set the resolution of the Correlation Grid
correlation_search_space_smear_deviationdouble0.03Set the Correlation Grid blur level
ParametersTypeDefault valueDescription
loop_search_space_dimensiondouble8.0Loop detection space range size
loop_search_space_resolutiondouble0.05Loop detection spatial resolution
loop_search_space_smear_deviationdouble0.03Loop detection blur level
ParametersTypeDefault valueDescription
distance_variance_penaltydoublesqrt(0.3)=0.09 (less than 1.0)Compensation coefficient for odometer during scan-matching
angle_variance_penaltydoublesqrt(deg2rad(20))=0.17453292Compensation coefficient for angle during scan-matching
fine_search_angle_offsetdoubledeg2rad(0.2)=0.0017453292Fine search angle range
coarse_search_angle_offsetdoubledeg2rad(20)=0.17453292Coarse search angle range
coarse_angle_resolutiondoubledeg2rad(2)=0.017453292Coarse search angle resolution
minimum_angle_penaltydouble0.9minimum angle penalty
minimum_distance_penaltydouble0.5Minimum distance penalty
use_response_expansionboolfalseWhether to increase the search scope if no good matches are found

8.5, TF transformation

Required TF transformationDescription
laser-->base_linkUsually a fixed value, the transformation between the lidar coordinate system and the base coordinate system, generally published by robot_state_publisher or static_transform_publisher
base_link-->odomTransformation between the map coordinate system and the robot odometer coordinate system, estimating the robot's pose in the map
Published by TF TransformDescription
map-->odomThe current estimate of the robot pose within the map frame (only provided if parameter "pub_map_odom_transform" is true).

View tf tree

image-20220224150211979