Skip to content

Commit 515179e

Browse files
committed
Merge pull request #241 from cra-ros-pkg/master
Merging orientation Mahalanobis fix
2 parents 0de2bec + 9837307 commit 515179e

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/ekf.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,29 @@ namespace RobotLocalization
162162

163163
innovationSubset = (measurementSubset - stateSubset);
164164

165-
// (2) Check Mahalanobis distance between mapped measurement and state.
166-
if (checkMahalanobisThreshold(innovationSubset, hphrInv, measurement.mahalanobisThresh_))
165+
// Wrap angles in the innovation
166+
for (size_t i = 0; i < updateSize; ++i)
167167
{
168-
// (3) Apply the gain to the difference between the state and measurement: x = x + K(z - Hx)
169-
// Wrap angles in the innovation
170-
for (size_t i = 0; i < updateSize; ++i)
168+
if (updateIndices[i] == StateMemberRoll ||
169+
updateIndices[i] == StateMemberPitch ||
170+
updateIndices[i] == StateMemberYaw)
171171
{
172-
if (updateIndices[i] == StateMemberRoll ||
173-
updateIndices[i] == StateMemberPitch ||
174-
updateIndices[i] == StateMemberYaw)
172+
while (innovationSubset(i) < -PI)
175173
{
176-
while (innovationSubset(i) < -PI)
177-
{
178-
innovationSubset(i) += TAU;
179-
}
180-
181-
while (innovationSubset(i) > PI)
182-
{
183-
innovationSubset(i) -= TAU;
184-
}
174+
innovationSubset(i) += TAU;
185175
}
186-
}
187176

177+
while (innovationSubset(i) > PI)
178+
{
179+
innovationSubset(i) -= TAU;
180+
}
181+
}
182+
}
183+
184+
// (2) Check Mahalanobis distance between mapped measurement and state.
185+
if (checkMahalanobisThreshold(innovationSubset, hphrInv, measurement.mahalanobisThresh_))
186+
{
187+
// (3) Apply the gain to the difference between the state and measurement: x = x + K(z - Hx)
188188
state_.noalias() += kalmanGainSubset * innovationSubset;
189189

190190
// (4) Update the estimate error covariance using the Joseph form: (I - KH)P(I - KH)' + KRK'

src/ukf.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,27 +239,28 @@ namespace RobotLocalization
239239
// (4) Apply the gain to the difference between the actual and predicted measurements: x = x + K(z - z_hat)
240240
innovationSubset = (measurementSubset - predictedMeasurement);
241241

242-
// (5) Check Mahalanobis distance of innovation
243-
if (checkMahalanobisThreshold(innovationSubset, invInnovCov, measurement.mahalanobisThresh_))
242+
// Wrap angles in the innovation
243+
for (size_t i = 0; i < updateSize; ++i)
244244
{
245-
// Wrap angles in the innovation
246-
for (size_t i = 0; i < updateSize; ++i)
245+
if (updateIndices[i] == StateMemberRoll ||
246+
updateIndices[i] == StateMemberPitch ||
247+
updateIndices[i] == StateMemberYaw)
247248
{
248-
if (updateIndices[i] == StateMemberRoll ||
249-
updateIndices[i] == StateMemberPitch ||
250-
updateIndices[i] == StateMemberYaw)
249+
while (innovationSubset(i) < -PI)
250+
{
251+
innovationSubset(i) += TAU;
252+
}
253+
254+
while (innovationSubset(i) > PI)
251255
{
252-
while (innovationSubset(i) < -PI)
253-
{
254-
innovationSubset(i) += TAU;
255-
}
256-
257-
while (innovationSubset(i) > PI)
258-
{
259-
innovationSubset(i) -= TAU;
260-
}
256+
innovationSubset(i) -= TAU;
261257
}
262258
}
259+
}
260+
261+
// (5) Check Mahalanobis distance of innovation
262+
if (checkMahalanobisThreshold(innovationSubset, invInnovCov, measurement.mahalanobisThresh_))
263+
{
263264

264265
state_.noalias() += kalmanGainSubset * innovationSubset;
265266

0 commit comments

Comments
 (0)