20 Commits

Author SHA1 Message Date
ab9ed67f97 feat: resume driving during a stationary recovery; host intrusion detector
- recovery_resume: while an allowed stationary behavior (detour_path)
  runs, probe the local planner; its command never reaches the arbiter;
  after N moving cycles cancel the recovery and resume the current plan,
  capped per leg
- host the env_monitor_core IntrusionDetector (EnvContext, footprint)
- runtime config: recovery_resume keys, priest_fallback keys, evade
  max_tf_gap / view_loss_timeout, SBPL detour options, env_monitor tuning
2026-11-27 22:06:59 +07:00
42b03e0d78 config(runtime): lane route planner, zone layers, trolley detection, MPCC profiles
- Position profile uses LaneRoutePlanner with PriestMpccLocalPlanner; new
  lane_route_planner_params.yaml, mpcc_local_planner_params.yaml and
  priest_mpcc_local_planner_params.yaml.
- Global costmap: DirectionalLayer plus forbidden/preferred/unpreferred zone
  layers (directional_layer_params.yaml) and the reference graph keys; the
  local costmap keeps the reference graph off.
- TrolleyDetectionActionHandler and a DetectTrolley compound action.
- Dock global planner notes (mating_edge, dock_face_offset), priest planner
  tuning, sbpl primitive path moved to pnkx_nav_core.
- Sim launch defaults to robot_type hook_150.
2026-11-10 16:38:10 +07:00
051e18f989 feat(move_base2): direction zone delivery and costmap readiness wait
- SensorGateway::pushStaticMap also dispatches to DIRECTIONAL_LAYER on
  the global costmap, before STATIC_LAYER: with a same-geometry map the
  directional layer goes PENDING before StaticLayer can report current,
  so a plan cannot pair the new map with the old zones.
- Static maps are replayed in arrival order instead of topic order, so a
  direction grid is never replayed before its static map.
- PlannerRunner checks every enabled global layer under the same lock as
  the snapshot. While a layer is not current it keeps the goal, reports
  waiting_for_costmap, logs the stale layers (throttled) and spends no
  planner_patience or watchdog budget. After costmap_ready_timeout [s]
  (default 10, 0 = legacy behaviour) the attempt fails as before. The
  key is added to config/runtime/move_base_common_params.yaml.
- Test fixture destroys the server before its fake ports (the control
  thread could call a destroyed port).

Full history: branch feature/direction-zone.
2026-11-04 13:24:22 +07:00
ac307b0358 feat: add the 10 config keys that were silently falling back to defaults
Runtime log kept printing "missing param '<key>', using default ..." for
every one of these at boot. None were dangerous (all default to the safe/
off value already), but a key nobody wrote down is a key nobody can find
when they go looking for it, and it invites someone assuming the default
is something else. Values match the C++ default exactly — this changes
nothing at runtime, only silences the warnings and gives each key a home
to be tuned from later.

- sensors: (new block) laser_sor_enabled/mean_k/stddev_mul — LaserScan SOR
  filter ahead of the costmap (SensorGatewayConfig).
- action_patience — tier-2 safety net for EXECUTING_ACTIONS (ActionPort
  contract: handler timeout is tier 1, this is tier 2, mission_timeout is
  tier 3); already referenced by name in the watchdog action_stall_budget
  comment, key itself was missing.
- recovery_namespace, action_namespace, mission_namespace — the
  mission_namespace comment already said "namespace đọc chúng là
  `mission_namespace` ở trên" pointing at a key that didn't exist yet.
- global_frame, require_current_costmap.
- debug.env — fourth debug switch alongside the existing state/plan/skip;
  updated "cả ba" -> "cả bốn" in the intro comment.
2026-09-12 22:40:22 +07:00
8bc4895a60 feat: lifecycle contract — cancel/pause must reach true quiescence before reporting done
Root cause (from a C++ host log, 2026-09-11): cancel during PLANNING only set
a discard flag on the planner thread, which ran to allocated_time before
CANCELLED could be reported; a queued next mission landed on a still-busy
planner and timed out too. Same class of bug existed for pause, recovery, and
implicitly for a legitimate ABORTED read while a component was still
unwinding. Full audit, decisions, and phased design in
docs/PLAN_LIFECYCLE_CANCEL_PAUSE_RESUME.md; old-vs-new behaviour per state in
docs/LIFECYCLE_BEHAVIOUR_MATRIX.md.

