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

1 Answer

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


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

Seen: 1,834 times

Last updated: Jul 16 '18