Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
smoother_benchmark_bringup.py
1 # Copyright (c) 2022 Samsung Research America
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 ExecuteProcess, IncludeLaunchDescription
20 from launch.launch_description_sources import PythonLaunchDescriptionSource
21 from launch_ros.actions import Node
22 
23 
24 def generate_launch_description() -> LaunchDescription:
25  nav2_bringup_dir = get_package_share_directory('nav2_bringup')
26  benchmark_dir = os.getcwd()
27  metrics_py = os.path.join(benchmark_dir, 'metrics.py')
28  config = os.path.join(
29  get_package_share_directory('nav2_bringup'), 'params', 'nav2_params.yaml'
30  )
31  map_file = os.path.join(benchmark_dir, 'maps', 'smoothers_world.yaml')
32  lifecycle_nodes = ['map_server', 'planner_server', 'smoother_server']
33 
34  static_transform_one = Node(
35  package='tf2_ros',
36  executable='static_transform_publisher',
37  output='screen',
38  arguments=[
39  '--x', '0',
40  '--y', '0',
41  '--z', '0',
42  '--roll', '0',
43  '--pitch', '0',
44  '--yaw', '0',
45  '--frame-id', 'base_link',
46  '--child-frame-id', 'map'
47  ],
48  )
49 
50  static_transform_two = Node(
51  package='tf2_ros',
52  executable='static_transform_publisher',
53  output='screen',
54  arguments=[
55  '--x', '0',
56  '--y', '0',
57  '--z', '0',
58  '--roll', '0',
59  '--pitch', '0',
60  '--yaw', '0',
61  '--frame-id', 'base_link',
62  '--child-frame-id', 'odom'
63  ],
64  )
65 
66  start_map_server_cmd = Node(
67  package='nav2_map_server',
68  executable='map_server',
69  name='map_server',
70  output='screen',
71  parameters=[
72  {'use_sim_time': True},
73  {'yaml_filename': map_file},
74  {'topic_name': 'map'},
75  ],
76  )
77 
78  start_planner_server_cmd = Node(
79  package='nav2_planner',
80  executable='planner_server',
81  name='planner_server',
82  output='screen',
83  parameters=[config],
84  )
85 
86  start_smoother_server_cmd = Node(
87  package='nav2_smoother',
88  executable='smoother_server',
89  name='smoother_server',
90  output='screen',
91  parameters=[config],
92  )
93 
94  start_lifecycle_manager_cmd = Node(
95  package='nav2_lifecycle_manager',
96  executable='lifecycle_manager',
97  name='lifecycle_manager',
98  output='screen',
99  parameters=[
100  {'use_sim_time': True},
101  {'autostart': True},
102  {'node_names': lifecycle_nodes},
103  ],
104  )
105 
106  rviz_cmd = IncludeLaunchDescription(
107  PythonLaunchDescriptionSource(
108  os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')
109  ),
110  launch_arguments={'namespace': ''}.items(),
111  )
112 
113  metrics_cmd = ExecuteProcess(
114  cmd=['python3', '-u', metrics_py], cwd=[benchmark_dir], output='screen'
115  )
116 
117  ld = LaunchDescription()
118  ld.add_action(static_transform_one)
119  ld.add_action(static_transform_two)
120  ld.add_action(start_map_server_cmd)
121  ld.add_action(start_planner_server_cmd)
122  ld.add_action(start_smoother_server_cmd)
123  ld.add_action(start_lifecycle_manager_cmd)
124  ld.add_action(rviz_cmd)
125  ld.add_action(metrics_cmd)
126  return ld