Robotics StackExchange | Archived questions

Run ros2 node using launch file with delay

Let's suppose we want to have a single launch file for our project. Some of our nodes are just sensor handlers. Moreover, sensor need some time to return proper data. The idea is to put some delay before running main node to use only correct data. Does launch files design provides some way to put delay on node? Of course we can put delay directly in Node constructor or process data to wait for proper values but this functionality may be useful as a parameter in launch file.

Asked by definitive on 2021-09-24 06:46:21 UTC

Comments

Shouldn't deterministic system initialisation and startup be achieved by using managed nodes with a lifecycle? Time-based coordination doesn't really work very well. State-based will be much more reliable.

Asked by gvdhoorn on 2021-09-24 07:24:55 UTC

To re-enforce what @gvdhoorn is saying: you don't want to design a ros system with startup order dependencies. That is unreliable, and makes restarting individual nodes difficult. Almost always a node should wait to see a particular message published (e.g Sensor data or Transform Frame or some state message), so it knows it is OK to proceed.

Asked by Mike Scheutzow on 2021-09-25 10:03:27 UTC

Answers

As others have mentioned above, starting nodes in this way isn't really recommended....

However, to answer your question, you're looking for the TimerAction. It's a one-shot timer, that you can use for something like this:

from launch.actions import TimerAction
...
TimerAction(period=60.0,
            actions=[Node(...), Node(...)]),

If you're really wanting to handle this in launch, again not recommended, you could make a custom action that subscribes to you sensor data, and when it receives valid data to start a list of Actions.

Asked by ChuiV on 2021-10-12 08:38:56 UTC

Comments