Skip to content

Commit

Permalink
ekf2: constrain max variance by zero innovation update
Browse files Browse the repository at this point in the history
Clipping the variance of the covariance matrix has a destabilizing
effect as it increases the correlation between the states.
  • Loading branch information
bresch authored and dagar committed Jan 15, 2025
1 parent 0723f75 commit 12a9087
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/modules/ekf2/EKF/covariance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,17 @@ void Ekf::constrainStateVariances()
void Ekf::constrainStateVar(const IdxDof &state, float min, float max)
{
for (unsigned i = state.idx; i < (state.idx + state.dof); i++) {
P(i, i) = math::constrain(P(i, i), min, max);
if (P(i, i) < min) {
P(i, i) = min;

} else if (P(i, i) > max) {
// Constrain the variance growth by fusing zero innovation as clipping the variance
// would artifically increase the correlation between states and destabilize the filter.
const float innov = 0.f;
const float R = 10.f * P(i, i); // This reduces the variance by ~10% as K = P / (P + R)
const float innov_var = P(i, i) + R;
fuseDirectStateMeasurement(innov, innov_var, R, i);
}
}
}

Expand All @@ -298,9 +308,7 @@ void Ekf::constrainStateVarLimitRatio(const IdxDof &state, float min, float max,
float limited_max = math::constrain(state_var_max, min, max);
float limited_min = math::constrain(limited_max / max_ratio, min, max);

for (unsigned i = state.idx; i < (state.idx + state.dof); i++) {
P(i, i) = math::constrain(P(i, i), limited_min, limited_max);
}
constrainStateVar(state, limited_min, limited_max);
}

void Ekf::resetQuatCov(const float yaw_noise)
Expand Down

0 comments on commit 12a9087

Please sign in to comment.