root/applications/pmsm/pmsm_estim.cpp @ 1179

Revision 1174, 1.9 kB (checked in by smidl, 14 years ago)

development of fixed Bierman code

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