8.ROS2_Cartographer mapping algorithm1. Introduction2. Use2.1. Configuration before use2.2. Specific use3. Node analysis3.1. Display calculation graph3.2. Cartographer_node node details3.3. TF transformation
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. A graph-building algorithm based on graph optimization (multi-threaded backend optimization, problem optimization of ceiling construction). Data from multiple sensors (such as LIDAR, IMU, and cameras) can be combined to simultaneously calculate the sensor's position and map the environment around the sensor.
The source code of cartographer mainly includes three parts: cartographer, cartographer_ros and ceres-solver (back-end optimization).

Cartographer uses the mainstream SLAM framework, which is a three-stage structure of feature extraction, closed-loop detection, and back-end optimization. A certain number of LaserScans form a submap, and a series of submaps constitute the global map. The cumulative error in the short-term process of using LaserScan to construct a submap is not large, but the long-term process of using a submap to construct a global map will have a large cumulative error. Therefore, closed-loop detection is needed to correct the positions of these submaps. The basic unit of closed-loop detection is submap, closed-loop detection uses the scan_match strategy. The focus of cartographer is the creation of submap subgraphs that integrate multi-sensor data (odometry, IMU, LaserScan, etc.) and the implementation of the scan_match strategy for closed-loop detection.
cartographer_ros runs under ROS and can accept various sensor data in the form of ROS messages.
After processing, it is published in the form of a message for easy debugging and visualization.
Note: Since the Muto series robots are equipped with multiple lidar devices, the factory system has been configured with routines for multiple devices. However, since the product cannot be automatically recognized, the lidar model needs to be manually set.
After entering the container: Make the following modifications according to the lidar type:
root@ubuntu:/# cdroot@ubuntu:~# vim .bashrc
After the modification is completed, save and exit vim, and then execute:
xxxxxxxxxxroot@jetson-desktop:~# source .bashrc------------------------------------ROS_DOMAIN_ID: 26my_robot_type: Muto | my_lidar: a1------------------------------------root@jetson-desktop:~#
You can see the current modified lidar type.
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.
First, the port binding operation needs to be performed on the host machine [that is, Muto's pi]. The two devices of lidar and serial port are mainly used here;
Then check whether the lidar and serial device are in the port binding state: on the host machine [that is, Muto's pi] refer to the following command to execute the check. The successful binding is as follows:
If it shows that the lidar or serial device is not bound, you can plug and unplug the USB cable to check again.
Enter the docker container and execute the following launch file in a terminal:
xxxxxxxxxxros2 launch yahboomcar_nav map_cartographer_launch.py
xxxxxxxxxxros2 launch yahboomcar_nav display_map_launch.py

ros2 run yahboomcar_ctrl yahboom_keyboard# Orros2 run teleop_twist_keyboard teleop_twist_keyboard
xxxxxxxxxxros2 launch yahboomcar_nav save_map_launch.py
Save path is as follows:
xxxxxxxxxx/root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_nav/maps/
A pgm picture, a yaml file yahboomcar.yaml
xxxxxxxxxximage: /root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_nav/maps/yahboomcar.pgmmode: trinaryresolution: 0.05origin: [-10, -10, 0]negate: 0occupied_thresh: 0.65free_thresh: 0.25
Parameter analysis:
xxxxxxxxxxrqt_graph

xxxxxxxxxxros2 run tf2_tools view_frames.py
