Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
route_tool.launch.py
1 # Copyright (c) 2025 John Chrosniak
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import os
16 
17 from ament_index_python.packages import get_package_share_directory
18 from launch import LaunchDescription
19 from launch.actions import DeclareLaunchArgument
20 from launch.substitutions import LaunchConfiguration
21 import launch_ros.actions
22 
23 
24 def generate_launch_description() -> LaunchDescription:
25 
26  # Nodes launching commands
27  map_file = LaunchConfiguration('yaml_filename')
28 
29  declare_map_file_cmd = DeclareLaunchArgument(
30  'yaml_filename',
31  default_value='',
32  description='Full path to an occupancy grid map yaml file',
33  )
34 
35  start_route_tool_cmd = launch_ros.actions.Node(
36  package='rviz2',
37  executable='rviz2',
38  output='screen',
39  arguments=[
40  '-d'
41  + os.path.join(
42  get_package_share_directory('nav2_rviz_plugins'),
43  'rviz',
44  'route_tool.rviz',
45  )
46  ],
47  )
48 
49  start_map_server = launch_ros.actions.Node(
50  package='nav2_map_server',
51  executable='map_server',
52  output='screen',
53  parameters=[{'yaml_filename': map_file}],
54  )
55 
56  start_lifecycle_manager_cmd = launch_ros.actions.Node(
57  package='nav2_lifecycle_manager',
58  executable='lifecycle_manager',
59  name='lifecycle_manager',
60  output='screen',
61  parameters=[
62  {'use_sim_time': False},
63  {'autostart': True},
64  {'node_names': ['map_server']},
65  ],
66  )
67 
68  return LaunchDescription(
69  [
70  declare_map_file_cmd,
71  start_route_tool_cmd,
72  start_map_server,
73  start_lifecycle_manager_cmd,
74  ]
75  )