ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Passing array of strings as launch arguments in ROS2 python launcher

asked 2020-01-12 05:56:32 -0500

fmrico gravatar image

Dear ROS users,

I am not able to set an array of string as a launch argument in a launcher:

def generate_launch_description():
    vals = ['A', 'B']
    model_files = LaunchConfiguration('model_files', default=vals)

    declare_model_file_cmd = DeclareLaunchArgument(
      'model_files',
       default_value=vals,
       description='PDDL Model file')

    # Specify the actions
    domain_expert_cmd = Node(
      package='plansys2_domain_expert',
      node_executable='domain_expert_node',
      node_name='domain_expert',
      output='screen',
      parameters=[{'model_files': model_files}])

    ld = LaunchDescription()
    ld.add_action(declare_model_file_cmd)
    ld.add_action(domain_expert_cmd)

    return ld

In my C++ node:

    declare_parameter("model_files", std::vector<std::string>());

I receive this message:

[domain_expert_node-1] terminate called after throwing an instance of 'rclcpp::ParameterTypeException'
[domain_expert_node-1]   what():  expected [string_array] got [string]

Does anybody know how to use an array of string as a launcher argument?

Best

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-17 12:22:30 -0500

jacobperron gravatar image

The error is happening because launch substitutions like LaunchConfiguration always return a string. So, in your example, vals is being concatenated into the single string "AB", which is not the array type that your node expects. Perhaps it's more of a workaround, but you can make your Python list a string instead. I.e. vals = "['A', 'B']". The same should work from the command line as well:

ros2 launch your.launch.py model_files:="[foo, bar, baz]"
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-01-12 05:56:32 -0500

Seen: 3,704 times

Last updated: Jan 17 '20