3 Commits

Author SHA1 Message Date
98e6109d24 feat: add the same 10 previously-missing config keys, same default values
Mirrors Test/move_base2 commit (T800_ws) — every new key uses the exact
C++ default, silencing the "missing param" boot warnings without changing
any runtime behaviour. Every existing tuned value (controller_frequency
30.0, planner_patience 2.0, recovery_behavior_enabled false, watchdog_period
0.0, ...) is untouched; parsed and diffed key-by-key against the dev tree
before committing.

Placed at this tree's own existing anchors, which have drifted slightly
from the dev copy's ordering (recovery_behavior_enabled sits before the
Watchdog block here, after it there) — content is identical, only the
insertion point differs to match what's actually around it.
2026-09-12 22:40:22 +07:00
f7398d9442 feat: navigation_get_component_status() + truthful PREEMPTING contract in the C API
Applies cleanly from T800_ws commit 2b0993b: this repo's nav_c_api_2.h/.cpp/
GUIDE.md were byte-identical to the pre-fix baseline (verified before
applying), so this is the same patch, not a manual reconstruction.

- NavComponentStatus struct + navigation_get_component_status(): lazy
  dlsym of the MoveBaseComponentStatus alias (see previous commit's two new
  headers); returns 0 rows if the loaded .so doesn't export it, so an old
  libmove_base2.so is not a crash, just no data.
- Doc: PREEMPTING is now a truthful "still winding down" state (see
  move_base2 commit 8bc4895, already pulled) — a host must poll to
  quiescence before resending, not resend on PREEMPTING as if it meant
  "acknowledged".

Kept for a future C# host per user request — the C API is the intended
integration point for that.
2026-09-12 22:26:41 +07:00
9095e58dec feat: bring the move_base2 cancel/pause/resume lifecycle fix onto new-1.0
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.
2026-09-12 22:20:57 +07:00
13 changed files with 376 additions and 8 deletions

View File

