What is the intuition behind behavior of $(anon name) in launch file?

asked 2021-02-09 02:01:34 -0600

Framework: ROS1 Melodic using rospy
My understanding so far from reading the documentation and testing:

  • The name specified in rospy.init_node("Name1") is applied only when rosrun is used to execute the script
  • In the case of roslaunch, <node name="Name2"...> always overrides the node name specified in the script

I would like to understand the intuition behind $(anon name).
If talker.py initializes node as- rospy.init_node("Name1", anonymous=True), I can run multiple rosrun's and spawn multiple talkers.

In order to achieve similar behavior through a launch file, I tried to employ the anon tag.

  <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />
  <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />

This launch file throws the error:
roslaunch file contains multiple nodes named [/foo_Nautilu5_275_3839872632107085818]. Please check all <node> 'name' attributes to make sure they are unique. Also check that $(anon id) use different ids. The traceback for the exception was written to the log file

What is the intuition behind such behavior? Should it not serve the same purpose as multiple rosrun's?

P.S. This is my first question on this forum. I would be grateful to receive suggestions that improve the question.

  1. anonymous=True
  2. $(anon foo)
edit retag flag offensive close merge delete


FYI As stated in the tutorial you linked to,

...multiple uses of $(anon foo) will create the same "anonymized" name... (for the example you show above)... Will generate an error that there are two nodes with the same name."

Why it does that......im not sure.... I think it is meant to work by anonymizing nodes across separate launch files, but not the same launch file launching the same node twice.

JackB gravatar image JackB  ( 2021-02-09 09:10:56 -0600 )edit

Right, I understand the cause of the error. I wanted to know the intuition behind designing it this way, i.e. the second part of your comment. It seems a little strange.

trunc8 gravatar image trunc8  ( 2021-02-09 09:23:15 -0600 )edit