Changeset 62 for tests

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

Location:
tests
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • tests/CMakeLists.txt

    r60 r62  
    4545include_directories (${BDM_SOURCE_DIR}/simulator_zdenek) 
    4646link_directories (${BDM_BINARY_DIR}/simulator_zdenek) 
     47link_directories (${BDM_BINARY_DIR}/simulator_zdenek/ekf_example) 
    4748add_executable (pmsm_sim pmsm_sim.cpp) 
    4849add_executable (pmsm_sim2 pmsm_sim2.cpp) 
     50add_executable (pmsm_sim3 pmsm_sim3.cpp) 
    4951target_link_libraries (pmsm_sim ${BdmLibs} pmsmsim netcdf_c++) 
    5052target_link_libraries (pmsm_sim2 ${BdmLibs} pmsmsim netcdf_c++) 
     53target_link_libraries (pmsm_sim3 ${BdmLibs} pmsmsim ekf_obj) 
  • tests/pmsm.h

    r54 r62  
    1010RV ry ( "7 8", "{oia, oib}", ones_i ( 2 ) ,zeros_i ( 2 )); 
    1111 
    12 //! State evolution model for a PMSM drive and its derivative with respect to $x$ 
     12//! State evolution model for a PMSM drive and its derivative with respect to \$x\$ 
    1313class IMpmsm : public diffbifn { 
    1414        double Rs, Ls, dt, Ypm, kp, p,  J, Mz; 
    1515 
    1616public: 
    17         IMpmsm() :diffbifn ( rx, ru ) {}; 
     17        IMpmsm() :diffbifn (rx.count(), rx, ru ) {}; 
    1818        //! Set mechanical and electrical variables 
    1919        void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;} 
     
    3434                xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; 
    3535                //om 
    36                 xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; 
     36                xk ( 2 ) = omm;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; 
    3737                //th 
    3838                xk ( 3 ) = rem(thm + omm*dt,2*pi); // <0..2pi> 
     
    5252                A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); 
    5353                // d om 
    54                 A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); 
    55                 A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) ); 
     54                A ( 2,0 ) = 0.0;//kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); 
     55                A ( 2,1 ) = 0.0;//kp*p*p * Ypm/J*dt* ( cos ( thm ) ); 
    5656                A ( 2,2 ) = 1.0; 
    57                 A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); 
     57                A ( 2,3 ) = 0.0;//kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); 
    5858                // d th 
    5959                A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; 
     
    6464}; 
    6565 
    66 //! Observation model for PMSM drive and its derivative with respect to $x$ 
     66//! Observation model for PMSM drive and its derivative with respect to \$x\$ 
    6767class OMpmsm: public diffbifn { 
    6868public: 
    69         OMpmsm() :diffbifn ( rx,ru ) {}; 
     69        OMpmsm() :diffbifn (2, rx,ru ) {}; 
    7070 
    7171        vec eval ( const vec &x0, const vec &u0 ) { 
  • 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}