Skip to content

Commit cfb38d9

Browse files
AlexeyMerzlyakovenricosutera
authored andcommitted
Refactor sim_time and composable node usage in Collision Monitor (ros-navigation#3604)
* Refactor sim_time and composable node usage in Collision Monitor launch script * Added namespace support * Fix comment Signed-off-by: enricosutera <[email protected]>
1 parent 3c0476d commit cfb38d9

File tree

2 files changed

+79
-26
lines changed

2 files changed

+79
-26
lines changed

nav2_collision_monitor/launch/collision_monitor_node.launch.py

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
from ament_index_python.packages import get_package_share_directory
2020

2121
from launch import LaunchDescription
22-
from launch.actions import DeclareLaunchArgument
23-
from launch.substitutions import LaunchConfiguration
22+
from launch.actions import DeclareLaunchArgument, GroupAction
23+
from launch.conditions import IfCondition
24+
from launch.substitutions import LaunchConfiguration, PythonExpression
25+
from launch.substitutions import NotEqualsSubstitution
26+
from launch_ros.actions import LoadComposableNodes, SetParameter
2427
from launch_ros.actions import Node
28+
from launch_ros.actions import PushRosNamespace
29+
from launch_ros.descriptions import ComposableNode
2530
from nav2_common.launch import RewrittenYaml
2631

2732

@@ -32,12 +37,17 @@ def generate_launch_description():
3237
# Constant parameters
3338
lifecycle_nodes = ['collision_monitor']
3439
autostart = True
40+
remappings = [('/tf', 'tf'),
41+
('/tf_static', 'tf_static')]
3542

3643
# Launch arguments
3744
# 1. Create the launch configuration variables
3845
namespace = LaunchConfiguration('namespace')
3946
use_sim_time = LaunchConfiguration('use_sim_time')
4047
params_file = LaunchConfiguration('params_file')
48+
use_composition = LaunchConfiguration('use_composition')
49+
container_name = LaunchConfiguration('container_name')
50+
container_name_full = (namespace, '/', container_name)
4151

4252
# 2. Declare the launch arguments
4353
declare_namespace_cmd = DeclareLaunchArgument(
@@ -55,43 +65,86 @@ def generate_launch_description():
5565
default_value=os.path.join(package_dir, 'params', 'collision_monitor_params.yaml'),
5666
description='Full path to the ROS2 parameters file to use for all launched nodes')
5767

58-
# Create our own temporary YAML files that include substitutions
59-
param_substitutions = {
60-
'use_sim_time': use_sim_time}
68+
declare_use_composition_cmd = DeclareLaunchArgument(
69+
'use_composition', default_value='True',
70+
description='Use composed bringup if True')
71+
72+
declare_container_name_cmd = DeclareLaunchArgument(
73+
'container_name', default_value='nav2_container',
74+
description='the name of conatiner that nodes will load in if use composition')
6175

6276
configured_params = RewrittenYaml(
6377
source_file=params_file,
6478
root_key=namespace,
65-
param_rewrites=param_substitutions,
79+
param_rewrites={},
6680
convert_types=True)
6781

68-
# Nodes launching commands
69-
start_lifecycle_manager_cmd = Node(
70-
package='nav2_lifecycle_manager',
71-
executable='lifecycle_manager',
72-
name='lifecycle_manager',
73-
output='screen',
74-
emulate_tty=True, # https://github.com/ros2/launch/issues/188
75-
parameters=[{'use_sim_time': use_sim_time},
76-
{'autostart': autostart},
77-
{'node_names': lifecycle_nodes}])
78-
79-
start_collision_monitor_cmd = Node(
80-
package='nav2_collision_monitor',
81-
executable='collision_monitor',
82-
output='screen',
83-
emulate_tty=True, # https://github.com/ros2/launch/issues/188
84-
parameters=[configured_params])
82+
# Declare node launching commands
83+
load_nodes = GroupAction(
84+
condition=IfCondition(PythonExpression(['not ', use_composition])),
85+
actions=[
86+
SetParameter('use_sim_time', use_sim_time),
87+
PushRosNamespace(
88+
condition=IfCondition(NotEqualsSubstitution(LaunchConfiguration('namespace'), '')),
89+
namespace=namespace),
90+
Node(
91+
package='nav2_lifecycle_manager',
92+
executable='lifecycle_manager',
93+
name='lifecycle_manager_collision_monitor',
94+
output='screen',
95+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
96+
parameters=[{'autostart': autostart},
97+
{'node_names': lifecycle_nodes}],
98+
remappings=remappings),
99+
Node(
100+
package='nav2_collision_monitor',
101+
executable='collision_monitor',
102+
output='screen',
103+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
104+
parameters=[configured_params],
105+
remappings=remappings)
106+
]
107+
)
108+
109+
load_composable_nodes = GroupAction(
110+
condition=IfCondition(use_composition),
111+
actions=[
112+
SetParameter('use_sim_time', use_sim_time),
113+
PushRosNamespace(
114+
condition=IfCondition(NotEqualsSubstitution(LaunchConfiguration('namespace'), '')),
115+
namespace=namespace),
116+
LoadComposableNodes(
117+
target_container=container_name_full,
118+
composable_node_descriptions=[
119+
ComposableNode(
120+
package='nav2_lifecycle_manager',
121+
plugin='nav2_lifecycle_manager::LifecycleManager',
122+
name='lifecycle_manager_collision_monitor',
123+
parameters=[{'autostart': autostart},
124+
{'node_names': lifecycle_nodes}],
125+
remappings=remappings),
126+
ComposableNode(
127+
package='nav2_collision_monitor',
128+
plugin='nav2_collision_monitor::CollisionMonitor',
129+
name='collision_monitor',
130+
parameters=[configured_params],
131+
remappings=remappings)
132+
],
133+
)
134+
]
135+
)
85136

86137
ld = LaunchDescription()
87138

88139
# Launch arguments
89140
ld.add_action(declare_namespace_cmd)
90141
ld.add_action(declare_use_sim_time_cmd)
91142
ld.add_action(declare_params_file_cmd)
143+
ld.add_action(declare_use_composition_cmd)
144+
ld.add_action(declare_container_name_cmd)
92145

93146
# Node launching commands
94-
ld.add_action(start_lifecycle_manager_cmd)
95-
ld.add_action(start_collision_monitor_cmd)
147+
ld.add_action(load_nodes)
148+
ld.add_action(load_composable_nodes)
96149

97150
return ld

nav2_collision_monitor/params/collision_monitor_params.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ collision_monitor:
5050
observation_sources: ["scan"]
5151
scan:
5252
type: "scan"
53-
topic: "/scan"
53+
topic: "scan"
5454
pointcloud:
5555
type: "pointcloud"
5656
topic: "/intel_realsense_r200_depth/points"

0 commit comments

Comments
 (0)