Ask Your Question

# Read parameter in launch file

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:

<launch>
<arg name="folderpath" value="/folderpath" />
<node pkg="rosbag" type="record" name="record" output="screen" args="-O $(arg folderpath) /rostopic"/> </launch>  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 close merge delete ## 2 Answers Sort by » oldest newest most voted 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. <launch> <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)"/>
</include>
</launch>


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

roslaunch package_name first_launch.launch launch_second:=true

more

## Comments

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.

( 2018-07-12 09:00:16 -0500 )edit

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

( 2018-07-12 09:08:09 -0500 )edit
• 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.

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 2,110 times

Last updated: Mar 26