Ask Your Question
0

How can I post to ros's callbackQueue()?

asked 2013-02-25 08:13:27 -0600

dcconner gravatar image

updated 2014-04-20 14:09:46 -0600

ngrennan gravatar image

Looking at the "Callbacks and Spinning" wiki, ROS apparently is using an event queue under the hood.

I would like to post a callback to this queue from within another callback.

Is this possible, and how do I do it?

Can you point me to example?

---Background ---

I have 4 callbacks that are processed. A,B,C, and D

Assume these get posted in FIFO order [C A D B].

I would like the first (C in the example) processed, to post another event E to the callback queue. So after processing, C, the queue should be [A D B E], so that A is processed next.

If I understand the wiki, I could call ros::spin() within the C callback function to process A-D-B, and then call E directly, but for various reasons I prefer to post a separate callback.

Thoughts?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-09-29 21:19:27 -0600

Thomas gravatar image

There is no safe option to achieve what you want. Given that a node can be configured with multi-threaded spinner, when you handle the callback of C, there is no guarantee all the callbacks have not been treated already.

A safer solution would be to make your callbacks fill a "normal" C++ structure (like a circular buffer from Boost or a std::queue) and then have your main thread / function making the changes you need.

It will:

  1. separate the communication layer from the logic layer
  2. make sure your node won't broke the day you will spin with another strategy
  3. simplify the algorithm
  4. be much more efficient (avoid the serialization/deserialization + the cost of handling the queue). Indeed, another safe option would be to publish from your callback. This probably would work but really seems overkill IMHO.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-02-25 08:13:27 -0600

Seen: 236 times

Last updated: Sep 29 '13