EKF: Fix critical bug in fusion of yaw and declination observations
This bug was in the derivation and resulted from use of a tan instead of an atan operator. The derivations have been reworked and the updated auto-code has been imported as part of this patch.
// Note only 2 terms are non-zero which can be used in matrix operations for calculation of Kalman gains and covariance update to significantly reduce cost
floatH_DECL[24]={};
H_DECL[16]=-t18*1.0f/(t19*t19)*t24;
H_DECL[17]=t21*t24;
H_DECL[16]=-magE*t5;
H_DECL[17]=magN*t5;
// Calculate the Kalman gains
floatKfusion[_k_num_states]={};
Kfusion[0]=t14*(P[0][17]*t25-P[0][16]*t26);
Kfusion[1]=t14*(P[1][17]*t25-P[1][16]*t26);
Kfusion[2]=t14*(P[2][17]*t25-P[2][16]*t26);
Kfusion[3]=t14*(P[3][17]*t25-P[3][16]*t26);
Kfusion[4]=t14*(P[4][17]*t25-P[4][16]*t26);
Kfusion[5]=t14*(P[5][17]*t25-P[5][16]*t26);
Kfusion[6]=t14*(P[6][17]*t25-P[6][16]*t26);
Kfusion[7]=t14*(P[7][17]*t25-P[7][16]*t26);
Kfusion[8]=t14*(P[8][17]*t25-P[8][16]*t26);
Kfusion[9]=t14*(P[9][17]*t25-P[9][16]*t26);
Kfusion[10]=t14*(P[10][17]*t25-P[10][16]*t26);
Kfusion[11]=t14*(P[11][17]*t25-P[11][16]*t26);
Kfusion[12]=t14*(P[12][17]*t25-P[12][16]*t26);
Kfusion[13]=t14*(P[13][17]*t25-P[13][16]*t26);
Kfusion[14]=t14*(P[14][17]*t25-P[14][16]*t26);
Kfusion[15]=t14*(P[15][17]*t25-P[15][16]*t26);
Kfusion[16]=-t14*(t16-P[16][17]*t25);
Kfusion[17]=t14*(t8-P[17][16]*t26);
Kfusion[18]=t14*(P[18][17]*t25-P[18][16]*t26);
Kfusion[19]=t14*(P[19][17]*t25-P[19][16]*t26);
Kfusion[20]=t14*(P[20][17]*t25-P[20][16]*t26);
Kfusion[21]=t14*(P[21][17]*t25-P[21][16]*t26);
Kfusion[22]=t14*(P[22][17]*t25-P[22][16]*t26);
Kfusion[23]=t14*(P[23][17]*t25-P[23][16]*t26);
Kfusion[0]=-t12*(P[0][16]*t22-P[0][17]*t23);
Kfusion[1]=-t12*(P[1][16]*t22-P[1][17]*t23);
Kfusion[2]=-t12*(P[2][16]*t22-P[2][17]*t23);
Kfusion[3]=-t12*(P[3][16]*t22-P[3][17]*t23);
Kfusion[4]=-t12*(P[4][16]*t22-P[4][17]*t23);
Kfusion[5]=-t12*(P[5][16]*t22-P[5][17]*t23);
Kfusion[6]=-t12*(P[6][16]*t22-P[6][17]*t23);
Kfusion[7]=-t12*(P[7][16]*t22-P[7][17]*t23);
Kfusion[8]=-t12*(P[8][16]*t22-P[8][17]*t23);
Kfusion[9]=-t12*(P[9][16]*t22-P[9][17]*t23);
Kfusion[10]=-t12*(P[10][16]*t22-P[10][17]*t23);
Kfusion[11]=-t12*(P[11][16]*t22-P[11][17]*t23);
Kfusion[12]=-t12*(P[12][16]*t22-P[12][17]*t23);
Kfusion[13]=-t12*(P[13][16]*t22-P[13][17]*t23);
Kfusion[14]=-t12*(P[14][16]*t22-P[14][17]*t23);
Kfusion[15]=-t12*(P[15][16]*t22-P[15][17]*t23);
Kfusion[16]=-t12*(t6-P[16][17]*t23);
Kfusion[17]=t12*(t14-P[17][16]*t22);
Kfusion[18]=-t12*(P[18][16]*t22-P[18][17]*t23);
Kfusion[19]=-t12*(P[19][16]*t22-P[19][17]*t23);
Kfusion[20]=-t12*(P[20][16]*t22-P[20][17]*t23);
Kfusion[21]=-t12*(P[21][16]*t22-P[21][17]*t23);
// Don't update wind states unless we are doing wind estimation