From a29147d6d258f219eed053c77226f5e90e3583b7 Mon Sep 17 00:00:00 2001 From: Paul Riseborough Date: Tue, 20 Oct 2015 13:04:45 +1100 Subject: [PATCH] AP_NavEKF2: Apply optimisations to optical flow covariance update These are the same optimisations that were successful with the magnetometer fusion --- .../AP_NavEKF2/AP_NavEKF2_OptFlowFusion.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_OptFlowFusion.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_OptFlowFusion.cpp index 0cbf031372..323b64afe8 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_OptFlowFusion.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_OptFlowFusion.cpp @@ -663,29 +663,33 @@ void NavEKF2_core::FuseOptFlow() // correct the covariance P = (I - K*H)*P // take advantage of the empty columns in KH to reduce the // number of operations - for (uint8_t i = 0; i<=stateIndexLim; i++) { - for (uint8_t j = 0; j<=5; j++) { + for (unsigned i = 0; i<=stateIndexLim; i++) { + for (unsigned j = 0; j<=5; j++) { KH[i][j] = Kfusion[i] * H_LOS[j]; } - for (uint8_t j = 6; j<=7; j++) { + for (unsigned j = 6; j<=7; j++) { KH[i][j] = 0.0f; } KH[i][8] = Kfusion[i] * H_LOS[8]; - for (uint8_t j = 9; j<=23; j++) { + for (unsigned j = 9; j<=23; j++) { KH[i][j] = 0.0f; } } - for (uint8_t i = 0; i<=stateIndexLim; i++) { - for (uint8_t j = 0; j<=stateIndexLim; j++) { - KHP[i][j] = 0; - for (uint8_t k = 0; k<=5; k++) { - KHP[i][j] = KHP[i][j] + KH[i][k] * P[k][j]; - } - KHP[i][j] = KHP[i][j] + KH[i][8] * P[8][j]; + for (unsigned j = 0; j<=stateIndexLim; j++) { + for (unsigned i = 0; i<=stateIndexLim; i++) { + ftype res = 0; + res += KH[i][0] * P[0][j]; + res += KH[i][1] * P[1][j]; + res += KH[i][2] * P[2][j]; + res += KH[i][3] * P[3][j]; + res += KH[i][4] * P[4][j]; + res += KH[i][5] * P[5][j]; + res += KH[i][8] * P[8][j]; + KHP[i][j] = res; } } - for (uint8_t i = 0; i<=stateIndexLim; i++) { - for (uint8_t j = 0; j<=stateIndexLim; j++) { + for (unsigned i = 0; i<=stateIndexLim; i++) { + for (unsigned j = 0; j<=stateIndexLim; j++) { P[i][j] = P[i][j] - KHP[i][j]; } }