-
Notifications
You must be signed in to change notification settings - Fork 522
Description
Feature request
Discovered while looking at #1916
Feature description
I think it would be useful to have a callback that gets run by the executor after the guard condition is triggered.
rclpy already has this feature.
This could be used to do work in the executor. One could use it to complete a future to work around #1916.
You can sort of do this now with timers with a 0 second period by canceling them in the callback. The timer callback won't run again until it's reset, so resetting is sort of like calling trigger()).
Implementation considerations
The GuardCondition class has a callback that gets called when it's triggered, but this isn't suitable for this feature.
| set_on_trigger_callback(std::function<void(size_t)> callback); |
This callback replaces the trigger implementation so that the rcl_trigger_guard_condition method never gets called, and the executor isn't woken. A different callback would be needed to implement this feature.
rclcpp/rclcpp/src/rclcpp/guard_condition.cpp
Lines 79 to 87 in 85a7046
| if (on_trigger_callback_) { | |
| on_trigger_callback_(1); | |
| } else { | |
| rcl_ret_t ret = rcl_trigger_guard_condition(&rcl_guard_condition_); | |
| if (RCL_RET_OK != ret) { | |
| rclcpp::exceptions::throw_from_rcl_error(ret); | |
| } | |
| unread_count_++; | |
| } |