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:
@@ -80,6 +80,50 @@ bool planarTransform(const tf3::BufferCore& tf, const std::string& from, const s
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t trackedNearestIndex(const std::vector<robot_geometry_msgs::PoseStamped>& plan,
|
||||
const robot_geometry_msgs::PoseStamped& pose, std::size_t hint,
|
||||
double back_m, double ahead_m)
|
||||
{
|
||||
if (plan.size() < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const std::size_t last_seg = plan.size() - 2;
|
||||
hint = std::min(hint, last_seg);
|
||||
|
||||
auto seg_len = [&](std::size_t i) {
|
||||
return std::hypot(plan[i + 1].pose.position.x - plan[i].pose.position.x,
|
||||
plan[i + 1].pose.position.y - plan[i].pose.position.y);
|
||||
};
|
||||
std::size_t lo = hint;
|
||||
for (double walked = 0.0; lo > 0 && walked < back_m; --lo)
|
||||
{
|
||||
walked += seg_len(lo - 1);
|
||||
}
|
||||
std::size_t hi = hint;
|
||||
for (double walked = 0.0; hi < last_seg && walked < ahead_m; ++hi)
|
||||
{
|
||||
walked += seg_len(hi);
|
||||
}
|
||||
|
||||
const double px = pose.pose.position.x;
|
||||
const double py = pose.pose.position.y;
|
||||
std::size_t best = hint;
|
||||
double best_distance = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = lo; i <= hi; ++i)
|
||||
{
|
||||
const double distance =
|
||||
pointToSegment(px, py, plan[i].pose.position.x, plan[i].pose.position.y,
|
||||
plan[i + 1].pose.position.x, plan[i + 1].pose.position.y);
|
||||
if (distance < best_distance)
|
||||
{
|
||||
best_distance = distance;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
std::size_t nearestIndex(const std::vector<robot_geometry_msgs::PoseStamped>& plan,
|
||||
const robot_geometry_msgs::PoseStamped& pose)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user