Runtime quiescence, not just "command sent":
- kPausing (new state) mirrors kCancelling: PAUSED/CANCELLED is only entered
  once planner and recovery are idle, the action reports terminal, and the
  robot is stopped per odometry (robot_stopped, stopped_measured_linear/
  angular_eps) — not merely "the command we sent was zero". settle_timeout
  bounds the wait; exceeding it still finishes but logs an ungated error
  naming which component was still busy, so a plugin that doesn't honour
  cancel/pause is visible instead of silently swallowed.
- PlannerRunner::running_planner_ (new): the instance the planner thread is
  actually inside makePlan() with, tracked separately from active_ — active_
  can already point at a different instance after swapPlanner() while the
  old attempt is still running. cancelPlan(), swapPlanner() (when a job is
  running_ or only pending_ and not yet picked up), and the destructor all
  preempt through this pointer now; the old code preempted through active_
  and could silently preempt the wrong (idle) instance after a profile swap.
- ComponentStatusBoard + per-component ComponentPhase (idle/busy/stopping/
  paused/hung), read by PlannerRunner, RecoveryRunner, ActionRunner and
  ControlLoop instead of ad hoc bools — this is what makes "did everything
  actually stop" answerable at all, and what the new Watchdog thread reads
  to flag a component busy-without-progress as hung (logged once at the
  edge) without the control loop needing to detect its own stall.
- Resume: PLANNING replans from the current pose. CONTROLLING re-issues
  setPlan() with the plan already in hand (decided: setPlan again, not a
  fresh plan) — the local planner needs nothing else since it already runs
  once per control cycle; a fresh plan on resume was considered and
  rejected as unnecessary work for a plan that's still valid.
- Command-to-zero on cancel/pause stays immediate (no deceleration ramp) —
  existing VelocityArbiter behaviour, left as is per a scoped decision.

Depends on: Test/sbpl (bd89924), pnkx_nav_core (2b0993b, robot_nav_core::
Preemptable + component_status_probe.h), Test/sbpl_lattice_planner (7456e99),
Test/recovery_core (254c7fc, onCancelRequested + ABI guard), Test/
sbpl_recovery (ea79686, worker-thread cancel), Test/action_core (669c3f7,
pause/resume + kCancelled), Test/dock_pattern_action (cc1ea74).

Verified: 13 gtest binaries / 528 tests, 0 failures. Runtime on the dev
machine (Gazebo + real ROS host + VDA5050 over MQTT), 6 scenarios — cancel
during PLANNING, pause/resume during PLANNING and CONTROLLING (incl.
submit-while-still-winding-down), pause-then-cancel during PLANNING and
CONTROLLING: no ABORTED/RECOVERING in any run, preempt lands within
hundredths of a millisecond of entering CANCELLING/PAUSING, PAUSED/CANCELLED
only reported once the robot is actually stopped per odometry. Full numbers
in the plan doc section 6.

Excluded from this commit (pre-existing, unrelated):
config/runtime/recovery_behaviors_params.yaml (allocated_time 1.0->2.0,
SBPLDetourPlanner tuning predating this work).

Not yet done (see plan doc "Trạng thái"): config tuning (phase 0, pending
per a scoping decision); runtime scenarios for cancel mid-detour and a 30 s
pause mid-action; commit to rb_ws is a separate step, not done here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-12 22:07:34 +07:00
7d00c5ab66 feat(rotate): áp relative_yaw trong resolveDeferredGoal, đổi binding rotate
- NavigationRequest: thêm relative_yaw [rad], NaN = không dùng, đi kèm
  được với goal_frame/relative_distance thay vì loại trừ.

- resolveDeferredGoal(): thêm nhánh has_yaw. Trước đây relative_distance
  = 0 khiến goal CHÉP NGUYÊN pose hiện tại kể cả orientation — chặng
  rotate coi như đã tới đích ngay khi nhận, không quay độ nào. Giờ tính
  yaw nền (từ pose hiện tại, hoặc từ frame nếu goal_frame có) rồi cộng
  relative_yaw, dựng lại quaternion đủ 4 thành phần. Log "Goal received"
  thêm yaw= để chặng quay không còn trông giống hệt chặng vị trí.

- mission_adapter_bridge.cpp: chở relative_yaw qua nguyên vẹn.

- Thêm 3 dòng debug (nhóm debug_plan, mặc định bật) trong
  runController(): kết quả isGoalReached() khi true (candidate=0, chưa
  từng tính lệnh), v/omega trước arbiter, v/omega sau arbiter — phân
  biệt "chưa từng có lệnh" / "lệnh bị cắt" / "lỗi ngoài move_base2".
  Bật khối log đã có sẵn nhưng bị comment từ trước.

- Binding rotate: PNKXRotateLocalPlanner -> HybridRotateLocalPlanner.

