Welcome to ROSMASTER M3 repository
09.Lifelong mapping
Lifelong Mapping
Lifelong Mapping1. Course Content2. Function Introduction3. Start the Agent4. Build the Map4.1 Run the Mapping Node4.2 Save the Pose Map4.2.1 Method 1: Save via Command Line4.2.2 Method 2: Save via Panel4.3 Save the Grid Map5. Restore Mapping State5.1 Restore from the Mapping Origin5.2 Restore from Any Point on the Map5.3 Save Mapping Progress
1. Course Content
- Run the sample program to build a grid map and a pose graph format map, and then restore the previous mapping state using the pose graph to continue mapping.
2. Function Introduction
The Lifelong Mapping feature is accomplished using the slam_toolbox algorithm to build a pose graph. It is designed to support robots in continuously building, updating, and maintaining maps in long-term, dynamic environments. Its features include:
- Map Persistence and Reuse: Supports resuming mapping after an interruption by storing and reloading pose-graph data through serialization and deserialization.
- Incremental Map Updates: Continues to expand on an existing map, updating for environmental changes (such as new objects or temporary obstacles). This is very important for mapping large scenes like warehouses, as it avoids having to start from scratch every time the environment changes.
Application Scenarios
- In scenarios like warehouses and shopping malls, robots need to perform long-term patrol and transport tasks. Lifelong mapping can dynamically update the map to cope with changes like moved shelves and temporary obstacles, while retaining valid historical data to avoid re-mapping.
- When a robot needs to pause due to low battery or task interruption, it can resume mapping by loading the existing pose graph upon restart, without starting from scratch. For example, a campus inspection robot can complete a large-area map in different time segments.
3. Start the Agent
Note: If it is already running, you do not need to start it again.
Enter the command in the vehicle's terminal:
start_agent
The terminal will print the following information, indicating a successful connection:

4. Build the Map
4.1 Run the Mapping Node
- Launch the mapping command in the vehicle's terminal:
For Raspberry Pi 5 users, if the ROS container is not started, you need to start it first,
xxxxxxxxxxbringup_m3
Open a terminal inside the container,
xxxxxxxxxxexec_m3
(ORIN)
xxxxxxxxxxros2 launch m3_bringup slam_toolbox.launch.py
(RDK & PI5 boards) Run in separate steps, with visualization launched on the accompanying virtual machine Rosmaster-M3-Ubuntu22.04,
xxxxxxxxxx# On the virtual machinerviz2 -d /home/yahboom/yahboomM3_ws/user_ws/src/m3_bringup/rviz/slam_toolbox_rviz.rviz# On the host machineros2 launch m3_bringup slam_toolbox.launch.py gui:=False[!NOTE]
- You can use the shortcut command
slamto start mapping.

- To control the vehicle's movement, you can use either keyboard or joystick control. Here, we use keyboard control as an example:
xxxxxxxxxxkeyboard_control
Click on the terminal window with the mouse and press z to reduce the speed appropriately.
- Press
I,<,J,Lto control the car to move forward, backward, turn left, and turn right, respectively, and presskto stop. Control the car to move slowly to complete the mapping.

4.2 Save the Pose Map
4.2.1 Method 1: Save via Command Line
- Run the command in the terminal:
xxxxxxxxxxros2 launch m3_bringup save_map.launch.py map_type:=posegraph
[!NOTE]
Optional launch parameters:
map_name: The name of the pose map to be saved, default ismap.
- The terminal prompt
result=0indicates that the pose map was saved successfully.

4.2.2 Method 2: Save via Panel
- In the blank space after
Serialize Map, enter the path and name for the pose map to be saved, then clickSerialize Mapto serialize the map.

- The terminal will display the following message to indicate that the pose map has been saved.

4.3 Save the Grid Map
- Run the following command in the terminal to save the map:
xxxxxxxxxxros2 launch m3_bringup save_map.launch.py
The terminal prompt Map saved successfully indicates that the map was saved successfully.

The saved grid map and pose map are in the
~/mapdirectory on the system, where:map.dataandmap.posegraphare the pose map files.map.pgmandmap.yamlare the grid map files.

- Then press
Ctrl+Cto end the mapping.
5. Restore Mapping State
5.1 Restore from the Mapping Origin
- If the vehicle is at the original starting point of the mapping, restore the mapping state with the following command:
xxxxxxxxxxros2 launch m3_bringup slam_toolbox.launch.py pose_graph:=map
pose_graph:=mapis the name of the pose map being passed in.
- You can then continue building or updating the map from the previously built map state.

5.2 Restore from Any Point on the Map
- If the robot is at any position on the map, first start the mapping node:
xxxxxxxxxxros2 launch m3_bringup slam_toolbox.launch.py pose_graph:=map
- As you can see, if the robot is not at the map's origin, the laser point cloud and the map environment features will not match.

- First, use the
2D Pose Estimatetool to give an approximate pose on the map.

- In the left toolbar, click
Clear Measurement Queue, and the current pose data will be automatically filled in.

- Then, in the options bar next to
Deserialize Map, enter the path of the previously saved pose map (note: do not include the file extension). - Then click
Deserialize Mapto deserialize the map.

- The robot has restored its correct pose in the global map, and you can now continue building or updating the map from the previously built state.

5.3 Save Mapping Progress
- You can also save pose maps with different names at various stages of the mapping process, similar to game saves, to restore the mapping state from different points of progress.
