update
This commit is contained in:
@@ -31,6 +31,8 @@ struct EkfSe2::Impl {
|
||||
|
||||
bool have_time = false;
|
||||
UnixTime last_predict;
|
||||
// Da chuyen sang mo hinh chuyen dong theo delta chua. Xem PredictLocked().
|
||||
bool use_delta_motion = false;
|
||||
UnixTime last_measurement;
|
||||
|
||||
EkfSe2Stats stats;
|
||||
@@ -50,6 +52,18 @@ struct EkfSe2::Impl {
|
||||
// Goi khi da giu mu.
|
||||
void PredictLocked(double dt) {
|
||||
if (dt <= 0.0) return;
|
||||
// ⚠️ Khi mo hinh chuyen dong theo DELTA dang chay, phep du doan nay KHONG
|
||||
// duoc dich pose nua.
|
||||
//
|
||||
// `UpdateImuYawRate` chay 200 Hz va cung goi `Predict`, nen pose se bi
|
||||
// tich phan HAI LAN: mot lan boi delta cua wheel odometry, mot lan boi
|
||||
// trang thai van toc o day. Da do: sai goc **148 do** sau mot lan xoay
|
||||
// tai cho -- lon den muc khong the nham voi sai so tinh vi nao.
|
||||
if (use_delta_motion) {
|
||||
// Chi noi rong hiep phuong sai theo thoi gian, khong dich trang thai.
|
||||
P += Q * dt;
|
||||
return;
|
||||
}
|
||||
|
||||
const double yaw = x(kYaw);
|
||||
const double vx = x(kVx);
|
||||
@@ -153,6 +167,58 @@ void EkfSe2::UpdateOdomTwist(UnixTime stamp, double vx, double vyaw,
|
||||
}
|
||||
}
|
||||
|
||||
void EkfSe2::UpdateOdomDelta(UnixTime stamp, double d_trans,
|
||||
double d_theta_enc, double d_theta_gyro,
|
||||
double var_trans, double var_theta_enc,
|
||||
double var_theta_gyro) {
|
||||
std::lock_guard<std::mutex> lk(impl_->mu);
|
||||
|
||||
// Tron hai nguon goc theo nghich dao phuong sai. Khi banh truot,
|
||||
// `var_theta_enc` phong len va gyro thang the -- do la ca ly do EKF ton tai.
|
||||
double d_theta = d_theta_enc;
|
||||
if (var_theta_enc > 0.0 && var_theta_gyro > 0.0) {
|
||||
const double we = 1.0 / var_theta_enc, wg = 1.0 / var_theta_gyro;
|
||||
d_theta = (we * d_theta_enc + wg * d_theta_gyro) / (we + wg);
|
||||
}
|
||||
|
||||
auto& x = impl_->x;
|
||||
auto& P = impl_->P;
|
||||
|
||||
// Tich phan diem GIUA: dung cung bac voi RK2 ma wheel_odom dung, de hai ben
|
||||
// khong le nhau mot bac.
|
||||
const double mid = x(kYaw) + 0.5 * d_theta;
|
||||
const double c = std::cos(mid), s = std::sin(mid);
|
||||
x(kX) += d_trans * c;
|
||||
x(kY) += d_trans * s;
|
||||
x(kYaw) = NormalizeAngle(x(kYaw) + d_theta);
|
||||
|
||||
// Van toc van la trang thai, de bao cao va de phat hien truot -- nhung
|
||||
// chung KHONG con tham gia vao phep tich phan pose nua.
|
||||
const double dt = impl_->last_predict.isZero()
|
||||
? 0.0
|
||||
: SecondsBetween(stamp, impl_->last_predict);
|
||||
if (dt > 1e-6) {
|
||||
x(kVx) = d_trans / dt;
|
||||
x(kVyaw) = d_theta / dt;
|
||||
}
|
||||
|
||||
// Lan truyen hiep phuong sai cua mo hinh chuyen dong.
|
||||
Eigen::Matrix<double, kN, kN> F = Eigen::Matrix<double, kN, kN>::Identity();
|
||||
F(kX, kYaw) = -d_trans * s;
|
||||
F(kY, kYaw) = d_trans * c;
|
||||
P = F * P * F.transpose();
|
||||
P(kX, kX) += var_trans * c * c;
|
||||
P(kY, kY) += var_trans * s * s;
|
||||
P(kYaw, kYaw) += (var_theta_enc > 0.0 && var_theta_gyro > 0.0)
|
||||
? 1.0 / (1.0 / var_theta_enc + 1.0 / var_theta_gyro)
|
||||
: var_theta_enc;
|
||||
|
||||
impl_->last_predict = stamp;
|
||||
impl_->last_measurement = stamp;
|
||||
impl_->use_delta_motion = true;
|
||||
impl_->stats.odom_updates++;
|
||||
}
|
||||
|
||||
void EkfSe2::UpdateImuYawRate(UnixTime stamp, double vyaw, double var) {
|
||||
Predict(stamp);
|
||||
std::lock_guard<std::mutex> lk(impl_->mu);
|
||||
|
||||
Reference in New Issue
Block a user