@@ -62,6 +62,24 @@ backup_global_planner: SBPLLatticePlanner
# local planner nằm trong các YAML runtime đồng hành (symlink từ pnkx_nav_core/config/). Không lặp # local planner nằm trong các YAML runtime đồng hành (symlink từ pnkx_nav_core/config/). Không lặp
# lại chúng ở đây để tránh hai nguồn cấu hình cho cùng một plugin. # lại chúng ở đây để tránh hai nguồn cấu hình cho cùng một plugin.
# =================================================================================================
# Đường vào cảm biến — lọc trước khi vào costmap (khác kho `sensor_store` ở file riêng, xem
# `sensor_store_params.yaml`: kho giữ bản THÔ, khối dưới đây lọc bản đi vào costmap).
# =================================================================================================
sensors:
# Bật lọc statistical-outlier-removal cho LaserScan trước khi đưa vào costmap.
# ► Chỉnh: mặc định TẮT có chủ đích — bật là âm thầm xoá bớt điểm vật cản khỏi costmap, không
# phải thứ nên tự xảy ra. Chỉ bật khi lidar thật có nhiễu đo được (điểm bay lơ lửng ngoài vật
# cản thật) và đã xác nhận qua log/rviz, không bật để "chắc ăn".
laser_sor_enabled: false
# [điểm] Số láng giềng gần nhất dùng để ước lượng khoảng cách trung bình. Chỉ đọc khi bật lọc.
laser_sor_mean_k: 10
# [-] Ngưỡng outlier = mean + hệ_số * stddev. Chỉ đọc khi bật lọc.
# ► Chỉnh: GIẢM lọc mạnh tay hơn (dễ mất vật cản thật ở biên); TĂNG lọc lơi hơn (dễ để nhiễu lọt).
laser_sor_stddev_mul: 1.0
# ================================================================================================= # =================================================================================================
# Nhịp điều khiển và các đồng hồ kiên nhẫn (contract 2026-08-04 — tách replan nền khỏi recovery) # Nhịp điều khiển và các đồng hồ kiên nhẫn (contract 2026-08-04 — tách replan nền khỏi recovery)
# ================================================================================================= # =================================================================================================
@@ -125,6 +143,15 @@ max_planning_retries: 0
# mà không trigger nào khác bắt được. Bật thì `oscillation_distance` bắt buộc phải > 0. # mà không trigger nào khác bắt được. Bật thì `oscillation_distance` bắt buộc phải > 0.
oscillation_timeout: -1 oscillation_timeout: -1
# [s] Trần thời gian cho MỘT action (EXECUTING_ACTIONS), tính từ lúc start. <= 0 = tắt.
# Lưới an toàn CUỐI CÙNG, không phải cơ chế timeout chính: (1) mỗi ActionHandler phải tự timeout
# theo hiểu biết thiết bị của nó ("nâng kệ quá 20 s là bất thường" khác "sạc 30 phút là bình
# thường") — đây là tầng chính; (2) khoá này là tầng 2, lưới cuối cho handler treo không tự thoát;
# (3) `mission_timeout` của mission layer đo cả chặng là tầng 3.
# ► Chỉnh: chỉ bật khi deployment biết chắc mọi action đều ngắn hơn một trần chung — bật sai với
# action hợp lệ chạy lâu (sạc) sẽ cancel action đó + ABORTED oan. Quá hạn -> cancel action.
action_patience: 0.0
# [m] Đi được quá quãng này thì: hết bị coi là quẩn, VÀ mọi cursor route recovery được reset, VÀ # [m] Đi được quá quãng này thì: hết bị coi là quẩn, VÀ mọi cursor route recovery được reset, VÀ
# trigger giám sát tuyến đang bị khoá được mở lại (contract 2026-08-05e). # trigger giám sát tuyến đang bị khoá được mở lại (contract 2026-08-05e).
# ► Chỉnh: đây là định nghĩa "có tiến độ thật". GIẢM (0.2–0.3) nếu robot ở khu chật ít khi đi nổi # ► Chỉnh: đây là định nghĩa "có tiến độ thật". GIẢM (0.2–0.3) nếu robot ở khu chật ít khi đi nổi
@@ -142,6 +169,28 @@ oscillation_distance: 0.5
# Phải <= oscillation_distance, không thì runtime từ chối config. # Phải <= oscillation_distance, không thì runtime từ chối config.
recovery_reset_min_travel: 0.10 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) # Giới hạn vận tốc — hàng rào CUỐI trước khi Twist rời runtime (VelocityArbiter)
# #
@@ -214,6 +263,30 @@ acc_lim_theta: 1.20
# chạy thường trực trên robot thật. # chạy thường trực trên robot thật.
runtime_stats_period: 0.0 runtime_stats_period: 0.0
# =================================================================================================
# Namespace cho các thành phần nạp plugin, và frame quy chiếu
# =================================================================================================
# Namespace chứa danh sách recovery behavior (`<ns>/behaviors`) trong YAML — xem
# `recovery_behaviors_params.yaml`.
recovery_namespace: recovery
# Namespace chứa danh sách action handler (`<ns>/handlers`) trong YAML — xem
# `action_handlers_params.yaml`.
action_namespace: actions
# Namespace chứa cấu hình mission layer — xem `mission_adapters_params.yaml`.
mission_namespace: mission_adapters
# Frame mà goal được quy về trước khi lập plan. Phải khác `robot_base_frame` (khai ở
# `costmap_common_params.yaml`), nếu không pose robot luôn là gốc toạ độ.
global_frame: map
# Chặn điều khiển bánh xe khi observation buffer của costmap điều khiển đã quá hạn.
# ► Chỉnh: default true = parity với move_base thế hệ 1. Tắt chỉ khi host tự đảm bảo costmap luôn
# mới — tắt sai nghĩa là controller có thể lái theo costmap cũ mà không ai chặn.
require_current_costmap: true
# Bật/tắt toàn bộ recovery. Danh sách behavior và route nằm ở `recovery_behaviors_params.yaml`, # Bật/tắt toàn bộ recovery. Danh sách behavior và route nằm ở `recovery_behaviors_params.yaml`,
# namespace `recovery`. # 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 # ► 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
@@ -233,13 +306,54 @@ recovery_behavior_enabled: false
MoveBase: MoveBase:
library_path: libmove_base2 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 -------------------------------------------------------------------- # --- 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 # 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
# là tiếng ồn: chúng mô tả đường đi BÌNH THƯỜNG, và tiếng ồn thường trực làm dòng thật sự bất # là tiếng ồn: chúng mô tả đường đi BÌNH THƯỜNG, và tiếng ồn thường trực làm dòng thật sự bất
# thường trôi mất giữa hàng nghìn dòng giống hệt nhau. # thường trôi mất giữa hàng nghìn dòng giống hệt nhau.
# #
# ► Mặc định BẬT cả ba. Tắt là lựa chọn có ý thức, không phải thứ đổi sau lưng người đang dựa vào # ► Mặc định BẬT cả bốn. Tắt là lựa chọn có ý thức, không phải thứ đổi sau lưng người đang dựa vào
# log để debug. # log để debug.
# #
# Dòng LỖI không nằm trong nhóm nào ở đây và không tắt được — ví dụ `abort detail: recovery route # Dòng LỖI không nằm trong nhóm nào ở đây và không tắt được — ví dụ `abort detail: recovery route
@@ -259,3 +373,8 @@ debug:
# ► Nhóm ỒN NHẤT — có thể in mỗi chu kỳ khi có gì đó sai kéo dài. Nhưng cũng chính là nhóm trả # ► Nhóm ỒN NHẤT — có thể in mỗi chu kỳ khi có gì đó sai kéo dài. Nhưng cũng chính là nhóm trả
# lời câu "robot đứng im mà không tầng nào báo lỗi", nên ĐỪNG tắt khi đang truy lỗi. # lời câu "robot đứng im mà không tầng nào báo lỗi", nên ĐỪNG tắt khi đang truy lỗi.
skip: true skip: true
# Một dòng tóm tắt feature của EnvMonitor mỗi giây khi đang giám sát (stall/unreachable/contact/
# ngân sách) — xem `env_monitor_params.yaml` cho tham số lõi của EnvMonitor.
# ► Rẻ, một dòng mỗi giây. Tắt khi không cần theo dõi EnvMonitor.
env: true

