diff --git a/configuration_files/sensors.yaml b/configuration_files/sensors.yaml index 9d164c3..f5b1926 100644 --- a/configuration_files/sensors.yaml +++ b/configuration_files/sensors.yaml @@ -194,7 +194,10 @@ mcu: # ⚠️ Chi bat sau khi DA FLASH firmware moi. Sai gia tri nay khong lam crash: # parser cua nhanh kia tu choi moi dong va IMU im lang tat -- trieu chung la # `wheel_odom: khong co IMU moi -> Odometry dang chay 'mu'`. - expect_timestamps: false + # + # Da flash va da kiem: log bao `ClockSync skew -59 ppm` (dai thach anh that), + # va `wheel_odom/lag` bao 0 ms. + expect_timestamps: true # ============ BU DO TRE IMU ============ # Firmware khong phat timestamp, nen stamp cua mot mau IMU la luc HOST doc @@ -218,7 +221,20 @@ mcu: # 3. Dat imu_lag_sec = XX/1000, chay lai. # 4. Lan nay log PHAI bao ~0 ms. Neu van bao XX thi mo hinh tre sai, dung # tang dai -- doc lai truoc. - imu_lag_sec: 0.0 + # + # --- 0.08: DO DUOC, khong phai chinh tay --- + # May do bao 80 ms sau tam lan lien tiep (mau 3500 -> 6500) trong luc lai vao + # ra cua. Dat vao day roi chay lai thi no bao 0 ms -- phep tu kiem chung. + # + # 80 ms do KHONG nam o phia host, nen firmware dong dau som cach may cung + # khong bot duoc: + # ~50 ms WT61PC loc/trung binh noi bo o che do 10 Hz + # ~23 ms day 2 khung Acc+Gyro qua day 9600 baud + # Ca hai deu xay ra TRUOC luc ESP32 dong dau. Xem firmware/imu_uart/README.md. + # + # ⚠️ Phai do lai neu doi tan so cam bien hoac baud cua day UART1 -- ca hai so + # hang tren deu phu thuoc chung. + imu_lag_sec: 0.08 # Ban ghi encoder `E,,,` la MO RONG moi -- giao # thuc cu chi co I/B/P. diff --git a/libs/vslam_odometry/include/vslam/ekf_se2.h b/libs/vslam_odometry/include/vslam/ekf_se2.h index 68c09fa..0b4248a 100644 --- a/libs/vslam_odometry/include/vslam/ekf_se2.h +++ b/libs/vslam_odometry/include/vslam/ekf_se2.h @@ -74,6 +74,10 @@ struct EkfSe2Stats { uint64_t imu_updates = 0; uint64_t rejected_outliers = 0; uint64_t time_resets = 0; + // Phep do den KHONG dung thu tu, lech duoi kMaxOutOfOrderSec. Binh thuong + // voi nhieu cam bien: IMU duoc bu 80 ms nen dau thoi gian cua no luon cu hon + // encoder. Con so nay tang deu la DUNG. Tang vot moi dang nghi. + uint64_t out_of_order = 0; double last_mahalanobis = 0.0; }; diff --git a/libs/vslam_odometry/src/ekf_se2.cc b/libs/vslam_odometry/src/ekf_se2.cc index 7ced937..2ad5e9e 100644 --- a/libs/vslam_odometry/src/ekf_se2.cc +++ b/libs/vslam_odometry/src/ekf_se2.cc @@ -134,6 +134,14 @@ struct EkfSe2::Impl { EkfSe2::EkfSe2(EkfSe2Config cfg) : impl_(std::make_unique(std::move(cfg))) {} EkfSe2::~EkfSe2() = default; +// Lech thu tu duoi nguong nay coi la binh thuong; tren nguong coi la nhay lui +// that (reset mo phong, phat lai ban ghi). +// +// 0.25 s: rong hon nhieu so voi 80 ms cua IMU hien tai -- de con cho cam bien +// cham hon -- nhung hep hon han cu nhay hang giay cua replay. Nhanh `dt < 0` +// nguyen thuy viet cho truong hop sau, khong phai truong hop truoc. +constexpr double kMaxOutOfOrderSec = 0.25; + void EkfSe2::Predict(UnixTime now) { std::lock_guard lk(impl_->mu); if (!impl_->have_time) { @@ -143,7 +151,27 @@ void EkfSe2::Predict(UnixTime now) { } const double dt = SecondsBetween(now, impl_->last_predict); if (dt < 0.0) { - // Thoi gian lui: reset mo phong hoac phat lai ban ghi. + // ⚠️ HAI chuyen khac nhau, truoc day gop lam mot. + // + // LECH THU TU NHO -- binh thuong voi nhieu cam bien, khong phai loi. + // IMU duoc bu `mcu.imu_lag_sec` = 80 ms nen dau thoi gian cua no LUON cu + // hon encoder (encoder chi bu `age`, co ms). Do la DUNG: 80 ms do la thoi + // diem do that, WT61PC loc noi bo ~50 ms roi day 2 khung qua day 9600 baud + // ~23 ms, ca hai deu truoc luc ESP32 dong dau. + // + // Reset moc o day lam EKF tien 80 ms theo encoder roi bi IMU keo lui, moi + // 100 ms mot lan: nhieu qua trinh cong hai lan moi chu ky va cac phep cap + // nhat roi sai thoi diem. Do duoc tren robot: `ekf: thoi gian lui` lap lien + // tuc -0.040 / -0.054 / -0.045 / -0.059 / -0.073 s. + // + // Ap phep do len trang thai hien tai va GIU nguyen moc. Gan dung -- sai so + // chi la phan trang thai doi trong 80 ms, voi mot phep do VAN TOC GOC thi + // khong dang ke. + if (-dt < kMaxOutOfOrderSec) { + impl_->stats.out_of_order++; + return; + } + // NHAY LUI LON -- reset mo phong hoac phat lai ban ghi. Moc het nghia. VSLAM_WARN("ekf: thoi gian lui " << dt << " s -- reset moc thoi gian"); impl_->last_predict = now; impl_->stats.time_resets++;