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:
@@ -29,6 +29,7 @@
|
||||
#include <move_base2/ports/clock_port.h>
|
||||
#include <move_base2/ports/controller_port.h>
|
||||
#include <move_base2/ports/costmap_status_port.h>
|
||||
#include <move_base2/ports/environment_port.h>
|
||||
#include <move_base2/ports/mission_port.h>
|
||||
#include <move_base2/ports/path_check_port.h>
|
||||
#include <move_base2/ports/planner_port.h>
|
||||
@@ -982,6 +983,129 @@ private:
|
||||
mutable std::size_t motion_query_count_ = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class FakeEnvironmentPort
|
||||
* @brief Cổng môi trường giả cho EnvMonitor: kịch bản quyết định cost_to_go / tiếp xúc, không cần costmap.
|
||||
*
|
||||
* Mặc định "không kết luận được" cho hình học và quỹ đạo (như cổng gốc thiếu costmap/TF) nhưng CÓ thân
|
||||
* (footprint) — để các test cũ chạy với EnvMonitor bật mà không sinh verdict nào.
|
||||
*/
|
||||
class FakeEnvironmentPort final : public EnvironmentPort
|
||||
{
|
||||
public:
|
||||
bool sampleGeometry(const EnvGeometryRequest& request, EnvGeometry& out) override
|
||||
{
|
||||
(void)request;
|
||||
++geometry_query_count_;
|
||||
if (!geometry_available_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
out = EnvGeometry();
|
||||
out.valid = true;
|
||||
out.free_radius = body_side_;
|
||||
out.cost.conclusive = true;
|
||||
out.cost.reachable = reachable_;
|
||||
out.cost.cost_to_go = reachable_ ? cost_to_go_ : std::numeric_limits<double>::infinity();
|
||||
out.edt_body_min = edt_body_min_;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sweepTrajectory(const EnvTrajectoryRequest& request, SweepResult& out, bool& used_local_plan) override
|
||||
{
|
||||
(void)request;
|
||||
++sweep_query_count_;
|
||||
used_local_plan = false;
|
||||
if (!sweep_available_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
out = SweepResult();
|
||||
out.conclusive = true;
|
||||
out.scanned = 1;
|
||||
out.blocked = contact_blocked_;
|
||||
out.distance = contact_blocked_ ? contact_distance_ : 0.0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool robotBodyExtents(double& front, double& rear, double& side) const override
|
||||
{
|
||||
if (!body_available_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
front = body_front_;
|
||||
rear = body_rear_;
|
||||
side = body_side_;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @param distance [m] quãng dọc quỹ đạo tới điểm chạm.
|
||||
void setContact(bool blocked, double distance = 0.1)
|
||||
{
|
||||
sweep_available_ = true;
|
||||
contact_blocked_ = blocked;
|
||||
contact_distance_ = distance;
|
||||
}
|
||||
|
||||
void setSweepAvailable(bool available)
|
||||
{
|
||||
sweep_available_ = available;
|
||||
}
|
||||
|
||||
/// @param cost_to_go [m] chi phí còn lại; @p edt_body_min [m] khoảng trống thân.
|
||||
void setGeometry(bool reachable, double cost_to_go, double edt_body_min = 1.0)
|
||||
{
|
||||
geometry_available_ = true;
|
||||
reachable_ = reachable;
|
||||
cost_to_go_ = cost_to_go;
|
||||
edt_body_min_ = edt_body_min;
|
||||
}
|
||||
|
||||
void setGeometryAvailable(bool available)
|
||||
{
|
||||
geometry_available_ = available;
|
||||
}
|
||||
|
||||
void setBodyExtents(double front, double rear, double side)
|
||||
{
|
||||
body_available_ = true;
|
||||
body_front_ = front;
|
||||
body_rear_ = rear;
|
||||
body_side_ = side;
|
||||
}
|
||||
|
||||
void setBodyAvailable(bool available)
|
||||
{
|
||||
body_available_ = available;
|
||||
}
|
||||
|
||||
std::size_t sweepQueryCount() const
|
||||
{
|
||||
return sweep_query_count_;
|
||||
}
|
||||
|
||||
std::size_t geometryQueryCount() const
|
||||
{
|
||||
return geometry_query_count_;
|
||||
}
|
||||
|
||||
private:
|
||||
bool geometry_available_ = false;
|
||||
bool reachable_ = true;
|
||||
double cost_to_go_ = 10.0; // [m]
|
||||
double edt_body_min_ = 1.0; // [m]
|
||||
bool sweep_available_ = false;
|
||||
bool contact_blocked_ = false;
|
||||
double contact_distance_ = 0.1; // [m]
|
||||
bool body_available_ = true;
|
||||
double body_front_ = 0.58; // [m]
|
||||
double body_rear_ = 0.58; // [m]
|
||||
double body_side_ = 0.48; // [m]
|
||||
std::size_t geometry_query_count_ = 0;
|
||||
std::size_t sweep_query_count_ = 0;
|
||||
};
|
||||
|
||||
class FakeMissionPort final : public MissionPort
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user