View File

@@ -460,6 +460,52 @@ theo dõi `navigation_get_twist`. Nếu C# có tầng an toàn giả định d
`cancel` từ host huỷ **cả order** (gồm hàng đợi mission), khác với huỷ nội bộ do chính mission layer `cancel` từ host huỷ **cả order** (gồm hàng đợi mission), khác với huỷ nội bộ do chính mission layer
phát ra chỉ dừng chặng đang chạy. phát ra chỉ dừng chặng đang chạy.
**Cancel nói thật từ 2026-09-11.** Sau `navigation_cancel()`, `navigation_get_state()` báo
`PREEMPTING` cho tới khi lõi **im hẳn**, rồi mới `PREEMPTED` (và chốt lại tới yêu cầu kế). "Im hẳn"
là ba điều kiện cùng đúng:
1. lệnh vận tốc = 0 **và** odom đọc ≈ 0 (bánh xe đã đứng, không chỉ lệnh);
2. thread global planner rảnh — một lượt `makePlan` đã huỷ mà plugin không cắt được (SBPL chạy tới
hết `allocated_time`) giữ thread bận nhiều giây, và `PREEMPTED` **không** được báo trong lúc đó;
3. action đang chạy (nếu có) đã trả terminal.
Luật cho host: **không gửi goal kế khi state còn `PREEMPTING`.**
```cpp
navigation_cancel(h);
NavigationState s;
do {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
navigation_get_state(h, &s);
} while (s == PREEMPTING);
// s == PREEMPTED (hoặc PENDING/… nếu đã có việc khác) → an toàn gửi goal kế
```
Gửi sớm không bị từ chối — goal kế đứng ở `PLANNING` tới khi thread rảnh — nhưng hàng đợi phía
host sẽ lệch nhịp với lõi. Trước 2026-09-11 lõi báo `PREEMPTED` sau đúng một cycle bất kể thread
planner; host tin, gửi goal kế, goal kế bị coi là hỏng và `ABORTED` sau ~3 s. Trần chờ là khoá
`settle_timeout` của `move_base2` (mặc định 2 s); quá trần lõi vẫn báo `PREEMPTED` và in lỗi.
### 6.5b. Trạng thái từng thành phần và `LOST` (2026-09-11)
| | Hàm | Đổi |
|---|---|---|
| + | `size_t navigation_get_component_status(NavigationHandle, NavComponentStatus* out, size_t max)` | mới |
Lõi giữ một bảng "ai đang bận / đã được bảo dừng / đã treo" cho 7 thành phần (`global_planner`,
`local_planner`, `recovery`, `action`, `costmap_global`, `costmap_local`, `control_loop`). Hàm này
chép bảng ra cho host; chỉ đọc atomic nên gọi được từ thread bất kỳ — kể cả khi control thread
đang treo, là lúc cần nó nhất. `phase`: 0 idle, 1 busy, 2 stopping, 3 paused, 4 hung; `hung` là kết
luận của watchdog (bận quá ngân sách mà không nhích). Trả 0 với runtime cũ không có capability.
**`LOST`:** control thread không kết thúc được cycle nào quá `control_loop_stall_budget` (mặc định
0.5 s) → `navigation_get_state()` báo `LOST` (ghi từ thread watchdog), `feed_back_str` nêu thời
gian. Host đọc `LOST` phải **tự đưa cmd_vel về 0** — twist từ `navigation_get_twist()` lúc đó là
giá trị cũ, stamp không tiến (mục 6). Hết treo, state thật quay lại.
Dùng khi cancel/pause có vẻ lâu: gọi hàm này, hàng nào `phase = 2` (stopping) lâu là plugin không
tuân preempt; `hung = 1` là treo thật.
### 6.6. Trần vận tốc ### 6.6. Trần vận tốc
| | Hàm | Đổi | | | Hàm | Đổi |

