-
Notifications
You must be signed in to change notification settings - Fork 470
Description
Feature request
Allow for user transition callbacks within lifecycle nodes (e.g., on_configure
) to defer work and be cancelable.
Backward compatible PR: #2214
Demo Repo
Feature description
Lifecycle transition callbacks currently must be synchronous. With the limitation of calling service within a service #773 and the advent of async services #1709, we would like to propose adding the ability to defer work within a user transition callback (e.g., on_configure
) and allowing these transitions to be cancelled.
Deferral + Cancelable transitions would allow for:
- nodes/entities with external transition dependencies to defer work until those dependencies are met (e.g., requests to external service(s) is/are ready/complete)
- attempting recovery mid-transition instead of needing to fully shutdown + fully bring the node back to a desired state
The change_state
process would ideally be deferrable + cancelable. This would allow for both long running functions (e.g., a long load in on_configure
) as well as free up the executor to process new events (e.g., nodes waiting on external dependencies).
Example code reference
void on_activate_async(
const rclcpp_lifecycle::State &state,
std::shared_ptr<rclcpp_lifecycle::ChangeStateHandler> change_state_hdl) {
std::thread t(&LifecycleTalker::defer_on_activate_work, this, change_state_hdl);
t.detach();
} // Off Executor
void defer_on_activate_work(
std::shared_ptr<rclcpp_lifecycle::ChangeStateHandler> change_state_hdl) {
/* Do work & */
/* Monitor for cancellation via change_state_hdl->is_cancelling() */
LifecycleNode::on_activate(state); // activate ManagedEntities
change_state_hdl->send_callback_resp(CallbackReturn::SUCCESS);
}