ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How do the executors check if a subscriber has something to do?

asked 2021-01-21 02:14:45 -0600

NEngelhard gravatar image

Hey!

I’m looking into the lower levels of ROS2, specifically the executors. In the spin we use Executor::get_next_ready_executable to get the next AnyExecutable that has something do do (“Check the subscriptions to see if there are any that are ready”). At first, I interpreted this as looking for a subscriber that has a non-empty msgs queue. But the get_next_subscription only looks as group->can_be_taken_from, which does not depend (in an obvious way, maybe I have missed something) on the queue.

So how should I interpret these calls and how can I check if there really is anything to do for the subscribers? (Is there any other way than calling _take and check the bool* ‘taken’?)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2021-01-21 11:21:41 -0600

sloretz gravatar image

So how should I interpret these calls and how can I check if there really is anything to do for the subscribers? (Is there any other way than calling _take and check the bool* ‘taken’?)

Currently the only way to know if there's any messages for a subscription is to put it into a waitset, call rcl_wait() to wait for a message, and finally call rcl_take() to get it.

The executor uses an rcl_waitset_t to wait for things to become ready. It puts everything - subscribers, timers, etc - it into a waitset, and then it calls rcl_wait(...). Even lower that goes to rmw_wait(...), which is implemented by each middleware. It returns when at least one thing in the waitset has become ready to execute, and the waitset itself is modified to say what's ready. When the executor calls rcl_take(...) it already knows there's something to do - sort of. Sometimes a middleware will say a subscription is ready but it's not because of a message. I forget when and why this happens, but checking taken says if there's a message or not.

edit flag offensive delete link more

Comments

@NEngelhard did this answer your question?

William gravatar image William  ( 2021-01-26 21:34:55 -0600 )edit

Thanks! That was what I was looking for. I'm exchanging DDS with a different message passing library that has it's own spinOnce so that I have to process all messages before spinning the other library that fills the ROS2-queues. It now works with subscribers, but not yet with services, but that needs some more work until I can ask a good question. Thanks again for your support!

NEngelhard gravatar image NEngelhard  ( 2021-01-27 01:36:42 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-01-21 02:14:45 -0600

Seen: 423 times

Last updated: Jan 21 '21