ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to override a parameter in an anonymous node?

asked 2012-10-17 00:36:36 -0500

Benoit Larochelle gravatar image

updated 2012-10-22 04:55:28 -0500

I created an Operator Control Unit (OCU) that works with heterogeneous robots. During exercises, several operators (each at one computer) launch the OCU with different parameters depending on the robots that they control. Therefore, each instance must use an anonymous node name.

So far, I have several launch files that all contain all parameters. I'm trying to organize them better to have a set of default parameters and values, and specific launch files would only change some values and define extra parameters when required.

My first idea was to create a base launch file that all other launch files would include. The problem that I observe is that the original parameter name is /ocu_long_anon_name/foo but the override is only /foo.

I looked at these two pages, but I cannot find information about this special case (anonymous overrides): http://ros.org/wiki/roslaunch/Tutorials/Roslaunch%20tips%20for%20larger%20projects and http://ros.org/wiki/roslaunch/XML.

I tried the following:

There is first a base launch file:

<!-- ocu_base.launch -->
<launch>

    <node name="$(anon ocu)" pkg="ocu" type="OCU" output="screen">

        <param name="foo" value="not bar"/>

    </node>

</launch>

And this:

<!-- ocu_ugv.launch -->
<launch> 

    <!-- Launches the OCU with default parameters -->
    <include file="$(find ocu)/launchers/ocu_base.launch">
        <param name="fooEMBEDDED" value="bar"/>
    </include>

    <param name="fooNORMAL" value="bar"/>
    <param name="$(anon ocu)/fooANON" value="bar"/>

</launch>

The results are the following:

fooEMBEDDED does not appear as a parameter at all

fooNORMAL comes out as /fooNormal

fooANON comes out as /ocu_different_long_anon_name/fooANON

So in the end, my original parameter is not overridden. :-(

The roslaunch documentation says that calling $(anon ocu) multiple times would yield the same result, but now I'm doing it from different launch files, and I get different anonymous names.

I'm not sure if I'm not doing it properly, or if it's even possible with roslaunch. Could arguments help in this situation? I don't need a specific solution, but rather one that makes it easy to create and maintain many launch files with many parameters.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-10-19 03:49:59 -0500

Benoit Larochelle gravatar image

updated 2012-10-22 03:07:15 -0500

Solution #1

A partially working solution for my particular case is to put default parameters in a yaml file, and include this file from all launch files. I have no more launch file hierarchy: they all launch the OCU directly. However, each launch file overrides the appropriate parameters and adds new ones. I get such a structure:

<!-- This launch file is used for the UAV -->

<launch>

<node name="$(anon ocu)" pkg="ocu" type="OCU" output="screen">

    <!-- Loads the OCU default parameters -->

    <rosparam command="load" file="$(find ocu)/launchers/ocu.yaml"/>

    <!-- Redefines and adds parameters -->

    <param name="showUAVCams" value="true"/>
    <param name="show3DMap" type="bool" value="true"/>
    <param name="robotType" type="string" value="UAV"/>

    <!-- These ones are necessary until they are placed in the yaml file -->
    <param name="ugv3DModelDescription" textfile="$(find ocu)/media/robot_model/NIFTi.urdf" />
    <param name="folderNameForSnapshots" value="$(find ocu)/snapshots" />

</node>

</launch>

As you can see, it does not yet completely work because my parameters with commands cannot be directly interpreted in the yaml file.

Solution #2

Another partially working solution is to create a homologous argument for each parameter.

There is first a base launch file:

<!-- ocu_base.launch -->
<launch>

    <!-- Here all arguments must be declared and their default values given -->
    <arg name="_imageTransportMode" default="theora"/>
    <arg name="_showArmControlPanel" default="false"/>
    <arg name="_robotType" default="UGV"/>
    <arg name="_ugv3DModelDescription" default="" />
    ...

    <node name="$(anon ocu)" pkg="ocu" type="OCU" output="screen">

        <!-- Here I map the parameters to take the values of the arguments -->
        <param name="imageTransportMode" type="string" value="$(arg _imageTransportMode)"/>
        <param name="showArmControlPanel" type="bool" value="$(arg _showArmControlPanel)"/>
        <param name="robotType" type="string" value="$(arg _robotType)"/>   
        <param name="ugv3DModelDescription" textfile="$(arg _ugv3DModelDescription)" />
        ...

    </node>

</launch>

And several robot-specific launch files:

<!-- ocu_uav.launch -->
<launch>

<!-- Launches the OCU with default parameters -->
<include file="$(find ocu)/launchers/ocu_base.launch">

        <arg name="_imageTransportMode" value="raw"/> 
        <arg name="_robotType" value="UAV"/>    

</include>

</launch>

The problem that I still have is that not all parameters are necessary in all robot-specific files. For example, in the case of the UAV, we do not have a URDF robot model. With standard parameters, I would simply not include the parameter ugv3DModelDescription at all. With arguments, I MUST give a value. I tried giving a blank string as the default argument, but then the parameter ugv3DModelDescription tries to load the text file "blank" and roslaunch fails.

edit flag offensive delete link more

Comments

I don't feel like this really answers the original question of overriding a parameter in an anonymous node (namespace) though.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-19 03:52:36 -0500 )edit

The solution I posted in my answer should cover this use case. If the value isn't set in the yaml for that parameter set, it shouldn't be set on the server.

dornhege gravatar image dornhege  ( 2012-10-22 04:07:01 -0500 )edit

I must not understand your answer correctly, because it does not seem like it would cover this case. If the value isn't set in the yaml file, then of course no robot_description parameter would exist. But how do I set one from ocu_ugv.launch, for example?

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-22 04:31:22 -0500 )edit

