Welcome to ROSMASTER M3 repository
14.Synchronous mapping and navigation
Synchronous Mapping and Navigation
Synchronous Mapping and Navigation1. Course Content2. Scenario Introduction3. Start the Agent4. Run the Example4.1 Start the Mapping and Navigation Node4.2 Save the Map5. Source Code Analysis5.1 View TF Tree5.2 Launch File
1. Course Content
- Run the sample program to perform simultaneous mapping and navigation in an unknown environment without a pre-existing grid map.
2. Scenario Introduction
- Suitable for scenarios where long-term map storage is not required and the task only needs to be completed once. (After the task is completed, the map can be saved for future use with
map_saver_cli). - Suitable for when a robot first enters an unmodeled scene, autonomously building an environmental map by being given a target pose and completing a specified area traversal or reaching a target point.
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. Run the Example
4.1 Start the Mapping and Navigation Node
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 board)
xxxxxxxxxxros2 launch m3_bringup nav2.launch.py slam:=True
(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/nav2.rviz# On the host machineros2 launch m3_bringup nav2.launch.py slam:=True gui:=False[!TIP]
Launch Parameter Descriptions
slam
- Whether to start the simultaneous mapping and navigation mode, default is
False.

- Use the
Nav2 Goaltool to give a target pose, and the robot can perform navigation while building the map.


4.2 Save the Map
- The commands for saving the grid map and the pose map are the same as in the previous lessons and will not be repeated here.
- Save the grid map:
xxxxxxxxxxros2 launch m3_bringup save_map.launch.py
- Save the pose graph map in
posegraphformat:
xxxxxxxxxxros2 launch m3_bringup save_map.launch.py map_type:=posegraph
5. Source Code Analysis
5.1 View TF Tree
In the terminal, enter:
xxxxxxxxxxros2 run rqt_tf_tree rqt_tf_tree- Here, the TF transformation from the
mapcoordinate frame to theodomcoordinate frame is provided by slam_toolbox.

5.2 Launch File
- Launch file path:
xxxxxxxxxx~/yahboomM3_ws/user_ws/src/m3_bringup/launch/navigation/nav2.launch.py
- The key code snippet below starts the Navigation2 stack node and enables synchronous mapping mode, with the mapping function provided by the slam_toolbox algorithm.
xxxxxxxxxx # Navigate while building the map nav_and_slam = GroupAction( condition=IfCondition(PythonExpression(["'", localization_mode, "' == 'amcl' and '", slam, "' == 'True' "])), actions=[ # Navigation using AMCL positioning method PushRosNamespace(namespace=namespace), IncludeLaunchDescription( PythonLaunchDescriptionSource(nav2_launch_file), launch_arguments={ "map": map_dir, "use_sim_time":use_sim_time, "params_file": params_file, 'slam': 'True', }.items(), ), # Log Printing LogInfo( msg=[Fore.GREEN+'====================Robot-M3 Navigation_SLAM Start ====================',Fore.RESET] ) ] )
- If you need to configure the slam_toolbox algorithm parameters for synchronous mapping and navigation, the path is as follows:
xxxxxxxxxx~/yahboomM3_ws/user_ws/src/m3_bringup/config/navigation_config/M3_nav2_params.yaml
x########################################################################## SLAM parameter configuration for simultaneous mapping and navigation#########################################################################slam_toolbox ros__parameters # Plugin params solver_pluginsolver_pluginsCeresSolver ceres_linear_solverSPARSE_NORMAL_CHOLESKY ceres_preconditionerSCHUR_JACOBI ceres_trust_strategyLEVENBERG_MARQUARDT ceres_dogleg_typeTRADITIONAL_DOGLEG ceres_loss_functionNone # ROS Parameters odom_frameodom map_framemap base_framebase_footprint scan_topic/scan use_map_savertrue modemapping #localization debug_loggingfalse throttle_scans1 transform_publish_period0.02 #if 0 never publishes odometry map_update_interval5.0 resolution0.05 min_laser_range0.05 #for rastering images max_laser_range12.0 #for rastering images minimum_time_interval0.5 transform_timeout0.2 tf_buffer_duration30. stack_size_to_use40000000 #// program needs a larger stack size to serialize large maps enable_interactive_modetrue # General Parameters use_scan_matchingtrue use_scan_barycentertrue minimum_travel_distance0.5 minimum_travel_heading0.5 scan_buffer_size10 scan_buffer_maximum_scan_distance10.0 link_match_minimum_response_fine0.1 link_scan_maximum_distance1.5 loop_search_maximum_distance3.0 do_loop_closingtrue loop_match_minimum_chain_size10 loop_match_maximum_variance_coarse3.0 loop_match_minimum_response_coarse0.35 loop_match_minimum_response_fine0.45 # Correlation Parameters - Correlation Parameters correlation_search_space_dimension0.5 correlation_search_space_resolution0.01 correlation_search_space_smear_deviation0.1 # Correlation Parameters - Loop Closure Parameters loop_search_space_dimension8.0 loop_search_space_resolution0.05 loop_search_space_smear_deviation0.03 # Scan Matcher Parameters distance_variance_penalty0.5 angle_variance_penalty1.0 fine_search_angle_offset0.00349 coarse_search_angle_offset0.349 coarse_angle_resolution0.0349 minimum_angle_penalty0.9 minimum_distance_penalty0.5 use_response_expansiontrue min_pass_through2 occupancy_threshold0.1