Changeset 250

Show
Ignore:
Timestamp:
01/26/09 20:39:40 (15 years ago)
Author:
smidl
Message:

useing ui in sim.cpp

Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libBM.h

    r229 r250  
    384384        RV Urv; // 
    385385public: 
     386        DS():Drv(RV0),Urv(RV0) {}; 
    386387        //! Returns full vector of observed data 
    387388        void getdata ( vec &dt ); 
  • bdm/stat/loggers.h

    r198 r250  
    3333        Array<string> names; 
    3434public: 
    35 //!Default constructor 
     35        //!Default constructor 
    3636        logger ( ) : entries(0),names ( 0 ) {} 
    3737 
    38 //! returns an identifier which will be later needed for calling the log() function 
     38        //! returns an identifier which will be later needed for calling the log() function 
    3939        virtual int add (const RV &rv, string name="" ) { 
    4040                int id=entries.length(); 
     
    4545        } 
    4646 
    47 //! log this vector 
     47        //! log this vector 
    4848        virtual void logit ( int id, const vec &v ) =0; 
    4949 
    50 //! Shifts storage position for another time step. 
     50        //! Shifts storage position for another time step. 
    5151        virtual void step() =0; 
    5252 
     
    5454        virtual void finalize() {}; 
    5555 
     56        //! Initialize the storage 
     57        virtual void init(){}; 
     58         
    5659        //! for future use 
    5760        virtual ~logger() {}; 
  • pmsm/CMakeLists.txt

    r233 r250  
    3030EXEC (mpf_load pmsmsim) 
    3131 
    32 EXEC (sim pmsmsim) 
     32#EXEC (sim pmsmsim config++) 
    3333EXEC (sim_var pmsmsim) 
    3434EXEC (sim_var_arx pmsmsim) 
  • pmsm/sim.cpp

    r223 r250  
    1111*/ 
    1212 
    13 #include <itpp/itbase.h> 
    14 #include <estim/libKF.h> 
    15 #include <estim/libPF.h> 
    16 #include <stat/libFN.h> 
    17  
    18 #include <stat/loggers.h> 
    19  
    20 #include "pmsm.h" 
    21 #include "simulator.h" 
    22 #include "sim_profiles.h" 
     13#include <config/uibuilder.h> 
     14#include <stat/libDS.h> 
     15#include "pmsmDS.h" 
    2316 
    2417using namespace itpp; 
    2518int main() { 
    26         // Kalman filter 
    27         int Ndat = 9000; 
    28         double h = 1e-6; 
    29         int Nsimstep = 125; 
     19        UIFile F("sim.bdm"); 
     20 
     21        logger* L;  
     22        UIbuild(F.lookup("logger"),&L); 
     23        pmsmDS * DS; 
     24        UIbuild(F.lookup("system"),&DS); 
     25        int Ndat; 
     26        F.lookupValue("ndat",Ndat); 
     27        // SET SIMULATOR 
     28 
     29        DS->log_add(*L); 
     30        L->init(); 
    3031         
    31         dirfilelog L("exp/sim",Ndat); 
     32        for ( int tK=1;tK<Ndat;tK++ ) { 
     33                DS->step(); 
     34                DS->logit(*L); 
     35        } 
    3236         
    33         // internal model 
    34         IMpmsm fxu; 
    35         //                  Rs    Ls        dt           Fmag(Ypm) kp   p    J     Bf(Mz) 
    36         fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989,   1.5 ,4.0, 0.04, 0.0 ); 
    37         // observation model 
    38         OMpmsm hxu; 
    39  
    40         vec mu0= "0.0 0.0 0.0 0.0"; 
    41 //      vec Qdiag ( "0.01 0.01 0.01 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    42         vec Qdiag ( "0.07 0.056 0.0007 0.0007" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    43         vec Rdiag ( "0.005 0.005" ); //var(diff(xth)) = "0.034 0.034" 
    44         EKFfull KFE ( rx,ry,ru ); 
    45         KFE.set_est ( mu0, diag ( vec("1 1 1 3.1415") )  ); 
    46         KFE.set_parameters ( &fxu,&hxu,diag(Qdiag),diag(Rdiag)); 
    47          
    48          
    49         int X_log = L.add(rx,"X"); 
    50         int Xp_log = L.add(rx,"Xp"); 
    51         int Xp2_log = L.add(rx,"Xp2"); 
    52         int E_log = L.add(rx,"E"); 
    53         int V_log = L.add(rx,"V"); 
    54         int U_log = L.add(ru,"U"); 
    55         int U2_log = L.add(ru,"U2"); 
    56         int R_log = L.add(RV("{_ }","16"),"R"); 
    57         int Ww_log = L.add(RV("{_ }","1"),"W"); 
    58         int R2_log = L.add(RV("{_ }","16"),"R2"); 
    59 //      int O_log = L.add(RV("{_ }","16"),"O"); 
    60         L.init(); 
    61  
    62         // SET SIMULATOR 
    63         //pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); 
    64         pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 6e-6, h ); 
    65         double Ww=0.0; 
    66         vec dt ( 2 ); 
    67  
    68         vec xm = zeros(4); 
    69         vec xt = zeros(4); 
    70         vec xp = zeros(4); 
    71         vec xp2 = zeros(4); 
    72         vec xp3 = zeros(4); 
    73         vec u=zeros(2); 
    74         vec u2=zeros(2); 
    75         ldmat R0(eye(4),1e-6*ones(4)); 
    76         ldmat R(R0); 
    77         ldmat R2(R0); 
    78          
    79         double frg=0.9; 
    80 //      vec vecW="0. 0. 0.2 0.4 0.4 0.2 0.0 -0.4 -0.6 -0.6 -0.4 0.0 0.0"; 
    81         vec vecW="1 2 4 9 4 2 0 -4 -9 -16 -4 0 0 0"; 
    82         vecW*=10.0; 
    83  
    84         for ( int tK=1;tK<Ndat;tK++ ) { 
    85                 //Number of steps of a simulator for one step of Kalman 
    86                 for ( int ii=0; ii<Nsimstep;ii++ ) { 
    87                         //simulator 
    88                         //sim_profile_steps1(Ww); 
    89                         sim_profile_vec01t(Ww,vecW); 
    90                         pmsmsim_step ( Ww ); 
    91                 }; 
    92                  
    93                 u(0)= KalmanObs[0]; 
    94                 u(1)= KalmanObs[1]; 
    95                 dt(0)= KalmanObs[2]; 
    96                 dt(1)= KalmanObs[3]; 
    97                 u2(0) = KalmanObs[4]; 
    98                 u2(1) = KalmanObs[5]; 
    99                 // Try what our model would predict! 
    100                 xp=fxu.eval(xm,u);  
    101                 xp2=fxu.eval(xm,zeros(2)); //ZERO input!!!!!!!! 
    102 //              xp3=fxu.eval(xm,u2);  
    103  
    104 //              KFE.bayes(concat(dt,u)); 
    105                 // This is simulator prediction 
    106                 xt=vec(x,4); //vec from C-array 
    107                 //Covariance   
    108                 R*=frg; 
    109                 R.add(R0,1-frg); 
    110                 R.opupdt(xt-xp,1.0); 
    111                 R2*=frg; 
    112                 R2.add(R0,1-frg); 
    113                 R2.opupdt(xt-xp2,1.0); 
    114                 xm = xt; 
    115                 L.logit(X_log, xt       );  
    116                 L.logit(Xp_log, xp      );  
    117                 L.logit(Xp2_log, xp2    );  
    118                 L.logit(U_log, u        );  
    119                 L.logit(U2_log, u2      );  
    120                 L.logit(Ww_log, vec_1(Ww));  
    121                 L.logit(R_log, vec(R.to_mat()._data(), 16 )); //3.33=1/(1-0.7) 
    122                 L.logit(R2_log, vec(R2.to_mat()._data(), 16 ));  
    123 //              L.logit(E_log, KFE._e()->mean() );  
    124 //              L.logit(O_log, vec(iCh._data(),16)); //3.33=1/(1-0.7) 
    125 //              L.logit(Efix_log, KFEep.mean() );  
    126 //              L.logit(M_log,  Mep.mean() );  
    127                  
    128                 L.step(); 
    129         } 
    130  
    131         L.finalize();  
    132         L.itsave("sim.it"); 
     37        L->finalize();  
    13338        return 0; 
    13439}