Setting delay between nodes in a launch file

asked 2019-05-09 02:21:14 -0600

Jan Tromp gravatar image

Hello everybody.

I am working on a project where i have 2 USB devices connected to my pc. The manufacturer provided the ros nodes to make a connection with the devices.

Now, the problem is: When i start both nodes in a launch file, one of them fails and gives me this message:

serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

I already found a way to fix this: i have to start node 1, wait for it to start up, which takes about 2 or 3 seconds, then start the second node. Now i've looked around and noticed there is not really a standard way to add a 'delay' or a 'sleep' in a launch file. I came across this question: Here they made a workaround for this issue, but this is from 3 years ago.

I wonder there is a better/cleaner way to do this three years after that solution.

So i'm looking for this:

<node name="node1" type="node1" pkg="pkg1"/>

delay of 3 seconds

<node name="node2" type="node2" pkg="pkg2"/>

Note: node 1 is in c++ and node 2 in python, don't know if this will make a difference.

Kind regards, Jan Tromp

I am working with: ros kinetic Ubuntu 16.04

edit retag flag offensive close merge delete


Did you see the other 2 answers (not the accepted one) to the question you linked? Especially the one by kushlik. Other than that you could put a waitForService/waitFor<something_that_loads_up_in_node_1_and_signals_its_readiness> in the constructor of node 2 before that exception is triggered.

aPonza gravatar image aPonza  ( 2019-05-09 04:36:21 -0600 )edit

Time-based control flow is definitely something that is possible, but I'm not sure why two nodes, communicating with different USB devices would have to be started in a staggered manner to avoid serial problems.

If they're not sharing devices, wouldn't the fact that you can't start them simultaneously point to an implementation problem in those nodes (ie: a bug or incorrect design)?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-09 04:58:35 -0600 )edit