This commit is contained in:
2026-08-10 17:20:30 +07:00
parent 2b4c897015
commit 65f8c7ce1c
3 changed files with 122 additions and 0 deletions

View File

@@ -860,6 +860,85 @@ TEST(NavigationServerPlannerData, PlanIsStampedWithTheControlLoopClock)
"treat it as stale and drop it";
}
// ================================================================================================
// getFeedback() — kết quả của một goal là SỰ KIỆN, không phải mức
//
// Lõi chỉ đứng ở state kết thúc đúng MỘT cycle (33 ms @ 30 Hz) rồi về kIdle. Host đọc getFeedback()
// theo chu kỳ riêng — đo được 100 ms trên robot thật — nên báo theo mức làm mất kết quả 2/3 số lần:
// host thấy CONTROLLING, lần đọc sau đã là PENDING, không có sự kiện hoàn thành nào, và người vận
// hành phải bấm cancel một order đã tới đích. Các test dưới đây khoá lại điều đó.
// ================================================================================================
TEST(NavigationServerFeedback, SucceededSurvivesLongerThanOneCycleSoASlowHostStillSeesIt)
{
Fixture fixture;
fixture.configure();
fixture.controller_.setNominalSpeed(0.3); // [m/s]
fixture.controller_.setScript({ ControllerScript::kOk, ControllerScript::kGoalReached });
ASSERT_TRUE(fixture.server_.moveTo(makeRequest(3.0).goal, 0.15, 0.10))
<< fixture.server_.lastRejectReason();
fixture.spin(4); // IDLE -> PLANNING -> CONTROLLING -> tới đích (terminal)
ASSERT_FALSE(fixture.server_.loop().hasActiveRequest());
// 20 cycle = 0.67 s, gấp 6 lần chu kỳ đọc 100 ms của host thật.
fixture.spin(20);
EXPECT_EQ(fixture.server_.getFeedback()->navigation_state,
robot::move_base_core::State::SUCCEEDED)
<< "the result vanished once the core returned to idle — a host polling slower than one "
"control cycle would never learn the goal finished";
}
TEST(NavigationServerFeedback, AbortedIsLatchedTheSameWaySoFailuresAreNotLostEither)
{
Fixture fixture;
ControlLoopConfig config = baseConfig();
config.state_machine.recovery_enabled = false; // hỏng là ABORT thẳng, không đi qua recovery
fixture.configure(config);
fixture.controller_.setScript({ ControllerScript::kFail });
ASSERT_TRUE(fixture.server_.moveTo(makeRequest(3.0).goal, 0.15, 0.10))
<< fixture.server_.lastRejectReason();
fixture.spin(30);
EXPECT_EQ(fixture.server_.getFeedback()->navigation_state, robot::move_base_core::State::ABORTED)
<< "a failed goal reports PENDING once the core idles — the fleet would wait forever for a "
"result that already exists";
}
TEST(NavigationServerFeedback, ANewRequestClearsTheLatchedResult)
{
Fixture fixture;
fixture.configure();
fixture.controller_.setNominalSpeed(0.3); // [m/s]
fixture.controller_.setScript({ ControllerScript::kOk, ControllerScript::kGoalReached });
ASSERT_TRUE(fixture.server_.moveTo(makeRequest(3.0).goal, 0.15, 0.10))
<< fixture.server_.lastRejectReason();
fixture.spin(6);
ASSERT_EQ(fixture.server_.getFeedback()->navigation_state,
robot::move_base_core::State::SUCCEEDED);
// Goal thứ hai: chốt cũ phải biến mất ngay, nếu không host đọc "đã xong" cho một goal vừa bắt đầu.
fixture.controller_.setScript({ ControllerScript::kOk });
ASSERT_TRUE(fixture.server_.moveTo(makeRequest(3.0).goal, 0.15, 0.10))
<< fixture.server_.lastRejectReason();
fixture.spin(3);
EXPECT_NE(fixture.server_.getFeedback()->navigation_state,
robot::move_base_core::State::SUCCEEDED)
<< "the previous result is still being reported while a new goal is running — the host would "
"mark the new order complete before the robot moved";
}
TEST(NavigationServerFeedback, NothingIsLatchedBeforeTheFirstRequest)
{
Fixture fixture;
fixture.configure();
fixture.spin(5);
EXPECT_EQ(fixture.server_.getFeedback()->navigation_state, robot::move_base_core::State::PENDING)
<< "a freshly booted runtime reports a terminal result although no goal has ever been sent";
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);