Cartographer

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 [Expansion Board Parameter Configuration] to set the IP and ROS_DOMAIN_ID on the board.

1. Introduction to Cartographer

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 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 uses 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 form a global map. The short-term cumulative error of using LaserScan to build submaps is not large, but the long-term process of using submaps to build a global map 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 uses scan_match strategy.

The focus 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.

2. Program Function Description

The car connects to the agent and runs the program. The map building interface will be displayed in rviz. The handheld radar moves in parallel. This algorithm needs to move slowly until the map is built. Then run the command to save the map.

3. Start and connect the agent

If you use the factory virtual machine system, you can enter in the terminal:

If you use a third-party virtual machine system, you need to install the docker development environment first, and open the terminal and enter:

image-20240102115650129

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

image-20231218205657812

4. Start the program

4.1 Run the command

If it is the Raspberry Pi desktop version and the Jetson Nano desktop version, you need to enter docker in advance and enter the terminal.

When the following interface appears, it means that you have successfully entered docker.

image-20240229172040987

Then enter in docker separately, (see the [Enter the same docker terminal] section)

Take the matching virtual machine as an example, terminal input,

First, start the car to process the underlying data program

image-20241122170910810

Then, start rviz, visualize the map, and input in the terminal.

image-20241122172701856

At this time, the map node has not been run, so there is no data. Next, run the map node and input in the terminal,

image-20241122180743630

Then hold the handheld radar and walk slowly and parallelly through the area that needs to be mapped. After the map is built, enter the following command to save the map and input in the terminal,

image-20241122180930775

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

Take the matching virtual machine as an example code path:

Two files will be generated, one is yahboom_map.pgm and the other is yahboom_map.yaml. Check the contents of yaml.

The other file is a pdf file,

image-20241122181123318

5. View the node communication graph

Terminal input,

image-20241122181208096

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

6. View TF tree

Terminal input,

image-20241122181252517

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

image-20241122181312800

7. Code analysis

Take the virtual machine as an example, here only the map_cartographer_launch.py for building the map is explained, this file path is,

map_cartographer_launch.py

Here, a launch file - cartographer_launch and a node that publishes static transformations - base_link_to_laser_tf_node are run.

** Taking the virtual machine as an example, take a closer look at cartographer_launch.py, which is located at,**

cartographer_launch.py

Here we mainly run the cartographer_node map building node and occupancy_grid_launch.py, and load the parameter configuration file.

lds_2d.lua,