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:
@@ -73,6 +73,10 @@ enum class VsrStream : uint8_t {
|
||||
// bao "xanh" cho mot he da mat hai nhanh an toan.
|
||||
kUltrasonic = 11,
|
||||
kBumper = 12,
|
||||
// MO RONG: tu the THAT 6-DoF, CHI ban ghi tu bo mo phong. De cham diem
|
||||
// offline (VO/VIO, z tren doc). Replay khong dua no vao duong ong nao --
|
||||
// khong stage nao duoc doc su that.
|
||||
kGroundTruth = 13,
|
||||
};
|
||||
|
||||
const char* VsrStreamName(VsrStream s);
|
||||
@@ -109,6 +113,11 @@ bool DecodeUltrasonicPayload(const std::string& buf, double* range, size_t* coun
|
||||
void EncodeBumperPayload(uint32_t mask, std::string* out);
|
||||
bool DecodeBumperPayload(const std::string& buf, uint32_t* mask);
|
||||
|
||||
// Ground truth 6-DoF: sau double x, y, z, roll, pitch, yaw cua base_footprint
|
||||
// trong frame world (z = do cao san duoi robot; pitch duong = mui chuc xuong).
|
||||
void EncodeGroundTruthPayload(const double pose6[6], std::string* out);
|
||||
bool DecodeGroundTruthPayload(const std::string& buf, double pose6[6]);
|
||||
|
||||
void EncodeCameraInfoPayload(const CameraInfo& info, std::string* out);
|
||||
bool DecodeCameraInfoPayload(const std::string& buf, CameraInfo* out);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/buffer_pool.h"
|
||||
#include "vslam/clock.h"
|
||||
#include "vslam/driver_config.h"
|
||||
#include "vslam/driver_interfaces.h"
|
||||
@@ -323,22 +324,30 @@ class RealSenseDriver : public CameraInterface {
|
||||
depth_img->data = static_cast<const uint8_t*>(depth.get_data());
|
||||
depth_img->keep_alive = keep; // KHONG copy: giu frameset song
|
||||
} else {
|
||||
Decimate16(praw, sw, sh, static_cast<int>(cfg_.decimate), &depth_buf_,
|
||||
// MOI khung mot bo dem RIENG tu pool, anh giu no qua keep_alive.
|
||||
//
|
||||
// ⚠️ Truoc day la MOT bo dem dung chung, "hop le toi lan goi Loop()
|
||||
// sau" -- du cho perception chay INLINE trong callback, nhung SlamLoop
|
||||
// giu khung depth/IR moi nhat qua Rtabmap::process (100-600 ms) tren
|
||||
// luong KHAC, va `BuildSensorData` boc cv::Mat quanh bo dem ma khong
|
||||
// copy. Khung sau (33 ms) ghi de giua chung: anh luu vao DB co the la
|
||||
// nua khung nay nua khung kia.
|
||||
auto buf = buf_pool_->Acquire();
|
||||
Decimate16(praw, sw, sh, static_cast<int>(cfg_.decimate), buf.get(),
|
||||
&depth_img->width, &depth_img->height);
|
||||
depth_img->step = depth_img->width * 2;
|
||||
depth_img->data = depth_buf_.data();
|
||||
// Bo dem cua ta: hop le toi lan goi Loop() sau. Consumer chay INLINE
|
||||
// trong callback (xem PerceptionPipeline) nen dieu do la du.
|
||||
depth_img->data = buf->data();
|
||||
depth_img->keep_alive = buf;
|
||||
}
|
||||
out.depth = depth_img;
|
||||
|
||||
if (cfg_.enable_infra1) {
|
||||
rs2::video_frame ir = fs.get_infrared_frame(1);
|
||||
if (ir) out.infra1 = WrapIr(ir, out.header, keep, &ir1_buf_);
|
||||
if (ir) out.infra1 = WrapIr(ir, out.header, keep);
|
||||
}
|
||||
if (cfg_.enable_infra2) {
|
||||
rs2::video_frame ir = fs.get_infrared_frame(2);
|
||||
if (ir) out.infra2 = WrapIr(ir, out.header, keep, &ir2_buf_);
|
||||
if (ir) out.infra2 = WrapIr(ir, out.header, keep);
|
||||
}
|
||||
|
||||
out.depth_info = info_;
|
||||
@@ -354,8 +363,7 @@ class RealSenseDriver : public CameraInterface {
|
||||
}
|
||||
|
||||
ImagePtr WrapIr(const rs2::video_frame& ir, const Header& hdr,
|
||||
const std::shared_ptr<FrameKeepAlive>& keep,
|
||||
std::vector<uint8_t>* buf) {
|
||||
const std::shared_ptr<FrameKeepAlive>& keep) {
|
||||
auto img = std::make_shared<Image>();
|
||||
img->header = hdr;
|
||||
img->format = PixelFormat::kMono8;
|
||||
@@ -367,10 +375,13 @@ class RealSenseDriver : public CameraInterface {
|
||||
img->data = static_cast<const uint8_t*>(ir.get_data());
|
||||
img->keep_alive = keep;
|
||||
} else {
|
||||
// Bo dem rieng moi khung, nhu depth o tren.
|
||||
auto buf = buf_pool_->Acquire();
|
||||
Decimate8(static_cast<const uint8_t*>(ir.get_data()), w, h,
|
||||
static_cast<int>(cfg_.decimate), buf, &img->width, &img->height);
|
||||
static_cast<int>(cfg_.decimate), buf.get(), &img->width, &img->height);
|
||||
img->step = img->width;
|
||||
img->data = buf->data();
|
||||
img->keep_alive = buf;
|
||||
}
|
||||
return img;
|
||||
}
|
||||
@@ -384,7 +395,10 @@ class RealSenseDriver : public CameraInterface {
|
||||
float depth_scale_ = 0.001f;
|
||||
CameraInfo info_;
|
||||
|
||||
std::vector<uint8_t> depth_buf_, ir1_buf_, ir2_buf_;
|
||||
// Bo dem anh da decimate (depth + IR). Moi khung lay bo dem rieng va tra
|
||||
// ve pool khi KHONG CON AI giu anh -- 0 malloc o trang thai on dinh.
|
||||
std::shared_ptr<BufferPool<std::vector<uint8_t>>> buf_pool_ =
|
||||
BufferPool<std::vector<uint8_t>>::Create(12);
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
std::thread thread_;
|
||||
|
||||
@@ -121,6 +121,7 @@ const char* VsrStreamName(VsrStream s) {
|
||||
case VsrStream::kEvent: return "event";
|
||||
case VsrStream::kUltrasonic: return "ultrasonic";
|
||||
case VsrStream::kBumper: return "bumper";
|
||||
case VsrStream::kGroundTruth: return "ground_truth";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
@@ -225,6 +226,15 @@ bool DecodeBumperPayload(const std::string& buf, uint32_t* mask) {
|
||||
return r.ok;
|
||||
}
|
||||
|
||||
void EncodeGroundTruthPayload(const double pose6[6], std::string* o) {
|
||||
for (int i = 0; i < 6; ++i) PutF64(o, pose6[i]);
|
||||
}
|
||||
bool DecodeGroundTruthPayload(const std::string& buf, double pose6[6]) {
|
||||
Reader r(buf);
|
||||
for (int i = 0; i < 6; ++i) pose6[i] = r.F64();
|
||||
return r.ok;
|
||||
}
|
||||
|
||||
void EncodeEncoderPayload(double l, double rr, std::string* o) {
|
||||
PutF64(o, l);
|
||||
PutF64(o, rr);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/buffer_pool.h"
|
||||
#include "vslam/log.h"
|
||||
#include "vslam/record_io.h"
|
||||
#include "vslam/scan_sanitizer.h"
|
||||
@@ -163,9 +164,20 @@ struct ReplaySource::Impl {
|
||||
// roi phat mot lan khi thay chunk depth ke tiep hoac khi het file.
|
||||
CameraFrame pending_frame;
|
||||
bool have_pending = false;
|
||||
std::vector<uint8_t> depth_storage;
|
||||
std::vector<uint8_t> infra1_storage;
|
||||
std::vector<uint8_t> infra2_storage;
|
||||
// Kho nho cho anh giai ma. MOI anh mot kho rieng, giu qua keep_alive:
|
||||
// SlamLoop giu khung moi nhat qua Rtabmap::process tren luong khac, va ba
|
||||
// kho dung chung (nhu truoc day) bi khung sau ghi de giua chung.
|
||||
std::shared_ptr<BufferPool<std::vector<uint8_t>>> img_pool =
|
||||
BufferPool<std::vector<uint8_t>>::Create(12);
|
||||
|
||||
// Giai ma mot anh vao kho rieng. null neu payload hong.
|
||||
ImagePtr DecodeImage(const std::string& payload) {
|
||||
auto img = std::make_shared<Image>();
|
||||
auto storage = img_pool->Acquire();
|
||||
if (!DecodeImagePayload(payload, img.get(), storage.get())) return nullptr;
|
||||
img->keep_alive = storage;
|
||||
return img;
|
||||
}
|
||||
CameraInfo last_info;
|
||||
bool have_info = false;
|
||||
|
||||
@@ -360,22 +372,22 @@ void ReplaySource::Run() {
|
||||
case VsrStream::kDepth: {
|
||||
// Chunk depth moi = khung truoc da day du -> phat khung truoc.
|
||||
impl_->FlushCameraFrame();
|
||||
auto img = std::make_shared<Image>();
|
||||
if (!DecodeImagePayload(payload, img.get(), &impl_->depth_storage)) break;
|
||||
ImagePtr img = impl_->DecodeImage(payload);
|
||||
if (!img) break;
|
||||
impl_->pending_frame.header = img->header;
|
||||
impl_->pending_frame.depth = img;
|
||||
impl_->have_pending = true;
|
||||
break;
|
||||
}
|
||||
case VsrStream::kInfra1: {
|
||||
auto img = std::make_shared<Image>();
|
||||
if (!DecodeImagePayload(payload, img.get(), &impl_->infra1_storage)) break;
|
||||
ImagePtr img = impl_->DecodeImage(payload);
|
||||
if (!img) break;
|
||||
impl_->pending_frame.infra1 = img;
|
||||
break;
|
||||
}
|
||||
case VsrStream::kInfra2: {
|
||||
auto img = std::make_shared<Image>();
|
||||
if (!DecodeImagePayload(payload, img.get(), &impl_->infra2_storage)) break;
|
||||
ImagePtr img = impl_->DecodeImage(payload);
|
||||
if (!img) break;
|
||||
impl_->pending_frame.infra2 = img;
|
||||
break;
|
||||
}
|
||||
@@ -385,6 +397,10 @@ void ReplaySource::Run() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VsrStream::kGroundTruth:
|
||||
// Su that tu bo mo phong: chi de cham diem offline. KHONG dua vao
|
||||
// duong ong -- khong stage nao duoc doc no.
|
||||
break;
|
||||
case VsrStream::kCmdVel:
|
||||
// Lenh dieu khien DA GHI la dau vao cua lop safety, khong phai dau ra.
|
||||
// Replay khong tu dong ap chung: viec do do wiring quyet dinh.
|
||||
|
||||
Reference in New Issue
Block a user