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
This commit is contained in:
2026-09-06 10:30:31 +07:00
parent f2097380e4
commit 261cc20ad4
26 changed files with 5589 additions and 7 deletions

View File

@@ -69,6 +69,7 @@ void readBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& b
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors);
void readDebug(robot::NodeHandle& nh, MoveBase2Config& config);
void readEnvMonitor(robot::NodeHandle& nh, MoveBase2Config& config);
void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config);
@@ -271,6 +272,7 @@ void readMoveBase2Fields(robot::NodeHandle& nh, MoveBase2Config& config)
readSensorStore(nh, config);
readDebug(nh, config);
readPathMonitor(nh, config.path_monitor);
readEnvMonitor(nh, config);
readBool(nh, "docking_requires_marker", config.docking_requires_marker);
readString(nh, "recovery_namespace", config.recovery_namespace);
@@ -320,6 +322,124 @@ void readDebug(robot::NodeHandle& nh, MoveBase2Config& config)
readBool(debug_nh, "state", config.debug_state);
readBool(debug_nh, "plan", config.debug_plan);
readBool(debug_nh, "skip", config.debug_skip);
readBool(debug_nh, "env", config.debug_env);
}
/// Đọc khối `env_monitor` (xem config/runtime/env_monitor_params.yaml).
void readEnvMonitor(robot::NodeHandle& nh, MoveBase2Config& config)
{
robot::NodeHandle env_nh(nh, "env_monitor");
EnvMonitorConfig& m = config.env_monitor;
EnvSamplingConfig& s = config.env_sampling;
readBool(env_nh, "enabled", m.enabled);
readDouble(env_nh, "grace_after_new_plan", m.grace_after_new_plan);
readDouble(env_nh, "check_period", s.check_period);
robot::NodeHandle body_nh(env_nh, "body");
readDouble(body_nh, "front_offset", s.body_front);
readDouble(body_nh, "rear_offset", s.body_rear);
readDouble(body_nh, "side_offset", s.body_side);
readDouble(body_nh, "padding", s.padding);
readInt(body_nh, "lethal_threshold", s.lethal_threshold);
robot::NodeHandle geo_nh(env_nh, "geometry");
readDouble(geo_nh, "horizon", s.horizon);
readDouble(geo_nh, "corridor_margin", s.corridor_margin);
readDouble(geo_nh, "corridor_cap", s.corridor_cap);
readDouble(geo_nh, "target_backoff", s.target_backoff);
readDouble(geo_nh, "robot_snap", s.robot_snap);
readDouble(geo_nh, "track_back", s.track_back);
readDouble(geo_nh, "track_ahead", s.track_ahead);
readDouble(geo_nh, "exit_ahead", s.exit_ahead);
robot::NodeHandle stall_nh(env_nh, "stall");
readBool(stall_nh, "enabled", m.stall.enabled);
readString(stall_nh, "action", m.stall.action);
readDouble(stall_nh, "window_s", m.stall.window_s);
readDouble(stall_nh, "window_m", m.stall.window_m);
readDouble(stall_nh, "min_commanded", m.stall.min_commanded);
readDouble(stall_nh, "eff_on", m.stall.eff_on);
readDouble(stall_nh, "eff_off", m.stall.eff_off);
readDouble(stall_nh, "confirm", m.stall.confirm);
readDouble(stall_nh, "goal_zone", m.stall.goal_zone);
readDouble(stall_nh, "slip_on", m.stall.slip_on);
readDouble(stall_nh, "slip_time", m.stall.slip_time);
readDouble(stall_nh, "min_commanded_since_goal", m.stall.min_commanded_since_goal);
readDouble(stall_nh, "retry_backoff", m.stall.retry_backoff);
readDouble(stall_nh, "jump_reject", m.stall.jump_reject);
readDouble(stall_nh, "disp_window_s", m.stall.disp_window_s);
readDouble(stall_nh, "disp_min", m.stall.disp_min);
readDouble(stall_nh, "disp_min_commanded", m.stall.disp_min_commanded);
robot::NodeHandle unreach_nh(env_nh, "unreachable");
readBool(unreach_nh, "enabled", m.unreachable.enabled);
readString(unreach_nh, "action", m.unreachable.action);
readDouble(unreach_nh, "static_on", m.unreachable.static_on);
readDouble(unreach_nh, "clean_start_margin", m.unreachable.clean_start_margin);
readDouble(unreach_nh, "retry_backoff", m.unreachable.retry_backoff);
robot::NodeHandle contact_nh(env_nh, "contact");
readBool(contact_nh, "enabled", m.contact.enabled);
readString(contact_nh, "action", m.contact.action);
readBool(contact_nh, "apply_command", m.contact.apply_command);
readString(contact_nh, "use_local_plan", s.use_local_plan);
readDouble(contact_nh, "local_plan_start_tol", s.local_plan_start_tol);
readDouble(contact_nh, "lookahead", s.contact_lookahead);
readInt(contact_nh, "confirm_cycles", m.contact.confirm_cycles);
readDouble(contact_nh, "trigger_static_time", m.contact.trigger_static_time);
readDouble(contact_nh, "clean_start_margin", m.contact.clean_start_margin);
readDouble(contact_nh, "brake_decel", m.contact.brake_decel);
readDouble(contact_nh, "min_speed", m.contact.min_speed);
readDouble(contact_nh, "min_check_speed", m.contact.min_check_speed);
readDouble(contact_nh, "release_hysteresis", m.contact.release_hysteresis);
readInt(contact_nh, "release_confirm_cycles", m.contact.release_confirm_cycles);
readDouble(contact_nh, "envelope_margin", m.contact.envelope_margin);
readDouble(contact_nh, "standdown_min_travel", m.contact.standdown_min_travel);
readDouble(contact_nh, "standdown_travel", m.contact.standdown_travel);
readBool(contact_nh, "envelope", m.contact.envelope);
robot::NodeHandle budget_nh(env_nh, "replan_budget");
readDouble(budget_nh, "min_travel", m.replan.min_travel);
readDouble(budget_nh, "escalate_factor", m.replan.escalate_factor);
readDouble(budget_nh, "escalate_window_m", m.replan.escalate_window_m);
readDouble(budget_nh, "escalate_max", m.replan.escalate_max);
robot::NodeHandle logger_nh(env_nh, "logger");
readBool(logger_nh, "enabled", config.env_logger.enabled);
readString(logger_nh, "log_dir", config.env_logger.log_dir);
readDouble(logger_nh, "flush_period", config.env_logger.flush_period);
std::vector<std::string> names;
env_nh.param("profiles", names, std::vector<std::string>{});
if (!names.empty())
{
s.profiles.clear();
for (const std::string& name : names)
{
if (name == "position")
{
s.profiles.push_back(MotionProfile::kPosition);
}
else if (name == "docking")
{
s.profiles.push_back(MotionProfile::kDocking);
}
else if (name == "go_straight")
{
s.profiles.push_back(MotionProfile::kGoStraight);
}
else if (name == "rotate")
{
s.profiles.push_back(MotionProfile::kRotate);
}
else
{
robot::log_warning("[move_base2] env_monitor/profiles: unknown profile '%s', ignored.\n",
name.c_str());
}
}
}
}
/// Đọc cấu hình đường vào cảm biến từ namespace con `sensors`.
@@ -594,6 +714,14 @@ bool MoveBase2Config::validate(std::string& error) const
return false;
}
if (env_monitor.enabled)
{
if (!env_monitor.validate(error) || !env_sampling.validate(error) || !env_logger.validate(error))
{
return false;
}
}
if (!velocity.validate(error))
{
return false;
@@ -843,6 +971,10 @@ ControlLoopConfig MoveBase2Config::toControlLoopConfig() const
config.backup_global_planner_name = backup_global_planner_name;
config.docking_requires_marker = docking_requires_marker;
config.path_monitor = path_monitor;
config.env_monitor = env_monitor;
config.env_sampling = env_sampling;
config.env_logger = env_logger;
config.debug_env = debug_env;
return config;
}