ndt_localization_launch.py
Go to the documentation of this file.
1 # Copyright 2024 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_plugin',
40  default_value='beluga_amcl::NdtAmclNode',
41  description='Localization node plugin to use if composition is enabled. ',
42  ),
43  DeclareLaunchArgument(
44  name='localization_prefix',
45  default_value='',
46  description='Set of commands/arguments to precede the node command (e.g. "timem --").',
47  ),
48  DeclareLaunchArgument(
49  name='localization_params_file',
50  default_value=str(example_dir_path / 'params' / 'default_ndt.ros2.yaml'),
51  description='Parameters file to be used to run the localization node.',
52  ),
53  DeclareLaunchArgument(
54  name='localization_map',
55  default_value=str(example_dir_path / 'maps' / 'turtlebot3_world.yaml'),
56  description='Map YAML file to be used by the map server node.',
57  ),
58  DeclareLaunchArgument(
59  name='localization_ndt_map',
60  default_value=str(example_dir_path / 'maps' / 'turtlebot3_world.hdf5'),
61  description='Map HDF5 file used by the localization node.',
62  ),
63  DeclareLaunchArgument(
64  name='use_composition',
65  default_value='False',
66  description='Whether to use composed node bringup.',
67  ),
68  DeclareLaunchArgument(
69  name='use_sim_time',
70  default_value='False',
71  description='Whether to use simulation clock.',
72  ),
73  ]
74 
75 
78  localization_plugin,
79  localization_prefix,
80  localization_params_file,
81  localization_map,
82  localization_ndt_map,
83  use_composition,
84  use_sim_time,
85 ):
86  use_composition = get_typed_value(use_composition, bool)
87  use_sim_time = get_typed_value(use_sim_time, bool)
88 
89  load_nodes = GroupAction(
90  actions=[
92  package='beluga_amcl',
93  executable='ndt_amcl_node',
94  namespace='',
95  name='ndt_amcl',
96  output='screen',
97  arguments=['--ros-args', '--log-level', 'info'],
98  prefix=localization_prefix,
99  params_file=localization_params_file,
100  extra_params={'map_path': localization_ndt_map},
101  ),
102  # Only used for map visualization in RVIZ, since the NDT map is loaded
103  # internally by the AMCL node.
104  Node(
105  package='nav2_map_server',
106  executable='map_server',
107  namespace='',
108  name='map_server',
109  output='screen',
110  arguments=['--ros-args', '--log-level', 'info'],
111  parameters=[
112  {'yaml_filename': localization_map},
113  ],
114  ),
115  Node(
116  package='nav2_lifecycle_manager',
117  executable='lifecycle_manager',
118  namespace='',
119  name='lifecycle_manager_localization',
120  output='screen',
121  arguments=['--ros-args', '--log-level', 'info'],
122  sigterm_timeout='20',
123  sigkill_timeout='20',
124  parameters=[
125  {'autostart': True},
126  {'node_names': ['map_server', 'ndt_amcl']},
127  ],
128  ),
129  ]
130  )
131 
132  load_composable_nodes = GroupAction(
133  actions=[
134  ComposableNodeContainer(
135  package='rclcpp_components',
136  executable='component_container',
137  namespace='',
138  name='amcl_component_container',
139  composable_node_descriptions=[
140  ComposableNode(
141  package='beluga_amcl',
142  plugin=localization_plugin,
143  name='ndt_amcl',
144  parameters=[localization_params_file],
145  ),
146  ComposableNode(
147  package='nav2_map_server',
148  plugin='nav2_map_server::MapServer',
149  name='map_server',
150  parameters=[
151  {'yaml_filename': localization_map},
152  ],
153  ),
154  ComposableNode(
155  package='nav2_lifecycle_manager',
156  plugin='nav2_lifecycle_manager::LifecycleManager',
157  name='lifecycle_manager_localization',
158  parameters=[
159  {'autostart': True},
160  {'node_names': ['map_server', 'ndt_amcl']},
161  ],
162  ),
163  ],
164  ),
165  ]
166  )
167 
168  return LaunchDescription(
169  [
170  SetParameter('use_sim_time', use_sim_time),
171  load_composable_nodes if use_composition else load_nodes,
172  ]
173  )
ndt_localization_launch.generate_launch_description
def generate_launch_description(localization_plugin, localization_prefix, localization_params_file, localization_map, localization_ndt_map, use_composition, use_sim_time)
Definition: ndt_localization_launch.py:77
ndt_localization_launch.get_launch_arguments
def get_launch_arguments()
Definition: ndt_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


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