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