Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferrable + Cancelable lifecycle change_state transition functions #2213

Open
tgroechel opened this issue Jun 13, 2023 · 1 comment
Open
Assignees

Comments

@tgroechel
Copy link

tgroechel commented Jun 13, 2023

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:

  1. 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)
  2. 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);
}
@tgroechel tgroechel changed the title Asynchronous lifecycle change_state Deferrable + Cancelable lifecycle change_state transition functions Jun 14, 2023
@ros-discourse
Copy link

This issue has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/deferrable-canceleable-lifecycle-transitions/32318/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants