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

Read parameter in launch file

asked 2018-07-12 05:52:51 -0600

3XTR3M3 gravatar image

updated 2018-07-16 08:36:06 -0600

Hi, I am new to ros and I am working with two launch files.

The first launch file launches a script written in cpp which sets a global parameter(creates folder with current date and time). The parameter just has the name of the folder created.

The second launch file needs to read this newly set parameter in its args tab. The second launch file is basically:

    <arg name="folderpath" value="/folderpath" />
    <node pkg="rosbag" type="record" name="record" output="screen" args="-O $(arg folderpath) /rostopic"/>

Can anyone suggest me how to do this?

P.S. Also, I can also dump the foldername to a Yaml file. Can this be read in second launch file?

Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-07-12 07:30:02 -0600

Choco93 gravatar image

updated 2018-07-12 07:30:35 -0600

You can use <include> tag to add 2nd launch file in the first one.

That way you should be able to get folder path, and you can add a conditional argument (bool), if that is set to true it will launch the second launch. Your first launch file should be something like this.

  <arg name="folder_path"    deafult="path"/>
  <arg name="launch_second" default="false"/>

  <include if="$(arg launch_second)" file="$(find package_name)/launch/second-launch.launch">
    <arg name="folderpath"  value="$(arg folder_path)"/>

and when launching the first launch file you can set launch_second to true like:

roslaunch package_name first_launch.launch launch_second:=true
edit flag offensive delete link more


Thanks for your reply. However my flow: 1) Run Launch_1 file which runs abc.cpp 2) abc.cpp calculates the parameter and then publishes it. I was able to store that temporary parameter in a yaml file too. 3) The second launch file should use the calculated parameter. So I don't think this will work.

3XTR3M3 gravatar image 3XTR3M3  ( 2018-07-12 09:00:16 -0600 )edit

Your question is ambiguous in that regard I'd say. You can take a look here then link

Choco93 gravatar image Choco93  ( 2018-07-12 09:08:09 -0600 )edit

answered 2021-03-26 14:56:21 -0600

130s gravatar image
  • If the code of the node that starts as part of the 2nd roslaunch is your custom code, then reference to the ROS Parameter from the code, assuming the Parameter name can be statically defined, say folderpath.
  • If the code is not your custom (I see in the OP that the node that starts in the 2nd launch is rosbag), then I'd say you'd have to add one new step before roslaunch executes e.g.


roslaunch 2nd.launch folderpath:=`rosparam get folderpath`

Either way, "1st laucnh" needs to start and sets the Parameter before 2nd one to start. Since roslaunch doesn't guarantee the order of nodes to start, you'd want to write a custom code to have a control over the timing to make your application robust.

edit flag offensive delete link more

Question Tools


Asked: 2018-07-12 05:52:51 -0600

Seen: 2,806 times

Last updated: Mar 26 '21