Localization correcting map->odom in the middle of a detection moves samples that were already collected into a different frame. The window then holds two clusters half a metre apart, the spread over the whole window stays above the limit for the rest of the timeout, and the action fails even though each cluster on its own is perfectly tight and the detector never made a mistake. jump_threshold > 0 turns on clustering. Samples are grouped by distance to the cluster CENTRE rather than to the nearest member: a sample caught while TF was interpolating sits between the two clusters and single-linkage would use it as a bridge to merge them back into one. A cluster may be committed only if it holds at least min_cluster_fraction of the window, at least min_cluster_samples in absolute terms, and has a sample newer than cluster_recency seconds. min_cluster_fraction is required to be > 0.5 so at most one cluster can ever qualify - no tie-break rule is needed, and two frames fighting 50/50 leave no winner, which is the right answer: with two centres 0.55 m apart, guessing docks half a metre off. The recency test is what separates the stale majority from the live one; a cluster that is large but cold is the pose from before the correction, in a frame localization has already discarded. Spread is then measured on the winning cluster only, so max_spread_xy/yaw keep their role as the safety gate. configure() rejects the combinations that can never succeed: jump_threshold below max_spread_xy would split good in-tolerance samples into fragments and fail on perfect data, min_cluster_fraction at exactly 0.5 loses uniqueness, and min_cluster_samples above min_samples can never be reached. filter_enabled: false is the deliberate escape hatch - commit the second sample and skip the window, spread and clustering entirely. The second and not the first, because the first lookup after the action starts can return a detection left in the buffer from before the robot stopped; a second sample with a different stamp proves the source is alive and the data is new. settle_delay and timeout still apply, and the timeout check drops to settle_delay alone since that path no longer needs a window. Defaults keep the previous behaviour: jump_threshold 0 means no clustering, filter_enabled true means the full filter.
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,
InstantActionSourceAdapternở 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ị:
- 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. - 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_patiencecủa state machine (mặc định tắt) vàmission_timeoutcủ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.