feat: trigger collision riêng, ngân sách recovery theo dịch chuyển, guard đo bằng thời gian/góc
Năm thay đổi của cùng một chiến dịch: robot đứng chết ở góc trụ và giữa đám đông. Mọi con số dưới đây lấy từ log sim ngày 3-4/9, ghi lại trong Test/COLLISION_GUARD_LOOP_FIX_PLAN.md. 1) Ngân sách recovery nạp lại theo DỊCH CHUYỂN (state_machine) Trước: recovery thành công + nộp path mới thì cursor route reset NGAY. Sim 4/9: guard chặn tại chỗ -> detour lập lại đúng đường cũ (cost y hệt, 0 ms) -> cursor về 0 -> chặn lại sau 2 cycle -> 249 vòng trong 52 s, robot bất động, controller_patience không bao giờ tích đủ vì path_blocked chen trước mỗi 0.2 s. Giờ chỉ nạp lại khi robot đã đi >= recovery_reset_min_travel (0.10 m) kể từ lần nạp trước; chưa đi thì tính như một lần thất bại -> route cạn -> mute -> controller_patience -> controlling_failed -> ABORT có lý do, ~2 s. Mốc theo origin đo quãng đường (reset cùng lúc với nó), nếu không thì 0.18 m sau path mới bị báo "0.00 m" và ABORT oan. 2) Guard loại trừ BASELINE (plan_inspector) Câu hỏi đổi từ "thân có đè LETHAL không" thành "lệnh này có đưa THÊM ô LETHAL vào thân không". Ô đã nằm dưới thân đệm tại pose hiện tại được gom thành baseline (rasterize diện tích ~600 ô, binary_search) và bỏ qua ở các mẫu sau. Sim 4/9: người kề hông ở 0.46 m ngang (thân 0.48 + đệm 0.05) làm mẫu đầu tiên báo "0.05 m" mãi dù PRIEST lệnh đi thẳng, SBPL (không đệm) bảo đi được, robot đứng chết. Trượt song song thì đi được, rẽ vào thì vẫn chặn. 3) Thân robot lấy từ FOOTPRINT COSTMAP collision_*_offset = 0 cả ba -> hỏi PathCheckPort::robotBodyExtents() mỗi cycle (footprint không đệm, cùng hình với SBPL và PRIEST). Đổi footprint lúc chạy là guard đổi theo, không phải chép số vào hai file. Khai tay thì phải đủ cả ba, khai lửng là config sai. Không có nguồn nào thì báo lỗi và KHÔNG kết luận — dừng mù là biến lỗi cấu hình thành robot chết. 4) "Sắp chạm" đo bằng THỜI GIAN và GÓC, không chỉ mét Mét dọc cung không nói lên gì với cung xoay gần tại chỗ: cùng 0.15 m, đi thẳng 0.36 m/s là chạm sau 0.4 s, còn xoay bò v 0.04 omega -0.5 (R 0.08 m) là quay 107 độ và còn 3.8 s — PRIEST đã thôi xoay sau 30-60 độ để thẳng hàng với path. Sim 16:26: 11 lần nổ trong 15 s tại góc trụ, xoay 0.9 rad mất 12 s thay vì 2 s. Giờ chỉ dừng khi t_contact <= collision_stop_time HOẶC turn <= collision_stop_angle; ngoài đó chỉ kẹp v. Đi thẳng (turn ~ 0) không đổi hành vi. Cung cũng không dò quá collision_lookahead_angle. 5) Trigger kCollision RIÊNG cho Phép đo 3 Trước dùng chung path_blocked. Phép đo 1 nổ ở 3 m nên lập lại đường là đủ; Phép đo 3 nổ khi đã sát vật, replan từ đúng pose đó thường trả cùng path hoặc không ra nghiệm (start trong vành 253) — muốn thoát phải ĐỔI POSE, tức back_up đứng trước detour_path. Route, ngân sách và khoá đều riêng. Ưu tiên collision > path_blocked > off_path. Cạn route vẫn là KHOÁ chứ không ABORT (contract 2026-08-05e). Config: tách path_monitor ra file riêng path_monitor_params.yaml, sắp xếp lại theo bốn phép đo; recovery_behaviors_params.yaml sắp xếp lại theo trigger và dọn bốn khoá chết của mô hình detour cũ. Khoá mới: recovery_reset_min_travel, collision_exclude_baseline, collision_stop_time, collision_stop_angle, collision_lookahead_angle. Debug (khoá debug/state): dòng "hit at sample K: <edge> edge touches cell (x, y)" và "body overlaps N LETHAL cell(s) ... letting it move" để phân biệt "góc thân quét tới" với "người bước tới" khi đọc log mà không có costmap. Verify: catkin_make --pkg move_base2 rc=0; ctest -R move_base2 15/15 (MotionCheck 16, CollisionGuard 13, RecoveryBudget 6, config 34). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013rayqed51UoUzE7QDRmM9K
This commit is contained in:
@@ -38,6 +38,17 @@ bool StateMachineConfig::validate(std::string& error) const
|
||||
"every cycle counts as oscillating";
|
||||
return false;
|
||||
}
|
||||
if (recovery_reset_min_travel < 0.0)
|
||||
{
|
||||
error = "recovery_reset_min_travel must be >= 0 [m] (0 = a new path always refills the route)";
|
||||
return false;
|
||||
}
|
||||
if (oscillation_distance > 0.0 && recovery_reset_min_travel > oscillation_distance)
|
||||
{
|
||||
error = "recovery_reset_min_travel must be <= oscillation_distance [m]: past that distance every "
|
||||
"route cursor is refilled anyway, so a larger value can never take effect";
|
||||
return false;
|
||||
}
|
||||
if (planner_patience <= 0.0 && max_planning_retries < 0)
|
||||
{
|
||||
// Từ khi lập plan chạy trên thread riêng, hai tham số này là thứ DUY NHẤT phát hiện được planner
|
||||
@@ -79,9 +90,11 @@ bool StateMachineConfig::validate(std::string& error) const
|
||||
|
||||
// Hai route giám sát tuyến được phép RỖNG (= tắt cơ chế tương ứng), nhưng index đã khai thì phải
|
||||
// trỏ vào behavior có thật: index giả sẽ thành `start()` vào một behavior không tồn tại lúc chạy.
|
||||
if (!indices_valid(recovery_routes.path_blocked) || !indices_valid(recovery_routes.off_path))
|
||||
if (!indices_valid(recovery_routes.path_blocked) || !indices_valid(recovery_routes.off_path) ||
|
||||
!indices_valid(recovery_routes.collision))
|
||||
{
|
||||
error = "recovery route 'path_blocked'/'off_path' references a behavior that was not loaded";
|
||||
error = "recovery route 'path_blocked'/'off_path'/'collision' references a behavior that was "
|
||||
"not loaded";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,6 +116,9 @@ std::string StateMachineConfig::describe() const
|
||||
out << " action_patience : " << action_patience << " s"
|
||||
<< (action_patience > 0.0 ? "" : " (off — handler times out on its own)") << '\n';
|
||||
out << " oscillation_distance : " << oscillation_distance << " m\n";
|
||||
out << " recovery_reset_min_travel : " << recovery_reset_min_travel << " m"
|
||||
<< (recovery_reset_min_travel > 0.0 ? "" : " (off — a new path always refills the route)")
|
||||
<< '\n';
|
||||
out << " max_planning_retries : " << max_planning_retries
|
||||
<< (max_planning_retries < 0 ? " (unlimited)" : "") << '\n';
|
||||
out << " recovery_enabled : " << (recovery_enabled ? "true" : "false") << '\n';
|
||||
@@ -115,7 +131,10 @@ std::string StateMachineConfig::describe() const
|
||||
{
|
||||
out << " recovery_routes : planning=" << recovery_routes.planning_failed.size()
|
||||
<< " controlling=" << recovery_routes.controlling_failed.size()
|
||||
<< " oscillation=" << recovery_routes.oscillation.size() << '\n';
|
||||
<< " oscillation=" << recovery_routes.oscillation.size()
|
||||
<< " path_blocked=" << recovery_routes.path_blocked.size()
|
||||
<< " off_path=" << recovery_routes.off_path.size()
|
||||
<< " collision=" << recovery_routes.collision.size() << '\n';
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
@@ -166,6 +185,8 @@ void StateMachine::reset()
|
||||
state_before_recovery_ = NavigationState::kPlanning;
|
||||
recovery_route_cursors_.fill(0);
|
||||
monitor_trigger_suppressed_.fill(false);
|
||||
has_path_reset_mark_ = false;
|
||||
travel_at_last_path_reset_ = 0.0;
|
||||
planning_retries_ = 0;
|
||||
request_has_goal_ = true;
|
||||
action_count_ = 0;
|
||||
@@ -214,6 +235,8 @@ std::size_t cursorSlot(RecoveryTrigger trigger)
|
||||
return 3;
|
||||
case RecoveryTrigger::kOffPath:
|
||||
return 4;
|
||||
case RecoveryTrigger::kCollision:
|
||||
return 5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -231,7 +254,8 @@ const std::size_t& StateMachine::recoveryRouteCursor(RecoveryTrigger trigger) co
|
||||
|
||||
bool StateMachine::isMonitorTrigger(RecoveryTrigger trigger)
|
||||
{
|
||||
return trigger == RecoveryTrigger::kPathBlocked || trigger == RecoveryTrigger::kOffPath;
|
||||
return trigger == RecoveryTrigger::kPathBlocked || trigger == RecoveryTrigger::kOffPath ||
|
||||
trigger == RecoveryTrigger::kCollision;
|
||||
}
|
||||
|
||||
void StateMachine::suppressMonitorTrigger(RecoveryTrigger trigger, StateMachineOutput& out)
|
||||
@@ -331,6 +355,8 @@ void StateMachine::acceptPendingRequest(const StateMachineInput& in, StateMachin
|
||||
last_oscillation_reset_ = in.now;
|
||||
sensor_stale_active_ = false;
|
||||
monitor_trigger_suppressed_.fill(false);
|
||||
has_path_reset_mark_ = false; // origin đo quãng đường đặt lại ngay dưới -> mốc cũ vô nghĩa
|
||||
travel_at_last_path_reset_ = 0.0;
|
||||
out.reset_oscillation_origin = true;
|
||||
enter(NavigationState::kPlanning, in.now, "new request accepted", out);
|
||||
}
|
||||
@@ -530,6 +556,11 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
// nghĩa là hình thế đã khác, thử vòng lại là đáng. Đứng im vì bị chắn thì không bao giờ tới
|
||||
// đây — đúng ý đồ: không đốt SBPL vào một tình huống chưa đổi.
|
||||
monitor_trigger_suppressed_.fill(false);
|
||||
|
||||
// Origin vừa đặt lại nên travelled_since_oscillation_reset sẽ về 0 ở cycle sau; mốc của
|
||||
// recovery_reset_min_travel phải đi theo, nếu không hiệu số âm sẽ khoá nạp lại vĩnh viễn.
|
||||
has_path_reset_mark_ = false;
|
||||
travel_at_last_path_reset_ = 0.0;
|
||||
}
|
||||
|
||||
if (controller == ControllerFeedback::kGoalReached)
|
||||
@@ -555,22 +586,30 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
// vòng đi đâu nữa — và TRƯỚC nhánh sinh lệnh: đã biết tuyến tắc thì không chạy thêm một cycle
|
||||
// nào về phía vật cản.
|
||||
//
|
||||
// `path_blocked` thắng `off_path` khi cả hai cùng đúng: tuyến bị chắn là NGUYÊN NHÂN, còn
|
||||
// lệch tuyến thường là HỆ QUẢ của việc local planner tự né chính vật cản đó.
|
||||
// Thứ tự ưu tiên khi nhiều cờ cùng đúng: `collision` (2026-09-04, Phép đo 3 — thân sắp chạm
|
||||
// trong 0.2 m) > `path_blocked` (tuyến tắc, 3 m trước) > `off_path`. Gần nhất xử lý trước;
|
||||
// tuyến bị chắn là NGUYÊN NHÂN, còn lệch tuyến thường là HỆ QUẢ của việc local planner tự
|
||||
// né chính vật cản đó. Mỗi trigger có route, cursor và khoá riêng — Phép đo 3 cạn route
|
||||
// không làm Phép đo 1 mất lượt.
|
||||
//
|
||||
// Trigger đang bị KHOÁ (lượt trước đã hết đường vòng, robot chưa đi đủ oscillation_distance)
|
||||
// thì bỏ qua hẳn nhánh này: bám tiếp plan cũ, để controller_patience làm việc của nó.
|
||||
if ((in.path_blocked && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kPathBlocked)]) ||
|
||||
(in.off_path && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kOffPath)]))
|
||||
const bool collision_open =
|
||||
in.collision && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kCollision)];
|
||||
const bool blocked_open =
|
||||
in.path_blocked && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kPathBlocked)];
|
||||
const bool off_path_open =
|
||||
in.off_path && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kOffPath)];
|
||||
if (collision_open || blocked_open || off_path_open)
|
||||
{
|
||||
const bool use_blocked =
|
||||
in.path_blocked && !monitor_trigger_suppressed_[cursorSlot(RecoveryTrigger::kPathBlocked)];
|
||||
const RecoveryTrigger trigger =
|
||||
use_blocked ? RecoveryTrigger::kPathBlocked : RecoveryTrigger::kOffPath;
|
||||
const RecoveryTrigger trigger = collision_open ? RecoveryTrigger::kCollision
|
||||
: blocked_open ? RecoveryTrigger::kPathBlocked
|
||||
: RecoveryTrigger::kOffPath;
|
||||
out.stop_planner = true;
|
||||
escalateToRecovery(trigger, in.now,
|
||||
use_blocked ? "the path ahead is blocked"
|
||||
: "the robot drifted off the plan",
|
||||
collision_open ? "the body is about to hit an obstacle"
|
||||
: blocked_open ? "the path ahead is blocked"
|
||||
: "the robot drifted off the plan",
|
||||
out);
|
||||
// Hết đường vòng: escalateToRecovery đã khoá trigger thay vì ABORT — không đổi state, chạy
|
||||
// tiếp xuống nhánh sinh lệnh của cycle này để robot không mất một nhịp điều khiển.
|
||||
@@ -585,6 +624,15 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
{
|
||||
last_valid_control_ = in.now;
|
||||
|
||||
// Phép đo 4 (PathMonitor): controller vẫn ra lệnh hợp lệ nhưng robot không tiến.
|
||||
if (in.no_progress)
|
||||
{
|
||||
out.stop_planner = true;
|
||||
escalateToRecovery(RecoveryTrigger::kOscillation, in.now, "no progress along the plan",
|
||||
out);
|
||||
break;
|
||||
}
|
||||
|
||||
if (config_.oscillation_timeout > 0.0 &&
|
||||
(in.now - last_oscillation_reset_).toSec() > config_.oscillation_timeout)
|
||||
{
|
||||
@@ -683,10 +731,37 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
// robot bám detour 1.1 s (~0.45 m) rồi gặp vật cản thứ hai và ABORT vì thiếu 5 cm.
|
||||
// Chỉ reset cho ca "thành công + path mới": `wait` thành công trivially sau N giây, reset
|
||||
// theo nó là route không bao giờ cạn — robot đứng chờ vô hạn thay vì ABORT báo fail.
|
||||
//
|
||||
// ĐIỀU KIỆN THÊM (2026-09-04): "path mới" chỉ nạp lại ngân sách khi robot ĐÃ DỊCH CHUYỂN ít
|
||||
// nhất recovery_reset_min_travel kể từ lần nạp lại trước. Sim 4/9: collision guard chặn tại
|
||||
// chỗ -> detour lập lại đúng đường cũ (cost y hệt, 0 ms) -> cursor về 0 -> chặn lại sau 2
|
||||
// cycle -> 249 vòng trong 52 s, robot bất động, controller_patience không bao giờ tích đủ vì
|
||||
// path_blocked chen trước mỗi 0.2 s. Một path mới mà robot không đi được một bước nào trên
|
||||
// đó không giải quyết sự cố gì, nên nó ăn vào ngân sách như một lần thất bại: route cạn ->
|
||||
// mute (05e) -> guard vẫn báo no_valid_command -> controller_patience -> controlling_failed
|
||||
// -> cạn -> ABORT có lý do. Có dịch chuyển thật (0.45 m của ca 08-05) thì vẫn nạp lại như cũ.
|
||||
const bool recovered_with_new_path = in.recovery == RecoveryFeedback::kSucceeded &&
|
||||
in.planner == PlannerFeedback::kPlanReady;
|
||||
std::size_t& cursor = recoveryRouteCursor(active_recovery_trigger_);
|
||||
bool refill = false;
|
||||
if (recovered_with_new_path)
|
||||
{
|
||||
const double travelled = in.travelled_since_oscillation_reset - travel_at_last_path_reset_;
|
||||
refill = !has_path_reset_mark_ || config_.recovery_reset_min_travel <= 0.0 ||
|
||||
travelled >= config_.recovery_reset_min_travel;
|
||||
if (refill)
|
||||
{
|
||||
has_path_reset_mark_ = true;
|
||||
travel_at_last_path_reset_ = in.travelled_since_oscillation_reset;
|
||||
}
|
||||
else
|
||||
{
|
||||
out.recovery_reset_denied = true;
|
||||
out.recovery_reset_travel = std::max(0.0, travelled);
|
||||
out.recovery_trigger = active_recovery_trigger_; // để bên gọi log đúng route bị trừ
|
||||
}
|
||||
}
|
||||
if (refill)
|
||||
{
|
||||
cursor = 0;
|
||||
}
|
||||
@@ -731,6 +806,11 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
sensor_stale_active_ = false;
|
||||
last_oscillation_reset_ = in.now;
|
||||
out.reset_oscillation_origin = true;
|
||||
// Origin đo quãng đường đặt lại ngay tại đây, nên từ cycle sau travelled đếm từ 0 kể từ
|
||||
// đúng lúc path mới được áp — chính là quãng mà recovery_reset_min_travel muốn đo. Mốc phải
|
||||
// về 0 theo (GIỮ has_path_reset_mark_): sim 4/9 mission 3 robot đi 0.18 m sau path mới mà
|
||||
// vẫn bị tính "0.00 m" vì mốc còn giữ giá trị của origin cũ.
|
||||
travel_at_last_path_reset_ = 0.0;
|
||||
out.run_controller = true;
|
||||
enter(NavigationState::kControlling, in.now,
|
||||
has_detour_path ? "recovery produced a detour path"
|
||||
@@ -853,6 +933,7 @@ StateMachineOutput StateMachine::update(const StateMachineInput& in)
|
||||
last_oscillation_reset_ = in.now;
|
||||
sensor_stale_active_ = false;
|
||||
out.reset_oscillation_origin = true;
|
||||
travel_at_last_path_reset_ = 0.0; // origin đặt lại -> mốc recovery_reset_min_travel về 0
|
||||
|
||||
if (state_before_pause_ == NavigationState::kControlling)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user