[ROS2] Is there a better way to mix LaunchConfiguration with simple 'str'?
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?
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.
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 There are different packages
launch.substitution
andlaunch.substitutions
. The latter is the one you need: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:List of substantiations is considered as substantiation itself. Put this wherever you want to use string with LaunchConfiguration and replace
/
withos.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 thanks a lot! Works beautifully. I'll close the answer with due credits.