0
$\begingroup$

Rosanswers logo

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


Originally posted by fmrico on ROS Answers with karma: 85 on 2020-01-12

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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]"

Originally posted by jacobperron with karma: 1870 on 2020-01-17

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.