This cannot be done with launchfiles (directly) because the order in which nodes are launched is not guaranteed.
Also, what it means for a node to have "started" is not well defined in general: is it when the OS creates the process? it starts executing? registers with the rosmaster? After it sets up publishers/subscribers?
From http://wiki.ros.org/roslaunch/XML/node:
roslaunch does not provide any guarantees about what order nodes start in. This is intentional: there is no way to externally know when a node is fully initialized, so all code that is launched must be robust to launching in any order.
You may be able to do what you want to do with the roslaunch api http://wiki.ros.org/roslaunch/API%20U...
although it is (in my opinion) usually easier and preferable to make the nodes not depend on start order.
Making the nodes not depend on startup order is really the best option and the proper ROS thing to do.
However, if you just need a quick hack to get something done (I definitely DO NOT recommend this long-term)
Write a script (wait.bash) that waits for the node to be launched (for example)
#!/usr/bin/env bash
roslaunch package with_the_dependee_nodes_that_start_first &
until rosnode list | grep "node"; do
:
done
echo "done"
Write the another launchfile that launches the dependent nodes (that start last) and in that
launchfile, also set a parameter using the script from part 1 as the command attribute:
< param name="node_start" command="$(find pkg)/scripts/wait.bash">
The parameters are guaranteed to be loaded prior to starting any nodes rhttp://wiki.ros.org/roslaunch/XML#Se....
Thus what happens is:
- The first launchfile, it tries to set the parameter node_start by running your script. It can only start the nodes
after the parameter is set (and hence after the script has completed).
- The script then runs a launchfile to start the dependee nodes and waits until they have "started"
(at least registered themselves with the rosmaster)
- Finally the main launchfile begins launching the other nodes