Files
move_base2/config/runtime/maker_sources.yaml
duongtd d10c240395 Feed per-marker docking parameters to the global planner
A docking global planner has no way to learn which marker the leg is for:
BaseGlobalPlanner::initialize() takes only the plugin name and the costmap,
and the plugin builds its own NodeHandle to read parameters. The only channel
left is the parameter tree, so copy the marker's keys into the planner's
namespace before the instance is built - the same shape as
Costmap2DROBOT::copyParentParameters() pouring parameters into each layer.

PlannerPort::bindDockingMarker() is called at the request gate, right before
swapPlanner(), because swapPlanner is where the instance is built and reads
its parameters. Copying afterwards would be a no-op: initialize() runs once.

- The destination is whatever global_planner the profile names, so a marker
  bound to a planner other than DockPlanner writes into that planner's
  namespace. Only DockPlanner reads footprint_dock today; the config
  documents that the value is inert elsewhere.
- The namespace is verified after construction. robot::NodeHandle silently
  falls back to its parent when a namespace does not resolve, so a mistyped
  marker would otherwise read footprint from ROOT - the robot footprint -
  and use it as the dock's size.
- The cached instance is rebuilt when the marker changes, and swapPlanner no
  longer short-circuits on an unchanged planner name, otherwise the second
  dock would run with the first dock's geometry. Rebuilds are skipped when
  the same marker is bound again.
- The replaced instance is retired rather than destroyed: the planner thread
  captures the active pointer and releases the mutex before calling into the
  plugin, so destroying it from the control thread is a use-after-free.

Add eight PlannerRunner tests. The test plugin now exports its initialize()
count and the footprint it read, which is the only way to observe from
outside that the rebuild actually happened.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 21:53:12 +07:00

87 lines
5.4 KiB
YAML

# =================================================================================================
# move_base2 — danh sách marker docking hợp lệ và cặp planner riêng của từng marker.
#
# Quy ước comment: dòng mô tả = LÀ GÌ / vì sao; `► Chỉnh:` = sửa thế nào cho đúng.
#
# Danh sách cho phép, dùng cho `BaseNavigation::dockTo(marker, ...)`.
#
# move_base2 docking quy `goal_frame` thành pose TUYỆT ĐỐI rồi chạy DockPlanner + local planner
# docking. Nó KHÔNG đọc bộ tham số per-marker của PNKXDockingLocalPlanner cũ (plugins,
# maker_goal_frame, delay, timeout, velocity, tolerance, lookahead) — những khoá đó nếu còn sót lại
# ở đâu đó cũng không có tác dụng.
# =================================================================================================
# Marker mà host được phép gửi xuống. Đây là ALLOW-LIST: tên không có trong dòng này bị từ chối
# ngay tại `dockTo`, không đi tới planner.
#
# ► Chỉnh: chỉ thêm/bớt TÊN, cách nhau bằng khoảng trắng. Giữ danh sách tối thiểu — mỗi tên thừa là
# một đường vào chưa được kiểm chứng. Sẽ bỏ hẳn khi `dockTo` được chuyển sang dock_sequences khai
# báo trong compound_actions_params.yaml.
maker_sources: trolley charger dock_station pallet
# Marker có entry ở đây dùng CẶP PLANNER RIÊNG. Marker rỗng, hoặc chỉ có trong `maker_sources` mà
# không nằm trong bảng này, sẽ dùng cặp `docking` mặc định của move_base_common_params.yaml.
#
# ► Chỉnh: chỉ khai marker nào THỰC SỰ cần planner khác mặc định. Tham số của planner nằm ở YAML
# riêng của plugin (dock_global_params.yaml, hybrid_local_planner_params.yaml), KHÔNG khai ở đây —
# trừ `footprint_dock` dưới đây.
#
# ── footprint_dock ────────────────────────────────────────────────────────────────────────────────
#
# Đa giác của ĐỐI TƯỢNG DOCK (kệ / trạm sạc), [m], trong frame của goal pose. KHÔNG phải footprint
# robot: footprint robot khai ở costmap và dùng cho collision check, còn khoá này vào khoảng dừng
# của DockCalc — điểm robot bắt đầu đoạn căn thẳng trước dock:
#
# alignment_distance = <extent mép robot dẫn đầu> + <extent tâm dock → mặt gần> + padding
#
# Chỉ dùng khi `dock_anchor: center`. Khai thiếu = dock bị coi là một điểm, robot tiến sát hơn dự
# tính đúng extent tới mặt gần.
#
# ── dock_anchor ───────────────────────────────────────────────────────────────────────────────────
#
# Goal pose của marker nằm ở đâu trên đối tượng dock:
# center — goal ở tâm footprint dock; DockPlanner cộng thêm extent từ tâm tới mặt tiếp cận
# (lấy từ footprint_dock). Mặc định khi không khai — giữ nguyên hành vi cũ.
# face — goal đã nằm ngay tâm MẶT tiếp cận; dock không đóng góp vào khoảng dừng,
# footprint_dock bị bỏ qua hoàn toàn (DockPlanner log info nếu vẫn khai).
#
# Hai khoá trên là các khoá DUY NHẤT trong bảng này được rót xuống plugin:
# `PlannerRunner::bindDockingMarker()` chép chúng sang namespace của `global_planner` khai ngay bên
# trên, TRƯỚC khi instance được dựng, rồi dựng lại instance khi marker đổi.
#
# ⚠ Chỉ `DockPlanner` đọc hai khoá này. Marker nào khai `global_planner: TwoPointsPlanner` thì giá
# trị vẫn được chép sang namespace đó nhưng không ai đọc — không lỗi, không log, chỉ là không có
# tác dụng.
#
# ► Chỉnh: đo kích thước THẬT của từng loại kệ/trạm — chúng khác nhau, để trùng số là mất tác dụng
# của việc khai theo marker. Trục x là hướng robot tiến vào. Chọn `dock_anchor` theo cách teach
# goal của từng loại: goal teach ở mặt (pallet, charger) → face; goal teach ở tâm (trolley chui
# gầm) → center.
docking_marker_profiles:
trolley:
global_planner: DockPlanner
local_planner: HybridLocalPlanner
# Goal ở trọng tâm xe trolley (robot chui gầm) → cộng extent tâm→mặt từ footprint_dock.
dock_anchor: center
footprint_dock: [[0.583,-0.48],[0.583,0.48],[-0.583,0.48],[-0.583,-0.48]]
charger:
global_planner: TwoPointsPlanner
local_planner: HybridLocalPlanner
# Goal teach ngay tâm mặt trạm sạc. Chỉ có tác dụng nếu đổi sang DockPlanner.
dock_anchor: face
footprint_dock: [[0.583,-0.48],[0.583,0.48],[-0.583,0.48],[-0.583,-0.48]]
dock_station:
global_planner: TwoPointsPlanner
local_planner: HybridLocalPlanner
dock_anchor: center
footprint_dock: [[0.583,-0.48],[0.583,0.48],[-0.583,0.48],[-0.583,-0.48]]
pallet:
global_planner: DockPlanner
local_planner: HybridLocalPlanner
# Goal teach ở tâm mặt pallet → dock không đóng góp khoảng dừng, footprint_dock bị bỏ qua.
dock_anchor: face
footprint_dock: [[0.9,-0.8],[0.9,0.8],[-0.9,0.8],[-0.9,-0.8]]