ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Is there a way to wait for certain topics to be published in a launchfile?

asked 2011-12-13 03:44:33 -0600

tom gravatar image

I'd like to run several nodes within one launchfile. The system only works properly provided necessary topics are published before some nodes are launched.

Is there a way to ensure a node is running before other node is started? Or, even better, to ensure a tf or topic are published before a node gets triggered within a launchfile?

I guess, even if not with ROS, this could be possible with bash scripts. Has anyone out there already provided such functionality?


edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted

answered 2011-12-13 03:47:48 -0600

dornhege gravatar image

updated 2011-12-13 03:48:10 -0600

AFAIK, the short answer is: No. You cannot even control the order nodes are started.

The better way should be that the nodes that are held back provide such functionality themselves, e.g. using a tf waitForTransform call.

edit flag offensive delete link more


Thanks. But what if I'd like to delay an existing node's execution? Is there a tool for that? One way would be to write a bash script calling a simple node blocking until tf is there and then executing the node of interest. Or maybe you see another, simple hack?
tom gravatar image tom  ( 2011-12-13 04:06:48 -0600 )edit
Do you want to delay it constantly or until tf is there. For tf use tf waitForTransform in the node. For a constant time it depends why you'd want to do that. You can use a bash script with a sleep, or sleep in the node at first (if that is a feature this node needs).
dornhege gravatar image dornhege  ( 2011-12-13 04:13:25 -0600 )edit
I first run an IMU basing on ros_serial. This takes a couple of seconds. I cannot run any other (already existing and I wouldn't like to change any working code not of my own) nodes before that happens. There is a similar issue between laser_scan_matcher and gmapping - the first must run before.
tom gravatar image tom  ( 2011-12-13 05:23:29 -0600 )edit
Best practice is for each node to wait for any transforms or topics it needs before entering its main loop. They should all work correctly independent of the launch order.
joq gravatar image joq  ( 2011-12-14 02:35:17 -0600 )edit
@tom: If there is a ROS node that doesn't behave nicely like it should, you can open an issue or new question about that. (Of course if the data is missing altogether some nodes might not work, at least until all data is available)
dornhege gravatar image dornhege  ( 2011-12-16 01:51:02 -0600 )edit

answered 2011-12-13 04:29:59 -0600

Mac gravatar image

You can also block waiting for services to be available; the nodes that Must Come Up First No Matter What could provide some dummy service, and the nodes that Must Come Up Second No Matter What could block waiting for that service to exist; that way, they don't start processing until the first ones are up.

edit flag offensive delete link more

answered 2014-04-24 02:36:15 -0600

koenlek gravatar image

I have figured out a way to do it. I build a script that nicely enables you to delay parts of your launch file. See my answer here, which includes clear instructions and the script:

edit flag offensive delete link more

answered 2018-01-08 22:06:04 -0600

P3TE_ gravatar image

I experienced a similar issue. I would find that if I run all the nodes at once on boot, most of the time, one of the stereo cameras would not work. To fix this, I've created a number of scripts to stagger the launch based on what topics are running and made a public repository for anyone to use:

Take a look at the for more information.

edit flag offensive delete link more

answered 2017-07-18 07:47:34 -0600

Maverobot gravatar image

Maybe this powerful yet simple tool -- expect -- can help you to manage launch files.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2011-12-13 03:44:33 -0600

Seen: 8,080 times

Last updated: Apr 24 '14