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 LaunchConfiguration, PythonExpression
22 from launch_ros.actions
import LoadComposableNodes, Node, PushROSNamespace, SetParameter
23 from launch_ros.descriptions
import ComposableNode, ParameterFile
27 def generate_launch_description() -> LaunchDescription:
29 bringup_dir = get_package_share_directory(
'nav2_bringup')
31 namespace = LaunchConfiguration(
'namespace')
32 keepout_mask_yaml_file = LaunchConfiguration(
'keepout_mask')
33 use_sim_time = LaunchConfigAsBool(
'use_sim_time')
34 autostart = LaunchConfigAsBool(
'autostart')
35 params_file = LaunchConfiguration(
'params_file')
36 use_composition = LaunchConfigAsBool(
'use_composition')
37 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
38 container_name = LaunchConfiguration(
'container_name')
39 container_name_full = (namespace,
'/', container_name)
40 use_respawn = LaunchConfigAsBool(
'use_respawn')
41 use_keepout_zones = LaunchConfigAsBool(
'use_keepout_zones')
42 log_level = LaunchConfiguration(
'log_level')
44 lifecycle_nodes = [
'keepout_filter_mask_server',
'keepout_costmap_filter_info_server']
47 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
49 yaml_substitutions = {
50 'KEEPOUT_ZONE_ENABLED': use_keepout_zones,
53 configured_params = ParameterFile(
55 source_file=params_file,
58 value_rewrites=yaml_substitutions,
64 stdout_linebuf_envvar = SetEnvironmentVariable(
65 'RCUTILS_LOGGING_BUFFERED_STREAM',
'1'
68 declare_namespace_cmd = DeclareLaunchArgument(
69 'namespace', default_value=
'', description=
'Top-level namespace'
72 declare_keepout_mask_yaml_cmd = DeclareLaunchArgument(
75 description=
'Full path to keepout mask yaml file to load',
78 declare_use_sim_time_cmd = DeclareLaunchArgument(
80 default_value=
'false',
81 description=
'Use simulation (Gazebo) clock if true',
84 declare_params_file_cmd = DeclareLaunchArgument(
86 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
87 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
90 declare_use_composition_cmd = DeclareLaunchArgument(
92 default_value=
'False',
93 description=
'Use composed bringup if True',
96 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
97 'use_intra_process_comms',
98 default_value=
'False',
99 description=
'Whether to use intra process communication',
102 declare_container_name_cmd = DeclareLaunchArgument(
104 default_value=
'nav2_container',
105 description=
'the name of container that nodes will load in if use composition',
108 declare_use_respawn_cmd = DeclareLaunchArgument(
110 default_value=
'False',
111 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
114 declare_use_keepout_zones_cmd = DeclareLaunchArgument(
115 'use_keepout_zones', default_value=
'True',
116 description=
'Whether to enable keepout zones or not'
119 declare_log_level_cmd = DeclareLaunchArgument(
120 'log_level', default_value=
'info', description=
'log level'
123 load_nodes = GroupAction(
124 condition=IfCondition(PythonExpression([
'not ', use_composition])),
126 PushROSNamespace(namespace),
127 SetParameter(
'use_sim_time', use_sim_time),
129 condition=IfCondition(use_keepout_zones),
130 package=
'nav2_map_server',
131 executable=
'map_server',
132 name=
'keepout_filter_mask_server',
136 parameters=[configured_params, {
'yaml_filename': keepout_mask_yaml_file}],
137 arguments=[
'--ros-args',
'--log-level', log_level],
138 remappings=remappings,
141 condition=IfCondition(use_keepout_zones),
142 package=
'nav2_map_server',
143 executable=
'costmap_filter_info_server',
144 name=
'keepout_costmap_filter_info_server',
148 parameters=[configured_params],
149 arguments=[
'--ros-args',
'--log-level', log_level],
150 remappings=remappings,
153 package=
'nav2_lifecycle_manager',
154 executable=
'lifecycle_manager',
155 name=
'lifecycle_manager_keepout_zone',
157 arguments=[
'--ros-args',
'--log-level', log_level],
160 {
'autostart': autostart}, {
'node_names': lifecycle_nodes}
170 load_composable_nodes = GroupAction(
171 condition=IfCondition(use_composition),
173 PushROSNamespace(namespace),
174 SetParameter(
'use_sim_time', use_sim_time),
176 target_container=container_name_full,
177 condition=IfCondition(use_keepout_zones),
178 composable_node_descriptions=[
180 package=
'nav2_map_server',
181 plugin=
'nav2_map_server::MapServer',
182 name=
'keepout_filter_mask_server',
185 {
'yaml_filename': keepout_mask_yaml_file}
187 remappings=remappings,
188 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
191 package=
'nav2_map_server',
192 plugin=
'nav2_map_server::CostmapFilterInfoServer',
193 name=
'keepout_costmap_filter_info_server',
194 parameters=[configured_params],
195 remappings=remappings,
196 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
202 target_container=container_name_full,
203 composable_node_descriptions=[
205 package=
'nav2_lifecycle_manager',
206 plugin=
'nav2_lifecycle_manager::LifecycleManager',
207 name=
'lifecycle_manager_keepout_zone',
210 {
'autostart': autostart,
'node_names': lifecycle_nodes}
212 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
220 ld = LaunchDescription()
223 ld.add_action(stdout_linebuf_envvar)
226 ld.add_action(declare_namespace_cmd)
227 ld.add_action(declare_keepout_mask_yaml_cmd)
228 ld.add_action(declare_use_sim_time_cmd)
229 ld.add_action(declare_params_file_cmd)
230 ld.add_action(declare_use_composition_cmd)
231 ld.add_action(declare_use_intra_process_comms_cmd)
232 ld.add_action(declare_container_name_cmd)
233 ld.add_action(declare_use_respawn_cmd)
234 ld.add_action(declare_use_keepout_zones_cmd)
235 ld.add_action(declare_log_level_cmd)
238 ld.add_action(load_nodes)
239 ld.add_action(load_composable_nodes)