Nav2 Navigation Stack - humble  humble
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 launch import LaunchDescription
18 from launch.actions import ExecuteProcess, IncludeLaunchDescription
19 from launch.launch_description_sources import PythonLaunchDescriptionSource
20 from launch_ros.actions import Node
21 from ament_index_python.packages import get_package_share_directory
22 
23 def generate_launch_description():
24  nav2_bringup_dir = get_package_share_directory('nav2_bringup')
25  benchmark_dir = os.getcwd()
26  metrics_py = os.path.join(benchmark_dir, 'metrics.py')
27  config = os.path.join(get_package_share_directory('nav2_bringup'), 'params', 'nav2_params.yaml')
28  map_file = os.path.join(benchmark_dir, 'maps', 'smoothers_world.yaml')
29  lifecycle_nodes = ['map_server', 'planner_server', 'smoother_server']
30 
31  static_transform_one = Node(
32  package = 'tf2_ros',
33  executable = 'static_transform_publisher',
34  output = 'screen',
35  arguments = ["0", "0", "0", "0", "0", "0", "base_link", "map"])
36 
37  static_transform_two = Node(
38  package = 'tf2_ros',
39  executable = 'static_transform_publisher',
40  output = 'screen',
41  arguments = ["0", "0", "0", "0", "0", "0", "base_link", "odom"])
42 
43  start_map_server_cmd = Node(
44  package='nav2_map_server',
45  executable='map_server',
46  name='map_server',
47  output='screen',
48  parameters=[{'use_sim_time': True},
49  {'yaml_filename': map_file},
50  {'topic_name': "map"}])
51 
52  start_planner_server_cmd = Node(
53  package='nav2_planner',
54  executable='planner_server',
55  name='planner_server',
56  output='screen',
57  parameters=[config])
58 
59  start_smoother_server_cmd = Node(
60  package='nav2_smoother',
61  executable='smoother_server',
62  name='smoother_server',
63  output='screen',
64  parameters=[config])
65 
66  start_lifecycle_manager_cmd = Node(
67  package='nav2_lifecycle_manager',
68  executable='lifecycle_manager',
69  name='lifecycle_manager',
70  output='screen',
71  parameters=[{'use_sim_time': True},
72  {'autostart': True},
73  {'node_names': lifecycle_nodes}])
74 
75  rviz_cmd = IncludeLaunchDescription(
76  PythonLaunchDescriptionSource(
77  os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
78  launch_arguments={'namespace': '',
79  'use_namespace': 'False'}.items())
80 
81  metrics_cmd = ExecuteProcess(
82  cmd=['python3', '-u', metrics_py],
83  cwd=[benchmark_dir], output='screen')
84 
85  ld = LaunchDescription()
86  ld.add_action(static_transform_one)
87  ld.add_action(static_transform_two)
88  ld.add_action(start_map_server_cmd)
89  ld.add_action(start_planner_server_cmd)
90  ld.add_action(start_smoother_server_cmd)
91  ld.add_action(start_lifecycle_manager_cmd)
92  ld.add_action(rviz_cmd)
93  ld.add_action(metrics_cmd)
94  return ld