33 | | // internal model |
34 | | IMpmsm fxu; |
35 | | // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz) |
36 | | fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); |
37 | | // observation model |
38 | | OMpmsm hxu; |
39 | | |
40 | | vec mu0= "0.0 0.0 0.0 0.0"; |
41 | | // vec Qdiag ( "0.01 0.01 0.01 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 |
42 | | vec Qdiag ( "0.07 0.056 0.0007 0.0007" ); //zdenek: 0.01 0.01 0.0001 0.0001 |
43 | | vec Rdiag ( "0.005 0.005" ); //var(diff(xth)) = "0.034 0.034" |
44 | | EKFfull KFE ( rx,ry,ru ); |
45 | | KFE.set_est ( mu0, diag ( vec("1 1 1 3.1415") ) ); |
46 | | KFE.set_parameters ( &fxu,&hxu,diag(Qdiag),diag(Rdiag)); |
47 | | |
48 | | |
49 | | int X_log = L.add(rx,"X"); |
50 | | int Xp_log = L.add(rx,"Xp"); |
51 | | int Xp2_log = L.add(rx,"Xp2"); |
52 | | int E_log = L.add(rx,"E"); |
53 | | int V_log = L.add(rx,"V"); |
54 | | int U_log = L.add(ru,"U"); |
55 | | int U2_log = L.add(ru,"U2"); |
56 | | int R_log = L.add(RV("{_ }","16"),"R"); |
57 | | int Ww_log = L.add(RV("{_ }","1"),"W"); |
58 | | int R2_log = L.add(RV("{_ }","16"),"R2"); |
59 | | // int O_log = L.add(RV("{_ }","16"),"O"); |
60 | | L.init(); |
61 | | |
62 | | // SET SIMULATOR |
63 | | //pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); |
64 | | pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 6e-6, h ); |
65 | | double Ww=0.0; |
66 | | vec dt ( 2 ); |
67 | | |
68 | | vec xm = zeros(4); |
69 | | vec xt = zeros(4); |
70 | | vec xp = zeros(4); |
71 | | vec xp2 = zeros(4); |
72 | | vec xp3 = zeros(4); |
73 | | vec u=zeros(2); |
74 | | vec u2=zeros(2); |
75 | | ldmat R0(eye(4),1e-6*ones(4)); |
76 | | ldmat R(R0); |
77 | | ldmat R2(R0); |
78 | | |
79 | | double frg=0.9; |
80 | | // vec vecW="0. 0. 0.2 0.4 0.4 0.2 0.0 -0.4 -0.6 -0.6 -0.4 0.0 0.0"; |
81 | | vec vecW="1 2 4 9 4 2 0 -4 -9 -16 -4 0 0 0"; |
82 | | vecW*=10.0; |
83 | | |
84 | | for ( int tK=1;tK<Ndat;tK++ ) { |
85 | | //Number of steps of a simulator for one step of Kalman |
86 | | for ( int ii=0; ii<Nsimstep;ii++ ) { |
87 | | //simulator |
88 | | //sim_profile_steps1(Ww); |
89 | | sim_profile_vec01t(Ww,vecW); |
90 | | pmsmsim_step ( Ww ); |
91 | | }; |
92 | | |
93 | | u(0)= KalmanObs[0]; |
94 | | u(1)= KalmanObs[1]; |
95 | | dt(0)= KalmanObs[2]; |
96 | | dt(1)= KalmanObs[3]; |
97 | | u2(0) = KalmanObs[4]; |
98 | | u2(1) = KalmanObs[5]; |
99 | | // Try what our model would predict! |
100 | | xp=fxu.eval(xm,u); |
101 | | xp2=fxu.eval(xm,zeros(2)); //ZERO input!!!!!!!! |
102 | | // xp3=fxu.eval(xm,u2); |
103 | | |
104 | | // KFE.bayes(concat(dt,u)); |
105 | | // This is simulator prediction |
106 | | xt=vec(x,4); //vec from C-array |
107 | | //Covariance |
108 | | R*=frg; |
109 | | R.add(R0,1-frg); |
110 | | R.opupdt(xt-xp,1.0); |
111 | | R2*=frg; |
112 | | R2.add(R0,1-frg); |
113 | | R2.opupdt(xt-xp2,1.0); |
114 | | xm = xt; |
115 | | L.logit(X_log, xt ); |
116 | | L.logit(Xp_log, xp ); |
117 | | L.logit(Xp2_log, xp2 ); |
118 | | L.logit(U_log, u ); |
119 | | L.logit(U2_log, u2 ); |
120 | | L.logit(Ww_log, vec_1(Ww)); |
121 | | L.logit(R_log, vec(R.to_mat()._data(), 16 )); //3.33=1/(1-0.7) |
122 | | L.logit(R2_log, vec(R2.to_mat()._data(), 16 )); |
123 | | // L.logit(E_log, KFE._e()->mean() ); |
124 | | // L.logit(O_log, vec(iCh._data(),16)); //3.33=1/(1-0.7) |
125 | | // L.logit(Efix_log, KFEep.mean() ); |
126 | | // L.logit(M_log, Mep.mean() ); |
127 | | |
128 | | L.step(); |
129 | | } |
130 | | |
131 | | L.finalize(); |
132 | | L.itsave("sim.it"); |
| 37 | L->finalize(); |