#include "ekf_example/matrix_vs.h" #include "ekf_example/ekf_obj.h" int main(){ int16 i; mat A = 0.99*eye(5); A(0.3) = 0.06; A(0,2) = 0.01; A(1,2) = 0.01; A(1,3) = -0.07; A(3,2) = 0.0001; RNG_randomize(); mat U=eye(5); for (int16 i=0; i<5;i++) { for (int16 j=i+1; j<5;j++) U(i,j)=2*randu(1)(0)-1; } mat Q = diag(vec(" 0.2000 0.3000 0.4000 0.5000 0.6")); vec R = vec(" 0.2000 0.3000"); vec D = randu(5)*0.9; vec xref = ones(5); int16 PSI[25]; int16 PSIU[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; int16 Uf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; int16 Gf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; int16 Df[5]={0,0,0,0,0}; int16 Dfold[5]={0,0,0,0,0}; int16 multip=1<<15; /////////// COPY imat Af=round_i(A*multip); mat_to_int16(Af, PSI); mat_to_int16(round_i(U*multip),Uf); vec_to_int16(round_i(D*multip), Df); int16 Qf[25]; mat_to_int16(round_i(Q*multip), Qf); int16 Rf[2]; vec_to_int16(round_i(R*multip), Rf); ////////////// Test mmultAU mmultAU(PSI,Uf,PSIU,5,5); mat PhiU =A*U; /* cout << "A*U" << round_i(PhiU*multip) < PUcmp(PSIU,5,5); // cout << "Delta PSI: " << round_i(PhiU*multip-(1<<(15-qAU))*PUcmp) <=0;i--){ sigma = 0.0; for (j=0; j Ucmp(Uf,5,5); Vec Dcmp(Df,5); cout << "Delta U: " << round_i(U*multip-Ucmp) << endl; cout << "Delat D: " << round_i(D*multip-Dcmp) << endl; // synchronize mat_to_int16(round_i(U*multip),Uf); vec_to_int16(round_i(D*multip), Df); vec ydif = 2*randu(2)-1; vec xp = 2*randu(5)-1; int16 difz[2]; vec_to_int16(round_i(ydif*multip), difz); int16 xf[5]; vec_to_int16(round_i(xp*multip), xf); cout << "x: "<< round_i(xp*multip) <