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:
@@ -33,6 +33,7 @@ using move_base2::testing::FakeClockPort;
|
||||
using move_base2::testing::FakeControllerPort;
|
||||
using move_base2::testing::FakeCostmapStatusPort;
|
||||
using move_base2::testing::FakeMissionPort;
|
||||
using move_base2::testing::FakeEnvironmentPort;
|
||||
using move_base2::testing::FakePathCheckPort;
|
||||
using move_base2::testing::FakePlannerPort;
|
||||
using move_base2::testing::FakePosePort;
|
||||
@@ -130,6 +131,7 @@ public:
|
||||
deps_.action = &action_;
|
||||
deps_.costmap_status = &costmap_status_;
|
||||
deps_.path_check = &path_check_;
|
||||
deps_.environment = &environment_;
|
||||
|
||||
std::string error;
|
||||
EXPECT_TRUE(loop_.configure(config, deps_, error)) << error;
|
||||
@@ -179,6 +181,7 @@ public:
|
||||
FakeActionPort action_;
|
||||
FakeCostmapStatusPort costmap_status_;
|
||||
FakePathCheckPort path_check_;
|
||||
FakeEnvironmentPort environment_;
|
||||
ControlLoopDeps deps_;
|
||||
|
||||
private:
|
||||
@@ -1886,6 +1889,120 @@ TEST(WalkingSkeletonCollisionGuard, HeldByTheGuardAfterTheRouteIsSpentEscalatesT
|
||||
EXPECT_TRUE(escalated) << "guard held the robot but nothing escalated";
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// @brief P4 (5/9): guard cũ tắt hẳn, kContact của EnvMonitor phanh thật và giơ cờ collision.
|
||||
ControlLoopConfig envContactConfig()
|
||||
{
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.enabled = false; // guard cũ tắt hẳn: chỉ EnvMonitor phanh
|
||||
config.env_monitor.enabled = true;
|
||||
config.env_monitor.stall.action = "log";
|
||||
config.env_monitor.unreachable.action = "log";
|
||||
config.env_monitor.contact.action = "recover";
|
||||
config.env_monitor.contact.apply_command = true;
|
||||
config.env_monitor.contact.confirm_cycles = 2;
|
||||
config.env_monitor.contact.trigger_static_time = 0.3; // [s] = 6 cycle, đủ ngắn cho test
|
||||
config.env_monitor.contact.clean_start_margin = 0.2; // [m]
|
||||
config.env_sampling.check_period = 0.01; // [s] < chu kỳ 0.05 -> tick nặng mỗi cycle
|
||||
return config;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(WalkingSkeletonEnvContact, BrakesAfterConfirmThenRaisesCollisionAfterStaticTime)
|
||||
{
|
||||
Fixture fixture(envContactConfig());
|
||||
driveToControlling(fixture);
|
||||
|
||||
// Tiếp xúc 0.10 m trên quỹ đạo, trong clean_start_margin: cycle 1 đếm, cycle 2 phanh -> lệnh 0.
|
||||
fixture.environment_.setContact(true, 0.10);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().angular.z, 0.0);
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "phanh nhưng chưa giơ cờ";
|
||||
|
||||
// Kề mũi đứng yên đủ trigger_static_time -> cờ collision -> route collision.
|
||||
int held = 0;
|
||||
for (int i = 0; i < 12 && fixture.loop_.state() == NavigationState::kControlling; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
++held;
|
||||
}
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
EXPECT_GE(held, 4) << "cờ phải chờ đủ trigger_static_time, không nổ cùng nhịp với phanh";
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonEnvContact, HeldWithTheRouteSpentEscalatesToControllingFailed)
|
||||
{
|
||||
// Cùng chuỗi bắt buộc như guard cũ: cạn route collision -> khoá -> brake giữ 0 nhưng controller
|
||||
// phải bị báo no_valid_command -> controller_patience -> controlling_failed. Không có bước này
|
||||
// robot đứng chết vô hạn với controller "ổn".
|
||||
Fixture fixture(envContactConfig());
|
||||
driveToControlling(fixture);
|
||||
fixture.recovery_.setScript({ RecoveryScript::kFailed });
|
||||
|
||||
fixture.environment_.setContact(true, 0.10);
|
||||
for (int i = 0; i < 12 && fixture.loop_.state() == NavigationState::kControlling; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
ASSERT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
|
||||
for (int i = 0; i < 4 && fixture.loop_.state() == NavigationState::kRecovering; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling)
|
||||
<< "detour thất bại phải quay về kControlling với route collision đã cạn";
|
||||
|
||||
// onRecoveryFinished xoá chuỗi phanh: tối đa confirm_cycles cycle lệnh có thể khác 0 rồi phanh lại.
|
||||
bool escalated = false;
|
||||
int nonzero_after_settle = 0;
|
||||
for (int i = 0; i < 60 && !escalated; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
if (i >= 3 && fixture.loop_.lastCommand().linear.x != 0.0)
|
||||
{
|
||||
++nonzero_after_settle;
|
||||
}
|
||||
escalated = fixture.loop_.state() == NavigationState::kRecovering &&
|
||||
fixture.recovery_.lastTrigger() == RecoveryTrigger::kControllingFailed;
|
||||
}
|
||||
EXPECT_TRUE(escalated) << "EnvMonitor held the robot but nothing escalated";
|
||||
EXPECT_EQ(nonzero_after_settle, 0) << "brake must hold once re-confirmed";
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonEnvContact, ContactBeyondTheStoppingDistanceCapsSpeedWithoutBraking)
|
||||
{
|
||||
Fixture fixture(envContactConfig());
|
||||
driveToControlling(fixture);
|
||||
const double v_free = fixture.loop_.lastCommand().linear.x;
|
||||
ASSERT_GT(v_free, 0.27);
|
||||
|
||||
// 2.0 m phía trước: bao sqrt(2·0.35·1.7) = 1.09 m/s > lệnh -> không đổi, không phanh.
|
||||
fixture.environment_.setContact(true, 2.0);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, v_free);
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
// 0.40 m: bao sqrt(2·0.35·(0.40 − margin 0.2 − dư 0.1)) = 0.265 m/s. Lệnh bị kẹp xuống đúng bao và GIỮ ở đó:
|
||||
// quãng phanh ở tốc độ đã kẹp = 0.10 m -> còn 0.30 m > margin -> không phải "sắp chạm", không phanh, không cờ.
|
||||
fixture.environment_.setContact(true, 0.40);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
EXPECT_NEAR(fixture.loop_.lastCommand().linear.x, std::sqrt(2.0 * 0.35 * 0.10), 1e-3) << "cycle " << i;
|
||||
}
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, BodyComesFromTheCostmapFootprintWhenOffsetsAreZero)
|
||||
{
|
||||
// Ba offset = 0: thân lấy từ footprint costmap qua cổng. Có footprint -> guard dò và dừng như khai
|
||||
|
||||
Reference in New Issue
Block a user