Navigation2学习笔记--总揽nav2_bringup导航包launch文件

launch文件是一个包的窗口,通过这个窗口我们可以知道一个软件包能干什么,具体调动了什么节点,需要加载什么参数,下面我们从总体看里面每个launch文件的作用。

环境:utuntu20.04  ros2 foxy  nav2不同版本大同小异。

具体怎么安装nav2参考:入门 — Navigation 2 1.0.0 文档

一 nav2_bringup导航包 launch文件结构

Navigation2学习笔记--总揽nav2_bringup导航包launch文件_第1张图片

二 所有的launch文件

1 localization_launch.py

2 slam_launch.py

3 navigation_launch.py

4 rviz_launch.py

5 bringup_launch.py              

6 spawn_tb3_launch.py

7 tb3_simulation_launch.py

8 multi_tb3_simulation_launch.py
 

三 每个launch作用

我们按包含关系从简单到复杂说起,lifecycle_manager是一个控制节点启动的,不影响逻辑关系,我们先不考虑。

1 localization_launch.py

启动节点关键代码

        Node(
            package='nav2_map_server',
            executable='map_server',
            name='map_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_amcl',
            executable='amcl',
            name='amcl',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

executable='map_server',    #地图服务

executable='amcl',               #基于粒子过滤器的定位技术,用于静态地图的定位。

作用:启动地图服务,在地图上给机器人定位。

2 slam_launch.py

启动节点关键代码

    slam_launch_file = os.path.join(slam_toolbox_dir, 'launch', 'online_sync_launch.py')
    start_slam_toolbox_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(slam_launch_file),
        launch_arguments={'use_sim_time': use_sim_time}.items())

    start_map_saver_server_cmd = Node(
            package='nav2_map_server',
            executable='map_saver_server',
            output='screen',
            parameters=[configured_params])

start_slam_toolbox_cmd一级套娃,启动了online_sync_launch.py

online_sync_launch.py关键代码

 start_sync_slam_toolbox_node = Node(
        parameters=[
          actual_params_file,
          {'use_sim_time': use_sim_time}
        ],
        package='slam_toolbox',
        executable='sync_slam_toolbox_node',
        name='slam_toolbox',
        output='screen')

executable='sync_slam_toolbox_node',   #启动了slam工具箱同步定位建图

executable='map_saver_server',     #启动了地图储存服务节点

作用:slam同步定位建图,储存地图。

3 navigation_launch.py

启动节点关键代码

        Node(
            package='nav2_controller',
            executable='controller_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_planner',
            executable='planner_server',
            name='planner_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_recoveries',
            executable='recoveries_server',
            name='recoveries_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_bt_navigator',
            executable='bt_navigator',
            name='bt_navigator',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_waypoint_follower',
            executable='waypoint_follower',
            name='waypoint_follower',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

executable='controller_server',     #启动机器人控制器

executable='planner_server',        #启动机器人规划器

executable='recoveries_server',   #启动机器人恢复服务器

executable='bt_navigator',            #启动行为树

executable='waypoint_follower',   #启动路点跟随

作用:启动导航核心节点,行为树 规划器 控制器 恢复器 路点跟随

4 rviz_launch.py

启动节点关键代码

start_rviz_cmd = Node(
        condition=UnlessCondition(use_namespace),
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=['-d', rviz_config_file],
        output='screen')

executable='rviz2',

作用:启动rviz2可视化机器人及导航

5 bringup_launch.py

启动节点关键代码

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(launch_dir, 'slam_launch.py')),
            condition=IfCondition(slam),
            launch_arguments={'namespace': namespace,
                              'use_sim_time': use_sim_time,
                              'autostart': autostart,
                              'params_file': params_file}.items()),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(launch_dir,
                                                       'localization_launch.py')),
            condition=IfCondition(PythonExpression(['not ', slam])),
            launch_arguments={'namespace': namespace,
                              'map': map_yaml_file,
                              'use_sim_time': use_sim_time,
                              'autostart': autostart,
                              'params_file': params_file,
                              'use_lifecycle_mgr': 'false'}.items()),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(launch_dir, 'navigation_launch.py')),
            launch_arguments={'namespace': namespace,
                              'use_sim_time': use_sim_time,
                              'autostart': autostart,
                              'params_file': params_file,
                              'default_bt_xml_filename': default_bt_xml_filename,
                              'use_lifecycle_mgr': 'false',
                              'map_subscribe_transient_local': 'true'}.items()),

