ros2 optionally launch node with no arguments
I have a node that takes zero or one argument. I want to use ros2 launch arguments to pass either zero or one argument to the the launch file which will then get passed down to the node. I'm having a bit of trouble with the 'zero' argument case.
LaunchDescription([
launch.actions.DeclareLaunchArgument(
"my_param",
default_value=[""], # default_value=[], has the same problem
description="optional parameter"
),
launch_ros.actions.Node(
package="my_package",
node_executable="my_node",
arguments=[launch.substitutions.LaunchConfiguration("my_param")]
),
])
When I do this, I can run my launch file with my_param:=foo
and foo
will get passed down to my node. No problem
When I run my launch file without any arguments, my_node still behaves like it got a positional argument - a single empty string. This is not how I intended to launch the node.
What do I need to do to make my_node behave like it got no arguments when I don't pass any arguments to launch?
The current behavior makes sense - the LaunchConfiguration substitution is getting resolved to an empty string and is getting put into the node's arguments array. What I need is a way to substitute the whole 'arguments' list passed to the node instead of substituting a single element in the list, but the Node object really wants a list of substitutions