Changeset 62 for tests/pmsm_sim2.cpp

Show
Ignore:
Timestamp:
04/06/08 20:14:56 (16 years ago)
Author:
smidl
Message:

nova simulace s EKFfixed a novy EKF na plnych maticich

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tests/pmsm_sim2.cpp

    r60 r62  
    1919#include "simulator.h" 
    2020 
    21 #include <netcdfcpp.h> 
    22 void write_to_nc ( NcFile &nc, mat &X, std::string Xn, Array<std::string> A ) { 
    23         char tmpstr[200]; 
    24         int Len = X.rows(); 
    25  
    26         sprintf ( tmpstr,"%s.length",Xn.c_str() ); 
    27         NcDim* lengt = nc.add_dim ( tmpstr, ( long ) Len ); 
    28         for ( int j=0; j<X.cols(); j++ ) { 
    29                 if ( j<A.length() ) 
    30                         sprintf ( tmpstr,"%s_%s",Xn.c_str(), ( A ( j ) ).c_str() ); 
    31                 else 
    32                         sprintf ( tmpstr,"%s_%d",Xn.c_str(),j ); 
    33                 // Create variables and their attributes 
    34                 NcVar* P = nc.add_var ( tmpstr, ncDouble, lengt ); 
    35                 const double* Dp = X._data(); 
    36                 P->put ( &Dp[j*Len],Len ); 
    37         } 
    38 } 
    39  
     21#include "iopom.h" 
    4022 
    4123using namespace itpp; 
     
    5436void set_simulator_t(double &Ww) { 
    5537 
    56         if (t>0.0) x[8]=1.2;    // 1A //0.2ZP 
     38        if (t>0.2) x[8]=1.2;    // 1A //0.2ZP 
    5739        if (t>0.4) x[8]=10.8;   // 9A 
    5840        if (t>0.6) x[8]=25.2;  // 21A 
     
    9981        if (t>8.3) x[8]=10.8;   // 9A 
    10082        if (t>8.5) x[8]=25.2;  // 21A 
     83         
     84//        x[8]=0.0; 
    10185} 
    10286 
    10387int main() { 
    10488        // Kalman filter 
    105         int Ndat = 30000; 
     89        int Ndat = 90000; 
    10690        double h = 1e-6; 
    10791        int Nsimstep = 125; 
     
    11397        // internal model 
    11498        IMpmsm fxu; 
    115         //                  Rs    Ls        dt       Fmag(Ypm) kp   p    J     Bf(Mz) 
     99        //                  Rs    Ls        dt           Fmag(Ypm) kp   p    J     Bf(Mz) 
    116100        fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989,   1.5 ,4.0, 0.04, 0.0 ); 
    117101        // observation model 
     
    119103 
    120104        vec mu0= "0.0 0.0 0.0 0.0"; 
    121         vec Qdiag ( "0.01 0.01 0.0001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    122         vec Rdiag ( "0.005 0.005" ); //var(diff(xth)) = "0.034 0.034" 
     105//      vec Qdiag ( "0.01 0.01 0.01 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
     106        vec Qdiag ( "18 18 157.9 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
     107        vec Rdiag ( "90 90" ); //var(diff(xth)) = "0.034 0.034" 
    123108        chmat Q ( Qdiag ); 
    124109        chmat R ( Rdiag ); 
    125110        EKFCh KFE ( rx,ry,ru ); 
    126         KFE.set_parameters ( &fxu,&hxu,Q,R ); 
    127         KFE.set_est ( mu0, chmat ( 1*ones ( 4 ) ) ); 
     111        KFE.set_est ( mu0, ( 1*eye ( 4 ) ) ); 
     112        KFE.set_parameters ( &fxu,&hxu,Qdiag,Rdiag); 
    128113 
    129114        RV rQ ( "100","{Q}","4","0" ); 
    130115        EKF_unQ KFEp ( rx,ry,ru,rQ ); 
     116        KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) ); 
    131117        KFEp.set_parameters ( &fxu,&hxu,Q,R ); 
    132         KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) ); 
    133118 
    134119        mgamma_fix evolQ ( rQ,rQ ); 
     
    139124        epdf& pfinit=evolQ._epdf(); 
    140125        M.set_est ( pfinit ); 
    141         evolQ.set_parameters ( 100000.0, Qdiag, 0.5 ); 
     126        evolQ.set_parameters ( 5000.0, Qdiag, 0.9999 ); 
    142127 
    143128        // 
     
    190175        //Exit program: 
    191176 
     177        char tmpstr[200]; 
     178        sprintf(tmpstr,"%s/%s","here/","format"); 
     179        ofstream  form(tmpstr); 
     180        form << "# Experimetal header file"<< endl; 
     181        dirfile_write(form,"here/",Xt,"X","{isa isb om th }" ); 
     182        dirfile_write ( form,"here",XtM,"XtM","{q1 q2 q3 q4 isa isb om th }" ); 
     183        dirfile_write ( form,"here",XtE,"XE","{isa isb om th }" ); 
     184        dirfile_write ( form,"here",Dt,"Dt","{isa isb ua ub }" ); 
     185 
    192186        //////////////// 
    193187        // Just Testing 
    194         NcFile nc ( "pmsm_sim.nc", NcFile::Replace ); // Create and leave in define mode 
     188/*      NcFile nc ( "pmsm_sim2.nc", NcFile::Replace ); // Create and leave in define mode 
    195189        if ( ! nc.is_valid() ) {        std::cerr << "creation of NCFile failed."<<endl;} 
    196190 
    197191        write_to_nc ( nc,Xt,"X","{isa isb om th }" ); 
    198         write_to_nc ( nc,XtM,"XtM","{q1 q2 isa isb om th }" ); 
     192        write_to_nc ( nc,XtM,"XtM","{q1 q2 q3 q4 isa isb om th }" ); 
    199193        write_to_nc ( nc,XtE,"XE","{isa isb om th }" ); 
    200         write_to_nc ( nc,Dt,"Dt","{isa isb ua ub }" ); 
     194        write_to_nc ( nc,Dt,"Dt","{isa isb ua ub }" );*/ 
    201195        return 0; 
    202196}