From cc3df0ecb2bcd7258e1a5b222d3ef43c17dcb741 Mon Sep 17 00:00:00 2001 From: trung09122002 Date: Wed, 7 Oct 2026 14:42:00 +0700 Subject: [PATCH] odom: goc quay EKF theo ENCODER mac dinh (pipeline.yaml ekf.gyro_yaw: false) -- WT61PC lech mot chieu khi chay: 07/10 gyro - encoder +0.11..+0.38 rad moi 30 s du quay trai hay phai (+71 do / 2.5 phut); log odom/yaw in hieu tuyet doi + nguon EKF --- app/src/app_config.cc | 3 ++- app/src/app_config.h | 1 + app/src/wiring.cc | 40 ++++++++++++++++++++----------- configuration_files/pipeline.yaml | 7 ++++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/src/app_config.cc b/app/src/app_config.cc index ee44f78..37a31b3 100644 --- a/app/src/app_config.cc +++ b/app/src/app_config.cc @@ -306,7 +306,7 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) { { const StatusResponse r = Reject(e, "pipeline.yaml ekf", - {"q_x", "q_y", "q_yaw", "q_vx", "q_vyaw", "max_dt"}); + {"q_x", "q_y", "q_yaw", "q_vx", "q_vyaw", "max_dt", "gyro_yaw"}); if (!r.ok()) return r; } out->ekf.q_x = e.get("q_x", out->ekf.q_x); @@ -315,6 +315,7 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) { out->ekf.q_vx = e.get("q_vx", out->ekf.q_vx); out->ekf.q_vyaw = e.get("q_vyaw", out->ekf.q_vyaw); out->ekf.sensor_timeout = e.get("max_dt", out->ekf.sensor_timeout); + out->ekf_gyro_yaw = e.get("gyro_yaw", out->ekf_gyro_yaw); const ConfigNode d = root["depth_filter"]; { diff --git a/app/src/app_config.h b/app/src/app_config.h index 1f2520f..b959dff 100644 --- a/app/src/app_config.h +++ b/app/src/app_config.h @@ -150,6 +150,7 @@ struct AppConfig { WheelOdometryConfig wheel_odom; // robot.yaml + pipeline.yaml EkfSe2Config ekf; // pipeline.yaml + bool ekf_gyro_yaw = false; // pipeline.yaml ekf.gyro_yaw: goc quay EKF theo gyro PerceptionConfig perception; // pipeline.yaml + robot.yaml SafetyConfig safety; // safety.yaml diff --git a/app/src/wiring.cc b/app/src/wiring.cc index 04ace51..0b85f58 100644 --- a/app/src/wiring.cc +++ b/app/src/wiring.cc @@ -87,8 +87,9 @@ StatusResponse Runtime::Wire() { std::lock_guard lk(odom_mu_); wheel_odom_->FeedGyroZ(m->header.stamp, m->angular_velocity.z); - // Goc quay cho EKF: TICH PHAN gyro theo DAU THOI GIAN mau (hinh thang), khong - // theo luc mau toi -- xem GyroYawFuser. + // Goc gyro (EKF dung khi `ekf.gyro_yaw: true`; log odom/yaw luon dung): TICH + // PHAN theo DAU THOI GIAN mau (hinh thang), khong theo luc mau toi -- xem + // GyroYawFuser. yaw_fuser_.AddGyro(m->header.stamp, m->angular_velocity.z); ekf_->UpdateImuYawRate(m->header.stamp, m->angular_velocity.z, m->angular_velocity_covariance[8] > 0.0 @@ -125,6 +126,8 @@ StatusResponse Runtime::Wire() { // ---------------- Encoder ---------------- if (base_ != nullptr) { + VSLAM_INFO("odom: goc quay EKF theo " << (cfg_->ekf_gyro_yaw ? "GYRO" : "ENCODER") + << " (pipeline.yaml ekf.gyro_yaw) -- gyro van so trong log odom/yaw"); base_->SetEncoderCallback([this](const EncoderReading& e) { if (!e.valid) return; Odometry o; @@ -162,8 +165,14 @@ StatusResponse Runtime::Wire() { // yen hai dau van 9.6%: loi ti le, khong phai lech gio). IMU cham // (10 Hz) / het tuoi thi chi encoder, nhu truoc 06/10. double d_theta_gyro = d_theta; - const bool gyro_ok = dt > 0.0 && yaw_fuser_.Step(e.stamp, d_theta, &d_theta_gyro); - if (!gyro_ok && yaw_fuser_.gyro_period() > 0.03) { + const bool gyro_step = dt > 0.0 && yaw_fuser_.Step(e.stamp, d_theta, &d_theta_gyro); + // EKF chi lay goc gyro khi pipeline.yaml `ekf.gyro_yaw: true`. Mac dinh + // TAT: WT61PC lech MOT CHIEU khi chay -- 07/10 14:27-14:29 gyro - encoder + // = +0.11..+0.38 rad moi 30 s du quay trai hay phai (+71 do trong 2.5 + // phut), dung yen thi tra 0 nen khong thay. Ban do chi encoder (28/09, + // 01/10) thi dung. GyroYawFuser van chay de log `odom/yaw` so hai nguon. + const bool gyro_ok = gyro_step && cfg_->ekf_gyro_yaw; + if (cfg_->ekf_gyro_yaw && !gyro_step && yaw_fuser_.gyro_period() > 0.03) { VSLAM_WARN_THROTTLE(60.0, "odom: IMU cham (chu ky " << yaw_fuser_.gyro_period() * 1e3 << " ms) -- goc quay chi theo encoder. Can IMU >= 33 Hz de dung gyro."); } @@ -187,24 +196,27 @@ StatusResponse Runtime::Wire() { height_->OnWheelStep(d_trans, pitch); if (cfg_->slope.horizontal_odom) d_trans_ekf = d_trans * std::cos(pitch); } - ekf_->UpdateOdomDelta(e.stamp, d_trans_ekf, d_theta, d_theta_gyro, + // Tat gyro thi EKF nhan DUNG goc encoder, khong phu thuoc ti le phuong sai. + ekf_->UpdateOdomDelta(e.stamp, d_trans_ekf, d_theta, gyro_ok ? d_theta_gyro : d_theta, var_tr, var_th_enc, var_th_gyro); - // Chan doan 30 s mot lan: goc quay RONG theo encoder va theo goc da - // ghep. Encoder sai ~2% (ban do 28/09, 01/10); lech xa hon khi dang - // quay = goc odometry co van de (07/10: thieu ~10%). + // Chan doan 30 s mot lan: goc quay RONG theo encoder va theo gyro + // (GyroYawFuser), in HIEU tuyet doi -- lech mot chieu (07/10: gyro + // +0.11..+0.38 rad moi 30 s) doc theo % se tuong la loi ti le. Encoder + // sai ~2% (ban do 28/09, 01/10). yaw_diag_enc_ += d_theta; yaw_diag_enc_abs_ += std::fabs(d_theta); - yaw_diag_fused_ += gyro_ok ? d_theta_gyro : d_theta; + yaw_diag_fused_ += gyro_step ? d_theta_gyro : d_theta; ++yaw_diag_steps_; - if (gyro_ok) ++yaw_diag_gyro_; + if (gyro_step) ++yaw_diag_gyro_; if (yaw_diag_t0_.isZero()) yaw_diag_t0_ = e.stamp; if (SecondsBetween(e.stamp, yaw_diag_t0_) >= 30.0) { - if (std::fabs(yaw_diag_enc_) > 0.5) { + if (yaw_diag_enc_abs_ > 0.5) { // co quay, ke ca quay qua lai VSLAM_INFO("odom/yaw: 30 s qua: quay rong encoder " << yaw_diag_enc_ - << " rad, da ghep " << yaw_diag_fused_ << " rad (" - << 100.0 * (yaw_diag_fused_ / yaw_diag_enc_ - 1.0) << "%), tong |quay| " + << " rad, gyro " << yaw_diag_fused_ << " rad (gyro - encoder " + << yaw_diag_fused_ - yaw_diag_enc_ << " rad), tong |quay| " << yaw_diag_enc_abs_ << " rad, " << 100 * yaw_diag_gyro_ / yaw_diag_steps_ - << "% buoc co gyro (chu ky " << yaw_fuser_.gyro_period() * 1e3 << " ms)"); + << "% buoc co gyro (chu ky " << yaw_fuser_.gyro_period() * 1e3 + << " ms) -- EKF theo " << (cfg_->ekf_gyro_yaw ? "GYRO" : "ENCODER")); } yaw_diag_enc_ = yaw_diag_enc_abs_ = yaw_diag_fused_ = 0.0; yaw_diag_steps_ = yaw_diag_gyro_ = 0; diff --git a/configuration_files/pipeline.yaml b/configuration_files/pipeline.yaml index 187999d..6b78563 100644 --- a/configuration_files/pipeline.yaml +++ b/configuration_files/pipeline.yaml @@ -14,6 +14,13 @@ ekf: # Bo qua mau cach mau truoc qua lau: ban ghi bi cat, hoac cam bien vua cam # lai. Tich phan qua mot lo hong 2 giay la bia them sai so. max_dt: 0.5 + # Goc quay EKF: false = theo ENCODER (nhu truoc 06/10), true = theo gyro + # WT61PC (GyroYawFuser). 07/10 tren robot that: gyro - encoder = +0.11..+0.38 + # rad moi 30 s, CA khi quay trai lan quay phai (+71 do trong 2.5 phut); dung + # yen thi WT61PC tra 0 nen khong thay. Ban do chi dung encoder (28/09, 01/10) + # thi dung. Chi bat lai khi da do/bu duoc lech gyro -- log `odom/yaw` van in + # gyro - encoder du tat hay bat. + gyro_yaw: false # ============ depth -> cloud -> loc ============ depth_filter: