From 82a1d44c5f0eb0faa6a09463c23d5f0bbe18ce5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=8C=E6=AC=A2=E9=86=89?= <264854363@qq.com> Date: Thu, 4 Jun 2026 15:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86slam=E8=B4=9F?= =?UTF-8?q?=E8=B4=A3=E5=AE=9A=E4=BD=8D=EF=BC=8Cmap=5Fserver=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=85=A8=E5=B1=80=E5=9C=B0=E5=9B=BE=E5=8F=91=E5=B8=83?= =?UTF-8?q?=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=AE=9E=E7=8E=B0=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E5=AE=9A=E4=BD=8D=E5=92=8C=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=20=E4=BD=86=E6=98=AF=E6=97=A0=E6=B3=95=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E6=9B=B4=E6=96=B0=E5=9C=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launch/gc_nav2_with_slam.launch.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/gc_navigation2_slamtoolbox/launch/gc_nav2_with_slam.launch.py b/src/gc_navigation2_slamtoolbox/launch/gc_nav2_with_slam.launch.py index 964ca70..7e20adc 100644 --- a/src/gc_navigation2_slamtoolbox/launch/gc_nav2_with_slam.launch.py +++ b/src/gc_navigation2_slamtoolbox/launch/gc_nav2_with_slam.launch.py @@ -31,6 +31,7 @@ def generate_launch_description(): pkg_dir, 'maps', 'my_map.posegraph') # =============================3.slam_toolbox 定位模式(替代 AMCL)========================================= + # 注意:slam_toolbox 的 /map 重映射到 /slam_map,避免覆盖 map_server 的全量地图 slam_toolbox_node = Node( package='slam_toolbox', executable='localization_slam_toolbox_node', @@ -39,31 +40,20 @@ def generate_launch_description(): parameters=[slam_params_file, {'use_sim_time': True, 'map_file_name': posegraph_path}], + remappings=[('/map', '/slam_map')], ) - # =============================4.仅启动 nav2 navigation(不含 localization)================================= - # 因为 slam_toolbox 已经替代了 AMCL,不需要再跑 localization_launch - navigation_launch = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - [nav2_bringup_dir, '/launch', '/navigation_launch.py']), - launch_arguments={ - 'use_sim_time': use_sim_time, - 'params_file': nav2_param_path}.items(), - ) - - # =============================5.map_server 单独启动(提供静态地图给 costmap)=============================== + # =============================4.map_server 提供全量静态地图给 global_costmap ============================= map_server_node = Node( package='nav2_map_server', executable='map_server', name='map_server', output='screen', - parameters=[nav2_param_path, - {'yaml_filename': map_yaml_path, + parameters=[{'yaml_filename': map_yaml_path, 'use_sim_time': True}], ) - # map_server 生命周期自动管理 - map_server_lifecycle_node = Node( + map_server_lifecycle = Node( package='nav2_lifecycle_manager', executable='lifecycle_manager', name='lifecycle_manager_map', @@ -73,7 +63,17 @@ def generate_launch_description(): 'node_names': ['map_server']}], ) - # =============================6.Gazebo仿真设置========================================================== + # =============================5.仅启动 nav2 navigation(不含 localization)================================= + # 因为 slam_toolbox 已经替代了 AMCL,不需要再跑 localization_launch + navigation_launch = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + [nav2_bringup_dir, '/launch', '/navigation_launch.py']), + launch_arguments={ + 'use_sim_time': use_sim_time, + 'params_file': nav2_param_path}.items(), + ) + + # =============================5.Gazebo仿真设置========================================================== robot_name_in_model = 'mycar' default_model_path = os.path.join( origincar_urdf_dir, "urdf", "origincar.urdf") @@ -109,7 +109,7 @@ def generate_launch_description(): ld.add_action(spawn_entity_cmd) ld.add_action(robot_state_publisher) ld.add_action(map_server_node) - ld.add_action(map_server_lifecycle_node) + ld.add_action(map_server_lifecycle) ld.add_action(slam_toolbox_node) ld.add_action(navigation_launch)