1
$\begingroup$

I'd like to define an argument in ROS2 launch file which is a list of tuples. How should the list in default_value be formatted?

def generate_launch_description():
   argument = LaunchConfiguration('argument', default_value=[(1, 0, 0), (0, 1, 0), (0, 0, 1)])
   node = Node(package='...', executable='...', parameters=[{'argument': argument}])
   return node, argument

Currently, I'm getting the following errors based on different formatting:

argument.default_value = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
>>> Failed to normalize given item of type '<class 'tuple'>', when only 'str' or 'launch.Substitution' were expected.

argument.default_value = ['(1, 0, 0)', '(0, 1, 0)', '(0, 0, 1)']
>>> In the node argument.value[0] is '(' whereas it should be (1, 0, 0). 
$\endgroup$
0
$\begingroup$

I found a solution which works yet is not perfect. When the argument value in the launch file is formatted as:

argument.default_value = "['(1, 0, 0)', '(0, 1, 0)', '(0, 0, 1)']"

the argument is passed to the node as:

argument.value[0]
>>> '(1, 0, 0)'

eval(argument.value[0])
>>> (1, 0, 0)

If anyone knows a way to skip eval(..) by passing Tuple directly, that'd be better.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.