View File

@@ -45,6 +45,17 @@
* the request; the control thread applies it on its next cycle. Returning from the call does * the request; the control thread applies it on its next cycle. Returning from the call does
* not mean the robot stopped — watch the state, or watch the twist. * not mean the robot stopped — watch the state, or watch the twist.
* *
* Since 2026-09-11 the state tells the truth about a cancel: after navigation_cancel() the
* core reports PREEMPTING until it is quiescent — the issued command is zero AND odometry
* reads zero, the global-planner thread is idle (a cancelled makePlan() that the plugin
* cannot interrupt keeps that thread busy for seconds), and any running action has reported
* terminal. Only then does it report PREEMPTED, and that result is latched until the next
* request. Poll navigation_get_state() and do not submit the next goal while it is
* PREEMPTING. A goal submitted early is not rejected — it waits in PLANNING until the
* thread frees — but it is the caller's queue that ends up out of step. The wait is bounded
* by move_base2's `settle_timeout` (default 2 s); on expiry the core still reports
* PREEMPTED and logs an error.
*
* 5. navigation_set_twist_linear() / _angular() set a velocity **ceiling**, and the sign of the * 5. navigation_set_twist_linear() / _angular() set a velocity **ceiling**, and the sign of the
* linear x component selects which direction the ceiling applies to. They now only reject * linear x component selects which direction the ceiling applies to. They now only reject
* NaN/Inf; the old runtime also returned false while a cancel was in flight, and that signal no * NaN/Inf; the old runtime also returned false while a cancel was in flight, and that signal no
@@ -175,6 +186,38 @@ extern "C"
*/ */
char *navigation_get_status_text(NavigationHandle handle); char *navigation_get_status_text(NavigationHandle handle);
/**
* @brief One row of the runtime's component status board (added 2026-09-11).
*
* `phase`: 0 idle, 1 busy, 2 stopping (told to cancel, not yet returned), 3 paused, 4 hung.
* `hung`: the watchdog's verdict — busy longer than the component's budget with no progress.
* Rows, in order: global_planner, local_planner, recovery, action, costmap_global, costmap_local,
* control_loop. Use `name` rather than the index when displaying.
*/
typedef struct
{
char name[32];
unsigned char phase;
unsigned char hung;
double seconds_in_phase;
double seconds_since_progress;
} NavComponentStatus;
/**
* @brief Per-component liveness of the runtime: who is busy, who was told to stop, who is hung.
*
* Reads atomics only — safe from any thread and, critically, still answers while the control
* thread itself is stalled (navigation_get_state() then reports LOST). Poll it when a cancel or
* pause seems to take long, or after LOST, to see which component is stuck.
*
* @param handle Navigation handle.
* @param out Array of at least @p max entries; may be NULL with max = 0 to query the count.
* @param max Capacity of @p out.
* @return Number of rows the runtime has (may exceed @p max); 0 if the runtime does not offer
* the capability (older move_base2) or is not initialized.
*/
size_t navigation_get_component_status(NavigationHandle handle, NavComponentStatus *out, size_t max);
// ============================================================================================ // ============================================================================================
// Sensor input // Sensor input
// ============================================================================================ // ============================================================================================

