Cartographer Mapping Algorithm

 

7.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 will use the radar scanning data during the movement, use the cartographer algorithm to build a map, and save the map after the construction is completed. This process is visualized in rviz.

7.2, Cartographer Introduction

Cartographer: https://google-cartographer.readthedocs.io/en/latest/

Cartographer ROS2: https://github.com/ros2/cartographer_ros

Cartographer is a 2D and 3D SLAM (simultaneous localization and mapping) library supported by Google's open source ROS system. The mapping algorithm is based on the method of graph optimization (multi-threaded backend optimization, problem optimization built by cere). It can combine data from multiple sensors (such as LIDAR, IMU and camera) to synchronously calculate the position of the sensor and draw the environment around the sensor.

The source code of cartographer mainly includes three parts: cartographer, cartographer_ros and ceres-solver (backend optimization).

cartographer adopts the mainstream SLAM framework, which is a three-stage feature extraction, closed-loop detection and backend optimization. A certain number of LaserScans form a submap, and a series of submaps constitute a global map. The short-term cumulative error of using LaserScan to construct submaps is not large, but the long-term process of using submaps to construct global maps will have a large cumulative error, so closed-loop detection is needed to correct the position of these submaps. The basic unit of closed-loop detection is submap, and closed-loop detection adopts scan_match strategy. The key content of cartographer is the creation of submaps that integrate multi-sensor data (odometry, IMU, LaserScan, etc.) and the implementation of scan_match strategy for closed-loop detection.

cartographer_ros runs under ROS and can receive various sensor data in the form of ROS messages. After processing, it is published in the form of messages for easy debugging and visualization.

7.3, Program code reference path

After SSH connects to the car, the location of the function source code is,

The source code of the virtual machine is located at,

7.4, Program startup

7.4.1, Map building

Open the virtual machine terminal and enter,

After SSH connects to the car, enter in the terminal,

image-20241113203120795

Unlock the [L1] button on the handle to control the car's movement. If you don't use the handle, you can use the keyboard to control the car's terminal input,

[Slowly move the car] to start building the map until the complete map is built.

image-20241113203317692

Note: When building the map, the slower the speed, the better the effect (especially the slower the rotation speed). If the speed is too fast, the effect will be very poor.

In addition, the path of cartographer related configuration parameters is,

You can modify it as needed, compile and run.

7.4.2, map saving

Input in the car terminal:

The map saving path is as follows:

1684831343375

Includes a .pgm picture and a .yaml file. Among them, the .yaml file content is as follows:

Parameter analysis:

7.4.3, view the topic communication node graph

Virtual machine terminal input,

1685092744116

7.4.4, view TF tree

Open the virtual machine terminal, input,

1685092942688