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 (EqualsSubstitution, LaunchConfiguration, NotEqualsSubstitution,
23 from launch_ros.actions
import LoadComposableNodes, Node, PushROSNamespace, SetParameter
24 from launch_ros.descriptions
import ComposableNode, ParameterFile
28 def generate_launch_description() -> LaunchDescription:
30 bringup_dir = get_package_share_directory(
'nav2_bringup')
32 namespace = LaunchConfiguration(
'namespace')
33 map_yaml_file = LaunchConfiguration(
'map')
34 use_sim_time = LaunchConfigAsBool(
'use_sim_time')
35 autostart = LaunchConfigAsBool(
'autostart')
36 params_file = LaunchConfiguration(
'params_file')
37 use_composition = LaunchConfigAsBool(
'use_composition')
38 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
39 container_name = LaunchConfiguration(
'container_name')
40 container_name_full = (namespace,
'/', container_name)
41 use_respawn = LaunchConfigAsBool(
'use_respawn')
42 log_level = LaunchConfiguration(
'log_level')
44 lifecycle_nodes = [
'map_server',
'amcl']
47 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
49 configured_params = ParameterFile(
51 source_file=params_file,
59 stdout_linebuf_envvar = SetEnvironmentVariable(
60 'RCUTILS_LOGGING_BUFFERED_STREAM',
'1'
63 declare_namespace_cmd = DeclareLaunchArgument(
64 'namespace', default_value=
'', description=
'Top-level namespace'
67 declare_map_yaml_cmd = DeclareLaunchArgument(
68 'map', default_value=
'', description=
'Full path to map yaml file to load'
71 declare_use_sim_time_cmd = DeclareLaunchArgument(
73 default_value=
'false',
74 description=
'Use simulation (Gazebo) clock if true',
77 declare_params_file_cmd = DeclareLaunchArgument(
79 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
80 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
83 declare_autostart_cmd = DeclareLaunchArgument(
86 description=
'Automatically startup the nav2 stack',
89 declare_use_composition_cmd = DeclareLaunchArgument(
91 default_value=
'False',
92 description=
'Use composed bringup if True',
95 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
96 'use_intra_process_comms',
97 default_value=
'False',
98 description=
'Use intra process communications if True',
101 declare_container_name_cmd = DeclareLaunchArgument(
103 default_value=
'nav2_container',
104 description=
'the name of container that nodes will load in if use composition',
107 declare_use_respawn_cmd = DeclareLaunchArgument(
109 default_value=
'False',
110 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
113 declare_log_level_cmd = DeclareLaunchArgument(
114 'log_level', default_value=
'info', description=
'log level'
117 load_nodes = GroupAction(
118 condition=IfCondition(PythonExpression([
'not ', use_composition])),
120 PushROSNamespace(namespace),
121 SetParameter(
'use_sim_time', use_sim_time),
123 condition=IfCondition(
124 EqualsSubstitution(LaunchConfiguration(
'map'),
'')
126 package=
'nav2_map_server',
127 executable=
'map_server',
132 parameters=[configured_params],
133 arguments=[
'--ros-args',
'--log-level', log_level],
134 remappings=remappings,
137 condition=IfCondition(
138 NotEqualsSubstitution(LaunchConfiguration(
'map'),
'')
140 package=
'nav2_map_server',
141 executable=
'map_server',
146 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
147 arguments=[
'--ros-args',
'--log-level', log_level],
148 remappings=remappings,
157 parameters=[configured_params],
158 arguments=[
'--ros-args',
'--log-level', log_level],
159 remappings=remappings,
162 package=
'nav2_lifecycle_manager',
163 executable=
'lifecycle_manager',
164 name=
'lifecycle_manager_localization',
166 arguments=[
'--ros-args',
'--log-level', log_level],
169 {
'autostart': autostart}, {
'node_names': lifecycle_nodes}
179 load_composable_nodes = GroupAction(
180 condition=IfCondition(use_composition),
182 PushROSNamespace(namespace),
183 SetParameter(
'use_sim_time', use_sim_time),
185 target_container=container_name_full,
186 condition=IfCondition(
187 EqualsSubstitution(LaunchConfiguration(
'map'),
'')
189 composable_node_descriptions=[
191 package=
'nav2_map_server',
192 plugin=
'nav2_map_server::MapServer',
194 parameters=[configured_params],
195 remappings=remappings,
196 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
201 target_container=container_name_full,
202 condition=IfCondition(
203 NotEqualsSubstitution(LaunchConfiguration(
'map'),
'')
205 composable_node_descriptions=[
207 package=
'nav2_map_server',
208 plugin=
'nav2_map_server::MapServer',
212 {
'yaml_filename': map_yaml_file},
214 remappings=remappings,
215 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
220 target_container=container_name_full,
221 composable_node_descriptions=[
224 plugin=
'nav2_amcl::AmclNode',
226 parameters=[configured_params],
227 remappings=remappings,
228 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
231 package=
'nav2_lifecycle_manager',
232 plugin=
'nav2_lifecycle_manager::LifecycleManager',
233 name=
'lifecycle_manager_localization',
236 {
'autostart': autostart,
'node_names': lifecycle_nodes}
238 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
246 ld = LaunchDescription()
249 ld.add_action(stdout_linebuf_envvar)
252 ld.add_action(declare_namespace_cmd)
253 ld.add_action(declare_map_yaml_cmd)
254 ld.add_action(declare_use_sim_time_cmd)
255 ld.add_action(declare_params_file_cmd)
256 ld.add_action(declare_autostart_cmd)
257 ld.add_action(declare_use_composition_cmd)
258 ld.add_action(declare_use_intra_process_comms_cmd)
259 ld.add_action(declare_container_name_cmd)
260 ld.add_action(declare_use_respawn_cmd)
261 ld.add_action(declare_log_level_cmd)
264 ld.add_action(load_nodes)
265 ld.add_action(load_composable_nodes)