Wait result of a callback before executing another subscribed to same topic

asked 2023-02-22 09:52:34 -0500

Dben gravatar image

I have 2 functions, in which each has a subscriber to the same topic, and I wish to wait the result of the first one to execute the second one.

I can't make them into one function since both are loaded in different classes loaded by pluginlib dynamically.

Looking into mutexes, I found this similar question here https://stackoverflow.com/questions/6... but it does not seem to guarantee a certain order. Following this example from stackoverflow, how could I extend it to wait for this variable to be set?

PS: using humble, but seems the tag is not there yet...

edit retag flag offensive close merge delete

Comments

I am not sure I completely understand the question, that being said assuming that the first callback does some processing on top of the data you want to subscribe, why not just simply re-publish that information for the second node?

Also, taking into consideration the following statement:

I can't make them into one function since both are loaded in different classes loaded by pluginlib dynamically.

It seems to me that you are using two nodelets which communicate by sharing the address to a certain block of memory. Having said that, if you are basing your design on performance concerns, keep in mind that having one nodelet re-publishing some preprocessed data to another is completely acceptable. Such practice is commonly carried with large point clouds through the use of pcl_ros' filter nodelets.

joao.aguizo gravatar image joao.aguizo  ( 2023-02-23 11:12:37 -0500 )edit

I realized that your tag points towards a ROS2 distribution. Even though I have not had the chance to experience with it, there should be a similar mechanism: https://docs.ros.org/en/rolling/Conce....

joao.aguizo gravatar image joao.aguizo  ( 2023-02-23 12:33:08 -0500 )edit

@Dben You have provided so few details that it is impossible to suggest anything. Designing in a dependency like this is usually a bad idea - it often makes the overall system operation less robust to error conditions.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-02-25 08:04:03 -0500 )edit