Report why an action failed instead of a bare "action failed"

FrameSamplerActionHandler already builds a precise reason for each way it can
fail: too few samples, detection too scattered, could not publish the output
frame, raw frame never appeared. All four reached the log as the same four
words, because control_loop read the tick, kept only the status, and dropped
the message, while the state machine passed a hard-coded string to finish().

Three field runs in a row could not be diagnosed for that reason: the detector
was healthy, the host confirmed pallet_raw was published and resolvable, and
the only thing navigation said was "action failed".

The handler message now travels through StateMachineInput into the terminal
reason, so it reaches the host feedback as well as the log, and control_loop
logs it directly - as an error when the action fails, as info when it succeeds,
where it carries the sample count worth comparing against the next failure.

StateMachineOutput::reason is a const char* and enter() stores the pointer
rather than copying, so the composed string lives in a StateMachine member.
Building it in a local would return a pointer into destroyed memory - every
other reason in that class is a string literal, so nothing had hit this before.
Two tests cover it: the message reaches the reason, and the reason survives the
StateMachineInput that carried it.

Config in this tree follows the same split as the robot: per-marker dock_anchor
and footprint_dock in maker_sources.yaml, detect handlers separated into
detect_charger and detect_pallet.
This commit is contained in:
2026-08-13 15:01:48 +07:00
parent d10c240395
commit 383a04fe29
11 changed files with 234 additions and 15 deletions

View File

@@ -430,6 +430,10 @@ private:
RecoveryFeedback recovery_feedback_ = RecoveryFeedback::kIdle;
ActionFeedback action_feedback_ = ActionFeedback::kIdle;
/// Lý do action handler đưa ra cho lần tick vừa rồi; chỉ giữ khi tick đó HỎNG, xem
/// @ref StateMachineInput::action_message.
std::string action_message_;
std::vector<robot_geometry_msgs::PoseStamped> latest_plan_;
/// Tuyến tham chiếu của chặng — xem @ref orderPlan. Chỉ ghi từ kết quả của PlannerRunner.
std::vector<robot_geometry_msgs::PoseStamped> order_plan_;

View File

@@ -153,6 +153,18 @@ struct StateMachineInput
RecoveryFeedback recovery = RecoveryFeedback::kIdle;
ActionFeedback action = ActionFeedback::kIdle;
/**
* Lý do action handler đưa ra cho lần tick vừa rồi; rỗng = handler không nói gì.
*
* Chỉ đọc khi @ref action là `kFailed`, và chỉ để ghép vào lý do kết thúc. Không có nó thì mọi
* kiểu hỏng của action đều hiện ra ngoài là đúng một chuỗi `"action failed"` — handler dò frame
* phân biệt được "thiếu mẫu", "dò ra nhưng tản quá", "không publish được" và "frame không bao giờ
* xuất hiện", bốn nguyên nhân với bốn cách xử lý khác nhau, mà người đọc log không thấy cái nào.
*
* Đây là chuỗi cho NGƯỜI đọc, không phải mã lỗi: state machine không rẽ nhánh theo nó.
*/
std::string action_message;
/**
* Lấy được pose robot hay không.
*
@@ -401,6 +413,16 @@ private:
std::size_t recovery_index_ = 0;
RecoveryTrigger active_recovery_trigger_ = RecoveryTrigger::kPlanningFailed;
/**
* Kho giữ lý do action hỏng sau khi ghép với @ref StateMachineInput::action_message.
*
* @ref StateMachineOutput::reason là `const char*` và chỉ lưu CON TRỎ, không sao chép. Mọi lý do
* khác trong lớp này là string literal nên sống suốt chương trình; riêng lý do này được dựng lúc
* chạy, nên phải sống ít nhất bằng object — dựng nó trong một biến cục bộ là trả về con trỏ tới
* bộ nhớ đã huỷ.
*/
std::string action_failure_reason_;
/**
* State đã leo thang vào recovery — quyết định đường quay về khi behavior kết thúc (contract
* 2026-08-04b): từ kControlling thì bám tiếp plan cũ, từ kPlanning (mất pose lúc lập plan) thì