Skip to content

Commit

Permalink
Fix a bug in the rotation observation update
Browse files Browse the repository at this point in the history
  • Loading branch information
rsasaki0109 committed Sep 23, 2021
1 parent ea57aa0 commit 8d96763
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/kalman_filter_localization/ekf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,21 @@ class EKFEstimator
pow(dx(ERROR_STATE::DTHX), 2) +
pow(dx(ERROR_STATE::DTHY), 2) +
pow(dx(ERROR_STATE::DTHZ), 2));

if (norm_quat < 1e-10) {
x_.segment(STATE::QX, 4) = Eigen::Vector4d(0, 0, 0, cos(norm_quat / 2));
Eigen::Quaterniond dq = Eigen::Quaterniond(0, 0, 0, cos(norm_quat / 2));
Eigen::Quaterniond q = Eigen::Quaterniond(x_(STATE::QW), x_(STATE::QX), x_(STATE::QY), x_(STATE::QZ));
Eigen::Quaterniond q_new = q * dq;
x_.segment(STATE::QX, 4) = Eigen::Vector4d(q_new.x(), q_new.y(), q_new.z(), q_new.w());
} else {
x_.segment(STATE::QX, 4) = Eigen::Vector4d(
Eigen::Quaterniond dq = Eigen::Quaterniond(
sin(norm_quat / 2) * dx(ERROR_STATE::DTHX) / norm_quat,
sin(norm_quat / 2) * dx(ERROR_STATE::DTHY) / norm_quat,
sin(norm_quat / 2) * dx(ERROR_STATE::DTHZ) / norm_quat,
cos(norm_quat / 2));
Eigen::Quaterniond q = Eigen::Quaterniond(x_(STATE::QW), x_(STATE::QX), x_(STATE::QY), x_(STATE::QZ));
Eigen::Quaterniond q_new = q * dq;
x_.segment(STATE::QX, 4) = Eigen::Vector4d(q_new.x(), q_new.y(), q_new.z(), q_new.w());
}

P_ = (EigenMatrix9d::Identity() - K * H) * P_;
Expand Down

0 comments on commit 8d96763

Please sign in to comment.