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

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

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

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 image fastestindian  ( 2019-11-21 17:04:59 -0500 )edit
1

@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 image Dmitriy  ( 2019-11-22 06:26:51 -0500 )edit

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

fastestindian gravatar image fastestindian  ( 2019-11-22 06:43:25 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

fastestindian gravatar image

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

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

Comments

Hi @Dmitriy@fastestindian Would you be so kind to share one full example for launching a xacro file and running robot_state_publisher?

RodBelaFarin gravatar image RodBelaFarin  ( 2020-05-14 08:48:08 -0500 )edit

Question Tools

3 followers

Stats

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

Seen: 1,520 times

Last updated: Nov 22 '19