Easier way to use the node namespace with parameters in Roslaunch/XML? [closed]
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: Crew12_Crew_Commander_K_output_file_name.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>
What's wrong with using the arg tag? It only adds one line per node, and can otherwise be used how you described.
If you have deep nested groupings
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.
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)
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.