#ifndef VSLAM_REPLAY_SOURCE_H #define VSLAM_REPLAY_SOURCE_H // Phat lai mot file .vsr qua CHINH cac interface driver. // // ================== VI SAO DAY LA MANH KHOA ================== // ReplaySources tra ve nhung LidarInterface / CameraInterface / McuInterface / // BaseInterface that -- cung kieu ma driver phan cung tra ve. // // Hau qua: vslam_node KHONG BIET minh dang chay live hay dang phat lai. Khong // co mot nhanh `if (replay)` nao trong logic. Moi thu doc tu file di qua dung // nhung duong ma du lieu that di qua: cung ScanSanitizer, cung EKF, cung // safety, cung SLAM. // // Day la loi ich kien truc lon nhat cua viec dung interface truu tuong + // factory, va la thu thay the cho ca Gazebo lan rosbag cung mot luc. // // ================== CHE DO TAT DINH ================== // Voi `deterministic = true`: MOT luong duy nhat, day moi ban ghi theo dung // thu tu stamp, dung ReplayClock. Chay lai cung mot file cho ra ket qua giong // het den tung byte. // // Dieu do CHI kha thi neu quy tac o clock.h duoc giu tu ngay dau: khong stage // nao goi UnixTime::now() truc tiep, moi stage nhan Clock& qua constructor. // Vi pham mot cho thoi la mat tinh tat dinh, va khong the sua bang cach sua // rieng replay. #include #include #include "vslam/clock.h" #include "vslam/driver_interfaces.h" namespace vslam { struct ReplayConfig { std::string path; // 1.0 = thoi gian that. 0 = chay nhanh nhat co the (khong ngu). double speed = 1.0; // Bo qua bao nhieu giay dau file, va chay bao lau. 0 = toan bo. double start_sec = 0.0; double duration_sec = 0.0; // Mot luong, day theo thu tu stamp. Bo qua `speed`. bool deterministic = false; // Lap lai tu dau khi het file. Dung khi debug UI. bool loop = false; // Ap ScanSanitizer len SCAN_RAW. Mac dinh true: ban ghi luu du lieu THO // (truoc sanitizer) chinh la de doi nguong roi test lai duoc. bool apply_sanitizer = true; ScanSanitizerConfig sanitizer; }; // So huu ca bon nguon. Huy object nay se dung viec phat lai. class ReplaySource { public: explicit ReplaySource(ReplayConfig cfg); ~ReplaySource(); ReplaySource(const ReplaySource&) = delete; ReplaySource& operator=(const ReplaySource&) = delete; StatusResponse Open(); // Dong ho ao. Moi stage phai dung dong ho NAY, khong phai dong ho he thong. ClockPtr clock() const; // Bon nguon nay la interface driver that. Dat callback nhu voi phan cung. LidarInterface* lidar(); CameraInterface* camera(); McuInterface* mcu(); BaseInterface* base(); // Chay het file (hoac het `duration_sec`). Chan cho toi khi xong. // Trong che do tat dinh, day la vong lap don luong duy nhat. void Run(); // Yeu cau dung som. An toan goi tu luong khac. void RequestStop(); // Config luc ghi, lay tu header cua file. Cho biet ban ghi chay voi nguong // nao -- mot ban ghi tu mo ta duoc. const std::string& recorded_config_json() const; struct Stats { uint64_t chunks = 0; uint64_t scans = 0; uint64_t imu = 0; uint64_t encoder = 0; uint64_t camera_frames = 0; uint64_t events = 0; uint64_t skipped = 0; // ngoai cua so start/duration bool truncated = false; // file hong giua chung double duration_sec = 0.0; }; Stats stats() const; private: struct Impl; std::unique_ptr impl_; }; } // namespace vslam #endif // VSLAM_REPLAY_SOURCE_H