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

Read launch file arguments "<arg>" from another launch file

asked 2016-02-17 18:55:06 -0500

JakeBaldwin gravatar image

My understanding of the use of the <arg> tag in launch files is that args must be visible at a higher launch file layers and passed down to lower launch file layers like this:

<launch>
  <arg name="robot_height" value="0.5"/>

  <include file="$(find package)/launch/robot.launch" >
  <arg name="robot_height" value="$(arg robot_height)" />
  </include>

</launch>

What I would really like to do is read arguments from lower layers and use them in higher layers. That would make it quite a bit more flexible and useful. I could have a global configs file for instance and read it from several launch files. Is something like this possible?

An alternative I attempted was to have a launch file set a parameters on the parameter server but as far as I could tell a launch file is unable to retrieve those parameters from the parameter server. I guess that makes sense based on the fact that a launch file is processed as a whole so the timing may not coordinate very well but wouldn't that be sweet!?!?

I guess what I'm really looking for is a way to have globally accessible variables between my launch files to make configuration a breeze. Is this possible?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2016-02-17 23:02:13 -0500

ahendrix gravatar image

Sorry; you cannot do this.

roslaunch is designed with explicit interfaces (args) passed between launch files. This keeps launch files readable and makes the dependencies between them explicit and easy to follow. (these are the same reasons why using globals in C/C++ is discouraged)

A launch file must declare any arg that it uses, and the only arguments that are passed to included launch files are those explicitly passed.

Launch files can only set parameters; they cannot read them. This is because roscore (and the parameter server) is not guaranteed to be running when roslaunch is loading and processing a launch file.

If you really want global configuration values, roslaunch can read environment variables, using the $(env) and $(optenv) substitutions.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-02-17 18:55:06 -0500

Seen: 2,780 times

Last updated: Sep 15 '21