Skip to content

Commit f14b6a2

Browse files
Add ros_arguments option to Node action (#249)
Signed-off-by: Christophe Bedard <[email protected]>
1 parent 58334b4 commit f14b6a2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

launch_ros/launch_ros/actions/node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(
125125
exec_name: Optional[SomeSubstitutionsType] = None,
126126
parameters: Optional[SomeParameters] = None,
127127
remappings: Optional[SomeRemapRules] = None,
128+
ros_arguments: Optional[Iterable[SomeSubstitutionsType]] = None,
128129
arguments: Optional[Iterable[SomeSubstitutionsType]] = None,
129130
**kwargs
130131
) -> None:
@@ -180,6 +181,9 @@ def __init__(
180181
wildcard namespace (`/**`) and other specific parameter declarations
181182
may overwrite it.
182183
184+
Using `ros_arguments` is equivalent to using `arguments` with a
185+
prepended '--ros-args' item.
186+
183187
:param: executable the name of the executable to find if a package
184188
is provided or otherwise a path to the executable to run.
185189
:param: package the package in which the node executable can be found
@@ -191,13 +195,15 @@ def __init__(
191195
or dictionaries of parameters.
192196
:param: remappings ordered list of 'to' and 'from' string pairs to be
193197
passed to the node as ROS remapping rules
198+
:param: ros_arguments list of ROS arguments for the node
194199
:param: arguments list of extra arguments for the node
195200
"""
196201
if package is not None:
197202
cmd = [ExecutableInPackage(package=package, executable=executable)]
198203
else:
199204
cmd = [executable]
200205
cmd += [] if arguments is None else arguments
206+
cmd += [] if ros_arguments is None else ['--ros-args'] + ros_arguments
201207
# Reserve space for ros specific arguments.
202208
# The substitutions will get expanded when the action is executed.
203209
cmd += ['--ros-args'] # Prepend ros specific arguments with --ros-args flag
@@ -218,6 +224,7 @@ def __init__(
218224
self.__node_namespace = namespace
219225
self.__parameters = [] if parameters is None else normalized_params
220226
self.__remappings = [] if remappings is None else list(normalize_remap_rules(remappings))
227+
self.__ros_arguments = ros_arguments
221228
self.__arguments = arguments
222229

223230
self.__expanded_node_name = self.UNSPECIFIED_NODE_NAME

test_launch_ros/test/test_launch_ros/actions/test_node.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ def _assert_launch_no_errors(self, actions):
4747
ls.include_launch_description(ld)
4848
assert 0 == ls.run()
4949

50-
def _create_node(self, *, parameters=None, remappings=None):
50+
def _create_node(self, *, parameters=None, remappings=None, ros_arguments=None):
5151
return launch_ros.actions.Node(
5252
package='demo_nodes_py', executable='talker_qos', output='screen',
5353
name='my_node', namespace='my_ns',
5454
exec_name='my_node_process',
55+
ros_arguments=ros_arguments,
5556
arguments=['--number_of_cycles', '1'],
5657
parameters=parameters,
5758
remappings=remappings,
@@ -92,6 +93,13 @@ def test_launch_node_with_remappings(self):
9293
for i in range(2):
9394
assert expanded_remappings[i] == ('chatter', 'new_chatter')
9495

96+
def test_launch_node_with_ros_arguments(self):
97+
node_action = self._create_node(ros_arguments=['--log-level', 'debug'])
98+
self._assert_launch_no_errors([node_action])
99+
100+
cmd_string = ' '.join(node_action.process_details['cmd'])
101+
assert '--ros-args --log-level debug' in cmd_string
102+
95103
def test_launch_required_node(self):
96104
# This node will never exit on its own, it'll keep publishing forever.
97105
long_running_node = launch_ros.actions.Node(

0 commit comments

Comments
 (0)