Files
vslam_cpp/test/test_wheel_odometry.cc
trung09122002 f91b755776 odom: so gyro voi encoder cung BANG THONG, khong chi cung thoi diem
Sau khi dinh thoi da dung han (wheel_odom/lag bao 0 ms sau khi dat
mcu.imu_lag_sec = 0.08), tren robot van con 7 lan bao TRUOT BANH. Doc
dau thi khong phai truot: 5 trong 7 lan encoder doc IT hon gyro, ma
truot lam encoder doc NHIEU hon su that.

Nguyen nhan la khac biet bang thong. WT61PC o che do 10 Hz bao TRUNG
BINH tren cua so 100 ms; encoder bao tuc thoi tren 20 ms. Luc robot doi
toc do quay thi hai thu lech nhau ma khong ben nao sai, va dich dau thoi
gian khong chua duoc -- no can chinh TAM cua so, khong can chinh do rong.

Sua: lay trung binh encoder tren dung cua so cua gyro roi moi so. Chu ky
gyro DO tu lich su chu khong khai bao trong config -- no phu thuoc
firmware va che do cam bien, va da doi mot lan roi.

Cai gia: trung binh hoa lam mo truot that ngan hon mot chu ky gyro, va
lam viec phat hien tre them chung ay. Co test rieng cho chuyen do
(TruotTHATVanBatDuocSauKhiTrungBinhHoa) vi mot bo phat hien truot da bi
lam mo qua tay con te hon la khong co: no tao cam giac an toan.

Test con loi ra mot bug that trong GyroAt(): dieu kien bien dung `>=`
nen khi `t` TRUNG DUNG dau thoi gian cua mau bien thi require_bracket tu
choi -- trong khi do la truong hop tot nhat, gia tri co san chinh xac.
Gyro 10 Hz voi encoder 50 Hz thi cu 5 lan lai trung mot lan: do duoc
59/199 lan phai lui ve so tho, va chinh chung sinh ra bao dong gia
0.4667 rad/s = do doc nhan tron mot chu ky gyro.

Them stats_.slip_coarse_updates de con thay duoc chuyen do tu ben ngoai,
tren robot that chu khong chi trong test.
2026-09-21 15:27:39 +07:00

508 lines
18 KiB
C++

