root/applications/pmsm/pmsm_estim.cpp @ 686

Revision 686, 1.9 kB (checked in by smidl, 15 years ago)

pmsm using new syntax for bayes

RevLine 
[357]1
2/*!
3\file
4\brief Multi-Estimator (developped for PMSM)
5
6
7 */
8
[654]9#include "base/user_info.h"
10#include "base/loggers.h"
[384]11#include "estim/kalman.h"
[366]12#include "pmsmDS.h"
[654]13#include "filters.h"
[666]14#include "base/datasources.h"
[357]15
[366]16
[357]17using namespace bdm;
18int 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(); }
[394]22        UIFile F ( fname );
[357]23
[654]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
[357]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               
[676]32        pDS->log_register ( *L, "true" );
33        string Ename;
[357]34        for (int i=0; i<nE; i++){
[676]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
[357]41        }
42        L->init();
43
44        vec dt=zeros ( pDS->_drv()._dsize() );   //data variable
45        Array<datalink*> Dls(nE); 
[686]46        Array<datalink*> Dlsc(nE); 
[357]47        for (int i=0; i<nE; i++){
[686]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
[357]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
[676]57                pDS->log_write ();
[357]58               
59                // Estimators
60                for (int i=0; i<nE; i++){
[686]61                        Es(i)->bayes ( Dls(i)->pushdown ( dt ), Dlsc(i)->pushdown(dt) );                // update estimates
[357]62
[676]63                        Es(i)->log_write ();
[357]64                }
65                // Regulators
66                L->step();
67        }
68
69        L->finalize();
70
71        for (int i=0; i<nE; i++){
72                delete Dls(i);
[686]73                delete Dlsc(i);
[357]74        }
75        return 0;
76}
Note: See TracBrowser for help on using the browser.