duongtd a6bc3dfa3d Move the sample filter out of the frame sampler so a second detector can use it
The handler was 1114 lines, of which roughly 200 were "read a pose from TF".
The rest was the filter: a sliding window, cluster rejection for localization
jumps, robust spread, a hold timer, and the diagnostics that make a failed
detection explainable. A detector that finds a dock plate in a laser scan
produces a pose per scan and needs all of that too, and writing it twice is
worse than the duplication - the two copies drift, and a fix lands in one.

PoseSampleFilter now owns the window, the clustering, the spread measurement,
the hold clock, the best-window record and the throttled progress log. The
handler keeps what is actually specific to being a TF source: the lookup and
its stamp-based dedupe, goal_frame, settle_delay and timeout, the simulated
goal path, writing the result back as a static transform, and the three
distinct timeout messages.

The line between them is source versus filtering. last_stamp_ stays with the
handler for that reason - deduplicating on a TF stamp is a property of that
source, and a detector reading from the shared sensor store will dedupe on an
arrival counter instead.

filter_enabled moves into the filter's config rather than staying with the
handler, because it decides whether the cluster keys are validated at all.
Split across two owners, that is one rule two places have to remember, and the
first time they disagree a config that used to load stops loading.

The filter validates its own keys and logs them with the instance name, so the
messages an operator has learned to read come out identical.

Behaviour is unchanged and the test files are untouched: 22 of 22 frame sampler
tests pass as they are. That is the point of doing it this way - the tests
cover exactly the code that moved, so passing them without editing them is what
distinguishes a refactor from a rewrite.

Both detectors now read the same YAML keys, so sample_window, max_spread_xy and
jump_threshold are learned once rather than once per detector.
2026-08-26 12:30:51 +07:00
2026-08-10 10:52:16 +07:00
2026-08-10 21:51:08 +07:00

action_core

Interface tick-based cho phần thực thi action của một mission, kèm bộ handler mặc định và registry nạp plugin.

Gói này không biết navigation là gì. Nó chỉ định nghĩa "một action được thực thi như thế nào" và cho phép nạp thêm loại action mới bằng file .so — cùng khuôn với recovery_core cho recovery behavior. Bên tiêu thụ hiện tại là move_base2::ActionRunner, nhưng contract không ràng buộc vào nó.

Action tới ActionRunner từ hai đường của VDA5050, và cả hai đi qua cùng bảng compound_actions nên cùng một actionType luôn có cùng một nghĩa:

  • node action của một order — mission layer cắt order thành chặng tại mỗi node có action;
  • instantActions — một message ngoài order, InstantActionSourceAdapter nở nó thành đúng chuỗi chặng như trên.

Handler vì thế không cần biết action đến bằng đường nào, và không được phép cư xử khác nhau theo đường vào.

Contract

class ActionHandler
{
  virtual bool configure(const std::string& name, robot::NodeHandle& nh) = 0;
  virtual std::vector<std::string> supportedActionTypes() const = 0;
  virtual bool start(const robot_protocol_msgs::Action& action, const robot::Time& now) = 0;
  virtual ActionTick update(const robot::Time& now) = 0;   // kRunning | kSucceeded | kFailed
  virtual void cancel() = 0;
};

Vòng đời: configure một lần khi nạp → start khi caller giao action → update mỗi control cycle → cancel nếu bị huỷ giữa chừng.

Hai điều kiện bắt buộc, cả hai đều là ràng buộc an toàn chứ không phải khuyến nghị:

  1. Không được block. update() chạy trên control thread ở tần số điều khiển. Chờ thiết bị thì giữ state nội bộ và trả kRunning; nhờ vậy cancel/pause/emergency luôn được phản hồi trong một cycle.
  2. Phải tự timeout. Đây là tầng 1 — tầng chính — trong contract 3 tầng, vì chỉ handler biết ngưỡng đúng cho thiết bị của nó ("nâng kệ quá 20 s là bất thường" khác hẳn "sạc 30 phút là bình thường"). Hai tầng còn lại thuộc về caller và cả hai đều là lưới cuối: action_patience của state machine (mặc định tắt) và mission_timeout của mission layer.

ActionTick cố ý không mang vận tốc: trong lúc chạy action không ai được phát cmd_vel. Action cần chuyển động phải được mô hình hoá thành motion profile của navigation, không phải do handler tự lái — hai nguồn vận tốc cùng lúc là lỗi đã tốn nhiều công để loại bỏ khỏi runtime này.

Bộ handler mặc định

Plugin actionType mặc định Chạy được trên robot thật?
WaitActionHandler wait Có. Chờ đúng khoảng thời gian lấy từ actionParameters của chính action (duration), có trần max_duration. Chờ chính là công việc, không giả vờ điều khiển gì
LogReportActionHandler logReport Có. Ghi nội dung action ra log rồi hoàn tất — đúng ngữ nghĩa mà VDA5050 định nghĩa cho action này
NoopActionHandler wait (cấu hình được) Không — chỉ sim/dev. Log rồi báo thành công sau duration giây. Một PickUp chạy qua đây nghĩa là robot báo "đã nâng kệ" trong khi càng nâng chưa nhúc nhích

NoopActionHandler vẫn có ba công dụng thật: cho actionType chưa có thiết bị chạy được, dựng deployment end-to-end trước khi phần cứng sẵn sàng, và làm fault-injection (hang: true) cho test.

Cấu hình

actions:
  handlers:
    - {name: waiter,   type: WaitActionHandler}
    - {name: reporter, type: LogReportActionHandler}

  waiter:
    action_types: [wait]
    default_duration: 0.0    # [s] khi action không kèm tham số `duration`
    max_duration: 600.0      # [s] trần cứng; vượt trần thì action THẤT BẠI, không bị cắt ngắn

  reporter:
    action_types: [logReport]

WaitActionHandler:
  library_path: libaction_core_wait_action_handler
LogReportActionHandler:
  library_path: libaction_core_log_report_action_handler

Danh sách handlers được phép rỗng — một hệ không có thiết bị nào thì mọi mission đều là nav-only. Khi đó ActionRegistry chỉ cảnh báo, và bên tiêu thụ mới là chỗ từ chối action kèm lý do nêu đích danh actionType không ai nhận.

Thiếu khoá library_path là nguyên nhân phổ biến nhất của "plugin build xong nhưng runtime báo không tìm thấy"; registry báo lỗi nêu đích danh khoá bị thiếu.

Build và test

catkin_make --pkg action_core

./devel/lib/action_core/action_registry_test
./devel/lib/action_core/wait_action_handler_test
./devel/lib/action_core/log_report_action_handler_test
./devel/lib/action_core/noop_action_handler_test

Test tự trỏ PNKX_NAV_CORE_CONFIG_DIR vào test/config/ và PNKX_NAV_CORE_LIBRARY_PATH vào devel/lib (overwrite = 0), nên chạy được thẳng qua ctest mà không cần source workspace.

Viết handler mới: xem docs/PLUGIN_GUIDE.md.

Description
No description provided
Readme 220 KiB
Languages
C++ 92.4%
CMake 7.6%