Changeset 318

Show
Ignore:
Timestamp:
04/23/09 13:19:04 (15 years ago)
Author:
smidl
Message:

pmsm CRB model

Files:
7 modified

Legend:

Unmodified
Added
Removed
  • doprava/k1.cpp

    r309 r318  
    4949 
    5050        // Definovat co se bude logovat 
    51         Efix.log_add(&L,"E"); 
     51        Efix.log_add(L,"E"); 
    5252        L.init(); // <<==== allocate memory for results 
    5353         
     
    5858 
    5959                //LOG results 
    60                 Efix.logit(&L);  
     60                Efix.logit(L);  
    6161                 
    6262                L.step(); 
  • pmsm/pmsm.h

    r283 r318  
    2727        IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2;}; 
    2828        //! Set mechanical and electrical variables 
    29         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;} 
     29        virtual 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;} 
    3030 
    3131        vec eval ( const vec &x0, const vec &u0 ) { 
     
    7777 
    7878//! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ 
    79 class IMpmsm2o : public diffbifn { 
     79class IMpmsm2o : public IMpmsm { 
    8080        protected: 
    81                 double Rs, Ls, dt, Ypm, kp, p,  J, Mz; 
     81//              double Rs, Ls, dt, Ypm, kp, p,  J, Mz; 
    8282                //! store first derivatives for the use in second derivatives 
    8383                double dia, dib, dom, dth; 
     
    8686                double iam, ibm, omm, thm, uam, ubm; 
    8787        public: 
    88                 IMpmsm2o() :diffbifn () {dimy=4;dimx=4;dimu=2;}; 
     88                IMpmsm2o() :IMpmsm () {}; 
    8989        //! Set mechanical and electrical variables 
    9090                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; d2t=dt*dt/2;} 
     
    111111                        xk ( 1 ) = ibm + dt*dib;// +d2t*d2ib; 
    112112                        xk ( 2 ) = omm +dt*dom;// +d2t*d2om; 
    113                         xk ( 3 ) = thm + dt*dth;// +d2t*d2th; // <0..2pi> 
     113                        xk ( 3 ) = thm + dt*dth;// +d2t*dom; // <0..2pi> 
    114114                         
    115115                        if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; 
     
    148148                // d th 
    149149                        A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; 
     150                        // FOR d2t*dom!!!!!!!!! 
     151/*                      A ( 3,0 ) = dt* kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); 
     152                        A ( 3,1 ) = dt* kp*p*p * Ypm/J*dt* ( cos ( thm ) ); 
     153                        A ( 3,2 ) = dt; 
     154                        A ( 3,3 ) = 1.0 + dt* kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );*/ 
    150155                } 
    151156 
  • pmsm/pmsmDS.h

    r280 r318  
    1212 
    1313#include <stat/loggers.h> 
     14#include <estim/libKF.h> 
    1415#include "simulator.h" 
    1516#include "pmsm.h" 
     
    2324        //! Setpoints of omega in timespans given by dt_prof 
    2425        vec profileWw; 
     26        //! Setpoints of Mz in timespans given by dt_prof 
     27        vec profileMz; 
    2528        //! time-step for profiles 
    2629        double dt_prof; 
     
    2932        //! options for logging, - log predictions of 'true' voltage 
    3033        bool opt_modu; 
     34        //! options for logging, -  
    3135public: 
    3236        //! Constructor with fixed sampling period 
     
    4650                static double dW; // increase of W 
    4751                static double Ww; // W 
     52                static double Mz; // W 
    4853                if ( t>=dt_prof*ind ) { 
    4954                        ind++; 
     55                        // check omega profile and set dW 
    5056                        if ( ind<profileWw.length() ) { 
    5157                                //linear increase 
     
    6167                                dW = 0; 
    6268                        } 
     69                        // Check Mz profile and set Mz 
     70                        if ( ind<profileMz.length() ) { 
     71                                //sudden increase 
     72                                Mz = profileMz(ind); 
     73                        } 
     74                        else { 
     75                                Mz = 0; 
     76                        } 
    6377                } 
    6478                Ww += dW; 
    6579                //Simulate Dt seconds! 
    66                 for ( int i=0;i<Dt;i++ ) {      pmsmsim_step ( Ww );} 
     80                for ( int i=0;i<Dt;i++ ) {      pmsmsim_step ( Ww , Mz);} 
    6781        }; 
    6882 
     
    100114                        L.logit ( L_optu , vec_2 ( ua,ub ) ); 
    101115                } 
     116                 
    102117        } 
    103118 
    104         void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;} 
     119        void set_profile ( double dt, const vec &Ww, const vec &Mz ) {dt_prof=dt; profileWw=Ww; profileMz=Mz;} 
    105120}; 
     121 
     122//! This class behaves like BM but it is evaluating EKF 
     123class pmsmCRB : public EKFCh{ 
     124        protected: 
     125                vec interr; 
     126                vec old_true; 
     127                vec secder; 
     128                int L_CRB; 
     129                int L_err; 
     130                int L_sec; 
     131        public: 
     132        //! constructor 
     133        pmsmCRB():EKFCh(){old_true=zeros(6);} 
     134 
     135        void bayes(const vec &dt){ 
     136                //assume we know state exactly: 
     137                vec true_state=vec(x,4); // read from pmsm 
     138                est.set_mu(true_state); 
     139                 
     140                //integration error 
     141                old_true(4)=KalmanObs[4]; 
     142                old_true(5)=KalmanObs[5];// add U 
     143                interr = (true_state - pfxu->eval(old_true)); 
     144                 
     145                //second derivative 
     146                IMpmsm2o* pf = dynamic_cast<IMpmsm2o*>(pfxu); 
     147                if (pf) {secder=pf->eval2o(vec_2(KalmanObs[4],KalmanObs[5]));} 
     148                                 
     149                EKFCh::bayes(dt); 
     150                old_true.set_subvector(0,true_state); 
     151        } 
     152         
     153        void log_add(logger &L, const string &name="" ){ 
     154                L_CRB=L.add(rx,"crb"); 
     155                L_err=L.add(rx,"err"); 
     156                L_sec=L.add(rx,"d2"); 
     157        } 
     158        void logit(logger &L){ 
     159                L.logit(L_err, interr); 
     160                L.logit(L_CRB,diag(est._R().to_mat())); 
     161                L.logit(L_sec,secder); 
     162        } 
     163}; 
  • pmsm/pmsm_estim.cpp

    r281 r318  
    3838 
    3939        DS->log_add ( *L ); 
    40         ivec L_est(nE); 
     40        string nic=""; 
    4141        for (int i=0; i<nE; i++){ 
    42                 L_est(i)= L->add ( Es(i)->posterior()._rv(), "" ); // estimate 
     42                Es(i)->log_add(*L,nic); // estimate 
    4343        } 
    4444        L->init(); 
     
    6161                        Es(i)->bayes ( Dls(i)->pushdown ( dt ) );               // update estimates 
    6262 
    63                         L->logit ( L_est(i), Es(i)->posterior().mean() ); 
     63                        Es(i)->logit (*L); 
    6464                } 
    6565                // Regulators 
  • pmsm/pmsm_ui.h

    r280 r318  
    2929                        string var=S["variant"]; 
    3030                        if (var=="Stat"){tmp=new IMpmsmStat;} 
    31                         if (var=="Mf"){tmp=new IMpmsmStat;} 
     31                        if (var=="2o"){tmp=new IMpmsm2o;} 
    3232                } else { 
    3333                        tmp= new IMpmsm; 
     
    6565                //Calling function tmp->tmp_set 
    6666                UIcall<pmsmDS*> ( S["params"], &tmp_set , tmp ); 
    67                 // 
    68                 if ( S.exists ( "profile" ) ) { 
    69                         tmp->set_profile ( S["tstep"],getvec ( S["profile"] ) ); 
    70                 } 
    71                 else { 
    72                         tmp->set_profile ( 1.0, vec ( "1" ) ); 
    73                 } 
     67                 
     68                // Default values of profiles for omega and Mz 
     69                vec profW=vec("1.0"); 
     70                vec profM=vec("0.0"); 
     71                double tstep=1.0; 
     72                 
     73                if ( S.exists ( "tstep" ) ) {tstep=S["tstep"];} 
     74                if ( S.exists ( "profileW" ) ) {profW=getvec ( S["profileW"] ) ;} 
     75                if ( S.exists ( "profileM" ) ) {profM=getvec ( S["profileM"] ) ;} 
     76                 
     77                tmp->set_profile (tstep , profW, profM); 
     78                 
     79                string opts=""; 
     80                if ( S.exists ( "options" ) ) {opts=(const char*)S["options"];} 
     81                tmp->set_options(opts); 
     82                 
    7483                return tmp; 
    7584        }; 
     
    7786}; 
    7887UIREGISTER ( UIpmsmDS ); 
     88 
     89class UIpmsmCRB: public UIbuilder { 
     90        public: 
     91                UIpmsmCRB():UIbuilder("pmsmCRB"){}; 
     92                bdmroot* build ( Setting &S ) const { 
     93                        diffbifn* IM; UIbuild(S["IM"],IM); 
     94                        diffbifn* OM; UIbuild(S["OM"],OM); 
     95                 
     96                //parameters 
     97                        pmsmCRB* E; E=new pmsmCRB; 
     98                        E->set_parameters(IM, OM, diag(getvec(S["dQ"])), diag(getvec(S["dR"]))); 
     99                 
     100                //statistics 
     101                        int dim=IM->dimension(); 
     102                        vec mu0; 
     103                        mat P0; 
     104                        if (S.exists("mu0")){mu0=getvec(S["mu0"]);}else{mu0=zeros(dim);}; 
     105                        if (S.exists("P0")){mu0=getmat(S["P0"],dim);}else{P0=eye(dim);}; 
     106                        E->set_statistics(mu0,P0); 
     107                 
     108                //connect 
     109                        RV* drv; UIbuild(S["drv"],drv); 
     110                        E->set_drv(*drv); 
     111                        RV* rv; UIbuild(S["rv"],rv); 
     112                        E->set_rv(*rv); 
     113                        return E; 
     114                }        
     115}; 
     116UIREGISTER ( UIpmsmCRB ); 
  • pmsm/simulator_zdenek/simulator.cpp

    r278 r318  
    329329 
    330330////////////////////////////////////////////////////////////////////////////////////////////////////// 
    331 void pmsmsim_step(double Ww)            // you must link array KalmanObs[] to EKF modul 
     331void pmsmsim_step(double Ww, double Mz)            // you must link array KalmanObs[] to EKF modul 
    332332{ 
    333333  double Umk, ub, uc; 
     
    338338//    *us=KalmanObs[0]; *(us+1)=KalmanObs[1]; 
    339339//     *us=ualfa; *(us+1)=ubeta; 
     340        //Mz 
     341        x[8]= Mz; 
     342         
    340343    pmsm_model(5); 
    341344 
  • pmsm/simulator_zdenek/simulator.h

    r278 r318  
    1818 
    1919extern void pmsmsim_set_parameters(double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0); 
    20 extern void pmsmsim_step(double Ww); 
     20extern void pmsmsim_step(double Ww, double Mz=0.0); 
    2121extern void pmsmsim_noreg_step(double ua, double ub); 
    2222