View File

@@ -14,13 +14,19 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <functional>
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/dll/import.hpp>
#include <boost/dll/runtime_symbol_info.hpp>
#include <robot/plugin_loader_helper.h>
#include <robot/robot.h> #include <robot/robot.h>
#include <move_base_core/common.h> #include <move_base_core/common.h>
#include <move_base_core/component_status_probe.h>
#include <move_base_core/navigation.h> #include <move_base_core/navigation.h>
#include <robot_sensor_msgs/DepthCameraData.h> #include <robot_sensor_msgs/DepthCameraData.h>
@@ -179,6 +185,65 @@ extern "C" bool navigation_get_state(NavigationHandle handle, NavigationState *o
} }
} }
extern "C" size_t navigation_get_component_status(NavigationHandle handle, NavComponentStatus *out,
size_t max)
{
if (!handle)
{
return 0;
}
try
{
// Capability tra MỘT lần theo alias trong .so navigation đang nạp (cùng đường mà
// navigation_create() đã đi). Runtime cũ không export alias → 0, không phải lỗi.
using Probe = std::function<std::size_t(robot::move_base_core::BaseNavigation *,
robot::move_base_core::ComponentStatusEntry *, std::size_t)>;
static Probe probe;
static bool probed = false;
if (!probed)
{
probed = true;
try
{
robot::PluginLoaderHelper loader;
const std::string path = loader.findLibraryPath("MoveBase");
probe = boost::dll::import_alias<std::size_t(robot::move_base_core::BaseNavigation *,
robot::move_base_core::ComponentStatusEntry *,
std::size_t)>(
path, robot::move_base_core::kComponentStatusProbeAlias,
boost::dll::load_mode::append_decorations);
}
catch (const std::exception &e)
{
robot::log_warning("navigation_get_component_status: runtime offers no '%s' capability: %s",
robot::move_base_core::kComponentStatusProbeAlias, e.what());
probe = nullptr;
}
}
if (!probe)
{
return 0;
}
std::vector<robot::move_base_core::ComponentStatusEntry> rows(max);
const std::size_t count = probe(as_navigation(handle), rows.empty() ? nullptr : rows.data(), max);
const std::size_t copied = count < max ? count : max;
for (std::size_t i = 0; i < copied && out != nullptr; ++i)
{
std::memcpy(out[i].name, rows[i].name, sizeof(out[i].name));
out[i].phase = rows[i].phase;
out[i].hung = rows[i].hung;
out[i].seconds_in_phase = rows[i].seconds_in_phase;
out[i].seconds_since_progress = rows[i].seconds_since_progress;
}
return count;
}
catch (...)
{
return 0;
}
}
extern "C" char *navigation_get_status_text(NavigationHandle handle) extern "C" char *navigation_get_status_text(NavigationHandle handle)
{ {
if (!handle) if (!handle)

View File

@@ -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 <cstddef>
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

View File

@@ -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<Preemptable*>` 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