Ask Your Question
1

Easier way to use the node namespace with parameters in Roslaunch/XML? [closed]

asked 2012-02-28 05:59:10 -0600

SL Remy gravatar image

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>
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by SL Remy
close date 2013-08-06 08:14:51

Comments

2

What's wrong with using the arg tag? It only adds one line per node, and can otherwise be used how you described.

Dan Lazewatsky gravatar imageDan Lazewatsky ( 2012-02-28 06:17:44 -0600 )edit

If you have deep nested groupings

SL Remy gravatar imageSL Remy ( 2012-02-28 07:16:13 -0600 )edit

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.

Dan Lazewatsky gravatar imageDan Lazewatsky ( 2012-02-28 07:25:26 -0600 )edit

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)

SL Remy gravatar imageSL Remy ( 2012-02-28 07:37:40 -0600 )edit

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.

SL Remy gravatar imageSL Remy ( 2012-02-28 07:41:08 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-03-01 18:24:07 -0600

SL Remy gravatar image

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-02-28 05:59:10 -0600

Seen: 1,639 times

Last updated: Mar 01 '12