#include "vslam/wheel_odometry.h"
#include <gtest/gtest.h>
#include <cmath>
#include <functional>
#include "vslam/geometry.h"
using namespace vslam;
namespace {
constexpr double kPi = 3.14159265358979323846;
WheelOdometryConfig Cfg() {
WheelOdometryConfig c;
c.wheel_radius = 0.075;
c.wheel_separation = 0.36;
return c;
}
// Quay banh de robot di THANG `dist` met.
double WheelRadForDistance(double dist, double radius) { return dist / radius; }
} // namespace
TEST(WheelOdometry, MauDauTienKhongSinhOdometry) {
WheelOdometry wo(Cfg());
Odometry o;
EXPECT_FALSE(wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o));
}
TEST(WheelOdometry, DiThangThiChiTangX) {
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pos = 0.0;
for (int i = 1; i <= 50; ++i) {
pos += WheelRadForDistance(0.02, r); // 2 cm moi buoc
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.0 + i * 0.02), pos, pos, &o));
}
const Pose2D p = wo.pose();
EXPECT_NEAR(p.x, 1.0, 1e-9) << "50 x 2 cm = 1 m";
EXPECT_NEAR(p.y, 0.0, 1e-12);
EXPECT_NEAR(p.theta, 0.0, 1e-12);
EXPECT_NEAR(wo.stats().total_distance, 1.0, 1e-9);
}
TEST(WheelOdometry, QuayTaiChoThiChiDoiYaw) {
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075, sep = 0.36;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
// Hai banh nguoc chieu, cung do lon -> quay tai cho.
// d_theta = (d_r - d_l) / sep; muon quay pi/2 thi d_r = -d_l = sep*pi/4.
const double d_wheel = sep * kPi / 4.0;
const double rad = d_wheel / r;
const int n = 50;
for (int i = 1; i <= n; ++i) {
const double f = static_cast<double>(i) / n;
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.0 + i * 0.02), -rad * f, rad * f, &o));
}
const Pose2D p = wo.pose();
EXPECT_NEAR(p.x, 0.0, 1e-9);
EXPECT_NEAR(p.y, 0.0, 1e-9);
EXPECT_NEAR(p.theta, kPi / 2.0, 1e-9);
}
TEST(WheelOdometry, RK2ChinhXacHonEulerTrenCungTron) {
// Tich phan RK2 dung goc GIUA doan. Tren mot cung tron, Euler (goc dau
// doan) luon lech VE MOT PHIA va sai so tich luy theo mot chieu.
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075, sep = 0.36;
const double R = 1.0; // ban kinh cung tron 1 m
const double arc = kPi / 2.0; // quay 90 do
const int n = 100;
const double d_center = R * arc / n;
const double d_theta = arc / n;
const double d_l = d_center - d_theta * sep / 2.0;
const double d_r = d_center + d_theta * sep / 2.0;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pl = 0.0, pr = 0.0;
for (int i = 1; i <= n; ++i) {
pl += d_l / r;
pr += d_r / r;
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.0 + i * 0.02), pl, pr, &o));
}
// Cung tron ban kinh 1 quay 90 do tu goc (0,0,0): tam o (0, 1), diem cuoi
// o (1, 1), huong pi/2.
const Pose2D p = wo.pose();
EXPECT_NEAR(p.theta, arc, 1e-9);
EXPECT_NEAR(p.x, 1.0, 2e-4) << "RK2 phai bam sat nghiem giai tich";
EXPECT_NEAR(p.y, 1.0, 2e-4);
}
TEST(WheelOdometry, DtAmThiResetChuKhongTichPhanLui) {
// Nhay lui thoi gian: reset mo phong hoac phat lai ban ghi. Tich phan mot
// dt am se day pose GIAT LUI, va EKF phia sau khong co cach nao biet.
WheelOdometry wo(Cfg());
Odometry o;
wo.Update(UnixTime::fromSec(10.0), 0.0, 0.0, &o);
wo.Update(UnixTime::fromSec(10.02), 1.0, 1.0, &o);
const Pose2D before = wo.pose();
EXPECT_FALSE(wo.Update(UnixTime::fromSec(5.0), 2.0, 2.0, &o));
EXPECT_EQ(wo.stats().time_resets, 1u);
const Pose2D after = wo.pose();
EXPECT_NEAR(after.x, before.x, 1e-12) << "pose khong duoc doi khi dt <= 0";
}
// --- Phat hien truot -------------------------------------------------------
TEST(WheelOdometry, KhongTruotThiSlipMetricGanKhong) {
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075, sep = 0.36;
const double omega = 0.5; // rad/s
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pl = 0.0, pr = 0.0;
for (int i = 1; i <= 20; ++i) {
const double t = 1.0 + i * 0.02;
const double d_theta = omega * 0.02;
pl += (-d_theta * sep / 2.0) / r;
pr += (d_theta * sep / 2.0) / r;
wo.FeedGyroZ(UnixTime::fromSec(t), omega); // gyro DONG Y voi encoder
ASSERT_TRUE(wo.Update(UnixTime::fromSec(t), pl, pr, &o));
}
EXPECT_LT(wo.slip_metric(), 1e-9);
EXPECT_FALSE(wo.slipping());
}
TEST(WheelOdometry, TruotThiSlipMetricBangDoLechThat) {
// slip_metric CHINH LA |omega_encoder - gyro_z|, do duoc tung chu ky.
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075, sep = 0.36;
const double omega_enc = 2.0; // banh bao quay 2 rad/s
const double omega_gyro = 0.5; // gyro noi chi 0.5 -> dang truot
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pl = 0.0, pr = 0.0;
for (int i = 1; i <= 10; ++i) {
const double t = 1.0 + i * 0.02;
const double d_theta = omega_enc * 0.02;
pl += (-d_theta * sep / 2.0) / r;
pr += (d_theta * sep / 2.0) / r;
wo.FeedGyroZ(UnixTime::fromSec(t), omega_gyro);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(t), pl, pr, &o));
}
EXPECT_NEAR(wo.slip_metric(), 1.5, 1e-9);
EXPECT_TRUE(wo.slipping());
EXPECT_GT(wo.stats().slip_events, 0u);
}
TEST(WheelOdometry, TruotThiNangCovariancePose) {
WheelOdometryConfig c = Cfg();
c.slip_cov_multiplier = 100.0;
auto run = [&](double gyro) {
WheelOdometry wo(c);
Odometry o;
const double r = 0.075;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pos = 0.0;
for (int i = 1; i <= 10; ++i) {
const double t = 1.0 + i * 0.02;
pos += WheelRadForDistance(0.02, r);
wo.FeedGyroZ(UnixTime::fromSec(t), gyro);
wo.Update(UnixTime::fromSec(t), pos, pos, &o);
}
return o;
};
const Odometry clean = run(0.0); // di thang, gyro dong y
const Odometry slip = run(5.0); // gyro noi dang quay manh -> truot
EXPECT_NEAR(slip.pose.covariance[0] / clean.pose.covariance[0], 100.0, 1e-6)
<< "truot phai nang covariance dung bang slip_cov_multiplier";
}
// ===========================================================================
// YAW-RATE COVARIANCE -- BAI KIEM QUAN TRONG NHAT CUA FILE
//
// Cach cu (cov_yaw/dt^2 voi he so co dinh) THIEU ~2 BAC. Da do tren robot
// that khi xoay tai cho:
// sai so that : omega encoder -3.635 vs gyro -1.377 = 2.26 rad/s
// sigma khai bao: 0.2 rad/s
// EKF nhan mot diem 11-sigma ma van tin -> yaw troi -> global_scan_init khop
// ra huong sai 40.8 do sau khi xoay 301 do.
// ===========================================================================
TEST(WheelOdometry, YawRateSigmaBangSaiSoDaDo) {
WheelOdometry wo(Cfg());
Odometry o;
const double r = 0.075, sep = 0.36;
// Tai lap dung con so da do: encoder -3.635, gyro -1.377.
const double omega_enc = -3.635;
const double omega_gyro = -1.377;
const double dt = 0.02;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pl = 0.0, pr = 0.0;
for (int i = 1; i <= 5; ++i) {
const double t = 1.0 + i * dt;
const double d_theta = omega_enc * dt;
pl += (-d_theta * sep / 2.0) / r;
pr += (d_theta * sep / 2.0) / r;
wo.FeedGyroZ(UnixTime::fromSec(t), omega_gyro);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(t), pl, pr, &o));
}
const double expected_slip = std::fabs(omega_enc - omega_gyro); // 2.258
EXPECT_NEAR(wo.slip_metric(), expected_slip, 1e-6);
const double sigma_wr = std::sqrt(o.twist.covariance[35]);
EXPECT_NEAR(sigma_wr, expected_slip, 1e-6)
<< "sigma yaw-rate PHAI bang sai so da do, khong phai he so doan truoc";
// Cach cu cho ~0.2 rad/s. Cach moi phai lon hon HANG CHUC lan.
EXPECT_GT(sigma_wr, 2.0);
EXPECT_GT(sigma_wr / 0.2, 10.0) << "phai sua duoc do lech 2 bac cua ban cu";
}
TEST(WheelOdometry, KhongCoGyroThiSigmaKhongDuocBangKhong) {
// San khi KHONG co gyro: slip_metric = 0, va neu dung thang thi sigma = 0
// -> EKF tin banh xe TUYET DOI, te hon ca truoc khi sua.
WheelOdometryConfig c = Cfg();
c.yaw_rate_sigma_no_imu = 0.50;
WheelOdometry wo(c);
Odometry o;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pos = 0.0;
for (int i = 1; i <= 5; ++i) {
pos += WheelRadForDistance(0.02, 0.075);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.0 + i * 0.02), pos, pos, &o));
}
EXPECT_NEAR(std::sqrt(o.twist.covariance[35]), 0.50, 1e-9);
EXPECT_GT(wo.stats().no_imu_updates, 0u);
}
TEST(WheelOdometry, CoGyroNhungKhongTruotVanCoSanNguong) {
// slip_metric = 0 khi khop hoan hao. Dung thang thi sigma = 0 -> EKF tin
// tuyet doi. yaw_rate_sigma_floor chan dieu do.
WheelOdometryConfig c = Cfg();
c.yaw_rate_sigma_floor = 0.02;
WheelOdometry wo(c);
Odometry o;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
double pos = 0.0;
for (int i = 1; i <= 5; ++i) {
const double t = 1.0 + i * 0.02;
pos += WheelRadForDistance(0.02, 0.075);
wo.FeedGyroZ(UnixTime::fromSec(t), 0.0);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(t), pos, pos, &o));
}
EXPECT_NEAR(std::sqrt(o.twist.covariance[35]), 0.02, 1e-9);
}
TEST(WheelOdometry, GyroCuThiCoiNhuKhongCo) {
WheelOdometryConfig c = Cfg();
c.imu_timeout = 0.5;
WheelOdometry wo(c);
Odometry o;
wo.FeedGyroZ(UnixTime::fromSec(1.0), 0.0);
wo.Update(UnixTime::fromSec(10.0), 0.0, 0.0, &o); // gyro cu 9 giay
double pos = WheelRadForDistance(0.02, 0.075);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(10.02), pos, pos, &o));
EXPECT_NEAR(std::sqrt(o.twist.covariance[35]), c.yaw_rate_sigma_no_imu, 1e-9);
}
TEST(WheelOdometry, ZRollPitchDanhDauKhongQuanSatDuoc) {
WheelOdometry wo(Cfg());
Odometry o;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.02), 0.1, 0.1, &o));
EXPECT_GE(o.pose.covariance[14], 1e5) << "z";
EXPECT_GE(o.pose.covariance[21], 1e5) << "roll -> IMU lo";
EXPECT_GE(o.pose.covariance[28], 1e5) << "pitch -> IMU lo";
}
TEST(WheelOdometry, CovarianceTyLeVoiQuangDuongKhongPhaiThoiGian) {
// Robot dung yen khong duoc tich them sai so, du dung bao lau.
WheelOdometry wo(Cfg());
Odometry o;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.02), 0.0, 0.0, &o));
const double cov_still = o.pose.covariance[0];
ASSERT_TRUE(wo.Update(UnixTime::fromSec(11.02), 0.0, 0.0, &o));
EXPECT_NEAR(o.pose.covariance[0], cov_still, 1e-15)
<< "dung yen 10 giay khong duoc lam covariance tang";
const double pos = WheelRadForDistance(0.5, 0.075);
ASSERT_TRUE(wo.Update(UnixTime::fromSec(11.04), pos, pos, &o));
EXPECT_GT(o.pose.covariance[0], cov_still * 100.0) << "di 0.5 m thi phai tang";
}
TEST(WheelOdometry, DeltaCuonVeGiuaHaiDauVanDung) {
// Chuan hoa DELTA de an toan voi ca hai kieu bao cao vi tri: tich luy khong
// gioi han, hoac cuon ve [-pi, pi].
WheelOdometry wo(Cfg());
Odometry o;
wo.Update(UnixTime::fromSec(1.0), kPi - 0.01, kPi - 0.01, &o);
// Vi tri cuon qua bien: pi-0.01 -> -pi+0.01, thuc te chi quay 0.02 rad.
ASSERT_TRUE(wo.Update(UnixTime::fromSec(1.02), -kPi + 0.01, -kPi + 0.01, &o));
EXPECT_NEAR(wo.pose().x, 0.02 * 0.075, 1e-9)
<< "cuon bien bi hieu thanh mot vong quay nguoc";
}
TEST(WheelOdometry, SetPoseVaReset) {
WheelOdometry wo(Cfg());
Odometry o;
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
wo.Update(UnixTime::fromSec(1.02), 1.0, 1.0, &o);
wo.SetPose(Pose2D{5.0, -3.0, 1.2});
EXPECT_NEAR(wo.pose().x, 5.0, 1e-12);
EXPECT_NEAR(wo.pose().theta, 1.2, 1e-12);
wo.Reset();
EXPECT_NEAR(wo.pose().x, 0.0, 1e-12);
EXPECT_EQ(wo.stats().updates, 0u);
}
// ===================== May do do tre IMU =====================
// `estimated_imu_lag_sec()` la mot DUNG CU DO: nguoi dung se doc so no in ra
// roi dat thang vao mcu.imu_lag_sec. Nen phai chung minh no do dung mot do tre
// DA BIET TRUOC, khong phai chi "chay khong crash".
namespace {
// Lai robot theo mot ho so toc do quay CO TANG GIAM, dong thoi dong dau gyro
// TRE `lag` giay so voi su that. Tra ve do tre may do uoc luong duoc.
double RunLagRig(double lag_sec) {
WheelOdometryConfig c = Cfg();
WheelOdometry wo(c);
Odometry o;
const double dt = 0.02; // encoder 50 Hz
const double gyro_dt = 0.005; // gyro 200 Hz
const double r = c.wheel_radius, sep = c.wheel_separation;
// omega(t): sin cham -- luc nao cung co tang/giam toc, dung cai ma may do can.
auto omega_true = [](double t) { return 0.7 * std::sin(2.0 * kPi * t / 4.0); };
double pl = 0.0, pr = 0.0;
double t_gyro = 0.0;
for (int k = 1; k <= 1200; ++k) { // 24 s
const double t = k * dt;
// Gyro chay nhanh hon encoder. Mau dong dau `s` do robot tai `s - lag`.
while (t_gyro <= t) {
wo.FeedGyroZ(UnixTime::fromSec(10.0 + t_gyro),
omega_true(t_gyro - lag_sec));
t_gyro += gyro_dt;
}
const double d_theta = omega_true(t) * dt;
pl += (-d_theta * sep / 2.0) / r;
pr += (d_theta * sep / 2.0) / r;
wo.Update(UnixTime::fromSec(10.0 + t), pl, pr, &o);
}
return wo.estimated_imu_lag_sec();
}
} // namespace
TEST(WheelOdometry, MayDoDoTreTimLaiDuocDoTreDaBiet) {
// Buoc luoi la 10 ms nen sai so <= 5 ms la het co the doi.
EXPECT_NEAR(RunLagRig(0.00), 0.00, 0.006) << "khong tre -> phai bao ~0";
EXPECT_NEAR(RunLagRig(0.05), 0.05, 0.006) << "tre 50 ms";
EXPECT_NEAR(RunLagRig(0.10), 0.10, 0.006) << "tre 100 ms";
}
TEST(WheelOdometry, MayDoDoTreBaoDuocCaBuTHUA) {
// Sau khi dat mcu.imu_lag_sec qua tay, dau thoi gian bi keo LUI qua da --
// tuong duong do tre AM. Luoi phai phu duoc phia am, neu khong thi bu thua
// nhin giong het bu dung va khong ai biet.
EXPECT_NEAR(RunLagRig(-0.05), -0.05, 0.006);
}
TEST(WheelOdometry, ChuaDuMauThiMayDoTraNaN) {
// Chua do duoc thi phai noi la chua do duoc, khong duoc tra 0 -- 0 la mot
// cau tra loi HOP LE ("khong tre"), va nguoi doc khong phan biet duoc.
WheelOdometry wo(Cfg());
Odometry o;
wo.FeedGyroZ(UnixTime::fromSec(1.0), 0.1);
wo.Update(UnixTime::fromSec(1.0), 0.0, 0.0, &o);
wo.Update(UnixTime::fromSec(1.02), 0.1, 0.1, &o);
EXPECT_TRUE(std::isnan(wo.estimated_imu_lag_sec()));
}
// ============ So cung bang thong ============
// Gyro 10 Hz bao TRUNG BINH tren cua so 100 ms; encoder bao tuc thoi tren
// 20 ms. Luc robot doi toc do quay thi hai thu lech nhau ma khong ben nao sai.
// Da do tren robot that: 7 lan bao truot gia sau khi dinh thoi da dung han
// (`wheel_odom/lag` bao 0 ms), va 5 trong 7 lan encoder doc IT hon gyro -- dau
// ma truot banh khong tao ra duoc.
namespace {
struct BandwidthRig {
int slip_events = 0;
double max_metric = 0.0;
uint64_t coarse = 0; // so lan phai lui ve so tho
uint64_t updates = 0;
};
// omega_true: toc do quay that theo thoi gian.
// enc_gain: he so nhan vao encoder. 1.0 = khong truot; 2.0 = banh quay gap
// doi quang duong that, tuc TRUOT.
BandwidthRig RunBandwidthRig(const std::function<double(double)>& omega_true,
double enc_gain, double t_end) {
WheelOdometryConfig c = Cfg();
WheelOdometry wo(c);
Odometry o;
const double dt = 0.02; // encoder 50 Hz
const double gyro_dt = 0.1; // gyro 10 Hz
const double r = c.wheel_radius, sep = c.wheel_separation;
// Gyro bao trung binh tren cua so DOI XUNG quanh dau thoi gian cua no. Do la
// cach nhin SAU khi mcu.imu_lag_sec da bu phan tre cua bo loc noi bo -- va
// con so do duoc do bang chinh may do trong lop nay.
auto gyro_window_mean = [&](double t) {
double sum = 0.0;
int n = 0;
for (double u = t - gyro_dt / 2; u <= t + gyro_dt / 2 + 1e-12; u += 0.002) {
sum += omega_true(u);
++n;
}
return sum / n;
};
BandwidthRig out;
double pl = 0.0, pr = 0.0, t_gyro = 0.0;
for (int k = 1; k * dt <= t_end; ++k) {
const double t = k * dt;
while (t_gyro <= t) {
wo.FeedGyroZ(UnixTime::fromSec(100.0 + t_gyro), gyro_window_mean(t_gyro));
t_gyro += gyro_dt;
}
const double d_theta = omega_true(t) * enc_gain * dt;
pl += (-d_theta * sep / 2.0) / r;
pr += (d_theta * sep / 2.0) / r;
if (wo.Update(UnixTime::fromSec(100.0 + t), pl, pr, &o)) {
if (wo.slipping()) ++out.slip_events;
out.max_metric = std::max(out.max_metric, wo.slip_metric());
}
}
out.coarse = wo.stats().slip_coarse_updates;
out.updates = wo.stats().updates;
return out;
}
// Ho so toc do co GOC GAY: dung yen, roi tang tuyen tinh, roi giu. Goc gay la
// cho do cong vo han -- noi trung binh cua so lech xa gia tri tuc thoi nhat.
double RampWithCorners(double t) {
if (t < 1.0) return 0.0;
if (t < 1.3) return 4.667 * (t - 1.0); // len 1.4 rad/s trong 0.3 s
if (t < 2.5) return 1.4;
if (t < 2.8) return 1.4 - 4.667 * (t - 2.5);
return 0.0;
}
} // namespace
TEST(WheelOdometry, GocGayCuaHoSoQuayKhongSinhBaoDongGia) {
// enc_gain = 1.0: banh bam san hoan toan. Moi chenh lech deu la giả.
const BandwidthRig r = RunBandwidthRig(RampWithCorners, 1.0, 4.0);
EXPECT_EQ(r.slip_events, 0)
<< "bao truot khi khong he truot; max_metric = " << r.max_metric
<< "; lui ve so tho " << r.coarse << "/" << r.updates << " lan";
EXPECT_LT(r.max_metric, Cfg().slip_omega_threshold);
// Neu lui ve so tho qua nhieu thi viec so cung bang thong khong thuc su chay,
// va test tren co the dang pass vi may man. Vai chu ky dau la binh thuong.
EXPECT_LT(r.coarse, r.updates / 4)
<< "lui ve so tho " << r.coarse << "/" << r.updates << " lan";
}
TEST(WheelOdometry, TruotTHATVanBatDuocSauKhiTrungBinhHoa) {
// ⚠️ Test quan trong nhat cua khoi nay.
//
// Trung binh hoa lam MO tin hieu. Neu lam qua tay thi truot that cung bi mo
// theo, va luc do bo phat hien truot thanh mot dong log vo dung -- te hon la
// khong co, vi no tao cam giac an toan.
//
// enc_gain = 2.0: banh quay gap doi quang duong that. Do la truot.
const BandwidthRig r = RunBandwidthRig(RampWithCorners, 2.0, 4.0);
EXPECT_GT(r.slip_events, 0) << "truot that bi trung binh hoa nuot mat";
EXPECT_GT(r.max_metric, 0.5);
}