1 | /*! |
---|
2 | \file |
---|
3 | \brief Models for synchronous electric drive using IT++ and BDM |
---|
4 | \author Vaclav Smidl. |
---|
5 | |
---|
6 | ----------------------------------- |
---|
7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
8 | |
---|
9 | Using IT++ for numerical operations |
---|
10 | ----------------------------------- |
---|
11 | */ |
---|
12 | |
---|
13 | #include <itpp/itbase.h> |
---|
14 | #include <stat/libFN.h> |
---|
15 | #include <stat/emix.h> |
---|
16 | #include <estim/ekf_templ.h> |
---|
17 | #include <estim/libPF.h> |
---|
18 | |
---|
19 | #include "pmsm.h" |
---|
20 | #include "simulator.h" |
---|
21 | #include "sim_profiles.h" |
---|
22 | |
---|
23 | #include <stat/loggers.h> |
---|
24 | |
---|
25 | using namespace itpp; |
---|
26 | |
---|
27 | int main() { |
---|
28 | // Kalman filter |
---|
29 | int Ndat = 90000; |
---|
30 | double h = 1e-6; |
---|
31 | int Nsimstep = 125; |
---|
32 | int Npar = 10; |
---|
33 | |
---|
34 | dirfilelog L("exp/pmsm_mix",1000); |
---|
35 | //memlog L(Ndat); |
---|
36 | |
---|
37 | // SET SIMULATOR |
---|
38 | pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); |
---|
39 | double Ww = 0.0; |
---|
40 | vec dt ( 2 ); |
---|
41 | vec ut ( 2 ); |
---|
42 | vec xtm=zeros ( 4 ); |
---|
43 | vec xdif=zeros ( 4 ); |
---|
44 | vec xt ( 4 ); |
---|
45 | vec ddif=zeros(2); |
---|
46 | IMpmsm fxu; |
---|
47 | // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz) |
---|
48 | fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); |
---|
49 | OMpmsm hxu; |
---|
50 | mat Qt=zeros ( 4,4 ); |
---|
51 | mat Rt=zeros ( 2,2 ); |
---|
52 | |
---|
53 | // ESTIMATORS |
---|
54 | vec mu0= "0.0 0.0 0.0 0.0"; |
---|
55 | vec Qdiag ( "62 66 454 0.03" ); //zdenek: 0.01 0.01 0.0001 0.0001 |
---|
56 | vec Rdiag ( "100 100" ); //var(diff(xth)) = "0.034 0.034" |
---|
57 | mat Q =diag( Qdiag ); |
---|
58 | mat R =diag ( Rdiag ); |
---|
59 | EKFfull Efix ( rx,ry,ru ); |
---|
60 | Efix.set_est ( mu0, 1*eye ( 4 ) ); |
---|
61 | Efix.set_parameters ( &fxu,&hxu,Q,R); |
---|
62 | |
---|
63 | RV rQR("10 11", "{Q R }", "4 2 ","0 0"); |
---|
64 | EKFful_unQR EKU (rx,ry,ru,rQR); |
---|
65 | EKU.set_est ( mu0, 1*ones ( 4 ) ); |
---|
66 | EKU.set_parameters ( &fxu,&hxu,diag(Qdiag),diag(Rdiag) ); |
---|
67 | |
---|
68 | //QU model |
---|
69 | egamma Gcom(rQR);Gcom.set_parameters(ones(6),vec("1 1 1e4 1e10 1 1")); |
---|
70 | /* cout << Gcom.mean() <<endl; |
---|
71 | cout << Gcom.sample() <<endl;*/ |
---|
72 | euni Ucom(rQR); Ucom.set_parameters(zeros(6),vec("60 60 453 0.03 100 100")); |
---|
73 | /* cout << Ucom.mean() <<endl; |
---|
74 | cout << Ucom.sample() <<endl;*/ |
---|
75 | Array<epdf*> Coms(2); |
---|
76 | Coms(0) = &Gcom; |
---|
77 | Coms(1) = &Ucom; |
---|
78 | emix Eevol(rQR); Eevol.set_parameters("0.1 0.9", Coms); |
---|
79 | // cout << Eevol.sample() <<endl; |
---|
80 | |
---|
81 | mepdf evolQR(rQR,rQR,&Eevol); |
---|
82 | MPF<EKFful_unQR> M ( rx,rQR, evolQR, evolQR, Npar, EKU ); |
---|
83 | M.set_est ( evolQR._epdf() ); |
---|
84 | |
---|
85 | epdf& Efix_ep = Efix._epdf(); |
---|
86 | epdf& M_ep = M._epdf(); |
---|
87 | |
---|
88 | //LOG |
---|
89 | RV rUD("12 13 14 15", "{u_isa u_isb i_isa i_isb }", ones_i(4),zeros_i(4)); |
---|
90 | int X_log = L.add(rx,"X"); |
---|
91 | int Efix_log = L.add(rx,"XF"); |
---|
92 | int M_log = L.add(concat(rQR,rx),"M"); |
---|
93 | L.init(); |
---|
94 | |
---|
95 | double dum=0.0; |
---|
96 | vec dumvec = vec_1(1.0); |
---|
97 | vec z= evolQR.samplecond(dumvec,dum) ; |
---|
98 | cout << z << endl; |
---|
99 | |
---|
100 | for ( int tK=1;tK<Ndat;tK++ ) { |
---|
101 | //Number of steps of a simulator for one step of Kalman |
---|
102 | for ( int ii=0; ii<Nsimstep;ii++ ) { |
---|
103 | sim_profile_steps1 ( Ww, true ); |
---|
104 | pmsmsim_step ( Ww ); |
---|
105 | }; |
---|
106 | // simulation via deterministic model |
---|
107 | ut ( 0 ) = KalmanObs[0]; |
---|
108 | ut ( 1 ) = KalmanObs[1]; |
---|
109 | dt ( 0 ) = KalmanObs[2]; |
---|
110 | dt ( 1 ) = KalmanObs[3]; |
---|
111 | |
---|
112 | //ESTIMATE |
---|
113 | Efix.bayes(concat(dt,ut)); |
---|
114 | // |
---|
115 | M.bayes(concat(dt,ut)); |
---|
116 | |
---|
117 | //LOG |
---|
118 | L.logit(X_log, vec(x,4)); //vec from C-array |
---|
119 | L.logit(Efix_log, Efix_ep.mean() ); |
---|
120 | L.logit(M_log, M_ep.mean() ); |
---|
121 | |
---|
122 | L.step(false); |
---|
123 | } |
---|
124 | |
---|
125 | L.step(true); |
---|
126 | //L.itsave("sim_var.it"); |
---|
127 | |
---|
128 | |
---|
129 | return 0; |
---|
130 | } |
---|