0
$\begingroup$

Rosanswers logo

At runtime (when I call roslaunch), I want to create a new subdirectory in a known directory, and pass that path to two different nodes as a rosparam.

How can I edit my .launch file to do this?

For example,I have the folder ~/datacapture. whenever I use roslaunch, I want to create a subdirectory based on the current time, (ie ~/datacacpture/20161129_1352/) and pass that into a few nodes using rosparams.

To further explain what I want to do, here is an example roslaunch file:

<launch>
  <node
    name="node_A"
    pkg="pkg_A"
    type="A"
    output="screen"
  >   
    <param name="dataDumpFolder" value="???" /> 
  </node>

  <node
    name="node_B"
    pkg="pkg_B"
    type="B"
    output="screen"
  >
    <param name="dataDumpFolder" value="???" />
  </node>
</launch>

What i want it to look like is this:

<launch>
  #1) create a new folder using current date.
  #2) pass it's filepath into a variable. let's call the variable, NEW_FOLDER_FILE_PATH

  <node
    name="node_A"
    pkg="pkg_A"
    type="A"
    output="screen"
  >   
    <param name="dataDumpFolder" value="NEW_FOLDER_FILE_PATH" />    
  </node>

  <node
    name="node_B"
    pkg="pkg_B"
    type="B"
    output="screen"
  >
    <param name="dataDumpFolder" value="NEW_FOLDER_FILE_PATH" />
  </node>
</launch>

Originally posted by IDrinkArizona on ROS Answers with karma: 11 on 2016-11-29

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You can use the command attribute to the <param> tag (documented here: http://wiki.ros.org/roslaunch/XML/param ) to run a command and set a parameter to the result.

If you have a script in my_pkg called create_directory.sh that creates the directory and prints the directory name, you can set the parameter with:

<param name="dataDumpFolder" command="$(find my_pkg)/create_directory.sh"/>

Note that your script will be called once for each <param> tag, so you probably want to make this a global parameter.


Originally posted by ahendrix with karma: 47576 on 2016-11-29

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.