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:
@@ -1282,6 +1282,48 @@ TEST(StateMachineActions, ActionFailureAbortsWithoutRecovery)
|
||||
EXPECT_TRUE(out.report_outcome);
|
||||
EXPECT_EQ(out.outcome, NavigationOutcome::kFailed);
|
||||
EXPECT_FALSE(out.start_recovery) << "recovery repairs navigation, it cannot rescue an action";
|
||||
EXPECT_STREQ(out.reason, "action failed")
|
||||
<< "handler im lặng thì vẫn phải có lý do chung, không được rỗng";
|
||||
}
|
||||
|
||||
TEST(StateMachineActions, ActionFailureReasonCarriesTheHandlerMessage)
|
||||
{
|
||||
// Handler dò frame phân biệt được "thiếu mẫu", "tản quá", "không publish được" và "frame không
|
||||
// xuất hiện". Không mang chuỗi đó ra ngoài thì cả bốn hiện lên log y hệt nhau — đã mất ba lần
|
||||
// chạy hiện trường liên tiếp vì không truy được nguyên nhân.
|
||||
Driver driver;
|
||||
ASSERT_EQ(driver.tick(requestWithActions(1, /*has_goal=*/false)).state,
|
||||
NavigationState::kExecutingActions);
|
||||
|
||||
StateMachineInput failed = actionFb(ActionFeedback::kFailed);
|
||||
failed.action_message = "action 'detect': only 12 sample(s) of 'pallet_raw', need 20";
|
||||
|
||||
const StateMachineOutput out = driver.tick(failed);
|
||||
ASSERT_EQ(out.state, NavigationState::kAborted);
|
||||
EXPECT_STREQ(out.reason,
|
||||
"action failed: action 'detect': only 12 sample(s) of 'pallet_raw', need 20");
|
||||
}
|
||||
|
||||
TEST(StateMachineActions, ActionFailureReasonOutlivesTheInputThatCarriedIt)
|
||||
{
|
||||
// `StateMachineOutput::reason` là `const char*` và chỉ lưu CON TRỎ. Lý do này được ghép lúc chạy
|
||||
// chứ không phải string literal, nên nếu nó nằm trong biến cục bộ hay trong chính `in` thì con trỏ
|
||||
// treo ngay khi lời gọi kết thúc — hỏng im lặng, sanitizer mới thấy.
|
||||
Driver driver;
|
||||
ASSERT_EQ(driver.tick(requestWithActions(1, /*has_goal=*/false)).state,
|
||||
NavigationState::kExecutingActions);
|
||||
|
||||
StateMachineOutput out;
|
||||
{
|
||||
StateMachineInput failed = actionFb(ActionFeedback::kFailed);
|
||||
failed.action_message = "action 'detect': detection unstable (spread xy=0.041 m)";
|
||||
out = driver.tick(failed);
|
||||
// `failed` bị huỷ ở đây, kéo theo buffer của action_message.
|
||||
}
|
||||
|
||||
ASSERT_EQ(out.state, NavigationState::kAborted);
|
||||
EXPECT_STREQ(out.reason,
|
||||
"action failed: action 'detect': detection unstable (spread xy=0.041 m)");
|
||||
}
|
||||
|
||||
TEST(StateMachineActions, CancelDuringActionCancelsPortAndEndsCancelled)
|
||||
|
||||
Reference in New Issue
Block a user