/* x(t+1|t) = Ax(t|t) + Bu(t) */
u[0] = sensor_gyro_get_z()*250/32768;
matrix_2x2_mul_2x1(A, x_post, Ax);
matrix_2x1_mul_1x1(B, u, Bu);
matrix_2x1_add_2x1(Ax, Bu, x_pri);
/* P(t+1|t) = AP(t|t)A^T + V */
matrix_2x2_mul_2x2(A, P_post, AP);
matrix_2x2_trans(A, AT);
matrix_2x2_mul_2x2(AP, AT, APAT);
matrix_2x2_add_2x2(APAT, V, P_pri);
/* eps(t) = y(t) - Cx(t|t-1) */
acc_x = sensor_acc_get_x();
acc_y = sensor_acc_get_y();
y[0] = atan(acc_x/acc_y)*180/M_PI;
matrix_1x2_mul_2x1(C, x_pri, Cx);
eps[0] = y[0] - Cx[0];
/* S(t) = CP(t|t-1)C^T + W */
matrix_1x2_mul_2x2(C, P_pri, CP);
matrix_1x2_mul_2x1(C, C, CPCT);
S[0] = CPCT[0] + W[0];
/* K(t) = P(t|t-1)C^TS(t)^-1 */
matrix_2x2_mul_2x1(P_pri, C, PCT);
S1[0] = 1/S[0];
matrix_2x1_mul_1x1(PCT, S1, K);
/* x(t|t) = x(t|t-1) + K(t)eps(t) */
matrix_2x1_mul_1x1(K, eps, Keps);
matrix_2x1_add_2x1(x_pri, Keps, x_post);
/* P(t|t) = P(t|t-1) - K(t)S(t)K(t)^T */
matrix_2x1_mul_1x1(K, S, KS);
matrix_2x1_mul_1x2(KS, K, KSKT);
matrix_2x2_sub_2x2(P_pri, KSKT, P_post);
Trwa ładowanie komentarzy...