Ask Your Question
0

[ROS2] Purpose of TextSubstitution

asked 2021-11-09 22:42:05 -0600

swiz23 gravatar image

In the ROS2 tutorials located at https://docs.ros.org/en/foxy/Tutorial..., the 'default_value' within the 'DeclareLaunchArgument' directive is assigned to TextSubstitution(text='0') or similar.

My question is why that is necessary. Can't you just do default_value='0'? It seems to work without the TextSubstitution directive.

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-09 23:25:20 -0600

aprotyas gravatar image

updated 2021-11-10 01:55:39 -0600

TextSubstitution is usually used to wrap literals in the launch description so they can be concatenated with other substitutions - but these substitutions must only be evaluated when the specific launch description is executed. In that context, it provides a uniform interface for all "substitutions".

https://github.com/ros2/launch/blob/b...


A partial purpose is that TextSubstitution must be constructed with a Text type, which indicates a value that contains a unicode string in a manner that is compatible with both Python 2 and Python 3 - so to work-around the differences in string handling/usage in Python2/3.

edit flag offensive delete link more

Comments

So is the purpose then to work-around the differences in string handling / usage in Python 2 and Python 3?

gvdhoorn gravatar image gvdhoorn  ( 2021-11-10 01:11:26 -0600 )edit

I'd say that's partly the reason - at least entirely the reason for there being the Text type.

More importantly, TextSubstitution is usually used to wrap literals in the launch description so they can be concatenated with other substitutions - but these substitutions must only be evaluated when the specific launch description is executed. In that context, it provides a uniform interface for all "substitutions".

https://github.com/ros2/launch/blob/b...

aprotyas gravatar image aprotyas  ( 2021-11-10 01:25:58 -0600 )edit

Seems like you should make this part of your answer proper, instead of a comment :)

The OP asks whyTextSubstitution exists and what it's used for. Your comment seems to explain that.

gvdhoorn gravatar image gvdhoorn  ( 2021-11-10 01:46:33 -0600 )edit
1

Yeah, I see how the actual "why" is in the comments. Edited to reflect that!

aprotyas gravatar image aprotyas  ( 2021-11-10 01:56:06 -0600 )edit

So if you're not planning on concatenating the LaunchArgument with something else - but just passing it to parameters within a node, there would be no need to do TextSubstitution?

swiz23 gravatar image swiz23  ( 2021-11-10 13:40:00 -0600 )edit

@swiz23 I believe so, yes. Having said that, you never know how downstream launch descriptions will try to wrap around what you have - very contrived example, but still. As such, it's probably best practice to just use Substitution types for default values.

aprotyas gravatar image aprotyas  ( 2021-11-11 00:09:33 -0600 )edit

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: 2021-11-09 22:42:05 -0600

Seen: 23 times

Last updated: Nov 10 '21