feat: lifecycle contract — cancel/pause must reach true quiescence before reporting done
Root cause (from a C++ host log, 2026-09-11): cancel during PLANNING only set a discard flag on the planner thread, which ran to allocated_time before CANCELLED could be reported; a queued next mission landed on a still-busy planner and timed out too. Same class of bug existed for pause, recovery, and implicitly for a legitimate ABORTED read while a component was still unwinding. Full audit, decisions, and phased design in docs/PLAN_LIFECYCLE_CANCEL_PAUSE_RESUME.md; old-vs-new behaviour per state in docs/LIFECYCLE_BEHAVIOUR_MATRIX.md. Runtime quiescence, not just "command sent": - kPausing (new state) mirrors kCancelling: PAUSED/CANCELLED is only entered once planner and recovery are idle, the action reports terminal, and the robot is stopped per odometry (robot_stopped, stopped_measured_linear/ angular_eps) — not merely "the command we sent was zero". settle_timeout bounds the wait; exceeding it still finishes but logs an ungated error naming which component was still busy, so a plugin that doesn't honour cancel/pause is visible instead of silently swallowed. - PlannerRunner::running_planner_ (new): the instance the planner thread is actually inside makePlan() with, tracked separately from active_ — active_ can already point at a different instance after swapPlanner() while the old attempt is still running. cancelPlan(), swapPlanner() (when a job is running_ or only pending_ and not yet picked up), and the destructor all preempt through this pointer now; the old code preempted through active_ and could silently preempt the wrong (idle) instance after a profile swap. - ComponentStatusBoard + per-component ComponentPhase (idle/busy/stopping/ paused/hung), read by PlannerRunner, RecoveryRunner, ActionRunner and ControlLoop instead of ad hoc bools — this is what makes "did everything actually stop" answerable at all, and what the new Watchdog thread reads to flag a component busy-without-progress as hung (logged once at the edge) without the control loop needing to detect its own stall. - Resume: PLANNING replans from the current pose. CONTROLLING re-issues setPlan() with the plan already in hand (decided: setPlan again, not a fresh plan) — the local planner needs nothing else since it already runs once per control cycle; a fresh plan on resume was considered and rejected as unnecessary work for a plan that's still valid. - Command-to-zero on cancel/pause stays immediate (no deceleration ramp) — existing VelocityArbiter behaviour, left as is per a scoped decision. Depends on: Test/sbpl (bd89924), pnkx_nav_core (2b0993b, robot_nav_core:: Preemptable + component_status_probe.h), Test/sbpl_lattice_planner (7456e99), Test/recovery_core (254c7fc, onCancelRequested + ABI guard), Test/ sbpl_recovery (ea79686, worker-thread cancel), Test/action_core (669c3f7, pause/resume + kCancelled), Test/dock_pattern_action (cc1ea74). Verified: 13 gtest binaries / 528 tests, 0 failures. Runtime on the dev machine (Gazebo + real ROS host + VDA5050 over MQTT), 6 scenarios — cancel during PLANNING, pause/resume during PLANNING and CONTROLLING (incl. submit-while-still-winding-down), pause-then-cancel during PLANNING and CONTROLLING: no ABORTED/RECOVERING in any run, preempt lands within hundredths of a millisecond of entering CANCELLING/PAUSING, PAUSED/CANCELLED only reported once the robot is actually stopped per odometry. Full numbers in the plan doc section 6. Excluded from this commit (pre-existing, unrelated): config/runtime/recovery_behaviors_params.yaml (allocated_time 1.0->2.0, SBPLDetourPlanner tuning predating this work). Not yet done (see plan doc "Trạng thái"): config tuning (phase 0, pending per a scoping decision); runtime scenarios for cancel mid-detour and a 30 s pause mid-action; commit to rb_ws is a separate step, not done here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -112,7 +112,7 @@ planner_frequency: 0.0
|
||||
# ► Chỉnh: đặt > thời gian lập plan xấu nhất của global planner. SBPL `allocated_time: 10.0` ở
|
||||
# sbpl_global_params.yaml ⇒ 2.0 s là NGẮN HƠN trần của chính planner: nếu thấy leo thang trong khi
|
||||
# planner vẫn đang chạy, tăng giá trị này lên trên trần đó.
|
||||
planner_patience: 2.0
|
||||
planner_patience: 25.0
|
||||
|
||||
# Số lần lập plan HỎNG liên tiếp được phép trước khi leo thang. 0 = hỏng một lượt là leo thang ngay.
|
||||
# ► Chỉnh: TĂNG (1–3) nếu planner thỉnh thoảng fail do costmap chưa kịp cập nhật lúc vừa nhận goal.
|
||||
@@ -120,6 +120,28 @@ planner_patience: 2.0
|
||||
# ai phát hiện (config validate chặn ca tắt cả hai).
|
||||
max_planning_retries: 0
|
||||
|
||||
# [s] Trần chờ ở CANCELLING và PAUSING cho tới khi runtime IM HẲN rồi mới báo CANCELLED/PREEMPTED
|
||||
# hoặc PAUSED ra host (trong lúc PAUSING host vẫn thấy tên state cũ + feed_back_str "pausing…").
|
||||
# "Im hẳn" = ba điều kiện cùng đúng: (1) lệnh vận tốc = 0 VÀ odom đọc ≈ 0 (xem hai khoá dưới),
|
||||
# (2) thread global planner rảnh và recovery đã dừng — kể cả lượt makePlan đã bị huỷ mà plugin không cắt được (SBPL
|
||||
# hiện chạy tới hết `allocated_time`), (3) action đang chạy đã trả terminal. Host đọc PREEMPTED là
|
||||
# "xong rồi, gửi goal kế được" — báo sớm thì goal kế bị `startPlan()` từ chối vì thread còn bận.
|
||||
# ► Chỉnh: mặc định 2.0. TĂNG (5–10) nếu SBPL `allocated_time` lớn và chưa có preempt (pha 2) — quá
|
||||
# trần vẫn CANCELLED nhưng runtime in LỖI "cancel settle timeout", không tắt được. 0 = TẮT: kết
|
||||
# thúc ngay khi lệnh = 0 như trước 11/9/2026 (host dễ gửi goal kế lúc planner còn bận).
|
||||
settle_timeout: 2.0
|
||||
|
||||
# [m/s] Ngưỡng coi robot ĐÃ DỪNG theo vận tốc ĐO ĐƯỢC (odom), dùng cho điều kiện (1) ở trên.
|
||||
# Lệnh về 0 không có nghĩa bánh xe đã đứng — driver còn giảm tốc; PREEMPTED báo lúc đó là báo cho
|
||||
# một robot đang trượt. Chỉ có tác dụng khi host đẩy odom vào (`addOdometry`); không có odom thì
|
||||
# tự lùi về đo bằng lệnh đã phát.
|
||||
# ► Chỉnh: TĂNG (0.05) nếu odom nhiễu giữ CANCELLING tới tận `settle_timeout` dù robot đã
|
||||
# đứng (xem log lỗi settle timeout với robot_stopped=no). 0 = bỏ odom, chỉ nhìn lệnh.
|
||||
stopped_measured_linear_eps: 0.02
|
||||
|
||||
# [rad/s] Như trên cho trục quay.
|
||||
stopped_measured_angular_eps: 0.02
|
||||
|
||||
# [s] Ở trong bán kính `oscillation_distance` quá lâu = coi là quẩn -> recovery `oscillation`.
|
||||
# ► Chỉnh: <= 0 là TẮT (giá trị hiện tại). Bật (vd 10–20 s) khi thấy robot lắc qua lắc lại tại chỗ
|
||||
# mà không trigger nào khác bắt được. Bật thì `oscillation_distance` bắt buộc phải > 0.
|
||||
@@ -220,6 +242,41 @@ acc_lim_theta: 1.20
|
||||
# chạy thường trực trên robot thật.
|
||||
runtime_stats_period: 0.0
|
||||
|
||||
# =================================================================================================
|
||||
# Watchdog thành phần (2026-09-11) — thread riêng đọc bảng trạng thái, kết luận "TREO"
|
||||
#
|
||||
# Mỗi thành phần (global planner, local planner, recovery, action, control loop) tự khai nó đang
|
||||
# bận/dừng/rảnh và "nhích" mỗi nhịp. Watchdog chạy trên thread riêng — control thread treo thì
|
||||
# không tự phát hiện được chính nó — và kết luận treo khi một hàng BẬN mà KHÔNG NHÍCH quá ngân sách.
|
||||
# Treo → in LỖI một lần (không tắt được); control loop treo → host đọc navigation_state = LOST và
|
||||
# phải tự đưa cmd_vel về 0. Đây là chẩn đoán, không phải điều khiển: state machine không đổi gì.
|
||||
# =================================================================================================
|
||||
|
||||
# [s] Chu kỳ kiểm của watchdog. 0 = TẮT watchdog (không có thread, không phát hiện treo).
|
||||
watchdog_period: 0.1
|
||||
|
||||
# [s] Trần MỘT lượt makePlan trên thread planner trước khi kết luận global planner TREO. Từ 11/9/2026
|
||||
# khoá này mới có tác dụng (trước đó đọc mà không dùng). PHẢI LỚN HƠN thời gian một lượt hợp lệ dài
|
||||
# nhất: với SBPL là `allocated_time` trong sbpl_global_params.yaml (đã là trần chung cho cả 3 lượt
|
||||
# replan nội bộ). ► Chỉnh: đặt ≈ allocated_time + 1. 0 = không giám sát hàng này.
|
||||
planner_timeout: 15.0
|
||||
|
||||
# [s] Trần MỘT lời gọi computeVelocityCommands của local planner. Priest 30–48 ms, Hybrid < 10 ms;
|
||||
# 0.5 s là "chắc chắn có gì đó hỏng" chứ không phải chậm. 0 = không giám sát.
|
||||
local_planner_call_budget: 0.5
|
||||
|
||||
# [s] Recovery behavior bận mà không nhích (không tick, worker detour không về) quá đây = treo.
|
||||
recovery_stall_budget: 5.0
|
||||
|
||||
# [s] Action handler bận mà không nhích quá đây = treo. 0 = TẮT (mặc định): handler tự timeout
|
||||
# theo thiết bị của nó (tầng 1), `action_patience` là tầng 2 — không cần tầng thứ ba.
|
||||
action_stall_budget: 0.0
|
||||
|
||||
# [s] Control thread không kết thúc được một cycle nào trong quãng này = TREO → host thấy LOST.
|
||||
# 0.5 s = 15 cycle @ 30 Hz. GIẢM (0.2) nếu host cần phản ứng nhanh hơn; không đặt < 3 cycle vì
|
||||
# một lượt detour/solve dài hợp lệ sẽ bị báo nhầm.
|
||||
control_loop_stall_budget: 0.5
|
||||
|
||||
# Bật/tắt toàn bộ recovery. Danh sách behavior và route nằm ở `recovery_behaviors_params.yaml`,
|
||||
# namespace `recovery`.
|
||||
# ► Chỉnh: false = mọi lỗi đi thẳng tới ABORTED, không thử phục hồi. Chỉ dùng khi cô lập lỗi lúc
|
||||
|
||||
Reference in New Issue
Block a user