Ask Your Question
0

ros2 concatenate string to launchargument

asked 2020-08-04 07:16:57 -0500

.zero gravatar image

updated 2020-08-06 09:53:17 -0500

Hello there,

I am trying to port an old melodic project to eloquent and was wondering on how to concatenate strings to an launch argument like so:

return LaunchDescription([
    DeclareLaunchArgument('id', default_value='75', description="an id"),
    DeclareLaunchArgument('target', default_value="robot_"+launch.substitutions.LaunchConfiguration('id')+"/target"),
    Node(
        package='wand_control',
        node_executable='wand_control',
        output='screen',
        node_name="wand_control",
        node_namespace="aq_"+launch.substitutions.LaunchConfiguration("id"),
        parameters=[{
            "target" : launch.substitutions.LaunchConfiguration('target')
        }]
    )
])

but there is an error on the line where I am trying to set the launch argument 'target':

must be str, not LaunchConfiguration

Is there a way to achieve that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-08-04 13:25:16 -0500

You can replace the string concatenation with an array, e.g.:

import launch
from launch.actions import DeclareLaunchArgument, LogInfo
from launch.substitutions import LaunchConfiguration


def generate_launch_description():
    return launch.LaunchDescription([
        DeclareLaunchArgument('id', default_value='75', description='an id'),
        DeclareLaunchArgument('target', default_value=['robot_', LaunchConfiguration('id'), '/target']),
        LogInfo(msg=LaunchConfiguration('target'))
    ])
edit flag offensive delete link more

Comments

Thank you! But why does it work that way?

.zero gravatar image .zero  ( 2020-08-06 10:24:28 -0500 )edit
1

Maybe somebody with a better understanding may be more suitable for this question.

But, the default_valueparameter is an array ( https://github.com/ros2/launch/blob/d...) and each element in the array is resolved as a substitution ( https://github.com/ros2/launch/blob/d...). Therefore, it shows that the DeclareLaunchArgument accepts a list of substitutions (or strings that are converted to substitutions).

Very often, substitutions accept a list, like PathJoinSubstitution( https://github.com/ros2/launch/blob/d...) and later it gets concatenated (https://github.com/ros2/launch/blob/d...)

lukicdarkoo gravatar image lukicdarkoo  ( 2020-08-08 09:01:33 -0500 )edit
0

answered 2020-10-01 07:47:18 -0500

atb033 gravatar image

You can do the following:

import launch
from launch.actions import DeclareLaunchArgument, LogInfo
from launch.substitutions import LaunchConfiguration


def generate_launch_description():

ld = launch.LaunchDescription()
declare_id = DeclareLaunchArgument('id', default_value='75', description='an id')
target = ['robot_', LaunchConfiguration('id'), '/target']
loginfo = LogInfo(msg = target)

ld.add_action(declare_id)
ld.add_action(loginfo)

return(ld)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-08-04 07:16:57 -0500

Seen: 56 times

Last updated: Aug 06