Easier way to use the node namespace with parameters in Roslaunch/XML?
Hello again,
It would be nice to have an easy way using something like $(node_name)
in the launch file to perform the substitution to produce a parameter like: Crew12CrewCommanderKoutputfilename.txt
(see below)
Since nodes (especially those in launch files) can be grouped repeatedly, setting arguments which set parameters that keep up with the names of the nodes is a bit laborious.
It seems as even a variant of $(anon name)
, minus the second integer, would work.
Am I thinking about this the wrong way?
Is the "right" way to do this really only in ros::this_node::getName()
(with string substitutions to get rid of the slashes, and then a recompilation)?
Have I missed a tutorial covering how this ought to be done?
<group ns = "Crew1">
<node pkg="fire_department" type="Firefighter" name="A">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name" />
</node>
<node pkg="fire_department" type="Firefighter" name="B">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name" />
</node>
....
<node pkg="fire_department" type="Crew_Commander" name="K">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name" />
</node>
</group>
...
...
<group ns = "Crew15">
<node pkg="fire_department" type="Firefighter" name="A">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name" />
</node>
<node pkg="fire_department" type="Firefighter" name="B">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name" />
</node>
....
<node pkg="fire_department" type="Crew_Commander" name="K">
<!-- set a private parameter for the node -->
<param name="output_file_name" value="$(node_name)_output_file_name.txt" />
</node>
</group>
Asked by SL Remy on 2012-02-28 06:59:10 UTC
Answers
The approach that I ended up taking was to pre-pend the node's namespace to the filename provided by the private parameter, making use of n_.getNamespace()
, and not forcing this into the launchfile.
This step prevents collisions in the shared file space.
Asked by SL Remy on 2012-03-01 19:24:07 UTC
Comments
What's wrong with using the arg tag? It only adds one line per node, and can otherwise be used how you described.
Asked by Dan Lazewatsky on 2012-02-28 07:17:44 UTC
If you have deep nested groupings
Asked by SL Remy on 2012-02-28 08:16:13 UTC
I don't understand how that makes a difference. Args are global within a single launch file. Additionally, for the specific example you posted, you should consider putting params in nodes' private namespaces rather than prefixing them.
Asked by Dan Lazewatsky on 2012-02-28 08:25:26 UTC
Hi dlaz and thanks for your comment. To get the fully-qualified name of this node would require one argument per parent. For deeply nested nodes (this was only 2) this gets tedious, especially when multiple launch files are used (e.g. firefighter->crew->watch->station->group->area->brigade)
Asked by SL Remy on 2012-02-28 08:37:40 UTC
Sorry, had trouble posting. To your follow up question, the private namespace doesn't help you if you're saving files, the namespace isn't preserved in the .ros directory.
Asked by SL Remy on 2012-02-28 08:41:08 UTC