Deferrable + Cancelable lifecycle `change_state` transition functions
@tgroechel is already working on this.
Since Jun 29, 2023.
- Dominant language
- C++
- Stars
- 805
- Forks
- 564
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 27
Description
Feature request
Allow for user transition callbacks within lifecycle nodes (e.g., on_configure) to defer work and be cancelable.
Backward compatible PR: https://github.com/ros2/rclcpp/pull/2214
Demo Repo
Feature description
Lifecycle transition callbacks currently must be synchronous. With the limitation of calling service within a service https://github.com/ros2/rclcpp/pull/773 and the advent of async services https://github.com/ros2/rclcpp/pull/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);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.