Ask Your Question
1

Use ros launch to create a directory and then pass it's path to different nodes

asked 2016-11-29 20:47:09 -0600

IDrinkArizona gravatar image

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>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-29 21:48:35 -0600

ahendrix gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-11-29 20:45:57 -0600

Seen: 625 times

Last updated: Nov 29 '16