duongtd ea79686eef 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>
2026-09-12 22:06:50 +07:00
2026-08-09 18:48:16 +07:00
2026-08-09 18:48:16 +07:00
2026-08-09 18:48:16 +07:00

sbpl_recovery

Recovery behavior họ path cho recovery_core: khi local planner bế tắc (vật cản chắn tuyến), behavior lập một đường vòng bằng một global planner plugin — mặc định SBPLLatticePlanner — rồi nối đường vòng vào phần còn lại của global plan hiện hành và trả về cho runtime bám tiếp.

Port từ navigation_experimental/sbpl_recovery (BSD, Eitan Marder-Eppstein) sang hệ sinh thái robot_* (không roscpp).

Khác bản gốc ở đâu

Bản gốc (ROS) Bản này
Tự lái: chạy pose_follower bên trong, publish thẳng cmd_vel Không lái. Trả RecoveryOutputType::kPath; runtime áp path và local planner đang active bám theo — một nguồn vận tốc duy nhất
Plan nhận qua topic NavfnROS/plan Plan đến từ RecoveryContext::plan — chính plan control loop đang bám
Sau recovery move_base replan nên chỉ cần lập tới điểm nối Splice: path trả về = đường vòng + phần plan cũ sau điểm nối, vì runtime không replan sau recovery (contract 2026-08-04b)
pluginlib boost::dll + BOOST_DLL_ALIAS(…, DetourPathRecovery) + library_path trong YAML

Local costmap hay global costmap?

Mặc định local costmap (use_global_costmap: false):

  • vật cản buộc phải vòng là thứ sensor vừa thấy — nằm tươi nhất trong local costmap;
  • cửa sổ lăn nhỏ nên một lượt SBPL bounded (~vài chục ms), chạy được trong một tick recovery.

Đổi lại hai ràng buộc:

  • điểm nối phải nằm trong cửa sổ local — vật cản chắn dài hơn nửa cửa sổ thì behavior trả kFailed và nhường behavior kế tiếp trong route;
  • local costmap chạy ở frame odom, plan ở frame map → cần RecoveryContext::tf (runtime đã nối sẵn). Thiếu TF thì lượt chạy bị từ chối kèm lý do.

use_global_costmap: true khi cần vòng xa hơn cửa sổ (đổi lại phụ thuộc độ tươi của obstacle layer trên global costmap).

Cấu hình

recovery:
  behaviors:
    - {name: detour_path, type: DetourPathRecovery}
  routes:
    # Thêm detour_path vào route nào cần đường vòng, ví dụ:
    # controlling_failed: [wait, detour_path]
  detour_path:
    planner_name: SBPLLatticePlanner  # global planner gen-1, nạp qua library_path ở root config
    use_global_costmap: false
    planning_distance: 2.0            # [m] điểm nối cách robot tối thiểu chừng này dọc plan
    sample_step: 0.5                  # [m] khoảng cách dọc plan giữa hai ứng viên điểm nối
    rejoin_clearance: 0.5             # [m] điểm nối cách POSE BẨN GẦN NHẤT tối thiểu chừng này
    attempts_per_run: 3               # số ứng viên thử tối đa một lượt (mỗi tick thử một ứng viên)
    timeout: 10.0                     # [s] trần lượt, recovery_core cưỡng chế

DetourPathRecovery:
  library_path: libsbpl_recovery

Planner đọc tham số từ namespace mang tên chính nó (SBPLLatticePlanner/…) — trùng tên với backup_global_planner thì dùng chung tuning, gồm cả primitive_filename (độ phân giải mprim phải khớp resolution của costmap được chọn).

Hai khoá lock_costmap: false và costmap_frame_override chỉ dành cho unit test với costmap placeholder — production không đặt.

Chọn điểm nối

Ứng viên điểm nối phải đặt được robot vào (RecoveryContext::collision, footprint thật) và cách pose bẩn gần nhất dọc plan ít nhất rejoin_clearance. Chọn thuần theo khoảng cách — như bản gốc — cho ra ứng viên nằm ngay trên vật cản đang chắn tuyến: planner không bao giờ tới được, mà mỗi lượt thử hỏng vẫn giữ mutex costmap trọn allocated_time và làm đói thread cập nhật costmap.

Không có ứng viên nào đặt được → start() trả false ngay, không chạy lượt SBPL nào. Context không có collision checker → quay về luật thuần-khoảng-cách (không biết thì không loại).

Verify

catkin_make --pkg sbpl_recovery
./devel/lib/sbpl_recovery/detour_path_recovery_test

Test dùng planner giả (TestLinePlanner, nạp qua đúng đường Boost.DLL) — kiểm chọn điểm nối, splice, thử-lại theo ứng viên, quy đổi frame map↔odom qua tf3, mất pose giữa lượt, và từ chối khi thiếu TF. Đường chạy với SBPL thật thuộc test tích hợp trên sim.

Description
No description provided
Readme 146 KiB
Languages
C++ 91.5%
CMake 8.5%