Skip to content

Commit 65c7621

Browse files
Added namespace support
1 parent 7fb82f8 commit 65c7621

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

nav2_collision_monitor/launch/collision_monitor_node.launch.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
from launch.actions import DeclareLaunchArgument, GroupAction
2323
from launch.conditions import IfCondition
2424
from launch.substitutions import LaunchConfiguration, PythonExpression
25+
from launch.substitutions import NotEqualsSubstitution
2526
from launch_ros.actions import LoadComposableNodes, SetParameter
2627
from launch_ros.actions import Node
28+
from launch_ros.actions import PushRosNamespace
2729
from launch_ros.descriptions import ComposableNode
30+
from nav2_common.launch import RewrittenYaml
2831

2932

3033
def generate_launch_description():
@@ -34,6 +37,8 @@ def generate_launch_description():
3437
# Constant parameters
3538
lifecycle_nodes = ['collision_monitor']
3639
autostart = True
40+
remappings = [('/tf', 'tf'),
41+
('/tf_static', 'tf_static')]
3742

3843
# Launch arguments
3944
# 1. Create the launch configuration variables
@@ -68,31 +73,46 @@ def generate_launch_description():
6873
'container_name', default_value='nav2_container',
6974
description='the name of conatiner that nodes will load in if use composition')
7075

76+
configured_params = RewrittenYaml(
77+
source_file=params_file,
78+
root_key=namespace,
79+
param_rewrites={},
80+
convert_types=True)
81+
82+
# Declare launch commands
7183
load_nodes = GroupAction(
7284
condition=IfCondition(PythonExpression(['not ', use_composition])),
7385
actions=[
7486
SetParameter('use_sim_time', use_sim_time),
87+
PushRosNamespace(
88+
condition=IfCondition(NotEqualsSubstitution(LaunchConfiguration('namespace'), '')),
89+
namespace=namespace),
7590
Node(
7691
package='nav2_lifecycle_manager',
7792
executable='lifecycle_manager',
7893
name='lifecycle_manager_collision_monitor',
7994
output='screen',
8095
emulate_tty=True, # https://github.com/ros2/launch/issues/188
8196
parameters=[{'autostart': autostart},
82-
{'node_names': lifecycle_nodes}]),
97+
{'node_names': lifecycle_nodes}],
98+
remappings=remappings),
8399
Node(
84100
package='nav2_collision_monitor',
85101
executable='collision_monitor',
86102
output='screen',
87103
emulate_tty=True, # https://github.com/ros2/launch/issues/188
88-
parameters=[params_file])
104+
parameters=[configured_params],
105+
remappings=remappings)
89106
]
90107
)
91108

92109
load_composable_nodes = GroupAction(
93110
condition=IfCondition(use_composition),
94111
actions=[
95112
SetParameter('use_sim_time', use_sim_time),
113+
PushRosNamespace(
114+
condition=IfCondition(NotEqualsSubstitution(LaunchConfiguration('namespace'), '')),
115+
namespace=namespace),
96116
LoadComposableNodes(
97117
target_container=container_name_full,
98118
composable_node_descriptions=[
@@ -101,12 +121,14 @@ def generate_launch_description():
101121
plugin='nav2_lifecycle_manager::LifecycleManager',
102122
name='lifecycle_manager_collision_monitor',
103123
parameters=[{'autostart': autostart},
104-
{'node_names': lifecycle_nodes}]),
124+
{'node_names': lifecycle_nodes}],
125+
remappings=remappings),
105126
ComposableNode(
106127
package='nav2_collision_monitor',
107128
plugin='nav2_collision_monitor::CollisionMonitor',
108129
name='collision_monitor',
109-
parameters=[params_file]),
130+
parameters=[configured_params],
131+
remappings=remappings)
110132
],
111133
)
112134
]

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)