This commit is contained in:
trung09122002
2026-09-22 09:31:16 +07:00
parent b5f0956b1d
commit 1efef2ef47
6 changed files with 157 additions and 11 deletions

View File

@@ -184,7 +184,7 @@ TEST(BinaryCodec, CloudGiamMauVaBoNaN) {
c.points[5] = PointXYZ{std::numeric_limits<float>::quiet_NaN(), 0.0f, 0.0f};
std::string buf;
EncodeCloud(c, UnixTime::fromSec(1.0), /*max_points=*/1000, 0.01f, &buf);
EncodeCloud(c, UnixTime::fromSec(1.0), /*max_points=*/1000, 0.01f, Pose2D{}, &buf);
// 16 header + 20 (origin3 + scale + n) + n*6
ASSERT_GE(buf.size(), 36u);
@@ -196,13 +196,56 @@ TEST(BinaryCodec, CloudGiamMauVaBoNaN) {
TEST(BinaryCodec, CloudRongVanHopLe) {
PointCloudXYZ c;
std::string buf;
EncodeCloud(c, UnixTime::fromSec(1.0), 1000, 0.01f, &buf);
EncodeCloud(c, UnixTime::fromSec(1.0), 1000, 0.01f, Pose2D{}, &buf);
EXPECT_EQ(buf.size(), 36u);
BinaryHeader h;
ASSERT_TRUE(DecodeHeader(buf, 0, &h));
EXPECT_EQ(h.type, BinaryType::kCloud);
}
// Diem phai DI THEO delta, neu khong thi phep bu do tre khong ton tai that.
//
// `delta` la `pose_now^-1 * pose_capture` (xem Runtime::WebLoop), nen robot
// TIEN 0.5 m ke tu luc chup cho ra delta.x = -0.5: diem tung o 1.0 m truoc
// mui gio chi con cach 0.5 m.
TEST(BinaryCodec, CloudApDeltaTinhTien) {
PointCloudXYZ c;
c.points.push_back(PointXYZ{1.0f, 0.0f, 0.0f});
std::string buf;
EncodeCloud(c, UnixTime::fromSec(1.0), 100, 0.01f, Pose2D{-0.5, 0.0, 0.0}, &buf);
ASSERT_EQ(buf.size(), 42u); // 16 header + 20 + 1*6
auto i16 = [&buf](size_t off) {
return static_cast<int16_t>(static_cast<uint8_t>(buf[off]) |
(static_cast<uint8_t>(buf[off + 1]) << 8));
};
EXPECT_NEAR(i16(36) * 0.01, 0.5, 1e-6);
EXPECT_NEAR(i16(38) * 0.01, 0.0, 1e-6);
}
// Xoay, khong chi tinh tien: quay tai cho la truong hop lam cloud va scan
// tach nhau ro nhat, va mot delta chi co tinh tien se khong bat duoc no.
TEST(BinaryCodec, CloudApDeltaXoay) {
PointCloudXYZ c;
c.points.push_back(PointXYZ{1.0f, 0.0f, 0.5f});
std::string buf;
// Robot da quay PHAI 90 do ke tu luc chup -> diem truoc mui gio o ben TRAI.
EncodeCloud(c, UnixTime::fromSec(1.0), 100, 0.01f,
Pose2D{0.0, 0.0, M_PI / 2.0}, &buf);
ASSERT_EQ(buf.size(), 42u);
auto i16 = [&buf](size_t off) {
return static_cast<int16_t>(static_cast<uint8_t>(buf[off]) |
(static_cast<uint8_t>(buf[off + 1]) << 8));
};
EXPECT_NEAR(i16(36) * 0.01, 0.0, 1e-6);
EXPECT_NEAR(i16(38) * 0.01, 1.0, 1e-6);
// z khong bi delta cham vao.
EXPECT_NEAR(i16(40) * 0.01, 0.5, 1e-6);
}
TEST(BinaryCodec, PathThuaHoa) {
std::vector<Pose2D> path;
for (int i = 0; i < 1000; ++i) {