Changeset 1380 for applications

Show
Ignore:
Timestamp:
08/01/11 22:11:09 (13 years ago)
Author:
smidl
Message:

MPF v C

Location:
applications/pmsm
Files:
2 added
9 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/pmsmDS.h

    r1377 r1380  
    2525{ 
    2626        LOG_LEVEL(pmsmDS,logvoltage); 
    27  
     27                 
    2828protected: 
    2929    //! indices of logged variables 
     
    3838    int Dt;     
    3939public: 
     40        double x[8]; 
     41        double KalmanObs[8]; 
    4042    //! Constructor with fixed sampling period 
    4143    pmsmDS () : DS() 
     
    4446        Drv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub o_om o_th Mz }" ); 
    4547                dtsize = Drv._dsize(); 
     48                pmsmsim_fill_xy(x,KalmanObs); 
    4649    } 
    4750    void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) 
     
    6669    void step() 
    6770    { 
     71                pmsmsim_fill_xy(x,KalmanObs); 
    6872        static int ind=0; 
    6973        static double dW; // increase of W 
    7074        static double Ww; // W 
    7175        static double Mz; // W 
     76        double t;  
     77                t=pmsmsim_get_t(); 
    7278        if ( t>=dt_prof*ind ) 
    7379        { 
     
    210216                void step() 
    211217                { 
     218                        double t=pmsmsim_get_t(); 
     219                         
    212220                        static int ind=0; 
    213221                        static double dW; // increase of W 
     
    256264         
    257265 
     266#ifdef XXX 
    258267//! This class behaves like BM but it is evaluating EKF 
    259268class pmsmCRB : public EKFfull 
     
    279288                vec &mu = est._mu(); 
    280289                //assume we know state exactly: 
    281         vec true_state=vec(x,4); // read from pmsm 
     290        vec true_state=0;//TODO vec(x,4); // read from pmsm 
    282291        mu=true_state; 
    283292 
     
    418427 
    419428UIREGISTER ( pmsmCRBMz ); 
     429#endif  
    420430 
    421431#endif 
  • applications/pmsm/simulator_zdenek/CMakeLists.txt

    r1344 r1380  
    11# Simulator library 
    2 add_library (pmsmsim simulator.cpp regulace.cpp) 
     2add_library (pmsmsim SHARED simulator.cpp regulace.cpp) 
    33 
    4 EXEC (test_UD  pmsmsim ekf_obj) 
    5 EXEC (test_Ch  pmsmsim ekf_obj) 
     4#EXEC (test_UD  pmsmsim ekf_obj) 
     5#EXEC (test_Ch  pmsmsim ekf_obj) 
    66 
    77add_executable(round_test round_test.cpp) 
  • applications/pmsm/simulator_zdenek/demo_example/main.CPP

    r38 r1380  
    3030FILE *fw; 
    3131 
    32 void main(void) 
     32int main(void) 
    3333{ 
    3434  h=1e-6; 
     
    7272 
    7373  fclose(fw); 
     74  return 0; 
    7475 } 
  • applications/pmsm/simulator_zdenek/ekf_example/CMakeLists.txt

    r1174 r1380  
    22 
    33include_directories(../../bdm) 
    4 add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp) 
     4add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp) 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp

    r1341 r1380  
    33 
    44#include "ekf_obj.h" 
    5 #include "../simulator.h" 
     5//#include "../simulator.h" 
    66 
    77double minQ(double Q){if (Q>1.0){ return 1.0;} else {return Q;};}; 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h

    r1341 r1380  
    2121#include "reference_Q15.h" 
    2222#include "parametry_motoru.h" 
     23#include "mpf_double.h" 
    2324 
    2425using namespace bdm; 
     
    564565 
    565566 
     567class MPF_pmsm_red:public BM{ 
     568 
     569 
     570public: 
     571                MPF_pmsm_red(){ 
     572                        dimy=2; 
     573                        dimc=2; 
     574                        mpf_init(1e-1, 1e-6, 1e-1); 
     575                }; 
     576        void bayes ( const vec &val, const vec &cond ) { 
     577                const double &isa = val(0); 
     578                const double &isb = val(1); 
     579                const double &usa = cond(0); 
     580                const double &usb = cond(1); 
     581                mpf_bayes(isa,isb,usa,usb); 
     582        } 
     583         
     584        class mp:public epdf{ 
     585        public: 
     586                mp():epdf(){set_dim(N);} 
     587                vec sample() const {return zeros(N);} 
     588                double evallog(const vec &v) const {return 0.0;} 
     589                vec mean() const {vec tmp(N); mpf_th(tmp._data()); return tmp;} 
     590                vec variance() const {return zeros(N);} 
     591        }; 
     592         
     593        mp mypdf; 
     594        const mp& posterior() const {return mypdf;} 
     595}; 
     596UIREGISTER(MPF_pmsm_red); 
    566597 
    567598 
  • applications/pmsm/simulator_zdenek/pmsm_sim.cpp

    r1378 r1380  
    1010                         usa = *mxGetPr(input[0]); 
    1111                         usb = *mxGetPr(input[1]); 
    12         pmsmsim_noreg_step(usa,usb); 
     12                        pmsmsim_noreg_step(usa,usb); 
    1313      }  
    1414    if ( n_input==1 ) { 
    15         double Ww = *mxGetPr(input[0]); 
    16         for (int i=0;i<125; i++){ 
    17           pmsmsim_step(Ww,0.0); 
     15                double Ww = *mxGetPr(input[0]); 
     16                for (int i=0;i<125; i++){ 
     17                pmsmsim_step(Ww,0.0); 
     18                } 
    1819        } 
    19     } 
    20     if (n_input==0){ 
    21       pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, 1e-6 ); 
    22     } 
    2320 
    24       output[0]= mxCreateDoubleMatrix(9, 1, mxREAL);  
     21   output[0]= mxCreateDoubleMatrix(9, 1, mxREAL);  
    2522        x_out= mxGetPr(output[0]); 
    2623         
    27         for (int i=0; i<9; i++){ 
    28             x_out[i]=x[i]; 
    29         } 
    30  
    31       output[1]= mxCreateDoubleMatrix(6, 1, mxREAL);  
     24        output[1]= mxCreateDoubleMatrix(6, 1, mxREAL);  
    3225        y_out= mxGetPr(output[1]); 
    3326         
    34         for (int i=0; i<5; i++){ 
    35             y_out[i]=KalmanObs[i]; 
    36         } 
    37  
     27        pmsmsim_fill_xy(x_out,y_out); 
    3828   
    3929} 
  • applications/pmsm/simulator_zdenek/simulator.cpp

    r1306 r1380  
    4242 
    4343// system state 
    44 double x[9]; // (isx,isy,wme,theta_e,M,Fsd,Isd,Isq,Mz) 
     44static double x[9]; // (isx,isy,wme,theta_e,M,Fsd,Isd,Isq,Mz) 
    4545 
    4646// internal variables of PWM module 
     
    7070 
    7171// output for EKF (voltages and measured currents, which are fed to KalmanObs) 
    72 double KalmanObs[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};      // usx, usy, Isx, Isy, usx_av, usy_av 
     72static double KalmanObs[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};      // usx, usy, Isx, Isy, usx_av, usy_av 
    7373 
    7474// real-time 
    75 double t=0.; //VS removed static due to clash with export in .h 
     75static double t=0.; //VS removed static due to clash with export in .h 
    7676 
    7777// stator voltage components in alfa beta (inluding impact of the real dc-link voltage) 
     
    510510////////////////////////////////////////////////////////////////////////////////////////////////////// 
    511511////////////////////////////////////////////////////////////////////////////////////////////////////// 
     512 
     513// for mexfile 
     514void pmsmsim_fill_parameters(double x_out[10]){ 
     515        x_out[0]= Rs; 
     516        x_out[1]= Ls; 
     517        x_out[2]= Fmag; 
     518        x_out[3]= Bf; 
     519        x_out[4]= p; 
     520        x_out[5]= kp; 
     521        x_out[6]= J; 
     522        x_out[7]= Uc; 
     523        x_out[8]= DT; 
     524        x_out[9]= h; 
     525} 
     526void pmsmsim_fill_xy(double xout[9], double yout[6]){ 
     527        for (int i=0;i<9;i++){ 
     528                xout[i]=x[i]; 
     529        } 
     530        for (int i=0;i<6;i++){ 
     531                yout[i]=KalmanObs[i]; 
     532        } 
     533} 
     534double pmsmsim_get_t() 
     535{ 
     536 return t; 
     537} 
     538 
  • applications/pmsm/simulator_zdenek/simulator.h

    r318 r1380  
    2020extern void pmsmsim_step(double Ww, double Mz=0.0); 
    2121extern void pmsmsim_noreg_step(double ua, double ub); 
     22extern void pmsmsim_fill_parameters(double P[10]); 
     23extern void pmsmsim_fill_xy(double xout[9], double yout[6]); 
     24extern double pmsmsim_get_t(); 
    2225 
    23 extern double x[9];  
    24 extern double t;  
    25 extern double KalmanObs[10];