17 from ament_index_python.packages
import get_package_share_directory
18 from launch
import LaunchDescription
19 from launch.actions
import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable
20 from launch.conditions
import IfCondition
21 from launch.substitutions
import (AndSubstitution, EqualsSubstitution, LaunchConfiguration,
22 NotEqualsSubstitution, PythonExpression)
23 from launch_ros.actions
import LoadComposableNodes, Node, PushROSNamespace, SetParameter
24 from launch_ros.descriptions
import ComposableNode, ParameterFile
28 def get_lifecycle_nodes(context):
30 if LaunchConfigAsBool(
'serve_static_map').perform(context) ==
'True':
31 lifecycle_nodes.append(
'map_server')
32 if LaunchConfigAsBool(
'use_localization').perform(context) ==
'True':
33 lifecycle_nodes.append(
'amcl')
34 return tuple(lifecycle_nodes)
37 def generate_launch_description() -> LaunchDescription:
39 bringup_dir = get_package_share_directory(
'nav2_bringup')
41 namespace = LaunchConfiguration(
'namespace')
42 map_yaml_file = LaunchConfiguration(
'map')
43 use_sim_time = LaunchConfigAsBool(
'use_sim_time')
44 use_localization = LaunchConfigAsBool(
'use_localization')
45 serve_static_map = LaunchConfigAsBool(
'serve_static_map')
46 params_file = LaunchConfiguration(
'params_file')
47 use_composition = LaunchConfigAsBool(
'use_composition')
48 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
49 container_name = LaunchConfiguration(
'container_name')
50 container_name_full = (namespace,
'/', container_name)
51 use_respawn = LaunchConfigAsBool(
'use_respawn')
52 log_level = LaunchConfiguration(
'log_level')
55 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
57 configured_params = ParameterFile(
59 source_file=params_file,
67 stdout_linebuf_envvar = SetEnvironmentVariable(
68 'RCUTILS_LOGGING_BUFFERED_STREAM',
'1'
71 declare_namespace_cmd = DeclareLaunchArgument(
72 'namespace', default_value=
'', description=
'Top-level namespace'
75 declare_map_yaml_cmd = DeclareLaunchArgument(
76 'map', default_value=
'', description=
'Full path to map yaml file to load'
79 declare_use_sim_time_cmd = DeclareLaunchArgument(
81 default_value=
'false',
82 description=
'Use simulation (Gazebo) clock if true',
85 declare_use_localization_cmd = DeclareLaunchArgument(
88 description=
'Whether to launch localization',
91 declare_serve_static_map_cmd = DeclareLaunchArgument(
93 default_value=use_localization,
94 description=
'Whether to serve the static map',
97 declare_params_file_cmd = DeclareLaunchArgument(
99 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
100 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
103 declare_use_composition_cmd = DeclareLaunchArgument(
105 default_value=
'False',
106 description=
'Use composed bringup if True',
109 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
110 'use_intra_process_comms',
111 default_value=
'False',
112 description=
'Use intra process communications if True',
115 declare_container_name_cmd = DeclareLaunchArgument(
117 default_value=
'nav2_container',
118 description=
'the name of container that nodes will load in if use composition',
121 declare_use_respawn_cmd = DeclareLaunchArgument(
123 default_value=
'False',
124 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
127 declare_log_level_cmd = DeclareLaunchArgument(
128 'log_level', default_value=
'info', description=
'log level'
131 load_nodes = GroupAction(
132 condition=IfCondition(PythonExpression([
'not ', use_composition])),
134 PushROSNamespace(namespace),
135 SetParameter(
'use_sim_time', use_sim_time),
137 condition=IfCondition(
140 EqualsSubstitution(LaunchConfiguration(
'map'),
''),
143 package=
'nav2_map_server',
144 executable=
'map_server',
149 parameters=[configured_params],
150 arguments=[
'--ros-args',
'--log-level', log_level],
151 remappings=remappings,
154 condition=IfCondition(
157 NotEqualsSubstitution(LaunchConfiguration(
'map'),
''),
160 package=
'nav2_map_server',
161 executable=
'map_server',
166 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
167 arguments=[
'--ros-args',
'--log-level', log_level],
168 remappings=remappings,
171 condition=IfCondition(use_localization),
178 parameters=[configured_params],
179 arguments=[
'--ros-args',
'--log-level', log_level],
180 remappings=remappings,
189 load_composable_nodes = GroupAction(
190 condition=IfCondition(use_composition),
192 PushROSNamespace(namespace),
193 SetParameter(
'use_sim_time', use_sim_time),
195 target_container=container_name_full,
196 condition=IfCondition(
199 EqualsSubstitution(LaunchConfiguration(
'map'),
''),
202 composable_node_descriptions=[
204 package=
'nav2_map_server',
205 plugin=
'nav2_map_server::MapServer',
207 parameters=[configured_params],
208 remappings=remappings,
209 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
214 target_container=container_name_full,
215 condition=IfCondition(
218 NotEqualsSubstitution(LaunchConfiguration(
'map'),
''),
221 composable_node_descriptions=[
223 package=
'nav2_map_server',
224 plugin=
'nav2_map_server::MapServer',
228 {
'yaml_filename': map_yaml_file},
230 remappings=remappings,
231 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
236 condition=IfCondition(use_localization),
237 target_container=container_name_full,
238 composable_node_descriptions=[
241 plugin=
'nav2_amcl::AmclNode',
243 parameters=[configured_params],
244 remappings=remappings,
245 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
253 ld = LaunchDescription()
256 ld.add_action(stdout_linebuf_envvar)
259 ld.add_action(declare_namespace_cmd)
260 ld.add_action(declare_map_yaml_cmd)
261 ld.add_action(declare_use_sim_time_cmd)
262 ld.add_action(declare_use_localization_cmd)
263 ld.add_action(declare_serve_static_map_cmd)
264 ld.add_action(declare_params_file_cmd)
265 ld.add_action(declare_use_composition_cmd)
266 ld.add_action(declare_use_intra_process_comms_cmd)
267 ld.add_action(declare_container_name_cmd)
268 ld.add_action(declare_use_respawn_cmd)
269 ld.add_action(declare_log_level_cmd)
272 ld.add_action(load_nodes)
273 ld.add_action(load_composable_nodes)