feat: run detour planning on a worker thread so cancel doesn't block the control loop

DetourPathRecovery was the one recovery behavior that mattered for the
onCancelRequested() fix in recovery_core (commit 254c7fc): it calls
SBPLDetourPlanner::makePlan() synchronously from update(), which runs on
the control thread — cancel arriving mid-search had nothing to preempt it
with, and the control loop itself would stall for the remainder of
allocated_time.

- Moves the search to a per-attempt worker thread (startWorker/workerBody/
  planInto/finishAttempt/waitWorker/joinWorker/requestWorkerStop); update()
  only polls.
- onCancelRequested() (new override): preempts via
  robot_nav_core::Preemptable if the inner planner supports it (see
  Test/sbpl_lattice_planner), then waits up to cancel_join_timeout (0.2 s)
  and joins — cancel now actually blocks until the worker is gone, not
  just until a flag is set.
- onStart() joins a stale worker from a previous attempt before starting a
  new one; destructor joins too.
- async_planning param (default true) so tests can force the old
  synchronous path when they need deterministic single-thread timing.
- Uses RECOVERY_CORE_EXPORT_BEHAVIOR for the ABI version symbol.
- test/plugins/test_line_planner.cpp: added plan_delay (simulate a slow
  search) and made it Preemptable, exported as TestSlowPlanner, to drive
  the new worker-thread cancel tests.

Depends on recovery_core commit 254c7fc (onCancelRequested hook + ABI
macro) and Test/sbpl_lattice_planner commit 7456e99 (Preemptable pattern
this follows).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-12 22:06:50 +07:00
parent 8f9326be04
commit ea79686eef
4 changed files with 400 additions and 19 deletions

View File

@@ -13,6 +13,8 @@ recovery:
- {name: detour_map, type: DetourPathRecovery}
- {name: detour_narrow, type: DetourPathRecovery}
- {name: detour_alias, type: DetourPathRecovery}
- {name: detour_async, type: DetourPathRecovery}
- {name: detour_slow, type: DetourPathRecovery}
detour:
planner_name: TestLinePlanner
@@ -21,6 +23,7 @@ recovery:
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
detour_flaky:
planner_name: TestFlakyPlanner # hai ứng viên đầu bị "chắn", ứng viên ba mới thông
@@ -29,6 +32,7 @@ recovery:
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
detour_dead:
planner_name: TestDeadPlanner # không ứng viên nào thông -> behavior phải kFailed
@@ -37,6 +41,7 @@ recovery:
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
detour_map:
planner_name: TestLinePlanner # plan ở frame map, costmap ở odom -> ép đường quy đổi TF
@@ -45,6 +50,7 @@ recovery:
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
# Tên instance KHÁC symbol: đọc param từ `DetourOnlyTuning`, nạp .so theo alias `TestLinePlanner`.
# Đây là đường mà cấu hình runtime dùng để cho detour một instance SBPL riêng (allocated_time
@@ -57,6 +63,25 @@ recovery:
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
# Đường bất đồng bộ (mặc định production): planner giả ngủ 0.3 s, có Preemptable.
detour_async:
planner_name: TestSlowPlanner
planning_distance: 1.0
sample_step: 0.5
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
cancel_join_timeout: 0.5 # [s]
# Cùng planner; instance riêng để test cancel giữa chừng không dính bộ đếm của instance trên.
detour_slow:
planner_name: TestSlowPlanner
planning_distance: 1.0
sample_step: 0.5
attempts_per_run: 3
lock_costmap: false
costmap_frame_override: odom
cancel_join_timeout: 0.5 # [s]
detour_narrow:
planner_name: TestOffsetPlanner # planner giả luôn vẽ đường vòng lệch 1.0 m khỏi tuyến
@@ -66,6 +91,7 @@ recovery:
max_deviation: 0.2 # [m] chặt hơn độ lệch của planner -> mọi ứng viên bị loại
lock_costmap: false
costmap_frame_override: odom
async_planning: false # planner giả tức thì — giữ đường đồng bộ để test đếm tick như cũ
# Bảng symbol -> thư viện cho Boost.DLL. Ba symbol planner cùng một .so; param của planner đọc theo
# namespace mang tên symbol.
@@ -80,6 +106,10 @@ TestDeadPlanner:
library_path: libsbpl_recovery_test_line_planner
fail_first_attempts: 1000
TestSlowPlanner:
library_path: libsbpl_recovery_test_line_planner
plan_delay: 0.3 # [s] một lượt "search" giả
# Luôn vẽ đường vòng lệch 1.0 m khỏi đoạn thẳng start->goal: dùng để kiểm guard max_deviation.
TestOffsetPlanner:
library_path: libsbpl_recovery_test_line_planner