- 13 test mới (deferred_goal_test.cpp + 2 ca bridge): quay giữ nguyên
  x/y chỉ đổi yaw, góc là delta theo hướng hiện tại, dấu âm quay ngược,
  quaternion chuẩn hoá, go_straight không bị đụng hướng, distance+yaw
  đi cùng nhau, frame+yaw lấy nền là hướng robot chứ không phải hướng
  frame đích, mất pose bị từ chối, NaN passthrough.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 10:46:58 +07:00
2a8e4167e8 refactor: bỏ hai công tắc mission_layer_enabled và docking_requires_marker
Mission layer giờ LUÔN chạy: mọi VDA5050 Order đi qua `mission_adapters` — cắt
thành chặng tại mỗi node có action, chỉ phần `released` được chạy,
`orderUpdateId` nối tiếp, `mission_timeout` làm lưới cuối. Đường lùi "order đi
thẳng xuống như một goal" không còn được chọn bằng config; nó chỉ còn là hành vi
tự động khi layer không nạp được nguồn nào, và vẫn kèm log cảnh báo.
`mission_namespace` rỗng giờ bị validate CHẶN — trước đây tắt layer là khỏi cần
namespace, giờ rỗng nghĩa là boot với một layer không đọc được nguồn nào.

Marker của profile docking thành TUỲ CHỌN: docking chạy bằng goal_frame đã quy
về pose tuyệt đối và local planner không đọc `maker_name`, nên
`PNKXDockingLocalPlanner` legacy — lý do duy nhất của công tắc — không còn được
dùng. Request có marker vẫn được validate và bind như cũ, chỉ bỏ nhánh từ chối
request không marker.

Bỏ theo: hai trường config, bốn chỗ đọc/describe/validate, hai khối YAML runtime
và hai dòng trong test config. Test: xoá RejectsDockingRequestWithoutMarker (trái
hợp đồng mới) và DisabledMissionLayerDoesNotNeedANamespace; đổi
MissionLayerIsEnabledByDefault -> MissionNamespaceHasADefault,
RejectsEnabledMissionLayerWithoutNamespace -> RejectsAnEmptyMissionNamespace.

Verify: catkin_make --pkg move_base2 rc=0; ctest -R move_base2 17/17.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013rayqed51UoUzE7QDRmM9K
2026-09-06 21:22:06 +07:00
c0a04b29ad refactor: xoá PathMonitor và PathCheckPort, EnvMonitor là bộ giám sát duy nhất; gộp refreshSnapshot
Xoá hạ tầng giám sát cũ đã tắt từ 5/9 (path_monitor/enabled: false), −2947 dòng:
- ControlLoop: PathMonitorConfig, updatePathMonitor / updateProgressMonitor / applyCollisionGuard /
  planIsBlocked / resetPathMonitor / rebuildPlanArcLength, toàn bộ member bốn phép đo, luật "plan
  mới bẩn thì giữ plan cũ" trong collectPlannerResult. Bốn cổng StateMachineInput giữ nguyên
  (off_path không còn nguồn, đặt false).
- ports/path_check_port.h, CostmapPathCheck trong NavigationRuntime.
- plan_inspector: bỏ checkPlan / checkMotion / PlanBlockResult / MotionCheckParams /
  MotionBlockResult; giữ planarTransform, nearestIndex, trackedNearestIndex, crossTrackError.
- Config: readPathMonitor, MoveBase2Config::path_monitor, validate; xoá
  config/runtime/path_monitor_params.yaml; comment YAML/state_machine đổi sang tên verdict EnvMonitor.
- Test: FakePathCheckPort, 30 test WalkingSkeletonPathMonitor/CollisionGuard, 13 test
  PlanInspectorCheck/Motion, 2 test validate thân guard.

P0(b): ControlLoop::step() gọi EnvironmentPort::refresh() một lần đầu cycle (không phụ thuộc
env_monitor/enabled); ControllerRunner::setSnapshotRefreshedByLoop(true) làm ba refreshSnapshot()
trong runner thành no-op — monitor và controller đọc cùng một lưới, một bản copy mỗi cycle.

Test: env_monitor 43, grid_analysis 33, plan_inspector 11, walking_skeleton 57, config_validation 32,
scenario 12, state_machine 100, navigation_server 56, controller_runner 28, velocity_arbiter 29,
planner_runner 31 — pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
2026-09-06 10:55:15 +07:00
f2097380e4 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
2026-09-04 19:35:25 +07:00
524939efeb config: priest sim — bật terminal_slide_max_dist 1.5 m (L1)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-28 23:42:29 +07:00
96df99fed2 config: priest — bật gate G1 + bao êm ái cho cây sim
10 khoá mới khớp priest_local_planner (gate theo khoảng cách, accel/decel/
jerk comfort, trần gia tốc góc, head slowdown slew) và bật
collision_check_enabled sau khi gate đổi sang phân mức dừng/giảm tốc.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-28 22:34:31 +07:00
c626c4d45d Retune the dev simulation config
Bench and Gazebo settings only; the robot trees are untouched.

