refactor: xoá PathMonitor và PathCheckPort, EnvMonitor là bộ giám sát duy nhất; gộp refreshSnapshot
Xoá hạ tầng giám sát cũ đã tắt từ 5/9 (path_monitor/enabled: false), −2947 dòng: - ControlLoop: PathMonitorConfig, updatePathMonitor / updateProgressMonitor / applyCollisionGuard / planIsBlocked / resetPathMonitor / rebuildPlanArcLength, toàn bộ member bốn phép đo, luật "plan mới bẩn thì giữ plan cũ" trong collectPlannerResult. Bốn cổng StateMachineInput giữ nguyên (off_path không còn nguồn, đặt false). - ports/path_check_port.h, CostmapPathCheck trong NavigationRuntime. - plan_inspector: bỏ checkPlan / checkMotion / PlanBlockResult / MotionCheckParams / MotionBlockResult; giữ planarTransform, nearestIndex, trackedNearestIndex, crossTrackError. - Config: readPathMonitor, MoveBase2Config::path_monitor, validate; xoá config/runtime/path_monitor_params.yaml; comment YAML/state_machine đổi sang tên verdict EnvMonitor. - Test: FakePathCheckPort, 30 test WalkingSkeletonPathMonitor/CollisionGuard, 13 test PlanInspectorCheck/Motion, 2 test validate thân guard. P0(b): ControlLoop::step() gọi EnvironmentPort::refresh() một lần đầu cycle (không phụ thuộc env_monitor/enabled); ControllerRunner::setSnapshotRefreshedByLoop(true) làm ba refreshSnapshot() trong runner thành no-op — monitor và controller đọc cùng một lưới, một bản copy mỗi cycle. Test: env_monitor 43, grid_analysis 33, plan_inspector 11, walking_skeleton 57, config_validation 32, scenario 12, state_machine 100, navigation_server 56, controller_runner 28, velocity_arbiter 29, planner_runner 31 — pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
This commit is contained in:
@@ -55,33 +55,6 @@ TEST(MoveBase2Config, DefaultsAreValid)
|
||||
EXPECT_TRUE(config.validate(error)) << error;
|
||||
}
|
||||
|
||||
TEST(MoveBase2Config, RejectsAPartiallyDeclaredCollisionBody)
|
||||
{
|
||||
// Thân guard: cả ba offset = 0 (lấy từ footprint costmap) hoặc cả ba > 0. Khai hai bỏ một là mũi
|
||||
// dò tâm hoặc hông không dò — config sai, không phải "mặc định".
|
||||
MoveBase2Config config = minimalValid();
|
||||
config.path_monitor.enabled = true;
|
||||
config.path_monitor.collision_enabled = true;
|
||||
config.path_monitor.collision_front_offset = 0.58; // [m]
|
||||
config.path_monitor.collision_rear_offset = 0.58; // [m]
|
||||
config.path_monitor.collision_side_offset = 0.0;
|
||||
std::string error;
|
||||
EXPECT_FALSE(config.validate(error));
|
||||
EXPECT_NE(error.find("collision_side_offset"), std::string::npos) << error;
|
||||
}
|
||||
|
||||
TEST(MoveBase2Config, AcceptsACollisionBodyTakenFromTheCostmapFootprint)
|
||||
{
|
||||
MoveBase2Config config = minimalValid();
|
||||
config.path_monitor.enabled = true;
|
||||
config.path_monitor.collision_enabled = true;
|
||||
config.path_monitor.collision_front_offset = 0.0;
|
||||
config.path_monitor.collision_rear_offset = 0.0;
|
||||
config.path_monitor.collision_side_offset = 0.0;
|
||||
std::string error;
|
||||
EXPECT_TRUE(config.validate(error)) << error;
|
||||
}
|
||||
|
||||
TEST(MoveBase2Config, RejectsRecoveryEnabledWithNoBehaviorLoaded)
|
||||
{
|
||||
// Ràng buộc thứ tự khởi tạo: RecoveryRunner không nạp được behavior nào mà
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#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>
|
||||
#include <move_base2/ports/pose_port.h>
|
||||
#include <move_base2/ports/recovery_port.h>
|
||||
@@ -864,125 +863,6 @@ private:
|
||||
mutable std::size_t query_count_ = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class FakePathCheckPort
|
||||
* @brief Cổng kiểm tuyến giả: kịch bản quyết định tuyến sạch hay bẩn, không cần costmap thật.
|
||||
*
|
||||
* `available_ = false` mô phỏng "không kết luận được" (thiếu TF/costmap) — bên gọi phải coi đó là
|
||||
* không biết, KHÔNG được suy thành sạch hay bẩn.
|
||||
*/
|
||||
class FakePathCheckPort final : public PathCheckPort
|
||||
{
|
||||
public:
|
||||
bool checkPlan(const std::vector<robot_geometry_msgs::PoseStamped>& plan,
|
||||
std::size_t from_index, double horizon, PlanBlockResult& out) const override
|
||||
{
|
||||
(void)from_index;
|
||||
(void)horizon;
|
||||
++query_count_;
|
||||
|
||||
if (!available_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
out = PlanBlockResult();
|
||||
out.blocked = blocked_;
|
||||
out.distance = distance_;
|
||||
out.scanned = plan.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @param distance [m] khoảng cách tới vật cản — bên gọi so với `min_detour_distance`.
|
||||
void setBlocked(bool blocked, double distance = 1.5)
|
||||
{
|
||||
blocked_ = blocked;
|
||||
distance_ = distance;
|
||||
}
|
||||
|
||||
/// Phép đo 3 (cung lệnh): kịch bản riêng, không dính `setBlocked` của phép đo 1.
|
||||
bool checkMotion(const robot_geometry_msgs::PoseStamped& robot_pose, double v, double omega,
|
||||
const MotionCheckParams& params, MotionBlockResult& out) const override
|
||||
{
|
||||
(void)robot_pose;
|
||||
(void)omega;
|
||||
(void)params;
|
||||
++motion_query_count_;
|
||||
if (!motion_available_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
out = MotionBlockResult();
|
||||
out.scanned = std::fabs(v) >= params.min_speed ? 1 : 0;
|
||||
out.blocked = out.scanned > 0 && motion_blocked_;
|
||||
out.sample = out.blocked ? 1 : -1;
|
||||
out.distance = out.blocked ? motion_distance_ : 0.0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @param distance [m] quãng dọc cung tới điểm chạm — bên gọi so với `collision_stop_distance`.
|
||||
void setMotionBlocked(bool blocked, double distance = 0.2)
|
||||
{
|
||||
motion_blocked_ = blocked;
|
||||
motion_distance_ = distance;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// @brief Giả lập footprint costmap; mặc định KHÔNG có (như PathCheckPort gốc).
|
||||
void setBodyExtents(double front, double rear, double side)
|
||||
{
|
||||
body_available_ = true;
|
||||
body_front_ = front;
|
||||
body_rear_ = rear;
|
||||
body_side_ = side;
|
||||
}
|
||||
|
||||
void setMotionAvailable(bool available)
|
||||
{
|
||||
motion_available_ = available;
|
||||
}
|
||||
|
||||
std::size_t motionQueryCount() const
|
||||
{
|
||||
return motion_query_count_;
|
||||
}
|
||||
|
||||
void setAvailable(bool available)
|
||||
{
|
||||
available_ = available;
|
||||
}
|
||||
|
||||
std::size_t queryCount() const
|
||||
{
|
||||
return query_count_;
|
||||
}
|
||||
|
||||
private:
|
||||
bool blocked_ = false;
|
||||
bool available_ = true;
|
||||
double distance_ = 1.5; // [m]
|
||||
mutable std::size_t query_count_ = 0;
|
||||
bool motion_blocked_ = false;
|
||||
bool body_available_ = false;
|
||||
double body_front_ = 0.0;
|
||||
double body_rear_ = 0.0;
|
||||
double body_side_ = 0.0;
|
||||
bool motion_available_ = true;
|
||||
double motion_distance_ = 0.2; // [m]
|
||||
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.
|
||||
|
||||
@@ -25,12 +25,10 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
using move_base2::checkPlan;
|
||||
using move_base2::crossTrackError;
|
||||
using move_base2::nearestIndex;
|
||||
using move_base2::trackedNearestIndex;
|
||||
using move_base2::PlanarTransform;
|
||||
using move_base2::PlanBlockResult;
|
||||
using move_base2::planarTransform;
|
||||
|
||||
robot_geometry_msgs::PoseStamped makePose(double x, double y, const std::string& frame = "map")
|
||||
@@ -61,128 +59,6 @@ nav_test_harness::FakeCostmap makeGrid()
|
||||
return nav_test_harness::FakeCostmap::centered(10.0, 0.05);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, CleanPlanIsNotBlocked)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
EXPECT_FALSE(result.blocked);
|
||||
EXPECT_GT(result.scanned, 0u);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, FreeSpaceValueIsNotBlocked)
|
||||
{
|
||||
// Bẫy của fork này: FREE_SPACE = 60, không phải 0. Đặt tường minh giá trị đó lên tuyến để khoá
|
||||
// lại bất biến "so sánh phải dùng hằng số có tên".
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setCostAt(1.0, 0.0, robot_costmap_2d::FREE_SPACE));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
EXPECT_FALSE(result.blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, LethalCellOnThePlanBlocks)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(1.5, 0.0));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
ASSERT_TRUE(result.blocked);
|
||||
EXPECT_NEAR(plan[result.index].pose.position.x, 1.5, 0.06);
|
||||
EXPECT_NEAR(result.distance, 1.5, 0.06);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, InscribedInflatedCountsAsBlocked)
|
||||
{
|
||||
// Ngưỡng là INSCRIBED_INFLATED_OBSTACLE chứ không phải LETHAL: ở đó tâm robot đặt vào là footprint
|
||||
// đã đệm chạm vật cản.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setCostAt(1.0, 0.0, robot_costmap_2d::INSCRIBED_INFLATED_OBSTACLE));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
EXPECT_TRUE(result.blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, UnknownCellIsNotBlocked)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setCostAt(1.0, 0.0, robot_costmap_2d::NO_INFORMATION));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
// Vùng chưa quét mà tính là chắn thì robot dừng ở mọi tuyến đi vào chỗ chưa thấy.
|
||||
EXPECT_FALSE(result.blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, HorizonCutsTheScanShort)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(2.5, 0.0));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
|
||||
EXPECT_FALSE(checkPlan(plan, 0, 1.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
EXPECT_TRUE(checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, ScanStartsAtFromIndex)
|
||||
{
|
||||
// Vật cản NẰM SAU lưng (phần plan đã đi qua) không được tính.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(0.5, 0.0));
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
|
||||
EXPECT_TRUE(checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
EXPECT_FALSE(checkPlan(plan, 15, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, OutOfGridStopsTheScanInsteadOfBlocking)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid(); // ±5 m
|
||||
const auto plan = linePlan(0.0, 20.0, 0.5);
|
||||
|
||||
const PlanBlockResult result = checkPlan(plan, 0, 20.0, *grid.costmap(), PlanarTransform());
|
||||
|
||||
EXPECT_FALSE(result.blocked);
|
||||
EXPECT_LT(result.scanned, plan.size()); // dừng ở rìa lưới, không quét hết
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, EmptyPlanAndBadArgumentsAreSafe)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
|
||||
EXPECT_FALSE(checkPlan({}, 0, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
EXPECT_FALSE(checkPlan(plan, 999, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
EXPECT_FALSE(checkPlan(plan, 0, 0.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorCheck, TransformIsAppliedToEveryPose)
|
||||
{
|
||||
// Plan ở "map", lưới ở "odom" lệch (2, 1): vật cản đặt theo toạ độ LƯỚI.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(-0.5, -1.0)); // = map (1.5, 0.0) sau khi trừ offset
|
||||
|
||||
PlanarTransform to_grid;
|
||||
to_grid.x = -2.0;
|
||||
to_grid.y = -1.0;
|
||||
|
||||
const auto plan = linePlan(0.0, 3.0, 0.1);
|
||||
|
||||
EXPECT_TRUE(checkPlan(plan, 0, 3.0, *grid.costmap(), to_grid).blocked);
|
||||
EXPECT_FALSE(checkPlan(plan, 0, 3.0, *grid.costmap(), PlanarTransform()).blocked);
|
||||
}
|
||||
|
||||
TEST(PlanInspectorNearest, ProjectsOntoSegmentsNotVertices)
|
||||
{
|
||||
const auto plan = linePlan(0.0, 3.0, 1.0); // pose tại x = 0,1,2,3
|
||||
@@ -305,263 +181,3 @@ int main(int argc, char** argv)
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
// =================================================================================================
|
||||
// Phép đo 3: cung lệnh — thân robot có sắp chạm vật cản THẬT không (2026-09-03).
|
||||
// =================================================================================================
|
||||
namespace
|
||||
{
|
||||
using move_base2::checkMotion;
|
||||
using move_base2::MotionBlockResult;
|
||||
using move_base2::MotionCheckParams;
|
||||
|
||||
MotionCheckParams bodyParams()
|
||||
{
|
||||
MotionCheckParams p;
|
||||
p.lookahead = 0.8;
|
||||
p.max_samples = 6;
|
||||
p.front_offset = 0.58;
|
||||
p.rear_offset = 0.58;
|
||||
p.side_offset = 0.48;
|
||||
p.padding = 0.05;
|
||||
p.cost_threshold = robot_costmap_2d::LETHAL_OBSTACLE;
|
||||
return p;
|
||||
}
|
||||
|
||||
TEST(MotionCheck, ClearArcIsNotBlocked)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked);
|
||||
// Bước dò bị kẹp về một ô lưới (0.05 m) nên 0.8 m là 16 mẫu, không phải max_samples = 6.
|
||||
EXPECT_EQ(r.scanned, 16);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, ThinWallBetweenCoarseSamplesIsStillCaught)
|
||||
{
|
||||
// Tường dày đúng MỘT ô tại x=1.30. Với bước thưa 0.8/6 = 0.133 m, mũi (0.63 m trước tâm) ở
|
||||
// mẫu 5 là 1.297 (chưa tới), mẫu 6 là 1.43 (đã qua) — cả hai sạch, robot đâm xuyên. Kẹp bước
|
||||
// về một ô lưới thì không mẫu nào nhảy qua được.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double y = -0.6; y <= 0.6; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(1.30, y));
|
||||
}
|
||||
MotionCheckParams p = bodyParams();
|
||||
p.max_samples = 6;
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, p, *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
EXPECT_NEAR(r.distance, 1.30 - 0.63, 0.06);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, LethalAheadOfTheNoseBlocksWithDistance)
|
||||
{
|
||||
// Tường tại x=1.2. Mũi robot vươn 0.58+0.05 = 0.63 m trước tâm, nên tâm chỉ cần đi ~0.57 m là
|
||||
// mũi chạm — phải báo ở mẫu ~0.53–0.67 m, KHÔNG phải khi tâm tới 1.2 m.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double y = -0.6; y <= 0.6; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(1.2, y));
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
EXPECT_GT(r.distance, 0.4);
|
||||
EXPECT_LT(r.distance, 0.8);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, InflationOnlyIsNotBlocked)
|
||||
{
|
||||
// Đây là toàn bộ lý do phép đo này tồn tại: ô INSCRIBED (253) là biên cho TÂM robot, đặt lên mũi
|
||||
// là đếm biên hai lần. Phủ 253 kín đường đi — robot vẫn phải được chạy.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = 0.0; x <= 2.0; x += 0.05)
|
||||
{
|
||||
for (double y = -0.7; y <= 0.7; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setCostAt(x, y, robot_costmap_2d::INSCRIBED_INFLATED_OBSTACLE));
|
||||
}
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, LethalUnderTheBodyDoesNotBlockParallelMotion)
|
||||
{
|
||||
// Người kề hông trái: hàng ô LETHAL ở y=0.51 (ngoài thân 0.48, trong thân đệm 0.53), dọc x từ
|
||||
// -0.2 tới 0.3 — đúng ca sim 4/9 làm guard báo 0.05 m mãi. Đi thẳng thì mép trái chỉ quét lại
|
||||
// đúng những ô đã nằm dưới thân -> không có ô mới -> phải cho đi.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = -0.2; x <= 0.3; x += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(x, 0.51));
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked) << "blocked at " << r.distance << " m";
|
||||
EXPECT_GE(r.baseline_cells, 1);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, LethalUnderTheBodyStillBlocksWhenTheArcAddsNewCells)
|
||||
{
|
||||
// Khối 3 hàng x 9 cột ở hông trái-sau (y=0.51/0.56/0.61, x từ -0.6 tới -0.2). Hàng trong cùng là
|
||||
// baseline; rẽ phải làm góc trái-sau văng ra ngoài lên hai hàng còn lại -> ô MỚI -> vẫn chặn, và
|
||||
// ở khoảng cách thật (> mẫu đầu 0.05 m) chứ không phải "0.05 m" máy móc.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = -0.6; x <= -0.2; x += 0.05)
|
||||
{
|
||||
for (double y = 0.51; y <= 0.62; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(x, y));
|
||||
}
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, -0.1, bodyParams(), *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
EXPECT_GT(r.distance, 0.05);
|
||||
EXPECT_LT(r.distance, 0.5);
|
||||
EXPECT_GE(r.baseline_cells, 1);
|
||||
// Chi tiết debug: chạm bằng cạnh TRÁI, ô chạm nằm bên trái phía sau tâm, baseline liệt kê ô bên trái.
|
||||
EXPECT_EQ(r.hit_edge, 2);
|
||||
EXPECT_GT(r.hit_y, 0.4);
|
||||
EXPECT_LT(r.hit_x, 0.0);
|
||||
ASSERT_GE(r.baseline_listed, 1);
|
||||
EXPECT_GT(r.baseline_xy[0][1], 0.4);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, LethalAheadOfTheNoseIsUnaffectedByBaseline)
|
||||
{
|
||||
// Có người kề hông (baseline) VÀ tường trước mũi: tường là ô mới, phải chặn y như không có baseline.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(0.0, 0.51));
|
||||
for (double y = -0.6; y <= 0.6; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(1.2, y));
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
EXPECT_GT(r.distance, 0.4);
|
||||
EXPECT_LT(r.distance, 0.8);
|
||||
EXPECT_GE(r.baseline_cells, 1);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, LookaheadAngleTruncatesTheArc)
|
||||
{
|
||||
// R = v/omega = 0.1 m: 0.8 m cung là quay 8 rad. Cắt ở 1.0 rad -> chỉ còn 0.1 m cung = 2 mẫu;
|
||||
// không cắt (pi) -> 0.31 m = 6 mẫu. Không có vật cản: chỉ đo số mẫu.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
MotionCheckParams p = bodyParams();
|
||||
p.lookahead_angle = 1.0;
|
||||
const MotionBlockResult cut = checkMotion(0.0, 0.0, 0.0, 0.4, 4.0, p, *grid.costmap());
|
||||
EXPECT_FALSE(cut.blocked);
|
||||
EXPECT_EQ(cut.scanned, 2);
|
||||
p.lookahead_angle = M_PI;
|
||||
const MotionBlockResult full = checkMotion(0.0, 0.0, 0.0, 0.4, 4.0, p, *grid.costmap());
|
||||
EXPECT_FALSE(full.blocked);
|
||||
EXPECT_GE(full.scanned, 6);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, BaselineDisabledKeepsTheOldVerdict)
|
||||
{
|
||||
// Đường lùi: tắt cờ thì ca "người kề hông + đi thẳng" lại bị chặn ngay mẫu đầu như trước 4/9.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = -0.2; x <= 0.3; x += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(x, 0.51));
|
||||
}
|
||||
MotionCheckParams p = bodyParams();
|
||||
p.exclude_baseline = false;
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, p, *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
EXPECT_LE(r.distance, 0.1);
|
||||
EXPECT_EQ(r.baseline_cells, 0);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, ArcCurvingAwayFromTheWallIsClear)
|
||||
{
|
||||
// Tường ngay trước mặt tại x=1.0 nhưng lệnh rẽ gắt trái (kappa = 1.5/0.3 = 5 1/m, R=0.2 m):
|
||||
// cung quay đi trước khi mũi tới tường. Gate quỹ đạo giấy cũng nói vậy — và đó là hành vi ĐÚNG
|
||||
// của phép đo này: nó đo lệnh thật, không đoán.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double y = -0.3; y <= 0.3; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(1.0, y));
|
||||
}
|
||||
MotionCheckParams p = bodyParams();
|
||||
p.side_offset = 0.0; // chỉ tâm/mũi/đuôi để test hình học cung, không dính probe hông
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.3, 1.5, p, *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, ThinPillarAtTheFrontCornerIsCaught)
|
||||
{
|
||||
// Trụ mảnh (một ô) tại x=1.0, y=+0.30: nằm giữa đường quét mũi (ngang 0) và đường quét hông
|
||||
// (ngang 0.53) của bản 5 điểm — bản đó không probe nào chạm, robot ôm trụ bằng góc trước-trái
|
||||
// (đo 4/9: near=0.36 m @ +70°). Chu vi bắt được ở mẫu mà cạnh mũi đi qua trụ.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(1.0, 0.30));
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
ASSERT_TRUE(r.blocked);
|
||||
// Cạnh mũi ở 0.58 + 0.05 = 0.63 trước tâm -> chạm khi tâm đi được ~0.37 m.
|
||||
EXPECT_NEAR(r.distance, 1.0 - 0.63, 0.06);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, PillarBetweenTwoWheelsIsCaughtByTheFrontEdge)
|
||||
{
|
||||
// Hai trụ cách nhau 0.45 m, robot chui giữa: bản 5 điểm để lọt cả hai; chu vi mũi chạm ngay.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(1.2, 0.225));
|
||||
ASSERT_TRUE(grid.setLethalAt(1.2, -0.225));
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_TRUE(r.blocked);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, SideProbeCatchesAWallBesideTheArc)
|
||||
{
|
||||
// Tường dọc bên trái tại y=+0.50, robot đi thẳng: chu vi với nửa rộng 0.48 + 0.05 = 0.53 chạm;
|
||||
// thu side_offset về 0 (dải rộng 2 x padding) thì không.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = 0.0; x <= 1.5; x += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(x, 0.50));
|
||||
}
|
||||
MotionCheckParams p = bodyParams();
|
||||
const MotionBlockResult with_side = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, p, *grid.costmap());
|
||||
EXPECT_TRUE(with_side.blocked);
|
||||
p.side_offset = 0.0;
|
||||
const MotionBlockResult no_side = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, p, *grid.costmap());
|
||||
EXPECT_FALSE(no_side.blocked);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, StandingStillScansNothing)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
ASSERT_TRUE(grid.setLethalAt(0.3, 0.0));
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.0, 0.5, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked);
|
||||
EXPECT_EQ(r.scanned, 0);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, ReverseMotionProbesBehind)
|
||||
{
|
||||
// Tường SAU lưng tại x=-1.2, lệnh lùi: đuôi (0.58+0.05) chạm trước khi tâm tới.
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double y = -0.6; y <= 0.6; y += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setLethalAt(-1.2, y));
|
||||
}
|
||||
const MotionBlockResult fwd = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(fwd.blocked);
|
||||
const MotionBlockResult rev = checkMotion(0.0, 0.0, 0.0, -0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
ASSERT_TRUE(rev.blocked);
|
||||
EXPECT_LT(rev.distance, 0.8);
|
||||
}
|
||||
|
||||
TEST(MotionCheck, UnknownCellsAreNotBlocked)
|
||||
{
|
||||
nav_test_harness::FakeCostmap grid = makeGrid();
|
||||
for (double x = 0.0; x <= 2.0; x += 0.05)
|
||||
{
|
||||
ASSERT_TRUE(grid.setCostAt(x, 0.0, robot_costmap_2d::NO_INFORMATION));
|
||||
}
|
||||
const MotionBlockResult r = checkMotion(0.0, 0.0, 0.0, 0.4, 0.0, bodyParams(), *grid.costmap());
|
||||
EXPECT_FALSE(r.blocked);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -34,7 +34,6 @@ 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;
|
||||
using move_base2::testing::FakeRecoveryPort;
|
||||
@@ -130,7 +129,6 @@ public:
|
||||
deps_.mission = &mission_;
|
||||
deps_.action = &action_;
|
||||
deps_.costmap_status = &costmap_status_;
|
||||
deps_.path_check = &path_check_;
|
||||
deps_.environment = &environment_;
|
||||
|
||||
std::string error;
|
||||
@@ -180,7 +178,6 @@ public:
|
||||
FakeMissionPort mission_;
|
||||
FakeActionPort action_;
|
||||
FakeCostmapStatusPort costmap_status_;
|
||||
FakePathCheckPort path_check_;
|
||||
FakeEnvironmentPort environment_;
|
||||
ControlLoopDeps deps_;
|
||||
|
||||
@@ -1403,7 +1400,7 @@ TEST(StaleCostmap, NullPortMeansNoGuard)
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// PathMonitor (contract 2026-08-04d)
|
||||
// Trợ giúp chung cho các ca có mission (submit + kiểm nhận).
|
||||
// ================================================================================================
|
||||
|
||||
namespace
|
||||
@@ -1417,359 +1414,8 @@ bool submitOk(Fixture& fixture, const NavigationRequest& request)
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/// Config có giám sát tuyến BẬT, ngưỡng ngắn để test không phải tua thời gian dài.
|
||||
ControlLoopConfig monitorConfig()
|
||||
{
|
||||
ControlLoopConfig config = baseConfig();
|
||||
config.state_machine.recovery_routes.planning_failed = { 0 };
|
||||
config.state_machine.recovery_routes.controlling_failed = { 0 };
|
||||
config.state_machine.recovery_routes.oscillation = { 0 };
|
||||
config.state_machine.recovery_routes.path_blocked = { 1 };
|
||||
config.state_machine.recovery_routes.off_path = { 1 };
|
||||
config.state_machine.recovery_routes.collision = { 1 };
|
||||
|
||||
config.path_monitor.enabled = true;
|
||||
config.path_monitor.check_period = 0.0; // quét mỗi cycle: test điều khiển thời gian bằng advance
|
||||
config.path_monitor.confirm_time = 0.2; // [s]
|
||||
config.path_monitor.horizon = 3.0; // [m]
|
||||
config.path_monitor.min_detour_distance = 0.5; // [m]
|
||||
// Phép đo lệch tuyến TẮT ở config cơ sở: pose giả đứng yên tại gốc còn plan giả nằm ở goal, nên
|
||||
// cross-track luôn lớn và sẽ át hết mọi ca về "tuyến bị chắn". Ca lệch tuyến có config riêng.
|
||||
config.path_monitor.max_cross_track = 0.0; // [m]
|
||||
config.path_monitor.grace_after_new_plan = 0.0; // tắt để test khai hoả được ngay
|
||||
return config;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, BlockedPathStopsTheRobotAfterConfirmTime)
|
||||
{
|
||||
Fixture fixture(monitorConfig());
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
// Recovery chạy dài để test quan sát được trạng thái DỪNG, thay vì thấy nó thoáng qua trong một
|
||||
// cycle rồi quay lại kControlling.
|
||||
fixture.recovery_.setScript(std::vector<RecoveryScript>(20, RecoveryScript::kRunning));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce(); // kPlanning
|
||||
fixture.stepOnce(); // kControlling
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
|
||||
// Chưa đủ confirm_time: robot vẫn chạy.
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_NEAR(fixture.loop_.lastCommand().linear.x, 0.0, 1e-9);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, PathBlockedCanBeDisabledOnItsOwn)
|
||||
{
|
||||
// Công tắc riêng (2026-08-06): tắt phép đo "tuyến bị chắn" mà không phải đặt `horizon` về 0 —
|
||||
// ngưỡng giữ nguyên để bật lại chỉ cần đổi một cờ, và đọc config thấy rõ ý định.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.path_blocked_enabled = false;
|
||||
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, FlickeringObstacleDoesNotStopTheRobot)
|
||||
{
|
||||
// Người đi ngang qua đúng một lượt quét không được làm robot dừng — đó là cả lý do có debounce.
|
||||
Fixture fixture(monitorConfig());
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.path_check_.setBlocked(i % 2 == 0, 1.5);
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, ObstacleTooCloseIsLeftToTheControllerPath)
|
||||
{
|
||||
// Vật cản sát nách: detour hầu như không ra nghiệm, và ca đó đã có controller_patience lo.
|
||||
Fixture fixture(monitorConfig());
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
fixture.path_check_.setBlocked(true, 0.2); // [m] < min_detour_distance
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, StaleCostmapSuppressesTheMonitor)
|
||||
{
|
||||
// Costmap quá hạn thì mọi kết luận về vật cản đều là quá khứ — không được khai hoả dựa vào nó.
|
||||
Fixture fixture(monitorConfig());
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
fixture.costmap_status_.setCurrent(false);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, UnavailableCheckIsTreatedAsUnknown)
|
||||
{
|
||||
// Cổng trả false = "không kết luận được". Không được suy thành bẩn (robot dừng oan mỗi lần TF trễ).
|
||||
Fixture fixture(monitorConfig());
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
fixture.path_check_.setAvailable(false);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, DockingLegIsNeverMonitored)
|
||||
{
|
||||
// Đường cong vào dock là một thể thống nhất; cắt ghép nó là phá chính hình học đó.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.docking_requires_marker = false;
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
|
||||
NavigationRequest request = makeRequest(3.0);
|
||||
request.profile = MotionProfile::kDocking;
|
||||
ASSERT_TRUE(submitOk(fixture, request));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, DriftingOffThePlanStopsTheRobot)
|
||||
{
|
||||
// Local planner tự né vật cản nhỏ (tầng 0) có thể kéo robot ra xa tuyến mà plan vẫn "sạch" và
|
||||
// controller vẫn ra lệnh — không trigger nào khác nhìn thấy tình huống này.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.max_cross_track = 0.4; // [m]
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
fixture.recovery_.setScript(std::vector<RecoveryScript>(20, RecoveryScript::kRunning));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
// Plan giả chỉ có pose goal (3, 0); robot bám sát nó thì cross-track nhỏ.
|
||||
fixture.pose_.setPosition(3.0, 0.1);
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
// Dạt sang bên quá ngưỡng: sau `confirm_time` thì dừng.
|
||||
fixture.pose_.setPosition(3.0, 0.9);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_NEAR(fixture.loop_.lastCommand().linear.x, 0.0, 1e-9);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, OffPathCanBeDisabledOnItsOwn)
|
||||
{
|
||||
// Đối xứng với `PathBlockedCanBeDisabledOnItsOwn`: ngưỡng `max_cross_track` vẫn để nguyên 0.4 m,
|
||||
// chỉ hạ cờ — cấu hình đã đo được giữ lại, bật lại là một dòng.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.max_cross_track = 0.4; // [m] ngưỡng thật, giữ nguyên
|
||||
config.path_monitor.off_path_enabled = false;
|
||||
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
fixture.pose_.setPosition(3.0, 5.0); // lệch rất xa
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, GracePeriodSuppressesTheOffPathCheck)
|
||||
{
|
||||
// Ngay sau khi đổi plan, pose robot có thể lệch nhất thời so với plan vừa tới (rõ nhất lúc
|
||||
// preempt/đổi chặng). Đo lệch tuyến lúc đó là khai hoả oan.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.max_cross_track = 0.4; // [m]
|
||||
config.path_monitor.grace_after_new_plan = 5.0; // [s] dài hơn hẳn kịch bản
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
fixture.pose_.setPosition(3.0, 5.0); // lệch rất xa
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, EmptyRouteDisablesTheMonitorInsteadOfAborting)
|
||||
{
|
||||
// Route rỗng nghĩa là behavior detour không nạp được (hoặc chưa khai). Giám sát mà không có
|
||||
// đường xử lý sẽ biến một cơ chế đang tắt thành ABORT ngay lần đầu thấy vật cản — đúng lỗi đã
|
||||
// gặp trên sim 2026-08-05. Đúng: không khai hoả, để controller_patience lo như trước.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.state_machine.recovery_routes.path_blocked.clear();
|
||||
config.state_machine.recovery_routes.off_path.clear();
|
||||
config.state_machine.recovery_routes.collision.clear();
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
EXPECT_GT(std::abs(fixture.loop_.lastCommand().linear.x), 0.0);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, OffPathRouteEmptyDisablesOnlyThatCheck)
|
||||
{
|
||||
// Hai phép đo độc lập: thiếu route của cái này không được làm câm cái kia.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.max_cross_track = 0.4; // [m]
|
||||
config.state_machine.recovery_routes.off_path.clear();
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
fixture.recovery_.setScript(std::vector<RecoveryScript>(20, RecoveryScript::kRunning));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
|
||||
// Lệch rất xa nhưng route off_path rỗng -> không khai hoả.
|
||||
fixture.pose_.setPosition(3.0, 5.0);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
// Còn path_blocked vẫn còn route thì vẫn phải chạy bình thường.
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonPathMonitor, BlockedFreshPlanDoesNotReplaceACleanOne)
|
||||
{
|
||||
// Luật "không thay plan sạch bằng plan bẩn": không có nó thì planner mù ghi đè đường vòng mỗi
|
||||
// nhịp replan nền và robot dừng-detour-chạy-dừng liên tục.
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.planner_frequency = 1000.0; // ép replan nền nổ mỗi cycle
|
||||
Fixture fixture(config);
|
||||
fixture.planner_.setScript(std::vector<PlannerScript>(20, PlannerScript::kOk));
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(40, ControllerScript::kOk));
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(3.0)));
|
||||
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
const std::size_t accepted_before = fixture.controller_.setPlanCount();
|
||||
|
||||
// Plan mới về đều đặn nhưng đều bị chắn -> controller không được nhận thêm plan nào.
|
||||
fixture.path_check_.setBlocked(true, 1.5);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
|
||||
EXPECT_EQ(fixture.controller_.setPlanCount(), accepted_before);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
@@ -1777,46 +1423,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// =================================================================================================
|
||||
// PathMonitor — phép đo 3: thân sắp chạm vật cản thật trên cung lệnh (2026-09-03).
|
||||
// EnvMonitor kContact — phanh theo quỹ đạo thật, cờ collision, leo thang khi route khoá (P4, 2026-09-05).
|
||||
// PathMonitor cũ (4 phép đo, PathCheckPort) đã xoá 6/9/2026 — xem Test/ENV_MONITOR_PLAN.md §4.19.
|
||||
// =================================================================================================
|
||||
namespace
|
||||
{
|
||||
ControlLoopConfig collisionConfig()
|
||||
{
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
// Chỉ phép đo 3 sống: hai phép đo cũ tắt để chứng minh nó tự giơ được cờ path_blocked một mình.
|
||||
config.path_monitor.path_blocked_enabled = false;
|
||||
config.path_monitor.off_path_enabled = false;
|
||||
config.path_monitor.collision_enabled = true;
|
||||
config.path_monitor.collision_lookahead = 0.8; // [m]
|
||||
config.path_monitor.collision_stop_distance = 0.35; // [m]
|
||||
config.path_monitor.collision_confirm_cycles = 2;
|
||||
config.path_monitor.collision_front_offset = 0.58; // [m]
|
||||
config.path_monitor.collision_rear_offset = 0.58; // [m]
|
||||
config.path_monitor.collision_side_offset = 0.48; // [m]
|
||||
config.path_monitor.collision_footprint_padding = 0.1; // [m]
|
||||
config.path_monitor.collision_brake_decel = 0.0;
|
||||
return config;
|
||||
}
|
||||
|
||||
/// @brief Chỉ Phép đo 4 sống. Cửa sổ/confirm rút ngắn để test chạy vài chục cycle.
|
||||
ControlLoopConfig progressConfig(const std::string& action = "recover")
|
||||
{
|
||||
ControlLoopConfig config = monitorConfig();
|
||||
config.path_monitor.path_blocked_enabled = false;
|
||||
config.path_monitor.off_path_enabled = false;
|
||||
config.path_monitor.collision_enabled = false;
|
||||
config.path_monitor.progress_enabled = true;
|
||||
config.path_monitor.progress_action = action;
|
||||
config.path_monitor.progress_window = 1.0; // [s] = 20 cycle
|
||||
config.path_monitor.progress_min_commanded = 0.05; // [m]
|
||||
config.path_monitor.progress_min_efficiency = 0.30;
|
||||
config.path_monitor.progress_clear_efficiency = 0.60;
|
||||
config.path_monitor.progress_confirm_time = 0.3; // [s] = 6 cycle
|
||||
config.path_monitor.progress_goal_zone = 0.6; // [m]
|
||||
return config;
|
||||
}
|
||||
|
||||
void driveToControlling(Fixture& fixture)
|
||||
{
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
@@ -1832,70 +1443,17 @@ void driveToControlling(Fixture& fixture)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, BrakesImmediatelyThenReplansAfterConfirm)
|
||||
{
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
|
||||
// Chạm trong quãng dừng: lệnh ra bằng 0 NGAY cycle này — trước cả khi cờ được giơ.
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
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) << "cycle 1: chưa đủ xác nhận";
|
||||
|
||||
// Cycle 2 xác nhận -> cờ path_blocked vào state machine ở cycle 3.
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, HeldByTheGuardAfterTheRouteIsSpentEscalatesToControllingFailed)
|
||||
{
|
||||
// Run 1 sim 2026-09-04: detour không ra nghiệm (start nằm trong vành 253), route path_blocked cạn,
|
||||
// guard giữ lệnh 0 nhưng vẫn báo command_valid -> controller_patience không chạy -> robot đứng
|
||||
// chết 20 s không một dòng log. Chuỗi bắt buộc: cạn route -> mute -> guard báo no_valid_command
|
||||
// -> controller_patience -> controlling_failed. Guard giữ 0 suốt chuỗi.
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
fixture.recovery_.setScript({ RecoveryScript::kFailed });
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
fixture.stepOnce(); // phanh, xác nhận, giơ cờ
|
||||
}
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
ASSERT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
|
||||
// Behavior tick ở cycle sau khi start, kết quả vào state machine ở cycle sau nữa.
|
||||
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 path_blocked đã cạn";
|
||||
|
||||
bool escalated = false;
|
||||
for (int i = 0; i < 40 && !escalated; ++i) // controller_patience 0.5 s = 10 cycle, dư địa rộng
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
escalated = fixture.loop_.state() == NavigationState::kRecovering &&
|
||||
fixture.recovery_.lastTrigger() == RecoveryTrigger::kControllingFailed;
|
||||
}
|
||||
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
|
||||
ControlLoopConfig config = baseConfig();
|
||||
config.state_machine.recovery_routes.planning_failed = { 0 };
|
||||
config.state_machine.recovery_routes.controlling_failed = { 0 };
|
||||
config.state_machine.recovery_routes.oscillation = { 0 };
|
||||
config.state_machine.recovery_routes.path_blocked = { 1 };
|
||||
config.state_machine.recovery_routes.collision = { 1 };
|
||||
config.env_monitor.enabled = true;
|
||||
config.env_monitor.stall.action = "log";
|
||||
config.env_monitor.unreachable.action = "log";
|
||||
@@ -2003,201 +1561,6 @@ TEST(WalkingSkeletonEnvContact, ContactBeyondTheStoppingDistanceCapsSpeedWithout
|
||||
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
|
||||
// tay; hình thân đúng là việc của costmap, không phải của người chép số vào hai file.
|
||||
ControlLoopConfig config = collisionConfig();
|
||||
config.path_monitor.collision_front_offset = 0.0;
|
||||
config.path_monitor.collision_rear_offset = 0.0;
|
||||
config.path_monitor.collision_side_offset = 0.0;
|
||||
Fixture fixture(config);
|
||||
fixture.path_check_.setBodyExtents(0.58, 0.58, 0.48);
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, NoBodyGeometryIsInconclusiveNotAStop)
|
||||
{
|
||||
// Offset = 0 mà cổng không có footprint: guard KHÔNG biết thân ở đâu thì không dừng, không giơ cờ,
|
||||
// chỉ kêu lỗi — cùng contract với TF/costmap hỏng. Dừng mù là biến lỗi cấu hình thành robot chết.
|
||||
ControlLoopConfig config = collisionConfig();
|
||||
config.path_monitor.collision_front_offset = 0.0;
|
||||
config.path_monitor.collision_rear_offset = 0.0;
|
||||
config.path_monitor.collision_side_offset = 0.0;
|
||||
Fixture fixture(config); // fake không setBodyExtents
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
ASSERT_GT(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
}
|
||||
EXPECT_EQ(fixture.path_check_.motionQueryCount(), 0u); // chưa có thân thì không dò
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, SlowTurnFarFromContactIsCappedNotStopped)
|
||||
{
|
||||
// Run 16:26: xoay bò v 0.04 ω −0.5 (R 0.08 m), chạm ở 0.15 m cung = quay 1.9 rad, còn 3.8 s.
|
||||
// Chưa "sắp" theo thời gian lẫn góc -> không dừng, không recovery, chỉ kẹp v <= (0.15−0.1)/1.0.
|
||||
Fixture fixture(collisionConfig()); // padding 0.1, stop_time 1.0, stop_angle 0.35 mặc định
|
||||
driveToControlling(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.04);
|
||||
fixture.controller_.setNominalTurnRate(-0.5);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.15);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
}
|
||||
EXPECT_EQ(fixture.recovery_.startCount(), 0u);
|
||||
EXPECT_GT(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
EXPECT_LE(fixture.loop_.lastCommand().linear.x, 0.05 + 1e-9);
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().angular.z, -0.5); // guard không đụng omega
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, SlowTurnCloseToContactStops)
|
||||
{
|
||||
// Cùng cú xoay nhưng chỉ còn 0.02 m cung = 0.25 rad <= stop_angle -> sắp chạm thật -> dừng.
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.04);
|
||||
fixture.controller_.setNominalTurnRate(0.5);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.02);
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kCollision);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, StraightCreepStillStops)
|
||||
{
|
||||
// Bò thẳng 0.05 m/s, chạm ở 0.15 m: 3 s nữa nhưng góc = 0 -> "sắp" theo góc -> dừng như trước.
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.05);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.15);
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, FastCurvedApproachStillStops)
|
||||
{
|
||||
// Lần nổ 115.1 của run 16:26: v 0.36 ω −0.27, chạm ở 0.20 m = 0.55 s -> sắp theo thời gian.
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
fixture.controller_.setNominalSpeed(0.36);
|
||||
fixture.controller_.setNominalTurnRate(-0.27);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.20);
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
fixture.stepOnce();
|
||||
fixture.stepOnce();
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, ContactBeyondStopDistanceDoesNotStop)
|
||||
{
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.7); // [m] > stop_distance 0.35
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
ASSERT_GT(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, CapsSpeedByRemainingDistanceWhenBrakeDecelIsSet)
|
||||
{
|
||||
ControlLoopConfig config = collisionConfig();
|
||||
config.path_monitor.collision_brake_decel = 0.1; // [m/s^2] -> cap sqrt(2*0.1*0.35) = 0.26 m/s
|
||||
Fixture fixture(config);
|
||||
driveToControlling(fixture);
|
||||
const double free_speed = fixture.loop_.lastCommand().linear.x;
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.7);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
const double cap = std::sqrt(2.0 * 0.1 * (0.7 - 0.35));
|
||||
EXPECT_LE(fixture.loop_.lastCommand().linear.x, cap + 1e-9);
|
||||
EXPECT_GT(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
EXPECT_LT(fixture.loop_.lastCommand().linear.x, free_speed);
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, OneCycleFlickerBrakesButDoesNotReplan)
|
||||
{
|
||||
// Một nhịp costmap nhấp nháy: lệnh 0 đúng một cycle (an toàn), nhưng không kéo recovery ra.
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
fixture.stepOnce();
|
||||
EXPECT_DOUBLE_EQ(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
fixture.path_check_.setMotionBlocked(false);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
}
|
||||
EXPECT_GT(fixture.loop_.lastCommand().linear.x, 0.0);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, DisabledFlagLeavesTheCommandAlone)
|
||||
{
|
||||
ControlLoopConfig config = collisionConfig();
|
||||
config.path_monitor.collision_enabled = false;
|
||||
Fixture fixture(config);
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
ASSERT_GT(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
}
|
||||
EXPECT_EQ(fixture.path_check_.motionQueryCount(), 0u);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonCollisionGuard, UnknownVerdictNeitherStopsNorClearsTheStreak)
|
||||
{
|
||||
Fixture fixture(collisionConfig());
|
||||
driveToControlling(fixture);
|
||||
|
||||
fixture.path_check_.setMotionAvailable(false); // thiếu TF/costmap: "không biết"
|
||||
fixture.path_check_.setMotionBlocked(true, 0.2);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling) << "cycle " << i;
|
||||
ASSERT_GT(fixture.loop_.lastCommand().linear.x, 0.0) << "cycle " << i;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Phép đo 4 — "planner đòi đi mà robot không tiến"
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -2215,63 +1578,3 @@ void runStalled(Fixture& fixture, int max_cycles)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(WalkingSkeletonProgressMonitor, StalledRobotEscalatesToOscillationRecovery)
|
||||
{
|
||||
Fixture fixture(progressConfig("recover"));
|
||||
driveToControlling(fixture);
|
||||
ASSERT_GT(fixture.loop_.lastCommand().linear.x, 0.0) << "controller phải đang đòi đi";
|
||||
|
||||
// Cần: 1 mẫu đủ tuổi window (20 cycle) + confirm 6 cycle + 1 cycle để state machine thấy cờ.
|
||||
runStalled(fixture, 60);
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kRecovering);
|
||||
EXPECT_EQ(fixture.recovery_.lastTrigger(), RecoveryTrigger::kOscillation);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonProgressMonitor, LogModeNeverEscalates)
|
||||
{
|
||||
Fixture fixture(progressConfig("log"));
|
||||
driveToControlling(fixture);
|
||||
|
||||
runStalled(fixture, 80);
|
||||
|
||||
// Cùng tình huống kẹt, mode "log" chỉ in cảnh báo: state machine không được thấy cờ.
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonProgressMonitor, NearTheGoalIsNotMeasured)
|
||||
{
|
||||
Fixture fixture(progressConfig("recover"));
|
||||
fixture.planner_.setScript({ PlannerScript::kOk });
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(400, ControllerScript::kOk));
|
||||
fixture.recovery_.setScript(std::vector<RecoveryScript>(20, RecoveryScript::kRunning));
|
||||
// Goal cách 0.3 m < progress_goal_zone 0.6 m: dừng chính xác / rot2goal có lệnh nhỏ mà không
|
||||
// tiến là hợp lệ, không được coi là kẹt.
|
||||
ASSERT_TRUE(submitOk(fixture, makeRequest(0.3)));
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
ASSERT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
|
||||
runStalled(fixture, 80);
|
||||
|
||||
EXPECT_EQ(fixture.loop_.state(), NavigationState::kControlling);
|
||||
}
|
||||
|
||||
TEST(WalkingSkeletonProgressMonitor, ZeroCommandIsWaitingNotStalling)
|
||||
{
|
||||
Fixture fixture(progressConfig("recover"));
|
||||
driveToControlling(fixture);
|
||||
|
||||
// Controller ngừng ra lệnh (hold chờ người): lệnh sau trọng tài về 0 -> cmd < min_commanded ->
|
||||
// KHÔNG đo. Phép đo 4 không được nhầm "chờ" với "kẹt".
|
||||
fixture.controller_.setScript(std::vector<ControllerScript>(400, ControllerScript::kFail));
|
||||
for (int i = 0; i < 60 && fixture.loop_.state() == NavigationState::kControlling; ++i)
|
||||
{
|
||||
fixture.stepOnce();
|
||||
}
|
||||
// Có thể rời kControlling vì controller_patience (kFail) — nhưng KHÔNG phải vì kOscillation.
|
||||
EXPECT_NE(fixture.recovery_.lastTrigger(), RecoveryTrigger::kOscillation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user