Skip to content

Commit

Permalink
Protect wrapping angles from NaN and inf +/- in ekf and ukf filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Piechula committed Mar 11, 2022
1 parent 5c9d411 commit 1cc497b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/ekf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <Eigen/Dense>
#include <rclcpp/duration.hpp>
#include <vector>
#include <cmath>

namespace robot_localization
{
Expand Down Expand Up @@ -173,9 +174,10 @@ void Ekf::correct(const Measurement & measurement)

// Wrap angles in the innovation
for (size_t i = 0; i < update_size; ++i) {
if (update_indices[i] == StateMemberRoll ||
if ((update_indices[i] == StateMemberRoll ||
update_indices[i] == StateMemberPitch ||
update_indices[i] == StateMemberYaw)
update_indices[i] == StateMemberYaw) &&
std::isfinite(innovation_subset(i)))
{
while (innovation_subset(i) < -PI) {
innovation_subset(i) += TAU;
Expand Down
6 changes: 4 additions & 2 deletions src/ukf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <robot_localization/ukf.hpp>
#include <Eigen/Cholesky>
#include <vector>
#include <cmath>


namespace robot_localization
Expand Down Expand Up @@ -240,9 +241,10 @@ void Ukf::correct(const Measurement & measurement)

// Wrap angles in the innovation
for (size_t i = 0; i < updateSize; ++i) {
if (update_indices[i] == StateMemberRoll ||
if ((update_indices[i] == StateMemberRoll ||
update_indices[i] == StateMemberPitch ||
update_indices[i] == StateMemberYaw)
update_indices[i] == StateMemberYaw) &&
std::isfinite(innovation_subset(i)))
{
while (innovation_subset(i) < -PI) {
innovation_subset(i) += TAU;
Expand Down

0 comments on commit 1cc497b

Please sign in to comment.