通过条件选择condition=IfCondition(slam),二选一启动:

slam_launch.py

localization_launch.py

'slam',default_value='False  所以默认启动 localization_launch.py

启动 navigation_launch.py

作用:这是一个通过launch文件套娃集齐了nav2导航需要的所有节点,按默认设置启动地图服务,在地图上给机器人定位,启动导航行为树 规划器 控制器 恢复器 路点跟随。

如果没有实体机器人,开启gazebo仿真机器人+bringup_launch.py+rviz_launch.py

如果有实体机器人,启动机器人底盘程序+bringup_launch.py+rviz_launch.py  nav2导航服务全部节点就都集齐了,可以开始自由导航了。

如果想同时建图并导航只需给launch文件加参数,启动 bringup_launch.py slam:=True 这时在陌生环境不需要提供地图,程序会一边建图,一边导航。

注意仿真机器人所有节点 use_sim_time=true (启用仿真时间),实体机器人所有节点use_sim_time=false (不启用仿真时间),时间设置错了会出现莫名其妙的问题。

6 spawn_tb3_launch.py

启动节点关键代码

            package='nav2_gazebo_spawner',
            executable='nav2_gazebo_spawner',
            output='screen',
            arguments=[
                '--robot_name', launch.substitutions.LaunchConfiguration('robot_name'),
                '--robot_namespace', launch.substitutions.LaunchConfiguration('robot_name'),
                '--turtlebot_type', launch.substitutions.LaunchConfiguration('turtlebot_type'),
                '-x', launch.substitutions.LaunchConfiguration('x_pose'),
                '-y', launch.substitutions.LaunchConfiguration('y_pose'),
                '-z', launch.substitutions.LaunchConfiguration('z_pose')]),

executable='nav2_gazebo_spawner',   

作用:启动gazebo产卵节点,在gazebo规定位置生成机器人

7 tb3_simulation_launch.py

启动节点关键代码

     start_gazebo_server_cmd = ExecuteProcess(
        condition=IfCondition(use_simulator),
        cmd=['gzserver', '-s', 'libgazebo_ros_init.so', world],
        cwd=[launch_dir], output='screen')

    start_gazebo_client_cmd = ExecuteProcess(
        condition=IfCondition(PythonExpression([use_simulator, ' and not ', headless])),
        cmd=['gzclient'],
        cwd=[launch_dir], output='screen')

   
   
    start_robot_state_publisher_cmd = Node(
        condition=IfCondition(use_robot_state_pub),
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='robot_state_publisher',
        namespace=namespace,
        output='screen',
        parameters=[{'use_sim_time': use_sim_time}],
        remappings=remappings,
        arguments=[urdf])

    rviz_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(os.path.join(launch_dir, 'rviz_launch.py')),
        condition=IfCondition(use_rviz),
        launch_arguments={'namespace': '',
                          'use_namespace': 'False',
                          'rviz_config': rviz_config_file}.items())

    bringup_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
        launch_arguments={'namespace': namespace,
                          'use_namespace': use_namespace,
                          'slam': slam,
                          'map': map_yaml_file,
                          'use_sim_time': use_sim_time,
                          'params_file': params_file,
                          'default_bt_xml_filename': default_bt_xml_filename,
                          'autostart': autostart}.items())

 start_gazebo_server_cmd     #启动gazebo服务端,加载ros插件

start_gazebo_client_cmd        #启动gazebo客户端

executable='robot_state_publisher',  #启动机器人模型

PythonLaunchDescriptionSource(os.path.join(launch_dir, 'rviz_launch.py')),  #启动rviz2显示机器人

PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')), #启动导航

作用:生成gazebo仿真机器人,启动导航服务,rviz显示机器人导航

7 multi_tb3_simulation_launch.py

作用:这个我也没有仔细研究,总体来说是在gazebo仿真环境生成多个机器人并导航。

Navigation2学习笔记--总揽nav2_bringup导航包launch文件_第2张图片

 参考:Nav2 — Navigation 2 1.0.0 文档

 我也是在学习阶段,写的不一定都对,欢迎朋友们留言讨论,共同进步!

你可能感兴趣的:(学习,笔记,机器人)