1 | |
---|
2 | /*! |
---|
3 | \file |
---|
4 | \brief Multi-Estimator (developped for PMSM) |
---|
5 | |
---|
6 | |
---|
7 | */ |
---|
8 | |
---|
9 | #include "pmsm_ui.h" |
---|
10 | #include "stat/loggers_ui.h" |
---|
11 | #include "estim/KF_ui.h" |
---|
12 | |
---|
13 | using namespace bdm; |
---|
14 | int main ( int argc, char* argv[] ) { |
---|
15 | const char *fname; |
---|
16 | if ( argc>1 ) {fname = argv[1]; } |
---|
17 | else { cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"<<endl; abort(); } |
---|
18 | UIFile F ( fname ); |
---|
19 | |
---|
20 | logger* L; |
---|
21 | DS * DS; |
---|
22 | Array<BM*> Es; // array of estimators |
---|
23 | int Ndat; //number of data records |
---|
24 | int nE; //number of estimators |
---|
25 | |
---|
26 | try { |
---|
27 | UIbuild ( F.lookup ( "logger" ),L ); |
---|
28 | UIbuild ( F.lookup ( "system" ),DS ); |
---|
29 | F.lookupValue ( "experiment.ndat",Ndat ); |
---|
30 | Setting& S=F.lookup ( "estimator" ); |
---|
31 | nE = S.getLength(); |
---|
32 | Es.set_size(nE); |
---|
33 | for(int i=0;i<nE;i++){ |
---|
34 | UIbuild (S[i] ,Es(i) ); |
---|
35 | } |
---|
36 | } |
---|
37 | catch UICATCH; |
---|
38 | |
---|
39 | DS->log_add ( *L ); |
---|
40 | string nic=""; |
---|
41 | for (int i=0; i<nE; i++){ |
---|
42 | Es(i)->log_add(*L,nic); // estimate |
---|
43 | } |
---|
44 | L->init(); |
---|
45 | |
---|
46 | vec dt=zeros ( DS->_drv()._dsize() ); //data variable |
---|
47 | Array<datalink*> Dls(nE); |
---|
48 | for (int i=0; i<nE; i++){ |
---|
49 | Dls(i)=new datalink( Es(i)->_drv(),DS->_drv() ); //datalink between a datasource and estimator |
---|
50 | } |
---|
51 | |
---|
52 | // Main cycle |
---|
53 | for ( int tK=1;tK<Ndat;tK++ ) { |
---|
54 | // Data Source |
---|
55 | DS->step(); // simulator step |
---|
56 | DS->getdata ( dt ); // read data |
---|
57 | DS->logit ( *L ); |
---|
58 | |
---|
59 | // Estimators |
---|
60 | for (int i=0; i<nE; i++){ |
---|
61 | Es(i)->bayes ( Dls(i)->pushdown ( dt ) ); // update estimates |
---|
62 | |
---|
63 | Es(i)->logit (*L); |
---|
64 | } |
---|
65 | // Regulators |
---|
66 | L->step(); |
---|
67 | } |
---|
68 | |
---|
69 | L->finalize(); |
---|
70 | |
---|
71 | delete L; |
---|
72 | delete DS; |
---|
73 | for (int i=0; i<nE; i++){ |
---|
74 | delete Dls(i); |
---|
75 | delete Es(i); |
---|
76 | } |
---|
77 | return 0; |
---|
78 | } |
---|