Open RaphLins opened 1 month ago
@RaphLins thanks for creating issue. it looks like this is not expected behavior. I would like to ask you to check if the problem stays (the same behavior) with jazzy
and humble
as well. that would be useful information if some changes in rolling
(or jazzy
) if the problem is not observed in humble.
@fujitatomoya Thank you for the feedback.
that would be useful information if some changes in
rolling
(orjazzy
) if the problem is not observed in humble.
I've checked and can confirm that the problem is also observed in both the latest humble
(v16.0.10
) and jazzy
.
I found Iron version has the issue, and it's unrelated to the DDS type (Cyclone DDS).
After checking code, I found
Executor::get_next_ready_executable() call waitresult->next_ready_subscription(). If the subscription has messages, it will generate an any_executable. It doesn't matter how many messages there are to receive for that subscription.
Executor::execute_any_executable() call Executor::execute_subscription(). In the processing code, it will only retrieve one message.
spin_some ensures that different subscriptions, clients, services, etc., with data will each be processed once, but only one data will be processed for the same target.
This is my understanding; please correct me if I'm wrong.
although this is not really user expectation described in this issue report header, this is designed behavior as @Barry-Xu-2018 explains above. rclcpp::spin_some
only waits on once to collect executables, and executes them once then exits. (it does not have any idea how many data are available from this wait.) i see this is not ideal for user expectation, but for supporting we probably need new rmw interface to get the information how many data are available on wait. right now we do not have bandwidth for this, so i will move this to backlog for now.
@RaphLins can you use rclcpp::spin_all
instead? i think that is what you are looking for.
@fujitatomoya Yes, I believe that rclcpp::spin_all
would work for me (or rather rclcpp::Executor::spin_all()
before jazzy
). Thank you; I was not aware of it.
In my opinion it would be worth considering an update of the description of spin_some
since I assume that other people might be using it incorectly as I did and are experiencing delayed callbacks (corresponding to the subscriber's history depth) without realizing it. Although this is only an issue if the publisher's frequency is higher than the subscriber's loop.
Bug report
Required Info:
Steps to reproduce issue
A topic is being published at a high frequency while a subscribed node calls
rclcpp::spin_some()
at a lower frequency.Expected behavior
According to its description,
rclcpp::spin_some
should execute "any immediately available work", so I would expect it to process all the available messages in the subscriber queue.Actual behavior
It only processes one message in the queue at a time, causing it to accumulate.
Additional information