Robotics StackExchange | Archived questions

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

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/64018377/avoiding-data-race-condition-between-two-ros-subscriber-callback-funtions 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...

Asked by Dben on 2023-02-22 10:52:34 UTC

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.

Asked by joao.aguizo on 2023-02-23 12:12:37 UTC

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/Concepts/About-Composition.html.

Asked by joao.aguizo on 2023-02-23 13:33:08 UTC

@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.

Asked by Mike Scheutzow on 2023-02-25 09:04:03 UTC

Answers