When I try, it goes into a different anonymous namespace, hence my question. How do I override/set a parameter in a node with an anonymous name?

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-22 04:32:32 -0500 )edit

I edited the problem description to make it clearer

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-22 04:49:49 -0500 )edit

If you want a yaml file, use my solution (they can have different param sets). If you want to set them manually, your 2nd solution should work. To exclude some from being set, you can use the "unless" attribute, although, you will need to set the default value to "false" or "0".

dornhege gravatar image dornhege  ( 2012-10-22 06:06:34 -0500 )edit

I'm sorry but I don't see how different param sets have anything to do with this question. I need just one set of default parameters, and specific launch files should override only what they need. I don't care if I use a yaml file or not, I just want a solution that works.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-22 21:31:58 -0500 )edit

I also do not understand how "unless" would help. The base launch file should always define the default set of parameters, irregardless of the hardware. Then the specific launch files should always define the parameters specific to the hardware.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-22 21:34:19 -0500 )edit
1

answered 2012-10-17 01:53:30 -0500

dornhege gravatar image

updated 2012-10-22 00:40:11 -0500

I'm not exactly sure, what you want to do, but I think using args should solve your problem.

Set the parameter in the base launch file to an arg that is passed in and then when launching multiple anonymous launches, you set the arg for the include (like you tried with param).

Update: I'm assuming you want to do the following:

  • There should only be one launch file for your node launching it anonymously
  • There is some other launch file that uses this launch file to launch multiple nodes
  • There are different sets of private parameters for this node that should be used

Given that is what you want, I'd suggest the following: ocu_base.launch:

<arg name="param_set" />

<node ...>
   <rosparam command="load" textfile="$(find ocu)/config/$(arg param_set).yaml">
</node>

main.launch:

<include file=...ocu_base.launch">
   <arg name="param_set" value="set1" />
</include>
<include file=...ocu_base.launch">
   <arg name="param_set" value="set2" />
</include>
...
edit flag offensive delete link more

Comments

What I'm trying to do is to override a parameter that was already defined in a node that has an anonymous name. I have now tried several options, but nothing worked perfectly.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-19 03:41:41 -0500 )edit

Arguments did not work because they do not have the attributes "textfile" and "command" and therefore I could not override with what I needed.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-19 03:42:25 -0500 )edit

You can reuse the args when loading the parameters (see updated answer).

dornhege gravatar image dornhege  ( 2012-10-19 04:48:46 -0500 )edit

The problem that I have with arguments is that they do not have the attributes "textfile" and "command". For example, how would I deal with this: <include file=...ocu_base.launch"> <arg name="robot_description" textfile="$(find ocu)/models/robot1.urdf" /> </include>

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-21 21:31:48 -0500 )edit

Use value= instead of textfile= and then reuse the passed in arg for robot_description in the ocu_base.launch to load the parameter using the normal rosparam command.

dornhege gravatar image dornhege  ( 2012-10-22 00:39:30 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2012-10-17 00:36:36 -0500

Seen: 2,226 times

Last updated: Oct 22 '12