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

This commit is contained in:
trung09122002
2026-10-07 14:42:00 +07:00
parent 3935ffe0cc
commit cc3df0ecb2
4 changed files with 36 additions and 15 deletions

View File

@@ -306,7 +306,7 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) {
{ {
const StatusResponse r = const StatusResponse r =
Reject(e, "pipeline.yaml ekf", 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; if (!r.ok()) return r;
} }
out->ekf.q_x = e.get<double>("q_x", out->ekf.q_x); out->ekf.q_x = e.get<double>("q_x", out->ekf.q_x);
@@ -315,6 +315,7 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) {
out->ekf.q_vx = e.get<double>("q_vx", out->ekf.q_vx); out->ekf.q_vx = e.get<double>("q_vx", out->ekf.q_vx);
out->ekf.q_vyaw = e.get<double>("q_vyaw", out->ekf.q_vyaw); out->ekf.q_vyaw = e.get<double>("q_vyaw", out->ekf.q_vyaw);
out->ekf.sensor_timeout = e.get<double>("max_dt", out->ekf.sensor_timeout); out->ekf.sensor_timeout = e.get<double>("max_dt", out->ekf.sensor_timeout);
out->ekf_gyro_yaw = e.get<bool>("gyro_yaw", out->ekf_gyro_yaw);
const ConfigNode d = root["depth_filter"]; const ConfigNode d = root["depth_filter"];
{ {

View File

@@ -150,6 +150,7 @@ struct AppConfig {
WheelOdometryConfig wheel_odom; // robot.yaml + pipeline.yaml WheelOdometryConfig wheel_odom; // robot.yaml + pipeline.yaml
EkfSe2Config ekf; // 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 PerceptionConfig perception; // pipeline.yaml + robot.yaml
SafetyConfig safety; // safety.yaml SafetyConfig safety; // safety.yaml

View File

@@ -87,8 +87,9 @@ StatusResponse Runtime::Wire() {
std::lock_guard<std::mutex> lk(odom_mu_); std::lock_guard<std::mutex> lk(odom_mu_);
wheel_odom_->FeedGyroZ(m->header.stamp, m->angular_velocity.z); 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 // Goc gyro (EKF dung khi `ekf.gyro_yaw: true`; log odom/yaw luon dung): TICH
// theo luc mau toi -- xem GyroYawFuser. // 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); yaw_fuser_.AddGyro(m->header.stamp, m->angular_velocity.z);
ekf_->UpdateImuYawRate(m->header.stamp, m->angular_velocity.z, ekf_->UpdateImuYawRate(m->header.stamp, m->angular_velocity.z,
m->angular_velocity_covariance[8] > 0.0 m->angular_velocity_covariance[8] > 0.0
@@ -125,6 +126,8 @@ StatusResponse Runtime::Wire() {
// ---------------- Encoder ---------------- // ---------------- Encoder ----------------
if (base_ != nullptr) { 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) { base_->SetEncoderCallback([this](const EncoderReading& e) {
if (!e.valid) return; if (!e.valid) return;
Odometry o; Odometry o;
@@ -162,8 +165,14 @@ StatusResponse Runtime::Wire() {
// yen hai dau van 9.6%: loi ti le, khong phai lech gio). IMU cham // 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. // (10 Hz) / het tuoi thi chi encoder, nhu truoc 06/10.
double d_theta_gyro = d_theta; double d_theta_gyro = d_theta;
const bool gyro_ok = dt > 0.0 && yaw_fuser_.Step(e.stamp, d_theta, &d_theta_gyro); const bool gyro_step = dt > 0.0 && yaw_fuser_.Step(e.stamp, d_theta, &d_theta_gyro);
if (!gyro_ok && yaw_fuser_.gyro_period() > 0.03) { // 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 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."); << " 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); height_->OnWheelStep(d_trans, pitch);
if (cfg_->slope.horizontal_odom) d_trans_ekf = d_trans * std::cos(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); var_tr, var_th_enc, var_th_gyro);
// Chan doan 30 s mot lan: goc quay RONG theo encoder va theo goc da // Chan doan 30 s mot lan: goc quay RONG theo encoder va theo gyro
// ghep. Encoder sai ~2% (ban do 28/09, 01/10); lech xa hon khi dang // (GyroYawFuser), in HIEU tuyet doi -- lech mot chieu (07/10: gyro
// quay = goc odometry co van de (07/10: thieu ~10%). // +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_ += d_theta;
yaw_diag_enc_abs_ += std::fabs(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_; ++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 (yaw_diag_t0_.isZero()) yaw_diag_t0_ = e.stamp;
if (SecondsBetween(e.stamp, yaw_diag_t0_) >= 30.0) { 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_ VSLAM_INFO("odom/yaw: 30 s qua: quay rong encoder " << yaw_diag_enc_
<< " rad, da ghep " << yaw_diag_fused_ << " rad (" << " rad, gyro " << yaw_diag_fused_ << " rad (gyro - encoder "
<< 100.0 * (yaw_diag_fused_ / yaw_diag_enc_ - 1.0) << "%), tong |quay| " << yaw_diag_fused_ - yaw_diag_enc_ << " rad), tong |quay| "
<< yaw_diag_enc_abs_ << " rad, " << 100 * yaw_diag_gyro_ / yaw_diag_steps_ << 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_enc_ = yaw_diag_enc_abs_ = yaw_diag_fused_ = 0.0;
yaw_diag_steps_ = yaw_diag_gyro_ = 0; yaw_diag_steps_ = yaw_diag_gyro_ = 0;

View File

@@ -14,6 +14,13 @@ ekf:
# Bo qua mau cach mau truoc qua lau: ban ghi bi cat, hoac cam bien vua cam # 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. # lai. Tich phan qua mot lo hong 2 giay la bia them sai so.
max_dt: 0.5 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 -> cloud -> loc ============
depth_filter: depth_filter: