From 0c33efea2ffe08e28fb3dbf3d5060584428442ff Mon Sep 17 00:00:00 2001 From: trung09122002 Date: Sun, 20 Sep 2026 15:14:17 +0700 Subject: [PATCH] update --- configuration_files/pipeline.yaml | 9 ++++- libs/vslam_drivers/src/zlac_base.cc | 37 ++++++++++++++++++- .../include/zlac_ros/zlac_motor_driver.hpp | 5 ++- .../thirdparty/zlac/src/zlac_motor_driver.cpp | 20 +++++++++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/configuration_files/pipeline.yaml b/configuration_files/pipeline.yaml index 55af60b..69b5964 100644 --- a/configuration_files/pipeline.yaml +++ b/configuration_files/pipeline.yaml @@ -46,7 +46,14 @@ gravity_align: # ============ Phat hien vuc ============ # Xem docs/PERCEPTION.md truoc khi doi bat ky so nao o day. cliff_detect: - enabled: true + # ⚠️⚠️ DANG TAT -- TAM THOI, de lai thu base/odometry/LiDAR ma khong bi + # phat hien vuc chen ngang. Bat lai bang `enabled: true`. + # + # TAT cliff nghia la robot KHONG CON phat hien vuc, mep cau thang hay bat + # ky cho hut nao. LiDAR khong thay xuong duoi mat phang quet cua no, va + # bumper chi bao SAU khi da cham. Chi lai o noi chac chan khong co mep roi, + # va co nguoi dung canh. + enabled: false # ⚠️ min_dist la VUNG MU HINH HOC, khong phai lua chon tuy y. # diff --git a/libs/vslam_drivers/src/zlac_base.cc b/libs/vslam_drivers/src/zlac_base.cc index 0e8b568..d5eb94e 100644 --- a/libs/vslam_drivers/src/zlac_base.cc +++ b/libs/vslam_drivers/src/zlac_base.cc @@ -207,8 +207,9 @@ class ZlacWrapper : public BaseInterface { if (!impl_) return; int32_t l = 0, r = 0; + double skew = 0.0; EncoderReading out; - if (!impl_->getPositionCounts(l, r)) { + if (!impl_->getPositionCounts(l, r, &skew)) { out.stamp = clock_->Now(); out.valid = false; { @@ -231,7 +232,35 @@ class ZlacWrapper : public BaseInterface { } const double scale = kTwoPi / static_cast(counts_per_rev_); - out.left_rad = static_cast(l - origin_l_) * scale; + double left_counts = static_cast(l - origin_l_); + + // ⚠️ BU DO LECH LAY MAU GIUA HAI BANH. + // + // Duong SDO doc hai banh bang hai giao dich tuan tu, nen banh PHAI duoc + // lay mau muon hon banh TRAI khoang `skew` giay. Cong thuc vi sai + // omega = (v_r - v_l) / L + // bien dung khoang lech do thanh QUAY GIA: o 0.3 m/s voi skew 5 ms, hai + // banh lech 1.5 mm, ra ~0.2 rad/s -- vua dung do lon cua canh bao + // "nghi TRUOT BANH" do duoc tren robot. + // + // Ngoai suy banh trai toi THOI DIEM cua banh phai bang chinh van toc gan + // nhat cua no, de hai gia tri cung mot moc thoi gian. + // + // Duong sua tan goc la map 0x6064:01 va :02 vao MOT TPDO (hai I32 = dung + // 8 byte CAN) -- luc do skew = 0 va khoi bu. Can khai bao mapping do + // trong master.dcf. + if (skew > 0.0 && have_prev_left_) { + const double dt = (out.stamp - prev_left_stamp_).toSec(); + if (dt > 1e-4) { + const double v_counts = (left_counts - prev_left_counts_) / dt; + left_counts += v_counts * skew; + } + } + prev_left_counts_ = static_cast(l - origin_l_); + prev_left_stamp_ = out.stamp; + have_prev_left_ = true; + + out.left_rad = left_counts * scale; // Banh phai lap doi chieu -- cung quy uoc voi KinematicsConfig o tren. // Thieu phep doi dau nay thi robot di thang ma odometry bao dang quay. out.right_rad = -static_cast(r - origin_r_) * scale; @@ -265,6 +294,10 @@ class ZlacWrapper : public BaseInterface { int32_t origin_l_ = 0, origin_r_ = 0; bool have_origin_ = false; UnixTime last_enc_; + // Mau truoc cua banh TRAI, de uoc van toc khi bu do lech lay mau. + double prev_left_counts_ = 0.0; + UnixTime prev_left_stamp_; + bool have_prev_left_ = false; mutable std::mutex cmd_mu_; double cmd_linear_ = 0.0, cmd_angular_ = 0.0; diff --git a/libs/vslam_drivers/thirdparty/zlac/include/zlac_ros/zlac_motor_driver.hpp b/libs/vslam_drivers/thirdparty/zlac/include/zlac_ros/zlac_motor_driver.hpp index 60da38a..57e0cb0 100644 --- a/libs/vslam_drivers/thirdparty/zlac/include/zlac_ros/zlac_motor_driver.hpp +++ b/libs/vslam_drivers/thirdparty/zlac/include/zlac_ros/zlac_motor_driver.hpp @@ -111,7 +111,8 @@ public: // "count". Ban goc chi co getActualRPM() -- tuc chi co van toc, va tich // phan van toc thi lo mot mau telemetry la mat vinh vien mot doan quang // duong ma khong phat hien duoc. Xem thirdparty/PROVENANCE.md. - bool getPositionCounts(int32_t& out_left, int32_t& out_right); + bool getPositionCounts(int32_t& out_left, int32_t& out_right, + double* out_skew_sec = nullptr); bool isReady() const { return hardware_ready_.load(); } bool hasConnectionLost() const { return connection_lost_.load(); } @@ -154,6 +155,8 @@ private: std::atomic cached_left_pos_raw_{0}; std::atomic cached_right_pos_raw_{0}; std::atomic cached_pos_valid_{false}; + // [vslam] Banh phai lay mau muon hon banh trai bay nhieu giay. + std::atomic cached_pos_skew_sec_{0.0}; void telemetryLoop(); // Target caching diff --git a/libs/vslam_drivers/thirdparty/zlac/src/zlac_motor_driver.cpp b/libs/vslam_drivers/thirdparty/zlac/src/zlac_motor_driver.cpp index 55ebcc6..0ff07b2 100644 --- a/libs/vslam_drivers/thirdparty/zlac/src/zlac_motor_driver.cpp +++ b/libs/vslam_drivers/thirdparty/zlac/src/zlac_motor_driver.cpp @@ -291,13 +291,28 @@ void ZlacMotorDriver::telemetryLoop() { auto rpdo = master_->RpdoMapped(node_id_); cached_left_pos_raw_ = static_cast(rpdo[0x6064][1]); cached_right_pos_raw_ = static_cast(rpdo[0x6064][2]); + // PDO: ca hai banh den trong CUNG mot khung CAN -> khong lech. + cached_pos_skew_sec_ = 0.0; pos_ok = true; } catch (...) { + // [vslam] DO do lech thay vi bo qua no. + // + // Hai lan doc la hai giao dich tuan tu, nen banh phai duoc lay mau + // SAU banh trai mot khoang. Moc thoi gian hieu dung cua moi lan doc + // nam o GIUA giao dich, nen: + // lech = (t2 - t0) / 2 + // Ben goi dung so nay de ngoai suy banh trai toi thoi diem cua banh + // phai; khong bu thi cong thuc vi sai bien khoang lech do thanh quay + // gia. + const auto t0 = std::chrono::steady_clock::now(); auto lp = sdo_read_sync(*master_, node_id_, 0x6064, 1); auto rp = sdo_read_sync(*master_, node_id_, 0x6064, 2); + const auto t2 = std::chrono::steady_clock::now(); if (lp.has_value() && rp.has_value()) { cached_left_pos_raw_ = lp.value(); cached_right_pos_raw_ = rp.value(); + cached_pos_skew_sec_ = + std::chrono::duration(t2 - t0).count() / 2.0; pos_ok = true; } } @@ -318,10 +333,13 @@ bool ZlacMotorDriver::getActualRPM(double& out_left_rpm, double& out_right_rpm) // [vslam] Xem PROVENANCE.md. 0x6064 la bo dem TUYET DOI trong driver motor: // lo mot mau thi mau sau van dung, khac han tich phan van toc. -bool ZlacMotorDriver::getPositionCounts(int32_t& out_left, int32_t& out_right) { +bool ZlacMotorDriver::getPositionCounts(int32_t& out_left, int32_t& out_right, + double* out_skew_sec) { if (!cached_pos_valid_.load()) return false; out_left = cached_left_pos_raw_.load(); out_right = cached_right_pos_raw_.load(); + // Banh PHAI duoc lay mau muon hon banh TRAI bay nhieu giay. 0 khi di qua PDO. + if (out_skew_sec) *out_skew_sec = cached_pos_skew_sec_.load(); return true; }