roslaunch define args in parent launch from file or child launch [closed]

asked 2018-05-28 10:43:47 -0500

TTDM gravatar image

updated 2018-06-01 07:18:23 -0500

gvdhoorn gravatar image

Edit : deleted as almost a doublon of this , same way to solve it, used a bash script to define an environment value and then define an arg in my launch from this env variable.


Hello,

I have an automatically created configuration file that is a result from a world generation plugin in gazebo in which I define a few parameters that depend on my randomly generated world. This file is currently an xml, but i also tried a yaml and I could change to any other simple format (i'm currently creating it in the gazebo plugin).

So this is the first file :

<launch>
    <arg name="spawnX" value=" -40.0 " />
    <arg name="spawnY" value=" 0.0 " />
    <arg name="spawnZ" value=" 3.66601 " />
</launch>

and then I have a main launch file which include the following lines :

<launch>
     <include file="$(find path_to_the_previous_launch_file)"/>
      <node name="spawn_model_in_gazebo" pkg="gazebo_ros" type="spawn_model"
       args="-param robot_description
             -urdf
             -x $(arg spawnX)
             -y $(arg spawnY)
             -z $(arg spawnZ)
             -model $(arg namespace)"
       respawn="false" output="screen">
      </node>
</launch>

But it seems that when I call "include file", it only transmit args from the parent to the child (if there are some that are explicitely given as arguments) and that it is impossible to access the child arguments into the parent : when I call a roslaunch on my main file, it return "spawnX doesn't exist".

As gvdhoorn highlighted, "params" works differently, but i canno't use params here since spawn_model from gazebo_ros needs command line arguments intead of rosparams. Or as I said in my initial post : "I believe that Another possibility would be to define x y z as rosparam(=param) instead of plain command line arguments in spawn_model but since i'm using a node from the core of ros kinetic, I feel like this would have been done if it was possible on this precise case."

So in order to transmit ma data as an argument, I know that I can inverse the parent/child relationship between the 2 launch files (and explicitely detail the arguments I want to share between the 2 launch files). This would work but this wouldn't make sense since the child is only giving a few (non critical) parameters to my main launch.

Another possibility seems to use environment variables but this isnt possible here considering that, for an environement variable, to be readable by a roslaunch, it needs to be set before the launch is called (AFAIK).

I could create a configuration file with only a variable par line and a bash script should do the work calling the args in command line but it's not practical to call a bash instead of directly calling a launch file, and it wouldn't be clear at all for maintainers or simply readability for new users.

I saw this old subject which seems to imply that it is impossible to load an argument, whether the parameter comes from a child launch file or any other type of files (and ... (more)

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by gvdhoorn
close date 2018-06-01 07:18:28.183341

Comments

params are not args, so what you have there cannot work.

but does not "load the child into the parent"

this makes little sense to me. roslaunch evaluates all launch files and sets all params before starting nodes. So all parameters are available to all nodes, regardless ..

gvdhoorn gravatar image gvdhoorn  ( 2018-05-28 11:02:18 -0500 )edit

.. of where those parameters are loaded.

What you are trying to do however, is use parameters as command line arguments, but that is not supported.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-28 11:03:28 -0500 )edit

Sorry, I edited, it lacked consistency indeed, I tried both using arg and param during my tests which explain the error here. In my case, I cannot use param since spawn_model from gazebo_ros does not use rosparam but command line arguements as you quickly noticed. ...

TTDM gravatar image TTDM  ( 2018-05-28 11:57:31 -0500 )edit

Using args, it usually work, the difference from the usual working case is that I want to define the args from a file called by the launch file, instead of directly defining them ionside the launch file. I know that args are local but maybe i can define an arg from a param define elsewhere?

TTDM gravatar image TTDM  ( 2018-05-28 12:01:51 -0500 )edit