13 Commits

Author SHA1 Message Date
1aa2a07469 refactor: host EnvMonitor from env_monitor_core, route per detector
EnvMonitor and its detectors now live in env_monitor_core. NavigationRuntime owns
the monitor; StateMachine runs each detector's own route (step or sequence,
lock or abort on exhaustion) with a cursor per detector. RecoveryRunner accepts
named routes for detectors outside the six built-in triggers.
2026-11-27 10:08:52 +07:00
0788bc666e build: tests off by default, nav_test_harness only for tests
BUILD_MOVE_BASE2_TESTS now defaults to OFF in both build modes.

nav_test_harness is a test-only package that exists only on the
development machine. It was a catkin component and a build/run
dependency, so configuring move_base2 failed on any machine without it,
even with the tests off. It is now found inside the test block only and
declared as test_depend. The scenario directory comes from the harness
package config instead of a guessed ../nav_test_harness path, and the
stale standalone include path is gone.
2026-11-17 20:36:12 +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
261cc20ad4 feat: EnvMonitor thay PathMonitor — giám sát môi trường bằng EDT/geodesic/quỹ đạo thật
Bộ giám sát mới trong ControlLoop (core/env_monitor, core/grid_analysis, ports/environment_port,
io/env_logger), thay bốn phép đo của PathMonitor (code cũ còn, tắt bằng path_monitor/enabled: false):

- kContact: dò tiếp xúc dọc quỹ đạo local planner (thay cung v/omega), bao tốc độ sqrt(2a(d - margin))
  có dư, phanh chỉ khi vượt bao, cờ collision khi kề mũi tĩnh 1 s; cổng xoay tại chỗ theo lệnh
  controller muốn; hysteresis + xác nhận khi nhả; đứng ra sau detour không dịch robot (nhường
  controller); giữ phanh khi route khoá thì báo no valid command để controller_patience leo thang.
- kStall: cost_to_go = geodesic tới điểm thoát 2 m dọc plan + phần plan còn lại, index plan bám cửa
  sổ, bộ lọc lật liên thông; cờ no_progress chỉ khi cổng dịch chuyển thực mở (robot không đi được
  đâu trong 12 s dù lệnh >= 1,5 m) — thay ngân sách replan cho stall.
- kUnreachable: liên thông tới điểm thoát, đang ở action log.
- EnvLogger ghi JSONL mỗi tick nặng; config/runtime/env_monitor_params.yaml đủ khoá, comment tiếng
  Việt; ControllerPort::measuredVelocity; FakeEnvironmentPort cho test.

Sim 5–6/9: hết churn detour, khe 1,25 m đi qua 0,5 m/s, lượt 6/9 10:15 2 detour/142 s không oan.
Test: grid_analysis 31, env_monitor 43, plan_inspector 37, walking_skeleton 87, các bộ khác pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
2026-09-06 10:30:31 +07:00
b102391fb8 Keep raw sensor readings so plugins can reach what the costmap threw away
Sensor data entered this runtime and disappeared into the costmap. At 0.05 m
with inflation the costmap has destroyed ray order and object shape, so a dock
detector fitting lines to find a V plate cannot reconstruct what the laser
saw - two 0.2 m wings on that grid are one blob. A reinforcement-learning
local planner wants the raw scan for the same reason. Neither had a route:
ActionContext held only TF, and LocalPlanner::initialize takes only a costmap.

NavigationServer now owns a SensorStore and feeds it from all five doors,
handing a read-only port to the action registry and to the controller runner.

The store gets the reading BEFORE the filter. Anything that wants filtering
filters upstream; the store does not know a filter exists. With laser SOR on,
the store and the costmap deliberately see different data - one wants outliers
gone, the other wants the true shape - and the comment at addLaserScan now
says so, because the one it replaces claimed the opposite.

remove* mirrors into the store, dropping readings while keeping the topic
declared. A host that has disowned data while the store still serves it means
the two disagree about what the robot can currently see, and max_age only
covers the tail of that.

Reaching a local planner without breaking every other one: widening
LocalPlanner::initialize would break hybrid, mppi, priest, stanley and
deep_mpc at once for the sake of one planner. A planner that wants sensor data
inherits SensorConsumer instead, and ControllerRunner finds out with a
dynamic_cast after loading it, at all three sites that build an instance and
always before initialize(). Planners that do not inherit it cast to null and
nothing happens, so nothing needs rebuilding. That cast crosses a .so boundary
and depends on matching RTTI, which a green build does not prove - hence the
log line, and hence TestControllerSensorProbe, dlopen'd like a real plugin, to
check it actually matches.

sensor_store/report_period prints what the store holds every N seconds, off by
default. Until a consumer exists it is the only way to see whether data
arrives at all, and it is what separates a mistyped topic from a dead sensor -
without it the two look identical. It reads age from the control loop's clock,
not robot::Time::now(), which is the wall clock while a simulated scan is not.

Config is refused at boot, not at first use: an unknown data_type, a short name
two packages share, a duplicate topic, a capacity below 1, a max_age that is
not positive. Declaring no sensor at all is valid and leaves the store empty
and silent - a runtime with no consumer of raw data holds nothing, which is an
answer rather than a reason to refuse to start.

robot_nav_msgs/OccupancyGrid is registered here rather than in
robot_sensor_ports, which ships only its own package's types; pulling
robot_nav_msgs into every translation unit that touches the store would be the
cost of doing otherwise.
2026-08-26 11:35:17 +07:00
ea02392c69 build: bỏ dependency PCL không dùng
Gói không include một header pcl/ nào. Khối find_package ở đây copy từ
recovery_core, mượn PCL_INCLUDE_DIRS phòng khi header robot_costmap_2d lộ
dependency PCL — nhưng robot_costmap_2d cũng không include PCL ở đâu cả.

Trên robot aarch64 có VTK 9.1 build kèm MPI, chuỗi PCL -> VTK -> VTK::mpi ->
MPI::MPI_C làm CMake gãy ở generate step: root project khai LANGUAGES CXX nên
find_package(MPI COMPONENTS C) không bao giờ thành công và target MPI::MPI_C
không được tạo. Máy dev không dính vì không cài VTK cmake package, find_VTK()
tìm không thấy rồi bỏ qua trong im lặng.

Bỏ find_package, PCL_INCLUDE_DIRS và nhánh if(PCL_FOUND).
2026-08-25 12:38:18 +07:00
2b4c897015 fix file cmake 2026-08-10 12:15:04 +07:00
3e4dd22bbb fix file cmake 2026-08-10 11:39:11 +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
4762a3032c first commit 2026-07-29 15:45:16 +07:00