From 9095e58dec547b5be35d8c2481c09f687c8b98d5 Mon Sep 17 00:00:00 2001 From: duongtd Date: Sat, 12 Sep 2026 22:20:57 +0700 Subject: [PATCH] feat: bring the move_base2 cancel/pause/resume lifecycle fix onto new-1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps 7 submodule pointers to the same fix already on T800_ws (branch dev_recovery_and_manager_mission there, this repo is on new-1.0 — the two branches share no common history, so this is a submodule pull + a manual reapply of two new headers, not a merge or cherry-pick): sbpl ca1ba36 -> bd89924 (SBPLPlanner abort flag) sbpl_lattice_planner 9c1667e -> 7456e99 (Preemptable + shared search budget) recovery_core c03d16f -> 254c7fc (onCancelRequested + ABI guard) sbpl_recovery 8f9326b -> ea79686 (detour search on a worker thread) action_core a6bc3df -> 669c3f7 (pause/resume + kCancelled + ABI guard) dock_pattern_action 302dd11 -> cc1ea74 (pause/resume) move_base2 7d00c5a -> 8bc4895 (the lifecycle contract itself) pnkx_nav_core's own two new in-tree headers (robot_nav_core::Preemptable, move_base_core::component_status_probe.h) are added here by hand, same content as T800_ws commit 2b0993b — required for sbpl_lattice_planner and move_base2 (now pulled above) to even compile; not a cherry-pick since new-1.0 and dev_recovery_and_manager_mission have no common ancestor. config/runtime/move_base_common_params.yaml: added the new keys only, every existing value (planner_patience 2.0, max_planning_retries 0, twist semantics, recovery_behavior_enabled false, ...) is untouched. settle_timeout: 2.0 and the two stopped_measured_*_eps keys are on, same as the dev tree — this is the correctness fix itself (cancel/pause now wait for real quiescence instead of reporting done while a component is still unwinding), and it changes report timing only, not any commanded velocity. The watchdog block is added but left OFF (watchdog_period: 0.0, dev tree has 0.1) — allocated_time: 10.0 in this tree's own sbpl_global_params.yaml means a legitimate long search could trip a naive planner_timeout as a false "hung"; leaving a brand-new diagnostic capability off until it's calibrated against real search/recovery/action timing on this robot matches the policy for new features in this config tree. Not brought over (flagged for a separate decision, see chat): nav_c_api_2.h/.cpp changes from T800_ws commit 2b0993b — this repo has no config/move_base_common_params.yaml at the top level (only config/runtime/), so it may not run the standalone c_api tree at all; and the two branches' disjoint history makes a blind reapply of an EXISTING file's diff riskier than the two brand-new headers above. Needs a decision, not a mechanical pull. Not pushed to origin/new-1.0 — local commit only, pending confirmation. --- config/runtime/move_base_common_params.yaml | 63 +++++++++++++++++++ .../Packages/actions/dock_pattern_action | 2 +- .../global_planners/sbpl_lattice_planner | 2 +- .../Packages/recoveries/sbpl_recovery | 2 +- src/Libraries/action_core | 2 +- src/Libraries/recovery_core | 2 +- src/Libraries/sbpl | 2 +- .../move_base_core/component_status_probe.h | 51 +++++++++++++++ .../include/robot_nav_core/preemptable.h | 44 +++++++++++++ src/Navigations/Packages/move_base2 | 2 +- 10 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 src/Navigations/Cores/move_base_core/include/move_base_core/component_status_probe.h create mode 100644 src/Navigations/Cores/robot_nav_core/include/robot_nav_core/preemptable.h diff --git a/config/runtime/move_base_common_params.yaml b/config/runtime/move_base_common_params.yaml index 05b7760..97159c6 100644 --- a/config/runtime/move_base_common_params.yaml +++ b/config/runtime/move_base_common_params.yaml @@ -142,6 +142,28 @@ oscillation_distance: 0.5 # Phải <= oscillation_distance, không thì runtime từ chối config. recovery_reset_min_travel: 0.10 +# [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 + # ================================================================================================= # Giới hạn vận tốc — hàng rào CUỐI trước khi Twist rời runtime (VelocityArbiter) # @@ -233,6 +255,47 @@ recovery_behavior_enabled: false MoveBase: library_path: libmove_base2 +# ================================================================================================= +# 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ì. +# +# ► Đang để TẮT trên bản robot thật (khác cây dev): watchdog vừa nạp (chưa chạy thử trên hiện +# trường), và `sbpl_global_params.yaml: allocated_time: 10.0` ở đây trùng cây dev — một lượt SBPL +# hợp lệ (goal xa) có thể chạm gần trần đó, nên bật ngay dễ báo TREO oan cho một lượt chỉ đang +# chậm. Bật (đặt lại `watchdog_period` > 0) sau khi đo thời gian lập plan/recovery/action thật +# trên robot và canh `planner_timeout` theo số đo đó (xem ► Chỉnh ngay dưới). +# ================================================================================================= + +# [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.0 + +# [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 + # --- Công tắc log chẩn đoán -------------------------------------------------------------------- # # Mọi dòng `[move_base2][debug]` trước đây in VÔ ĐIỀU KIỆN. Trên robot chạy cả ca, phần lớn chúng diff --git a/src/Algorithms/Packages/actions/dock_pattern_action b/src/Algorithms/Packages/actions/dock_pattern_action index 302dd11..cc1ea74 160000 --- a/src/Algorithms/Packages/actions/dock_pattern_action +++ b/src/Algorithms/Packages/actions/dock_pattern_action @@ -1 +1 @@ -Subproject commit 302dd113f3b14a90b4e78a3942baac4454cb5674 +Subproject commit cc1ea744455f1ec5e28af13b042f55a718567247 diff --git a/src/Algorithms/Packages/global_planners/sbpl_lattice_planner b/src/Algorithms/Packages/global_planners/sbpl_lattice_planner index 9c1667e..7456e99 160000 --- a/src/Algorithms/Packages/global_planners/sbpl_lattice_planner +++ b/src/Algorithms/Packages/global_planners/sbpl_lattice_planner @@ -1 +1 @@ -Subproject commit 9c1667eb3cdcc57bc9e188580a2aada4d9c99d9a +Subproject commit 7456e99372a6a20b9c83f3b7f0d42cce4028447a diff --git a/src/Algorithms/Packages/recoveries/sbpl_recovery b/src/Algorithms/Packages/recoveries/sbpl_recovery index 8f9326b..ea79686 160000 --- a/src/Algorithms/Packages/recoveries/sbpl_recovery +++ b/src/Algorithms/Packages/recoveries/sbpl_recovery @@ -1 +1 @@ -Subproject commit 8f9326be04d14673eaae4df13477f056950be89e +Subproject commit ea79686eef7077ec15de413826a94c9a5c226f37 diff --git a/src/Libraries/action_core b/src/Libraries/action_core index a6bc3df..669c3f7 160000 --- a/src/Libraries/action_core +++ b/src/Libraries/action_core @@ -1 +1 @@ -Subproject commit a6bc3dfa3d2205502a6d1e3cd9f797a54d1b23e9 +Subproject commit 669c3f7c06dcdfd2e1252bcd04b43edfbb33fcf8 diff --git a/src/Libraries/recovery_core b/src/Libraries/recovery_core index c03d16f..254c7fc 160000 --- a/src/Libraries/recovery_core +++ b/src/Libraries/recovery_core @@ -1 +1 @@ -Subproject commit c03d16f98c0fda0a9c1a96cb5796b5c8c944948e +Subproject commit 254c7fc181702083f3c54b2340751d914c681148 diff --git a/src/Libraries/sbpl b/src/Libraries/sbpl index ca1ba36..bd89924 160000 --- a/src/Libraries/sbpl +++ b/src/Libraries/sbpl @@ -1 +1 @@ -Subproject commit ca1ba369817d63b0c82e6d3331670584c6f0a422 +Subproject commit bd8992469e14976c3dd0ff86cd11876a11f6aa26 diff --git a/src/Navigations/Cores/move_base_core/include/move_base_core/component_status_probe.h b/src/Navigations/Cores/move_base_core/include/move_base_core/component_status_probe.h new file mode 100644 index 0000000..5bcd048 --- /dev/null +++ b/src/Navigations/Cores/move_base_core/include/move_base_core/component_status_probe.h @@ -0,0 +1,51 @@ +/********************************************************************* + * + * Software License Agreement (BSD License) + * + * move_base_core — optional capability: per-component liveness of a navigation runtime. + * + * Author: DuongTD + *********************************************************************/ +#ifndef MOVE_BASE_CORE_COMPONENT_STATUS_PROBE_H +#define MOVE_BASE_CORE_COMPONENT_STATUS_PROBE_H + +#include + +namespace robot +{ +namespace move_base_core +{ + +class BaseNavigation; + +/** + * One row of the runtime's component status board, flattened for a C/.NET host. + * + * Deliberately NOT a virtual on BaseNavigation: that would change the vtable every host binary was + * built against. Instead the navigation plugin .so exports a free function under the Boost.DLL + * alias @ref kComponentStatusProbeAlias and a host that wants it dlsym()s it (nav_c_api_2: + * navigation_get_component_status). Runtimes without the alias simply do not offer it. + * + * `phase` values: 0 idle, 1 busy, 2 stopping, 3 paused, 4 hung (mirrors move_base2::ComponentPhase). + * `hung` is the watchdog's verdict — busy for longer than the component's budget without progress. + */ +struct ComponentStatusEntry +{ + char name[32]; + unsigned char phase; + unsigned char hung; + double seconds_in_phase; + double seconds_since_progress; +}; + +/// Fills up to @p max entries for @p navigation; returns how many rows the runtime has (may exceed max). +using ComponentStatusProbeFn = std::size_t (*)(BaseNavigation* navigation, ComponentStatusEntry* out, + std::size_t max); + +/// Boost.DLL alias name the navigation plugin exports the probe under (added 2026-09-11). +constexpr const char* kComponentStatusProbeAlias = "MoveBaseComponentStatus"; + +} // namespace move_base_core +} // namespace robot + +#endif // MOVE_BASE_CORE_COMPONENT_STATUS_PROBE_H diff --git a/src/Navigations/Cores/robot_nav_core/include/robot_nav_core/preemptable.h b/src/Navigations/Cores/robot_nav_core/include/robot_nav_core/preemptable.h new file mode 100644 index 0000000..513ce36 --- /dev/null +++ b/src/Navigations/Cores/robot_nav_core/include/robot_nav_core/preemptable.h @@ -0,0 +1,44 @@ +/********************************************************************* + * + * Software License Agreement (BSD License) + * + * robot_nav_core — optional mixin for plugins whose work can be interrupted from another thread. + * + * Author: DuongTD + *********************************************************************/ +#ifndef ROBOT_NAV_CORE_PREEMPTABLE_H +#define ROBOT_NAV_CORE_PREEMPTABLE_H + +namespace robot_nav_core { + +/** + * @class Preemptable + * @brief A plugin that can cut short a long-running call (makePlan, a recovery attempt) when asked. + * + * Deliberately a separate interface instead of a new virtual on BaseGlobalPlanner / + * BaseLocalPlanner: adding a slot to those vtables would force every already-built plugin .so to be + * rebuilt in lock-step, and a stale one would crash on load. A plugin opts in by inheriting this + * class as well; the runtime discovers support with `dynamic_cast` and falls back to + * "discard the result when it arrives" for plugins that do not. + * + * Contract for implementers: + * - preempt() is called from ANOTHER thread than the one inside the long call. It must be + * lock-free, allocation-free and return immediately — typically one atomic store. + * - The long call must poll the flag often (per expansion / per iteration) and return promptly, + * reporting failure; a partial result must not be handed back as a success. + * - Every new call must start with the flag cleared, so a preempt aimed at the previous call + * cannot kill the next one. + * + * Added 2026-09-11 for the move_base2 cancel/pause path (SBPLLatticePlanner, DetourPathRecovery). + */ +class Preemptable { +public: + virtual ~Preemptable() = default; + + /// Request that the call currently running on the plugin's worker returns as soon as possible. + virtual void preempt() = 0; +}; + +} // namespace robot_nav_core + +#endif // ROBOT_NAV_CORE_PREEMPTABLE_H diff --git a/src/Navigations/Packages/move_base2 b/src/Navigations/Packages/move_base2 index 7d00c5a..8bc4895 160000 --- a/src/Navigations/Packages/move_base2 +++ b/src/Navigations/Packages/move_base2 @@ -1 +1 @@ -Subproject commit 7d00c5ab664b50bf54dc5b3904289df53d44e5f3 +Subproject commit 8bc4895a60dd1ebfbf3885a7a52d8d33a7e6db3e