|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +from launch import LaunchDescription |
| 4 | +from launch.actions import ( |
| 5 | + DeclareLaunchArgument, |
| 6 | + GroupAction, |
| 7 | + IncludeLaunchDescription, |
| 8 | + OpaqueFunction |
| 9 | +) |
| 10 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 11 | +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution |
| 12 | +from launch_ros.actions import PushRosNamespace, SetRemap |
| 13 | +from ament_index_python.packages import get_package_share_directory |
| 14 | + |
| 15 | + |
| 16 | +ARGUMENTS = [ |
| 17 | + DeclareLaunchArgument('use_sim_time', default_value='true', |
| 18 | + choices=['true', 'false'], |
| 19 | + description='Use sim time'), |
| 20 | + DeclareLaunchArgument('params_file', |
| 21 | + default_value=PathJoinSubstitution([ |
| 22 | + get_package_share_directory('drl_agent'), |
| 23 | + 'config', |
| 24 | + 'nav2.yaml' |
| 25 | + ]), |
| 26 | + description='Nav2 parameters'), |
| 27 | + DeclareLaunchArgument('namespace', default_value='', |
| 28 | + description='Robot namespace') |
| 29 | +] |
| 30 | + |
| 31 | + |
| 32 | +def launch_setup(context, *args, **kwargs): |
| 33 | + pkg_nav2_bringup = get_package_share_directory('nav2_bringup') |
| 34 | + |
| 35 | + nav2_params = LaunchConfiguration('params_file') |
| 36 | + namespace = LaunchConfiguration('namespace') |
| 37 | + use_sim_time = LaunchConfiguration('use_sim_time') |
| 38 | + |
| 39 | + namespace_str = namespace.perform(context) |
| 40 | + if (namespace_str and not namespace_str.startswith('/')): |
| 41 | + namespace_str = '/' + namespace_str |
| 42 | + |
| 43 | + launch_nav2 = PathJoinSubstitution( |
| 44 | + [pkg_nav2_bringup, 'launch', 'navigation_launch.py']) |
| 45 | + |
| 46 | + nav2 = GroupAction([ |
| 47 | + PushRosNamespace(namespace), |
| 48 | + SetRemap(namespace_str + '/global_costmap/scan', namespace_str + '/scan'), |
| 49 | + SetRemap(namespace_str + '/local_costmap/scan', namespace_str + '/scan'), |
| 50 | + |
| 51 | + IncludeLaunchDescription( |
| 52 | + PythonLaunchDescriptionSource(launch_nav2), |
| 53 | + launch_arguments=[ |
| 54 | + ('use_sim_time', use_sim_time), |
| 55 | + ('params_file', nav2_params.perform(context)), |
| 56 | + ('use_composition', 'False'), |
| 57 | + ('namespace', namespace_str) |
| 58 | + ] |
| 59 | + ), |
| 60 | + ]) |
| 61 | + |
| 62 | + return [nav2] |
| 63 | + |
| 64 | + |
| 65 | +def generate_launch_description(): |
| 66 | + ld = LaunchDescription(ARGUMENTS) |
| 67 | + ld.add_action(OpaqueFunction(function=launch_setup)) |
| 68 | + return ld |
0 commit comments