17 from ament_index_python.packages
import get_package_share_directory
18 from launch
import LaunchDescription
19 from launch.actions
import (DeclareLaunchArgument, GroupAction, IncludeLaunchDescription,
20 SetEnvironmentVariable)
21 from launch.conditions
import IfCondition
22 from launch.launch_description_sources
import PythonLaunchDescriptionSource
23 from launch.substitutions
import LaunchConfiguration, PythonExpression
24 from launch_ros.actions
import Node
25 from launch_ros.descriptions
import ParameterFile
29 def generate_launch_description() -> LaunchDescription:
31 bringup_dir = get_package_share_directory(
'nav2_bringup')
32 launch_dir = os.path.join(bringup_dir,
'launch')
35 namespace = LaunchConfiguration(
'namespace')
36 slam = LaunchConfigAsBool(
'slam')
37 map_yaml_file = LaunchConfiguration(
'map')
38 keepout_mask_yaml_file = LaunchConfiguration(
'keepout_mask')
39 speed_mask_yaml_file = LaunchConfiguration(
'speed_mask')
40 graph_filepath = LaunchConfiguration(
'graph')
41 use_sim_time = LaunchConfigAsBool(
'use_sim_time')
42 params_file = LaunchConfiguration(
'params_file')
43 autostart = LaunchConfigAsBool(
'autostart')
44 use_composition = LaunchConfigAsBool(
'use_composition')
45 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
46 container_name = LaunchConfiguration(
'container_name')
47 use_respawn = LaunchConfigAsBool(
'use_respawn')
48 log_level = LaunchConfiguration(
'log_level')
49 use_localization = LaunchConfigAsBool(
'use_localization')
50 use_keepout_zones = LaunchConfigAsBool(
'use_keepout_zones')
51 use_speed_zones = LaunchConfigAsBool(
'use_speed_zones')
54 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
56 yaml_substitutions = {
57 'KEEPOUT_ZONE_ENABLED': use_keepout_zones,
58 'SPEED_ZONE_ENABLED': use_speed_zones,
61 configured_params = ParameterFile(
63 source_file=params_file,
66 value_rewrites=yaml_substitutions,
72 stdout_linebuf_envvar = SetEnvironmentVariable(
73 'RCUTILS_LOGGING_BUFFERED_STREAM',
'1'
76 declare_namespace_cmd = DeclareLaunchArgument(
77 'namespace', default_value=
'', description=
'Top-level namespace'
80 declare_slam_cmd = DeclareLaunchArgument(
81 'slam', default_value=
'False', description=
'Whether run a SLAM'
84 declare_map_yaml_cmd = DeclareLaunchArgument(
85 'map', default_value=
'', description=
'Full path to map yaml file to load'
88 declare_keepout_mask_yaml_cmd = DeclareLaunchArgument(
89 'keepout_mask', default_value=
'',
90 description=
'Full path to keepout mask yaml file to load'
93 declare_speed_mask_yaml_cmd = DeclareLaunchArgument(
94 'speed_mask', default_value=
'',
95 description=
'Full path to speed mask yaml file to load'
98 declare_graph_file_cmd = DeclareLaunchArgument(
100 default_value=
'', description=
'Path to the graph file to load'
103 declare_use_localization_cmd = DeclareLaunchArgument(
104 'use_localization', default_value=
'True',
105 description=
'Whether to enable localization or not'
108 declare_use_keepout_zones_cmd = DeclareLaunchArgument(
109 'use_keepout_zones', default_value=
'True',
110 description=
'Whether to enable keepout zones or not'
113 declare_use_speed_zones_cmd = DeclareLaunchArgument(
114 'use_speed_zones', default_value=
'True',
115 description=
'Whether to enable speed zones or not'
118 declare_use_sim_time_cmd = DeclareLaunchArgument(
120 default_value=
'false',
121 description=
'Use simulation (Gazebo) clock if true',
124 declare_params_file_cmd = DeclareLaunchArgument(
126 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
127 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
130 declare_autostart_cmd = DeclareLaunchArgument(
132 default_value=
'true',
133 description=
'Automatically startup the nav2 stack',
136 declare_use_composition_cmd = DeclareLaunchArgument(
138 default_value=
'True',
139 description=
'Whether to use composed bringup',
142 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
143 'use_intra_process_comms',
144 default_value=
'False',
145 description=
'Whether to use intra process communications',
148 declare_container_name_cmd = DeclareLaunchArgument(
150 default_value=
'nav2_container',
151 description=
'the name of container that nodes will load in if use composition',
154 declare_use_respawn_cmd = DeclareLaunchArgument(
156 default_value=
'False',
157 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
160 declare_log_level_cmd = DeclareLaunchArgument(
161 'log_level', default_value=
'info', description=
'log level'
165 bringup_cmd_group = GroupAction(
168 condition=IfCondition(use_composition),
171 package=
'rclcpp_components',
172 executable=
'component_container',
173 parameters=[configured_params, {
'autostart': autostart}],
174 arguments=[
'--isolated',
'--executor-type',
'single-threaded',
175 '--ros-args',
'--log-level', log_level],
176 remappings=remappings,
179 IncludeLaunchDescription(
180 PythonLaunchDescriptionSource(
181 os.path.join(launch_dir,
'slam_launch.py')
183 condition=IfCondition(PythonExpression([slam,
' and ', use_localization])),
185 'namespace': namespace,
186 'use_sim_time': use_sim_time,
187 'autostart': autostart,
188 'use_respawn': use_respawn,
189 'params_file': params_file,
192 IncludeLaunchDescription(
193 PythonLaunchDescriptionSource(
194 os.path.join(launch_dir,
'localization_launch.py')
196 condition=IfCondition(PythonExpression([
'not ', slam,
' and ', use_localization])),
198 'namespace': namespace,
199 'map': map_yaml_file,
200 'use_sim_time': use_sim_time,
201 'autostart': autostart,
202 'params_file': params_file,
203 'use_composition': use_composition,
204 'use_intra_process_comms': use_intra_process_comms,
205 'use_respawn': use_respawn,
206 'container_name': container_name,
210 IncludeLaunchDescription(
211 PythonLaunchDescriptionSource(
212 os.path.join(launch_dir,
'keepout_zone_launch.py')
214 condition=IfCondition(use_keepout_zones),
216 'namespace': namespace,
217 'keepout_mask': keepout_mask_yaml_file,
218 'use_sim_time': use_sim_time,
219 'params_file': params_file,
220 'use_composition': use_composition,
221 'use_intra_process_comms': use_intra_process_comms,
222 'use_respawn': use_respawn,
223 'container_name': container_name,
227 IncludeLaunchDescription(
228 PythonLaunchDescriptionSource(
229 os.path.join(launch_dir,
'speed_zone_launch.py')
231 condition=IfCondition(use_speed_zones),
233 'namespace': namespace,
234 'speed_mask': speed_mask_yaml_file,
235 'use_sim_time': use_sim_time,
236 'params_file': params_file,
237 'use_composition': use_composition,
238 'use_intra_process_comms': use_intra_process_comms,
239 'use_respawn': use_respawn,
240 'container_name': container_name,
244 IncludeLaunchDescription(
245 PythonLaunchDescriptionSource(
246 os.path.join(launch_dir,
'navigation_launch.py')
249 'namespace': namespace,
250 'use_sim_time': use_sim_time,
251 'autostart': autostart,
252 'graph': graph_filepath,
253 'params_file': params_file,
254 'use_composition': use_composition,
255 'use_intra_process_comms': use_intra_process_comms,
256 'use_respawn': use_respawn,
257 'use_keepout_zones': use_keepout_zones,
258 'use_speed_zones': use_speed_zones,
259 'container_name': container_name,
266 ld = LaunchDescription()
269 ld.add_action(stdout_linebuf_envvar)
272 ld.add_action(declare_namespace_cmd)
273 ld.add_action(declare_slam_cmd)
274 ld.add_action(declare_map_yaml_cmd)
275 ld.add_action(declare_keepout_mask_yaml_cmd)
276 ld.add_action(declare_speed_mask_yaml_cmd)
277 ld.add_action(declare_graph_file_cmd)
278 ld.add_action(declare_use_sim_time_cmd)
279 ld.add_action(declare_params_file_cmd)
280 ld.add_action(declare_autostart_cmd)
281 ld.add_action(declare_use_composition_cmd)
282 ld.add_action(declare_use_intra_process_comms_cmd)
283 ld.add_action(declare_container_name_cmd)
284 ld.add_action(declare_use_respawn_cmd)
285 ld.add_action(declare_log_level_cmd)
286 ld.add_action(declare_use_localization_cmd)
287 ld.add_action(declare_use_keepout_zones_cmd)
288 ld.add_action(declare_use_speed_zones_cmd)
291 ld.add_action(bringup_cmd_group)