feat: resume driving during a stationary recovery; host intrusion detector
- recovery_resume: while an allowed stationary behavior (detour_path) runs, probe the local planner; its command never reaches the arbiter; after N moving cycles cancel the recovery and resume the current plan, capped per leg - host the env_monitor_core IntrusionDetector (EnvContext, footprint) - runtime config: recovery_resume keys, priest_fallback keys, evade max_tf_gap / view_loss_timeout, SBPL detour options, env_monitor tuning
This commit is contained in:
@@ -204,6 +204,112 @@ StateMachineInput requestWithActions(std::size_t action_count, bool has_goal = t
|
||||
// Cấu hình
|
||||
// ================================================================================================
|
||||
|
||||
|
||||
TEST(StateMachineRecoveryResume, RejectsInvalidConfig)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
std::string error;
|
||||
config.recovery_resume_confirm_cycles = 0;
|
||||
EXPECT_FALSE(config.validate(error));
|
||||
config.recovery_resume_confirm_cycles = 3;
|
||||
config.recovery_resume_min_speed = 0.0;
|
||||
EXPECT_FALSE(config.validate(error));
|
||||
config.recovery_resume_min_speed = 0.05;
|
||||
config.recovery_resume_max_per_leg = -1;
|
||||
EXPECT_FALSE(config.validate(error));
|
||||
}
|
||||
|
||||
TEST(StateMachineRecoveryResume, ConfirmsAndResetsOnStaleAndNoMotion)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.recovery_resume_enabled = true;
|
||||
Driver driver(config);
|
||||
driver.driveToControlling();
|
||||
driver.advance(2.1);
|
||||
ASSERT_EQ(driver.tick(controller(ControllerFeedback::kNoValidCommand)).state, NavigationState::kRecovering);
|
||||
StateMachineInput probe = recovery(RecoveryFeedback::kRunning);
|
||||
probe.recovery_probe_moving = true;
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
probe.costmap_current = false;
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
probe.costmap_current = true;
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
probe.recovery_probe_moving = false;
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
probe.recovery_probe_moving = true;
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
const auto out = driver.tick(probe);
|
||||
EXPECT_EQ(out.state, NavigationState::kControlling);
|
||||
EXPECT_TRUE(out.cancel_recovery);
|
||||
EXPECT_TRUE(out.apply_plan);
|
||||
EXPECT_TRUE(out.recovery_resumed);
|
||||
EXPECT_FALSE(out.report_outcome);
|
||||
}
|
||||
|
||||
TEST(StateMachineRecoveryResume, QuotaResetsOnNewRequest)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.recovery_resume_enabled = true;
|
||||
config.recovery_resume_confirm_cycles = 1;
|
||||
config.recovery_resume_max_per_leg = 1;
|
||||
Driver driver(config);
|
||||
driver.driveToControlling();
|
||||
driver.advance(2.1);
|
||||
ASSERT_EQ(driver.tick(controller(ControllerFeedback::kNoValidCommand)).state, NavigationState::kRecovering);
|
||||
StateMachineInput probe = recovery(RecoveryFeedback::kRunning);
|
||||
probe.recovery_probe_moving = true;
|
||||
ASSERT_TRUE(driver.tick(probe).recovery_resumed);
|
||||
driver.advance(2.1);
|
||||
ASSERT_EQ(driver.tick(controller(ControllerFeedback::kNoValidCommand)).state, NavigationState::kRecovering);
|
||||
EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
StateMachineInput request;
|
||||
request.has_pending_request = true;
|
||||
EXPECT_EQ(driver.tick(request).state, NavigationState::kPlanning);
|
||||
ASSERT_EQ(driver.tick(planReady()).state, NavigationState::kControlling);
|
||||
driver.advance(2.1);
|
||||
ASSERT_EQ(driver.tick(controller(ControllerFeedback::kNoValidCommand)).state, NavigationState::kRecovering);
|
||||
EXPECT_TRUE(driver.tick(probe).recovery_resumed);
|
||||
}
|
||||
|
||||
TEST(StateMachineRecoveryResume, DetectorSequenceRefillsItsOwnRoute)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.recovery_resume_enabled = true;
|
||||
config.recovery_resume_confirm_cycles = 1;
|
||||
move_base2::DetectorRoute route;
|
||||
route.name = "intrusion";
|
||||
route.route = {0, 1};
|
||||
route.sequence = true;
|
||||
config.detector_routes = {route};
|
||||
Driver driver(config);
|
||||
driver.driveToControlling();
|
||||
StateMachineInput fire;
|
||||
fire.detector_fired = 1;
|
||||
ASSERT_EQ(driver.tick(fire).recovery_index, 0u);
|
||||
StateMachineInput done = recovery(RecoveryFeedback::kSucceeded);
|
||||
auto next = driver.tick(done);
|
||||
ASSERT_TRUE(next.recovery_chain_continues);
|
||||
ASSERT_EQ(next.recovery_index, 1u);
|
||||
StateMachineInput probe = recovery(RecoveryFeedback::kRunning);
|
||||
probe.recovery_probe_moving = true;
|
||||
ASSERT_TRUE(driver.tick(probe).recovery_resumed);
|
||||
next = driver.tick(fire);
|
||||
EXPECT_TRUE(next.start_recovery);
|
||||
EXPECT_EQ(next.recovery_index, 0u);
|
||||
}
|
||||
|
||||
TEST(StateMachineRecoveryResume, DisabledIgnoresProbe)
|
||||
{
|
||||
Driver driver;
|
||||
driver.driveToControlling();
|
||||
driver.advance(2.1);
|
||||
ASSERT_EQ(driver.tick(controller(ControllerFeedback::kNoValidCommand)).state, NavigationState::kRecovering);
|
||||
StateMachineInput probe = recovery(RecoveryFeedback::kRunning);
|
||||
probe.recovery_probe_moving = true;
|
||||
for (int i = 0; i < 5; ++i) EXPECT_FALSE(driver.tick(probe).cancel_recovery);
|
||||
}
|
||||
|
||||
TEST(StateMachineConfig, RejectsOscillationTimeoutWithoutDistance)
|
||||
{
|
||||
StateMachineConfig config = baseConfig();
|
||||
|
||||
@@ -226,6 +226,159 @@ std::string join(const std::vector<std::string>& items)
|
||||
// Cấu hình và cửa vào
|
||||
// ================================================================================================
|
||||
|
||||
// Enters recovery after a valid plan, then lets the fake controller answer probes.
|
||||
void enterProbeRecovery(Fixture& fixture)
|
||||
{
|
||||
fixture.controller_.setScript({ControllerScript::kFail});
|
||||
fixture.recovery_.setScript({RecoveryScript::kRunning});
|
||||
std::string reason;
|
||||
ASSERT_TRUE(fixture.loop_.submit(makeRequest(3.0), reason)) << reason;
|
||||
for (int i = 0; i < 100 && fixture.loop_.state() != NavigationState::kRecovering; ++i)
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
fixture.controller_.setScript({ControllerScript::kOk});
|
||||
fixture.controller_.isGoalReached(); // prime the fake without involving the control loop
|
||||
fixture.stepOnce(); // first recovery tick establishes kRunning
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, ProbeCommandIsDiscardedAndStaleResetsConfirmation)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
config.state_machine.recovery_resume_confirm_cycles = 3;
|
||||
Fixture fixture(config);
|
||||
fixture.recovery_.setRecoveryVelocity(true, -0.15);
|
||||
enterProbeRecovery(fixture);
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
fixture.stepOnce();
|
||||
EXPECT_NEAR(fixture.loop_.lastCommand().linear.x, -0.15, 1e-9);
|
||||
const auto calls = fixture.controller_.computeCount();
|
||||
fixture.costmap_status_.setCurrent(false);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.controller_.computeCount(), calls);
|
||||
fixture.costmap_status_.setCurrent(true);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 1u);
|
||||
EXPECT_EQ(fixture.controller_.setPlanCount(), 2u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, ZeroAndUnlistedBehaviorNeverCancel)
|
||||
{
|
||||
for (bool allowed : {false, true})
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {allowed ? "fake_behavior_0" : "other"};
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.0);
|
||||
const auto calls = fixture.controller_.computeCount();
|
||||
for (int i = 0; i < 5; ++i) fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
if (!allowed) EXPECT_EQ(fixture.controller_.computeCount(), calls);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, ReverseCountsAsMovement)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
config.state_machine.recovery_resume_confirm_cycles = 1;
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.controller_.setNominalSpeed(-0.1);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 1u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, PlannerFailureResetsConfirmation)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
config.state_machine.recovery_resume_confirm_cycles = 2;
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.stepOnce();
|
||||
fixture.controller_.setScript({ControllerScript::kFail});
|
||||
fixture.controller_.isGoalReached();
|
||||
fixture.stepOnce();
|
||||
fixture.controller_.setScript({ControllerScript::kOk});
|
||||
fixture.controller_.isGoalReached();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 1u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, StaleSkipsProbeEvenIfNormalCostmapGuardIsDisabled)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.require_current_costmap = false;
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.costmap_status_.setCurrent(false);
|
||||
const auto calls = fixture.controller_.computeCount();
|
||||
for (int i = 0; i < 5; ++i) fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.controller_.computeCount(), calls);
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, MissingPoseSkipsProbeAndResetsConfirmation)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
config.state_machine.recovery_resume_confirm_cycles = 2;
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.stepOnce();
|
||||
const auto calls = fixture.controller_.computeCount();
|
||||
fixture.pose_.setAvailable(false);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.controller_.computeCount(), calls);
|
||||
fixture.pose_.setAvailable(true);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 1u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, AngularVelocityAloneDoesNotCountAsMovement)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_enabled = true;
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.0);
|
||||
fixture.controller_.setNominalTurnRate(0.2);
|
||||
for (int i = 0; i < 5; ++i) fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
}
|
||||
|
||||
TEST(ControlLoopRecoveryResume, DisabledNeverCallsProbe)
|
||||
{
|
||||
auto config = baseConfig();
|
||||
config.state_machine.recovery_resume_behaviors = {"fake_behavior_0"};
|
||||
Fixture fixture(config);
|
||||
enterProbeRecovery(fixture);
|
||||
const auto calls = fixture.controller_.computeCount();
|
||||
for (int i = 0; i < 5; ++i) fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.controller_.computeCount(), calls);
|
||||
EXPECT_EQ(fixture.recovery_.cancelCount(), 0u);
|
||||
}
|
||||
|
||||
TEST(ControlLoop, RefusesToConfigureWithMissingPorts)
|
||||
{
|
||||
ControlLoop loop;
|
||||
|
||||
Reference in New Issue
Block a user