Optional list of strings as launch argument in python
How can I pass optional list of strings as parameter on python?
Here is my current test
In my launch:
my_param = LaunchConfiguration("my_param")
...
DeclareLaunchArgument(
"my_param",
default_value=[],
),
...
launch_ros.actions.Node(
package="X", executable="Y",
parameters=[
{
"my_param": my_param,
}
],
And then, in my node class:
declare_parameter(
name="my_param",
descriptor=ParameterDescriptor(
type=ParameterType.PARAMETER_STRING_ARRAY,
),
)
my_param = self.get_parameter("my_param").get_parameter_value().string_array_value
It triggers this:
rclpy.exceptions.InvalidParameterTypeException: Trying to set parameter 'my_param' to '' of type 'STRING', expecting type 'STRING_ARRAY'
It seems the variable is converted to a string somehow in the meantime.
Edit: it seems I was right https://answers.ros.org/question/341540/passing-array-of-strings-as-launch-arguments-in-ros2-python-launcher/. By passing default_value="['']", instead, and then ignoring it in my code, it works. But this is not clean...Any alternative?
Asked by Dben on 2022-10-20 11:08:28 UTC
Comments