Skip to content

Commit a2cd220

Browse files
Update the documentation to use composable nodes with keepout filters (ros-navigation#536)
Co-authored-by: Filipe Pinto <[email protected]>
1 parent c54b2e9 commit a2cd220

File tree

1 file changed

+91
-44
lines changed

1 file changed

+91
-44
lines changed

tutorials/docs/navigation2_with_keepout_filter.rst

+91-44
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Since filter mask image was created as a copy of main map, other fields of YAML-
8787

8888
Each costmap filter reads incoming meta-information (such as filter type or data conversion coefficients) in a messages of ``nav2_msgs/CostmapFilterInfo`` type. These messages are being published by `Costmap Filter Info Publisher Server <https://github.com/ros-planning/navigation2/tree/main/nav2_map_server/src/costmap_filter_info>`_. The server is running as a lifecycle node. According to the `design document <https://github.com/ros-planning/navigation2/blob/main/doc/design/CostmapFilters_design.pdf>`_, ``nav2_msgs/CostmapFilterInfo`` messages are going in a pair with ``OccupancyGrid`` filter mask topic. Therefore, along with Costmap Filter Info Publisher Server there should be enabled a new instance of Map Server configured to publish filter mask.
8989

90-
In order to enable Keepout Filter in your configuration, both servers should be enabled as a lifecycle nodes in Python launch-file. For example, this might look as follows, though adding them as Composition Nodes to your Navigation Component Container is also possible:
90+
In order to enable Keepout Filter in your configuration, both servers should be enabled as a lifecycle nodes in Python launch-file. It is also possible to add them as Composition Nodes to your Navigation Component Container, which might look as follows:
9191

9292
.. code-block:: python
9393
@@ -96,17 +96,20 @@ In order to enable Keepout Filter in your configuration, both servers should be
9696
from ament_index_python.packages import get_package_share_directory
9797
9898
from launch import LaunchDescription
99-
from launch.actions import DeclareLaunchArgument
100-
from launch.substitutions import LaunchConfiguration
101-
from launch_ros.actions import Node
99+
from launch.actions import DeclareLaunchArgument, GroupAction
100+
from launch.conditions import IfCondition
101+
from launch.substitutions import LaunchConfiguration, PythonExpression
102+
from launch.substitutions import NotEqualsSubstitution
103+
from launch_ros.actions import Node, LoadComposableNodes
104+
from launch_ros.actions import PushRosNamespace
105+
from launch_ros.descriptions import ComposableNode
102106
from nav2_common.launch import RewrittenYaml
103107
104108
105109
def generate_launch_description():
106110
# Get the launch directory
107111
costmap_filters_demo_dir = get_package_share_directory('nav2_costmap_filters_demo')
108112
109-
# Create our own temporary YAML files that include substitutions
110113
lifecycle_nodes = ['filter_mask_server', 'costmap_filter_info_server']
111114
112115
# Parameters
@@ -115,6 +118,9 @@ In order to enable Keepout Filter in your configuration, both servers should be
115118
autostart = LaunchConfiguration('autostart')
116119
params_file = LaunchConfiguration('params_file')
117120
mask_yaml_file = LaunchConfiguration('mask')
121+
use_composition = LaunchConfiguration('use_composition')
122+
container_name = LaunchConfiguration('container_name')
123+
container_name_full = (namespace, '/', container_name)
118124
119125
# Declare the launch arguments
120126
declare_namespace_cmd = DeclareLaunchArgument(
@@ -132,14 +138,20 @@ In order to enable Keepout Filter in your configuration, both servers should be
132138
description='Automatically startup the nav2 stack')
133139
134140
declare_params_file_cmd = DeclareLaunchArgument(
135-
'params_file',
136-
default_value=os.path.join(costmap_filters_demo_dir, 'params', 'keepout_params.yaml'),
137-
description='Full path to the ROS 2 parameters file to use')
141+
'params_file',
142+
description='Full path to the ROS2 parameters file to use')
138143
139144
declare_mask_yaml_file_cmd = DeclareLaunchArgument(
140-
'mask',
141-
default_value=os.path.join(costmap_filters_demo_dir, 'maps', 'keepout_mask.yaml'),
142-
description='Full path to filter mask yaml file to load')
145+
'mask',
146+
description='Full path to filter mask yaml file to load')
147+
148+
declare_use_composition_cmd = DeclareLaunchArgument(
149+
'use_composition', default_value='True',
150+
description='Use composed bringup if True')
151+
152+
declare_container_name_cmd = DeclareLaunchArgument(
153+
'container_name', default_value='nav2_container',
154+
description='The name of container that nodes will load in if use composition')
143155
144156
# Make re-written yaml
145157
param_substitutions = {
@@ -152,35 +164,68 @@ In order to enable Keepout Filter in your configuration, both servers should be
152164
param_rewrites=param_substitutions,
153165
convert_types=True)
154166
155-
# Nodes launching commands
156-
start_lifecycle_manager_cmd = Node(
157-
package='nav2_lifecycle_manager',
158-
executable='lifecycle_manager',
159-
name='lifecycle_manager_costmap_filters',
160-
namespace=namespace,
161-
output='screen',
162-
emulate_tty=True, # https://github.com/ros2/launch/issues/188
163-
parameters=[{'use_sim_time': use_sim_time},
164-
{'autostart': autostart},
165-
{'node_names': lifecycle_nodes}])
166-
167-
start_map_server_cmd = Node(
168-
package='nav2_map_server',
169-
executable='map_server',
170-
name='filter_mask_server',
171-
namespace=namespace,
172-
output='screen',
173-
emulate_tty=True, # https://github.com/ros2/launch/issues/188
174-
parameters=[configured_params])
175-
176-
start_costmap_filter_info_server_cmd = Node(
177-
package='nav2_map_server',
178-
executable='costmap_filter_info_server',
179-
name='costmap_filter_info_server',
180-
namespace=namespace,
181-
output='screen',
182-
emulate_tty=True, # https://github.com/ros2/launch/issues/188
183-
parameters=[configured_params])
167+
load_nodes = GroupAction(
168+
condition=IfCondition(PythonExpression(['not ', use_composition])),
169+
actions=[
170+
Node(
171+
package='nav2_map_server',
172+
executable='map_server',
173+
name='filter_mask_server',
174+
namespace=namespace,
175+
output='screen',
176+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
177+
parameters=[configured_params]),
178+
Node(
179+
package='nav2_map_server',
180+
executable='costmap_filter_info_server',
181+
name='costmap_filter_info_server',
182+
namespace=namespace,
183+
output='screen',
184+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
185+
parameters=[configured_params]),
186+
Node(
187+
package='nav2_lifecycle_manager',
188+
executable='lifecycle_manager',
189+
name='lifecycle_manager_costmap_filters',
190+
namespace=namespace,
191+
output='screen',
192+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
193+
parameters=[{'use_sim_time': use_sim_time},
194+
{'autostart': autostart},
195+
{'node_names': lifecycle_nodes}])
196+
]
197+
)
198+
199+
load_composable_nodes = GroupAction(
200+
condition=IfCondition(use_composition),
201+
actions=[
202+
PushRosNamespace(
203+
condition=IfCondition(NotEqualsSubstitution(LaunchConfiguration('namespace'), '')),
204+
namespace=namespace),
205+
LoadComposableNodes(
206+
target_container=container_name_full,
207+
composable_node_descriptions=[
208+
ComposableNode(
209+
package='nav2_map_server',
210+
plugin='nav2_map_server::MapServer',
211+
name='filter_mask_server',
212+
parameters=[configured_params]),
213+
ComposableNode(
214+
package='nav2_map_server',
215+
plugin='nav2_map_server::CostmapFilterInfoServer',
216+
name='costmap_filter_info_server',
217+
parameters=[configured_params]),
218+
ComposableNode(
219+
package='nav2_lifecycle_manager',
220+
plugin='nav2_lifecycle_manager::LifecycleManager',
221+
name='lifecycle_manager_costmap_filters',
222+
parameters=[{'use_sim_time': use_sim_time},
223+
{'autostart': autostart},
224+
{'node_names': lifecycle_nodes}]),
225+
]
226+
)
227+
]
228+
)
184229
185230
ld = LaunchDescription()
186231
@@ -190,9 +235,11 @@ In order to enable Keepout Filter in your configuration, both servers should be
190235
ld.add_action(declare_params_file_cmd)
191236
ld.add_action(declare_mask_yaml_file_cmd)
192237
193-
ld.add_action(start_lifecycle_manager_cmd)
194-
ld.add_action(start_map_server_cmd)
195-
ld.add_action(start_costmap_filter_info_server_cmd)
238+
ld.add_action(declare_use_composition_cmd)
239+
ld.add_action(declare_container_name_cmd)
240+
241+
ld.add_action(load_nodes)
242+
ld.add_action(load_composable_nodes)
196243
197244
return ld
198245
@@ -231,7 +278,7 @@ Ready-to-go standalone Python launch-script, YAML-file with ROS parameters and f
231278
$ cd ~/tutorials_ws
232279
$ colcon build --symlink-install --packages-select nav2_costmap_filters_demo
233280
$ source ~/tutorials_ws/install/setup.bash
234-
$ ros2 launch nav2_costmap_filters_demo costmap_filter_info.launch.py params_file:=src/navigation2_tutorials/nav2_costmap_filters_demo/params/keepout_params.yaml mask:=src/navigation2_tutorials/nav2_costmap_filters_demo/maps/keepout_mask.yaml
281+
$ ros2 launch nav2_costmap_filters_demo costmap_filter_info.launch.py params_file:=`pwd`/src/navigation2_tutorials/nav2_costmap_filters_demo/params/keepout_params.yaml mask:=`pwd`/src/navigation2_tutorials/nav2_costmap_filters_demo/maps/keepout_mask.yaml use_composition:=True
235282
236283
3. Enable Keepout Filter
237284
------------------------

0 commit comments

Comments
 (0)