Support lifecycle-managed timers in rclcpp_lifecycle::LifecycleNode
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Bắt đầu với LifecycleNode::create_timer() và create_wall_timer(), sau đó xem xét hành vi chuyển trạng thái vòng đời được mô tả ở đây và thảo luận về thiết kế trong PR #2261. Giải quyết các câu hỏi còn bỏ ngỏ về API và trạng thái chuyển tiếp với các maintainer; được xem là hoàn thành khi có một API timer được quản lý bởi vòng đời đã được thống nhất và các bài kiểm thử bao phủ trạng thái không hoạt động, trạng thái hoạt động, các chuyển tiếp lặp lại, việc tạo khi đang hoạt động và các chuyển tiếp thất bại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
rclcpp_lifecycle::LifecycleNode does not provide an API for managing timer callback execution based on lifecycle state.
Currently, LifecycleNode::create_timer() and create_wall_timer() create regular rclcpp timers whose callback execution is not managed by lifecycle transitions.
As a result, if an executor is spinning, timer callbacks may run even when the node is Unconfigured or Inactive.
This is not a claim that the existing timer APIs are incorrect.
The issue is that LifecycleNode does not provide an API for opting into lifecycle-managed timer behavior.
This issue proposes the following behavior for lifecycle-managed timers:
| Lifecycle state or transition | Proposed timer behavior |
|---|---|
Unconfigured |
Do not start executing new timer callbacks |
Inactive |
Do not start executing new timer callbacks |
Successful transition to Active |
Start or resume callback execution for timers that have already been created |
Active |
Allow lifecycle-managed timer callbacks to execute |
| Successful deactivation | cancel() the timer; callbacks already in flight may complete |
| Successful cleanup / shutdown | Prevent new timer callbacks from starting and clean up the timer |
The start behavior for a timer created while the node is already Active, and the behavior when a lifecycle transition fails, are left as open questions below.
Motivation
Applications may need to control periodic timer-based work according to lifecycle state.
However, because LifecycleNode does not provide a lifecycle-managed timer option, each application must implement this control separately.
The ROS 2 Managed Nodes design describes Inactive as a state in which the node is not performing any processing.
The lifecycle_talker demo also uses a regular timer and includes a comment that a future version will add a timer following the same lifecycle management as a lifecycle publisher. This comment provides historical context that lifecycle-managed timers have been considered before.
Inspection of the LifecycleNode implementations in Rolling and Jazzy found that neither branch provides a separate lifecycle-managed timer API.
On Jazzy, I confirmed that callbacks from a regular create_wall_timer() execute while the node is both Unconfigured and Inactive.
This result demonstrates the current behavior of regular timers; it does not imply that the existing API violates an explicitly documented lifecycle contract.
Design / Implementation Considerations
There are three possible API directions to consider.
Add a new API
- Add separate APIs for creating lifecycle-managed timers.
Change the existing APIs
- Change the default behavior of
LifecycleNode::create_timer()andcreate_wall_timer()so that they create lifecycle-managed timers. - Add an option to the existing APIs for selecting managed or unmanaged behavior.
For now, I propose adding separate APIs.
Changing the default behavior of the existing APIs could alter timer behavior in Inactive without a compile error for existing applications that use auto or rclcpp::TimerBase::SharedPtr.
Adding an option would preserve existing calls, but the same function would provide different lifecycle behavior, requiring readers to inspect the option at each call site to determine whether a timer is lifecycle-managed.
Separate APIs would preserve existing application behavior while making the distinction between regular and lifecycle-managed timers explicit at each call site.
For example, the following APIs could be considered:
create_lifecycle_timer(...)
create_lifecycle_wall_timer(...)
To assess the feasibility of the proposed behavior, I tested a downstream implementation that calls cancel() and reset() on timers in response to lifecycle transitions.
The Jazzy-based tests confirmed that new callbacks did not start while the node was Inactive, callbacks executed while it was Active, and timer callback execution resumed across repeated activate/deactivate cycles.
This validation only establishes the feasibility of the proposed lifecycle behavior.
The actual upstream API names, signatures, return types, and internal management approach remain open for discussion with the maintainers.
PR #2261 proposed separate APIs for lifecycle-managed timers and integration with lifecycle transitions, but it was closed without being merged.
The review raised design questions about whether callbacks should execute before activation under different autostart settings and how a timer created while the node is already Active should behave.
This issue does not request adopting the implementation from #2261 as-is.
Its purpose is to clarify behavior based on lifecycle state and timer creation timing, and to revisit the API design for lifecycle-managed timers.
I would appreciate maintainer guidance on the following:
- Is lifecycle-managed timer support still desired for Rolling?
- Which direction would be preferable: adding separate APIs, changing the default behavior of the existing APIs, or adding an option to the existing APIs?
- If a lifecycle-managed timer is created while the node is already
Active, should it start immediately? - How should a managed timer behave when a lifecycle transition fails?
Additional Information
Lifecycle-managed timer support for rclcpp_lifecycle::LifecycleNode in Rolling
- Ngôn ngữ chính
- C++
- Star
- 815
- Fork
- 572
- Merge trung bình
- 6 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ros2/rclcpp
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
EventsCBGExecutor timers on ROS time stall after a backward /clock jumpCó thể đã có người làm @Yadunund đã nhận 3 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Late /clock delivery under use_sim_time stalls node now() for ~0.33 s (found via ros2_control controller time)Có thể đã có người làm @JeremiahM37 đã nhận 1 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
ros2/rclcpp#3329 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
:farmer: Flaky EventsCBGExecutor test: reentrant callback group fails to run callbacks concurrentlyĐang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Copy constructor exception leaks intra-process message allocationCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DarkStarSystems/pcons#224 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
LizardByte/Sunshine#5953 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
(S1 - Need confirmation)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
CleverRaven/Cataclysm-DDA#89133 ·
Maintainer thường phản hồi trong vòng 1 ngày