Cartographer-SLAM mapping

Cartographer-SLAM mapping1. Course Content2. Introduction to Cartographer2.1 Introduction2.2 Related Materials3. Preparation3.1 Content Description3.2 Starting the Agent4. Run the case4.1 Mapping Process4.2 Save the map4.3 Saving pbstream format maps5. Node parsing5.1 Displaying the Node Computation Graph5.2 TF Transformation5.3 Cartographer Node Details

 

1. Course Content

  1. Learn the robot cartographer mapping algorithm for SLAM mapping function

    After running the sample program, use the keyboard or handle to control the robot to move and complete the map construction and save the map.

2. Introduction to Cartographer

2.1 Introduction

Cartographer is an open-source 2D and 3D SLAM (simultaneous localization and mapping) library from Google, supported by the ROS system. This mapping algorithm utilizes graph optimizations (multi-threaded backend optimization and problem optimization built using Cere). It combines data from multiple sensors (such as LIDAR, IMU, and cameras) to simultaneously calculate sensor positions and map the surrounding environment.

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

image-20230420170956628

Cartographer uses the mainstream SLAM framework, which consists of a three-step process of feature extraction, loop closure detection, and backend optimization. A certain number of LaserScans form a submap, and a series of submaps form the global map. While the short-term cumulative error of constructing submaps using LaserScans is small, the long-term cumulative error of constructing a global map using submaps is significant. Therefore, loop closure detection is required to correct the positions of these submaps. The basic unit of loop closure detection is the submap, which uses the scan_match strategy. Cartographer focuses on creating submaps that fuse multi-sensor data (odometry, IMU, LaserScan, etc.) and implementing the scan_match strategy for loop closure 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 a message to facilitate debugging and visualization.

2.2 Related Materials

GitHub repository

Official Documentation

3. Preparation

3.1 Content Description

This lesson uses the Jetson Orin NX as an example. For Raspberry Pi and Jetson Nano boards, you need to open a terminal and enter the command to enter the Docker container. Once inside the Docker container, enter the commands mentioned in this lesson in the terminal. For instructions on entering the Docker container, refer to the product tutorial [Configuration and Operation Guide]--[Enter the Docker (Jetson Nano and Raspberry Pi 5 users, see here)]. For Orin and NX boards, simply open a terminal and enter the commands mentioned in this lesson.

3.2 Starting the Agent

Note: To test all cases, you must start the docker agent first. If it has already been started, you do not need to start it again.

Enter the command in the vehicle terminal:

The terminal prints the following information, indicating that the connection is successful

image-20250613104101795

4. Run the case

4.1 Mapping Process

Notice:

The vehicle terminal starts the underlying sensor command:

Restart the mapping command:

The rviz visualization function can be started on the vehicle side or the virtual machine side. You can choose either method to start it. It is forbidden to start it on the virtual machine side and the vehicle side repeatedly:

Taking the configuration of a virtual machine as an example, open a terminal and start the rviz visualization interface:

Start the rviz visualization interface command on the vehicle:

image-20250613105853967

Open another terminal in the virtual machine to start the keyboard control node (you can also use the handle remote control):

image-20250613105933290

Click the window in the terminal with the mouse, press z to reduce the speed appropriately, press I, <, J, L to control the car to move forward, backward, turn left, and turn right respectively, and control the car to move slowly to complete the map building

image-20250613110228449

4.2 Save the map

Open a new terminal on the car and save the map

The terminal prompts "Map saved successfully" to indicate that the map has been saved successfully.

image-20250613152219166

The map save path is as follows:

jetson orin nano, jetson orin NX :

Jetson Orin Nano, Raspberry Pi :

You need to enter docker first

A pgm image, a yaml file yahboom_map.yaml

Parameter analysis:

4.3 Saving pbstream format maps

Map files in pbstream format are used for repositioning navigation, which will be explained in subsequent chapters.

After the map is built, open a new terminal and enter the command to end the map track:

Then open another terminal to save the pbstream format map file:

Save command on jetson orin nano and jetson orin NX s:

Save the command on Jetson Orin Nano and Raspberry Pi :

You need to enter docker first

5. Node parsing

5.1 Displaying the Node Computation Graph

image-20250613110905491

5.2 TF Transformation

The virtual machine terminal runs:

The image size is too large. The original image can be viewed in the folder of this course.

11

5.3 Cartographer Node Details

Enter the above command in the terminal to view the subscription and publishing topics related to the gmapping node.