Ask Your Question
0

[ROS2] Is there a better way to mix LaunchConfiguration with simple 'str'?

asked 2019-10-01 07:41:06 -0600

Dmitriy gravatar image

Hi. This is how I launch xacro right now:

    xacro = Node(
        package='xacro',
        node_executable='xacro',
        node_namespace=LaunchConfiguration(args.MODEL_NAME_ARG),
        arguments=[
            [
                launch.substitutions.TextSubstitution(
                    text=get_package_share_directory('robot_description') + '/models/'),
                LaunchConfiguration(args.MODEL_ARG),
                launch.substitutions.TextSubstitution(text='/'),
                LaunchConfiguration(args.MODEL_ARG),
                launch.substitutions.TextSubstitution(text='.xacro'),
            ],
            '-o',
            urdf,
        ],
)

Resulting path looks like ./install/robot_description/share/robot_description/models/my_model/my_model.xacro. Not related to just xacro, is there a human readable better way to do such substitution?

edit retag flag offensive close merge delete

Comments

Hi @Dmitriy, did you manage to find a way around this? I cant find a way to substitute the value of the argument as a string.

 DeclareLaunchArgument(
        'urdf',
        default_value='file.urdf',
        description='urdf file name')

 urdf_path =os.path.join(get_package_share_directory('robot_bringup'), 'urdf',
                            LaunchConfiguration('urdf'))

https://answers.ros.org/question/3226...

I tried the suggestion there "The launch argument's value is stored in the "Launch Configurations", and those can be accessed using a substitution called launch.substitution.LaunchConfiguration(name) -> string" but LaunchConfiguration doesnt seem to be a member of launch.substitution in Dashing.

fastestindian gravatar imagefastestindian ( 2019-11-21 17:04:59 -0600 )edit

@fastestindian There are different packages launch.substitution and launch.substitutions. The latter is the one you need:

from launch.substitutions import LaunchConfiguration

I guess there is a typo in the answer you mention.


Note you cannot use os.path.join until LaunchConfiguration will be substantiated, i.e. will have context of the actual launch. This is my original problem. :( Substantiation can be accessed only from other substantiations. Resulting pattern I came to:

[
    get_package_share_directory('robot_bringup'),
    '/urdf/',
    LaunchConfiguration('urdf'),
]

List of substantiations is considered as substantiation itself. Put this wherever you want to use string with LaunchConfiguration and replace / with os.path.sep if you still want to. Values in list are merged without any spaces or other symbols and you may use either LaunchConfiguration, strings or another launch.substantions as list members.

Dmitriy gravatar imageDmitriy ( 2019-11-22 06:26:51 -0600 )edit

@Dmitriy thanks a lot! Works beautifully. I'll close the answer with due credits.

fastestindian gravatar imagefastestindian ( 2019-11-22 06:43:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-11-22 06:46:51 -0600

fastestindian gravatar image

updated 2019-11-22 06:47:13 -0600

Fix by @Dmitriy integrated into my launch script.

def generate_launch_description():

   return launch.LaunchDescription([

    DeclareLaunchArgument(
        'urdf',
        default_value='file.urdf',
        description='urdf file name'),

    launch_ros.actions.Node(
            package="robot_state_publisher", node_executable="robot_state_publisher", node_name="state_publisher",
            output="screen",
            arguments=[[get_package_share_directory('robot_bringup'), '/urdf/', LaunchConfiguration('urdf') ]]),

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

2 followers

Stats

Asked: 2019-10-01 07:41:06 -0600

Seen: 75 times

Last updated: Nov 22 '19