root/applications/pmsm/pmsm_estim.cpp @ 342

Revision 342, 1.6 kB (checked in by smidl, 15 years ago)

Barcelona

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