drivers,sim: moi khung anh mot bo dem rieng (sua tranh chap voi SlamLoop o RealSense/sim/replay); sim: IMU dong hoc tu quy dao 6-DoF, tan so phat/tre/bias, ground truth vao .vsr, vslam_record --robot --gt

This commit is contained in:
trung09122002
2026-10-03 18:55:55 +07:00
parent 26ee1a3b72
commit 0dd2546ab1
13 changed files with 845 additions and 51 deletions

View File

@@ -5,6 +5,7 @@
#include <cmath>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <unistd.h>
@@ -320,6 +321,66 @@ TEST(ReplaySource, LenhMotorKhiReplayDiVaoHuKhong) {
std::remove(path.c_str());
}
TEST(ReplaySource, AnhCuKhongBiKhungSauGhiDe) {
// Nhu bo mo phong va driver RealSense: anh da phat ra phai giu nguyen noi
// dung du nguon da giai ma them nhieu khung -- SlamLoop giu khung moi nhat
// qua Rtabmap::process tren luong khac. Truoc day ba kho giai ma dung chung.
const std::string path = TempPath("img_hold");
{
RecordWriterConfig c;
c.path = path;
RecordWriter w(c);
ASSERT_TRUE(w.Open().ok());
for (int k = 0; k < 6; ++k) {
const UnixTime stamp = UnixTime::fromSec(1737000000.0 + 0.1 * k);
std::vector<uint8_t> depth(4 * 2 * 2), ir(4 * 2);
for (size_t i = 0; i < depth.size(); ++i) depth[i] = static_cast<uint8_t>(10 * k + i);
for (size_t i = 0; i < ir.size(); ++i) ir[i] = static_cast<uint8_t>(100 + 10 * k + i);
Image d;
d.header.stamp = stamp;
d.width = 4; d.height = 2; d.step = 8;
d.format = PixelFormat::kMono16;
d.depth_scale = 0.001f;
d.data = depth.data();
Image r = d;
r.step = 4;
r.format = PixelFormat::kMono8;
r.data = ir.data();
std::string pd, pr;
EncodeImagePayload(d, &pd);
EncodeImagePayload(r, &pr);
w.Write(VsrStream::kDepth, stamp, pd);
w.Write(VsrStream::kInfra1, stamp, pr);
}
w.Close();
}
ReplayConfig cfg;
cfg.path = path;
cfg.deterministic = true;
ReplaySource rs(cfg);
ASSERT_TRUE(rs.Open().ok());
std::vector<CameraFrame> frames;
std::vector<std::vector<uint8_t>> depth_copy, ir_copy;
rs.camera()->SetCallback([&](const CameraFrame& f) {
frames.push_back(f);
depth_copy.emplace_back(f.depth->data, f.depth->data + 16);
ir_copy.emplace_back(f.infra1->data, f.infra1->data + 8);
});
rs.camera()->Open();
rs.Run();
ASSERT_EQ(frames.size(), 6u);
for (size_t k = 0; k < frames.size(); ++k) {
EXPECT_EQ(std::memcmp(frames[k].depth->data, depth_copy[k].data(), 16), 0)
<< "depth khung " << k << " bi ghi de";
EXPECT_EQ(std::memcmp(frames[k].infra1->data, ir_copy[k].data(), 8), 0)
<< "IR khung " << k << " bi ghi de";
EXPECT_EQ(frames[k].depth->data[0], static_cast<uint8_t>(10 * k));
}
std::remove(path.c_str());
}
TEST(ReplaySource, FileKhongTonTaiThiBaoLoi) {
ReplayConfig cfg;
cfg.path = "/khong/ton/tai/abc.vsr";