Planners: the position profile moves to PriestLocalPlanner, and the three
docking profiles all point at HybridDockingLocalPlanner instead of the Stanley
instances. Loop drops to 20 Hz, command_semantics back to twist for the sim
drive, max_vel_x to 1.20, recovery behaviours and the path monitor off while
the docking chain is under test.

PRIEST runs cem 3 with performance_metrics off and debug_level 0, which is the
configuration the CPU measurements were taken at. Metrics have to stay off for
any further benchmark.

The SBPL primitive path pointed into rl_ws, a workspace that is not on this
machine; it now points at the copy in sbpl_lattice_planner. sensor_store's
report_period goes to 0 to stop the periodic dump. The sim launch defaults
robot_type to T800 and re-enables depth_image_proc.

The VDA5050 charger flow replaces the pallet fixture: DetectCharger and the
charger marker, with the trailing back-off commented out. The rotate compound
action is renamed to lowercase to match what the config reader looks up.
2026-08-27 13:22:26 +07:00
d0c8a0bcdc feat: gate the move_base2 diagnostic logs behind config switches
Seven [move_base2][debug] lines printed unconditionally on every cycle. On a
robot running a full shift that is noise: they describe the normal path, and
constant noise buries the one line that is actually abnormal.

Three switches, grouped by what they answer, all defaulting to on so turning
them off is a deliberate act rather than something that changes behind whoever
is relying on the log:

  debug/state  state machine transitions, printed on change, not per cycle
  debug/plan   controller accepting or rejecting a plan, recovery paths
  debug/skip   why the controller was skipped while CONTROLLING

The abort-detail line stays unconditional and loses its [debug] tag. It is the
reason a mission failed and prints once per abort; a config that can silence it
is a config in which the robot fails silently.

The read path runs YAML debug/{state,plan,skip} into MoveBase2Config, which
carries it to ControlLoopConfig. describe() prints the resulting state at boot
so nobody has to guess why a log went quiet.

Nothing computes differently: stripping every log statement from the old and
new control_loop.cpp leaves a three-line difference, and all three are comments.
The gated arguments are pure reads.
2026-08-27 13:21:58 +07:00
fd0249d3d0 Document the sliding-window detection and switch go_straight to Stanley
action_handlers_params now describes what sample_window means after the change:
it bounds the sliding window and sets when the first evaluation happens, while
timeout is the deadline the detection has to converge within. min_samples gates
whether a window is judged at all rather than failing the attempt outright, and
max_spread_* now reads "no window met this before the timeout".

hold_time is declared with its default of 0, which keeps publishing on the
first good window. Raising it to 0.5-1.0 s guards the case a single window
cannot catch: perception locking steadily onto the wrong object, where the
samples are tight but tight around the wrong place.

go_straight moves from PNKXGoStraightLocalPlanner to
StanleyGoStraightLocalPlanner, the alias the Stanley library exports for a
straight two-point leg, so the profile no longer depends on the old planner.
2026-08-13 22:47:00 +07:00
b3ca39cfdc Document the simulation Stanley profile parameter by parameter
stanley_local_planner_params.yaml carried a short header and bare values, so
tuning it meant reading the source to find out what each key did and which log
line showed whether it needed changing. Every parameter now states what it
controls, which direction to move it, and the symptom that calls for it, with
the diagnostic line to read named alongside.

The docking block keeps its own copy of the full parameter set rather than
inheriting: StanleyDockingLocalPlanner is a separate instance of the same
library reading the block that matches its alias, so a key missing there falls
back to the built-in default, not to the position profile's value.

Simulation values: max_vel_x raised to 1.20 m/s, and the detect handler's
simulated_offset_yaw sign corrected to +0.09 rad so the fake target sits on the
same side as the real one.

move_base2_sim.launch is deliberately left out: it currently carries a local
Gazebo experiment (robot_type APM, world include commented out).
2026-08-13 22:17:33 +07:00
383a04fe29 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.
2026-08-13 15:01:48 +07:00
20ae52ea84 update 2026-08-09 19:17:02 +07:00
5375a9da9e update 2026-08-06 15:17:59 +07:00
701d25f952 optimal & fix file cmake 2026-08-03 22:41:32 +07:00
d8babff20b optimal 2026-07-30 09:24:47 +07:00