update
This commit is contained in:
@@ -58,6 +58,21 @@ StatusResponse Runtime::Wire() {
|
||||
|
||||
std::lock_guard<std::mutex> lk(odom_mu_);
|
||||
wheel_odom_->FeedGyroZ(m->header.stamp, m->angular_velocity.z);
|
||||
// ⚠️ TICH PHAN gyro, khong lay mot mau.
|
||||
//
|
||||
// IMU chay 200 Hz con encoder 50 Hz, nen moi khoang odom co ~4 mau.
|
||||
// Lay MOT mau roi nhan voi ca khoang 20 ms la phep hinh chu nhat tren
|
||||
// mot tin hieu dang doi nhanh -- da do: sai goc 150 do sau mot lan xoay.
|
||||
if (have_gyro_) {
|
||||
const double dti = SecondsBetween(m->header.stamp, gyro_stamp_);
|
||||
if (dti > 0.0 && dti < 0.1) {
|
||||
gyro_dtheta_ += 0.5 * (gyro_z_ + m->angular_velocity.z) * dti;
|
||||
gyro_dt_ += dti;
|
||||
}
|
||||
}
|
||||
gyro_z_ = m->angular_velocity.z;
|
||||
gyro_stamp_ = m->header.stamp;
|
||||
have_gyro_ = true;
|
||||
ekf_->UpdateImuYawRate(m->header.stamp, m->angular_velocity.z,
|
||||
m->angular_velocity_covariance[8] > 0.0
|
||||
? m->angular_velocity_covariance[8]
|
||||
@@ -105,9 +120,47 @@ StatusResponse Runtime::Wire() {
|
||||
// Do chinh la cach wheel_odom bao "dang truot, dung tin toi". Thay
|
||||
// bang hang so o day la vut bo toan bo co che phat hien truot -- va
|
||||
// no im lang, vi EKF van chay va van cho ra mot pose trong nhu that.
|
||||
ekf_->UpdateOdomTwist(e.stamp, o.twist.twist.linear.x,
|
||||
o.twist.twist.angular.z, o.twist.covariance[0],
|
||||
o.twist.covariance[35]);
|
||||
// ⚠️ Mo hinh chuyen dong theo DELTA, khong theo van toc da loc.
|
||||
//
|
||||
// Do duoc: sau mot lan xoay tai cho, goc cua wheel odometry lech
|
||||
// +0.000 do so voi ground truth, goc cua EKF lech +0.814 do. Bo loc
|
||||
// lam hong mot phep do von chinh xac, va sai so goc do khong bao gio
|
||||
// duoc tra lai. Xem ghi chu o `EkfSe2::UpdateOdomDelta`.
|
||||
const Pose2D now_pose = wheel_odom_->pose();
|
||||
if (have_prev_odom_) {
|
||||
const double dx = now_pose.x - prev_odom_.x;
|
||||
const double dy = now_pose.y - prev_odom_.y;
|
||||
// Dau cua doan di chuyen theo huong dang quay ve.
|
||||
const double heading = std::cos(prev_odom_.theta) * dx +
|
||||
std::sin(prev_odom_.theta) * dy;
|
||||
const double d_trans = std::copysign(std::hypot(dx, dy), heading);
|
||||
double d_theta = NormalizeAngle(now_pose.theta - prev_odom_.theta);
|
||||
|
||||
const double dt = SecondsBetween(e.stamp, prev_odom_stamp_);
|
||||
// Gyro da duoc TICH PHAN trong callback IMU. Chi nhan neu no phu
|
||||
// gan het khoang odom -- thieu mau thi tich phan khong dai dien.
|
||||
const bool gyro_ok = gyro_dt_ > 0.5 * dt && dt > 0.0;
|
||||
const double d_theta_gyro = gyro_ok ? gyro_dtheta_ : d_theta;
|
||||
|
||||
// Phuong sai: wheel_odom bao qua twist.covariance -- do chinh la
|
||||
// cho no noi "dang truot, dung tin toi".
|
||||
//
|
||||
// Gyro: nhieu trang, nen phuong sai cua TICH PHAN ti le voi dt
|
||||
// (buoc ngau nhien), khong voi dt^2.
|
||||
const double var_th_enc =
|
||||
std::max(o.twist.covariance[35] * dt * dt, 1e-12);
|
||||
const double var_th_gyro =
|
||||
gyro_ok ? std::max(2.4e-7 * dt, 1e-12) : 1e9;
|
||||
const double var_tr = std::max(o.twist.covariance[0] * dt * dt, 1e-12);
|
||||
|
||||
ekf_->UpdateOdomDelta(e.stamp, d_trans, d_theta, d_theta_gyro,
|
||||
var_tr, var_th_enc, var_th_gyro);
|
||||
}
|
||||
gyro_dtheta_ = 0.0;
|
||||
gyro_dt_ = 0.0;
|
||||
prev_odom_ = now_pose;
|
||||
prev_odom_stamp_ = e.stamp;
|
||||
have_prev_odom_ = true;
|
||||
latest_odom_ = o;
|
||||
have_odom_ = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user