This commit is contained in:
trung09122002
2026-09-25 09:04:37 +07:00
parent d6f1afac31
commit 0093df0508
7 changed files with 139 additions and 5 deletions

View File

@@ -269,6 +269,63 @@ TEST(NodeCloud, DepthRaDiemOFrameBase) {
}
}
namespace {
// Luoi 2D toan o TRONG, khong xoay, goc duoi-trai tai (ox, oy).
OccupancyGrid Luoi(uint32_t w, uint32_t h, double ox, double oy) {
OccupancyGrid g;
g.resolution = 0.05f;
g.width = w;
g.height = h;
g.origin.position.x = ox;
g.origin.position.y = oy;
g.origin.orientation.w = 1.0;
g.data.assign(static_cast<size_t>(w) * h, 0);
return g;
}
VoxelGrid Voxels(std::vector<VoxelIndex> cells) {
VoxelGrid v;
v.resolution = 0.05f;
v.cells = std::move(cells);
return v;
}
} // namespace
TEST(MarkVoxelObstacles, ChiLayDaiDoCaoCuaRobot) {
// Goc luoi (-0.5, -0.5): kiem ca phep tru goc, khong chi phep chia.
OccupancyGrid g = Luoi(20, 20, -0.5, -0.5);
const VoxelGrid v = Voxels({
K(3, 4, 6), // z = 0.325 m -> trong dai [0.10, 0.55] -> tuong
K(5, 5, 16), // z = 0.825 m -> tren noc robot -> bo
K(6, 6, 1), // z = 0.075 m -> san -> bo
});
EXPECT_EQ(MarkVoxelObstacles(v, 0.10, 0.55, &g), 1u);
// x = 0.175 -> (0.175 + 0.5) / 0.05 = 13; y = 0.225 -> 14.
EXPECT_EQ(g.data[14 * 20 + 13], 100);
// K(5,5,*) roi vao o (15, 15), K(6,6,*) vao o (16, 16).
EXPECT_EQ(g.data[15 * 20 + 15], 0) << "voxel 0.825 m khong duoc danh dau";
EXPECT_EQ(g.data[16 * 20 + 16], 0) << "voxel 0.075 m khong duoc danh dau";
}
TEST(MarkVoxelObstacles, NgoaiLuoiThiBoQua) {
OccupancyGrid g = Luoi(20, 20, 0.0, 0.0);
const VoxelGrid v = Voxels({K(100, 100, 6), K(-3, 2, 6), K(2, -1, 6)});
EXPECT_EQ(MarkVoxelObstacles(v, 0.10, 0.55, &g), 0u);
for (int8_t c : g.data) EXPECT_EQ(c, 0);
}
TEST(MarkVoxelObstacles, ODaLaTuongThiKhongDemLai) {
OccupancyGrid g = Luoi(20, 20, 0.0, 0.0);
g.data[4 * 20 + 3] = 100; // tuong tu LiDAR
g.data[5 * 20 + 3] = -1; // chua biet -> van danh dau duoc
const VoxelGrid v = Voxels({K(3, 4, 6), K(3, 5, 6)});
EXPECT_EQ(MarkVoxelObstacles(v, 0.10, 0.55, &g), 1u);
EXPECT_EQ(g.data[4 * 20 + 3], 100);
EXPECT_EQ(g.data[5 * 20 + 3], 100);
}
TEST(NodeCloud, KhongCoDepthThiRong) {
// Node quet voi camera_3d=false: khong co depth -> rong, khong nem loi.
rtabmap::SensorData data;