diff --git a/libs/vslam_drivers/src/mcu_bridge.cc b/libs/vslam_drivers/src/mcu_bridge.cc index 5977107..2e070d8 100644 --- a/libs/vslam_drivers/src/mcu_bridge.cc +++ b/libs/vslam_drivers/src/mcu_bridge.cc @@ -267,7 +267,27 @@ class McuBridge : public McuInterface { double host_s = 0.0; UnixTime stamp; - if (sync_.ToHost(mcu_s, &host_s)) { + // ⚠️ KIEM tinh hop ly truoc khi tin. `ready()` cua ClockSync bat ngay khi + // co 2 mau, va fit tu 2 diem cach nhau mot chu ky IMU thi ra bat cu gi. + // + // Do duoc tren robot: lan chuyen tu dong ho host sang dong ho MCU lam dau + // thoi gian nhay LUI 29.1 GIAY. Do khong phai sai so, do la vo nghia -- mot + // mau vua den thi thoi diem do cua no phai cach `t_recv` dung do tre mot + // chieu cua duong truyen, tuc vai mili giay. Lech 29 s thi phep fit dang + // noi ve mot vu tru khac. + // + // 1 giay la nguong RAT rong so voi vai ms that su, co y: no chi de bat cai + // vo nghia, khong de tinh chinh. + const bool sane = sync_.ToHost(mcu_s, &host_s) && + std::fabs(host_s - t_recv) < 1.0; + if (!sane && sync_.ready()) { + ++sync_rejected_; + VSLAM_WARN_THROTTLE(10.0, + "mcu: ClockSync cho thoi diem lech " << (host_s - t_recv) + << " s so voi luc nhan duoc dong -- bo qua, dung dong ho host. " + "Lan thu " << sync_rejected_ << "."); + } + if (sane) { stamp = UnixTime::fromSec(host_s); // In DINH KY chu khong in mot lan. // @@ -423,6 +443,7 @@ class McuBridge : public McuInterface { // khong can khoa. McuTimeUnwrapper unwrap_; ClockSync sync_; + uint64_t sync_rejected_ = 0; // lan ClockSync cho ket qua vo nghia uint64_t unhandled_records_ = 0; // B / E / U / K: chua co nguoi dung uint32_t seq_ = 0; diff --git a/libs/vslam_odometry/src/wheel_odometry.cc b/libs/vslam_odometry/src/wheel_odometry.cc index ccecea1..a90b02c 100644 --- a/libs/vslam_odometry/src/wheel_odometry.cc +++ b/libs/vslam_odometry/src/wheel_odometry.cc @@ -295,7 +295,19 @@ bool WheelOdometry::Update(UnixTime stamp, double pos_l, double pos_r, const double period = GyroPeriodSec(); double w_enc = omega_encoder; double g = gyro_z_; - const UnixTime t_ref = stamp - Duration::fromSec(period); + // Lui 1.5 chu ky chu khong phai 1. + // + // Voi 1 chu ky thi `t_ref` co tuoi dung bang T, trong khi mau gyro moi nhat + // co tuoi bat ky trong [0, T]. Chi can mot mau gyro den tre chut la `t_ref` + // roi ra SAU mau moi nhat va het kep duoc. Do duoc: `[tho:G]` 9 lan, voi + // T = 0.1002 s. + // + // 1.5 chu ky cho `t_ref` nam giua mau moi nhat va mau ke truoc trong moi + // truong hop binh thuong. Cai gia la phat hien truot tre them nua chu ky + // (~50 ms) -- khong dang ke voi mot tin hieu chi de nang covariance. + // + // Phep so van dung: ca hai ben deu lay tai `t_ref`, chi la doc tre hon. + const UnixTime t_ref = stamp - Duration::fromSec(period * 1.5); // Ghi ro LY DO khi phai lui ve so tho. Mot chu "[tho]" tron khong du: da // mat mot vong do-sua-chay vi no chi noi "that bai" chu khong noi o dau,