localization_launch.py
Go to the documentation of this file.
1 # Copyright 2023 Ekumen, Inc.
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 from pathlib import Path
16 
17 from ament_index_python.packages import get_package_share_directory
18 
19 from launch import LaunchDescription
20 from launch.actions import DeclareLaunchArgument
21 from launch.actions import GroupAction
22 from launch_ros.actions import ComposableNodeContainer
23 from launch_ros.actions import Node
24 from launch_ros.descriptions.composable_node import ComposableNode
25 from launch.utilities.type_utils import get_typed_value
26 
27 from launch_ros.actions import SetParameter
28 
29 from beluga_example.launch_utils import with_launch_arguments
30 from beluga_example.launch_utils import (
31  get_node_with_arguments_declared_from_params_file,
32 )
33 
34 
36  example_dir_path = Path(get_package_share_directory('beluga_example'))
37  return [
38  DeclareLaunchArgument(
39  name='localization_package',
40  default_value='beluga_amcl',
41  description='Package that provides the localization node to launch.',
42  choices=['beluga_amcl', 'nav2_amcl'],
43  ),
44  DeclareLaunchArgument(
45  name='localization_node',
46  default_value='amcl_node',
47  description='Localization node to launch.',
48  ),
49  DeclareLaunchArgument(
50  name='localization_plugin',
51  default_value='beluga_amcl::AmclNode',
52  description='Localization node plugin to use if composition is enabled. ',
53  ),
54  DeclareLaunchArgument(
55  name='localization_prefix',
56  default_value='',
57  description='Set of commands/arguments to precede the node command (e.g. "timem --").',
58  ),
59  DeclareLaunchArgument(
60  name='localization_params_file',
61  default_value=str(example_dir_path / 'params' / 'default.ros2.yaml'),
62  description='Parameters file to be used to run the localization node.',
63  ),
64  DeclareLaunchArgument(
65  name='localization_map',
66  default_value=str(example_dir_path / 'maps' / 'turtlebot3_world.yaml'),
67  description='Map YAML file to be used by the localization node.',
68  ),
69  DeclareLaunchArgument(
70  name='use_composition',
71  default_value='False',
72  description='Whether to use composed node bringup.',
73  ),
74  DeclareLaunchArgument(
75  name='use_sim_time',
76  default_value='False',
77  description='Whether to use simulation clock.',
78  ),
79  ]
80 
81 
84  localization_package,
85  localization_node,
86  localization_plugin,
87  localization_prefix,
88  localization_params_file,
89  localization_map,
90  use_composition,
91  use_sim_time,
92 ):
93  use_composition = get_typed_value(use_composition, bool)
94  use_sim_time = get_typed_value(use_sim_time, bool)
95 
96  load_nodes = GroupAction(
97  actions=[
99  package=localization_package,
100  executable=localization_node,
101  namespace='',
102  name='amcl',
103  output='screen',
104  arguments=['--ros-args', '--log-level', 'info'],
105  prefix=localization_prefix,
106  params_file=localization_params_file,
107  ),
108  Node(
109  package='nav2_map_server',
110  executable='map_server',
111  namespace='',
112  name='map_server',
113  output='screen',
114  arguments=['--ros-args', '--log-level', 'info'],
115  parameters=[
116  {'yaml_filename': localization_map},
117  ],
118  ),
119  Node(
120  package='nav2_lifecycle_manager',
121  executable='lifecycle_manager',
122  namespace='',
123  name='lifecycle_manager_localization',
124  output='screen',
125  arguments=['--ros-args', '--log-level', 'info'],
126  sigterm_timeout='20',
127  sigkill_timeout='20',
128  parameters=[
129  {'autostart': True},
130  {'node_names': ['map_server', 'amcl']},
131  ],
132  ),
133  ]
134  )
135 
136  load_composable_nodes = GroupAction(
137  actions=[
138  ComposableNodeContainer(
139  package='rclcpp_components',
140  executable='component_container',
141  namespace='',
142  name='amcl_component_container',
143  composable_node_descriptions=[
144  ComposableNode(
145  package=localization_package,
146  plugin=localization_plugin,
147  name='amcl',
148  parameters=[localization_params_file],
149  ),
150  ComposableNode(
151  package='nav2_map_server',
152  plugin='nav2_map_server::MapServer',
153  name='map_server',
154  parameters=[
155  {'yaml_filename': localization_map},
156  ],
157  ),
158  ComposableNode(
159  package='nav2_lifecycle_manager',
160  plugin='nav2_lifecycle_manager::LifecycleManager',
161  name='lifecycle_manager_localization',
162  parameters=[
163  {'autostart': True},
164  {'node_names': ['map_server', 'amcl']},
165  ],
166  ),
167  ],
168  ),
169  ]
170  )
171 
172  return LaunchDescription(
173  [
174  SetParameter('use_sim_time', use_sim_time),
175  load_composable_nodes if use_composition else load_nodes,
176  ]
177  )
localization_launch.get_launch_arguments
def get_launch_arguments()
Definition: localization_launch.py:35
beluga_example.launch_utils
Definition: launch_utils.py:1
beluga_example.launch_utils.get_node_with_arguments_declared_from_params_file
def get_node_with_arguments_declared_from_params_file(*params_file, name, namespace='/', extra_params={}, **kwargs)
Definition: launch_utils.py:68
beluga_example.launch_utils.with_launch_arguments
def with_launch_arguments(List[DeclareLaunchArgument] arguments_to_declare)
Definition: launch_utils.py:32
localization_launch.generate_launch_description
def generate_launch_description(localization_package, localization_node, localization_plugin, localization_prefix, localization_params_file, localization_map, use_composition, use_sim_time)
Definition: localization_launch.py:83


beluga_example
Author(s):
autogenerated on Tue Jul 16 2024 03:00:09