Skip to content

Commit

Permalink
#190 Add optional decoupling of XY from the EKF
Browse files Browse the repository at this point in the history
Helps flying manually with a ranging sensor for only Z. Can
be enabled by adding in config.mk:

ESTIMATOR=kalman
CFLAGS += -DUPDATE_KALMAN_WITH_RANGING -DKALMAN_DECOUPLE_XY
  • Loading branch information
ataffanel committed Jan 12, 2017
1 parent 650a47b commit 2b0958d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/modules/src/estimator_kalman.c
Expand Up @@ -316,6 +316,21 @@ static void stateEstimatorAssertNotNaN()
}
#endif

#ifdef KALMAN_DECOUPLE_XY
// Reset a state to 0 with max covariance
// If called often, this decouples the state to the rest of the filter
static void decoupleState(stateIdx_t state)
{
// Set all covariance to 0
for(int i=0; i<STATE_DIM; i++) {
P[state][i] = 0;

This comment has been minimized.

Copy link
@mikehamer

mikehamer Jan 12, 2017

Contributor

Here you need:

P[state][i] = P[i][state] = 0;

This comment has been minimized.

Copy link
@ataffanel

ataffanel Jan 12, 2017

Author Member

Thanks for noticing! I fixed it in in 0bcffe8.

}
// Set state variance to maximum
P[state][state] = MAX_COVARIANCE;
// set state to zero
S[state] = 0;
}
#endif

// --------------------------------------------------

Expand All @@ -330,6 +345,14 @@ void stateEstimatorUpdate(state_t *state, sensorData_t *sensors, control_t *cont

uint32_t tick = xTaskGetTickCount(); // would be nice if this had a precision higher than 1ms...

#ifdef KALMAN_DECOUPLE_XY
// Decouple position states
decoupleState(STATE_X);
decoupleState(STATE_PX);
decoupleState(STATE_Y);
decoupleState(STATE_PY);
#endif

// Average the last IMU measurements. We do this because the prediction loop is
// slower than the IMU loop, but the IMU information is required externally at
// a higher rate (for body rate control).
Expand Down

0 comments on commit 2b0958d

Please sign in to comment.