root/pmsm/mpf_load.cpp @ 254

Revision 254, 2.7 kB (checked in by smidl, 15 years ago)

create namespace bdm

Line 
1/*!
2  \file
3  \brief Simulation of disturbances in PMSM model, EKF runs with simulated covariances
4  \author Vaclav Smidl.
5
6  \ingroup PMSM
7  -----------------------------------
8  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
9
10  Using IT++ for numerical operations
11  -----------------------------------
12*/
13
14#include <itpp/itbase.h>
15#include <stat/libFN.h>
16#include <estim/libKF.h>
17#include <estim/libPF.h>
18#include <estim/ekf_templ.h>
19#include <math/chmat.h>
20
21#include "pmsm.h"
22#include "simulator.h"
23#include "sim_profiles.h"
24
25#include <stat/loggers.h>
26
27using namespace bdm;
28
29class IMpmsm_load :  public IMpmsm {
30        public:
31                IMpmsm_load() :IMpmsm() {};
32                void condition ( const vec &val ) {Mz = val(0);}
33};
34
35int main() {
36        // Kalman filter
37        int Ndat = 90000;
38        double h = 1e-6;
39        int Nsimstep = 125;
40        int Npart = 200;
41
42        dirfilelog L("exp/mpf_load",1000);
43       
44        // SET SIMULATOR
45        pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h );
46        double Ww = 0.0;
47        vec dt ( 2 );
48        vec ut ( 2 );
49       
50        IMpmsm_load fxu;
51        IMpmsm fxu0;
52        //                  Rs    Ls        dt           Fmag(Ypm) kp   p    J     Bf(Mz)
53        fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989,   1.5 ,4.0, 0.04, 0.0 );
54        fxu0.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989,   1.5 ,4.0, 0.04, 0.0 );
55        OMpmsm hxu;
56
57        // ESTIMATORS
58        vec mu0= "0.0 0.0 0.0 0.0";
59        vec Qdiag0 ( "62 66 454 0.03" ); //zdenek: 0.01 0.01 0.0001 0.0001
60        vec Qdiag ( "6 6 1 0.003" ); //zdenek: 0.01 0.01 0.0001 0.0001
61        vec Rdiag ( "100 100" ); //var(diff(xth)) = "0.034 0.034"
62        mat Q =diag( Qdiag );
63        mat R =diag ( Rdiag );
64        EKFfull Efix ( rx,ry,ru );
65        Efix.set_est ( mu0, 1*eye ( 4 )  );
66        Efix.set_parameters ( &fxu0,&hxu,diag(Qdiag0),R);
67
68        RV rMz=RV("{Mz }");
69        mlnorm<ldmat> evolMz(rMz,rMz);
70        evolMz.set_parameters(mat("1"),vec("0"),ldmat(1.0*vec("1")));
71        evolMz.condition(" 0.0");
72       
73        EKFCh_cond Ep ( rx,ry,ru,rMz );
74        Ep.set_est ( mu0, 1*eye ( 4 ) );
75        Ep.set_parameters ( &fxu,&hxu,Q,R);
76       
77        MPF<EKFCh_cond> M ( rx,rMz,evolMz,evolMz, Npart, Ep  );
78        M.set_est(evolMz._epdf());
79
80        //LOG
81        int X_log = L.add(rx,"X");
82        int E_log = L.add(rx,"EX");
83        int M_log = L.add(concat(rMz,rx),"MX");
84        L.init();
85
86        for ( int tK=1;tK<Ndat;tK++ ) {
87                //Number of steps of a simulator for one step of Kalman
88                for ( int ii=0; ii<Nsimstep;ii++ ) {
89                        sim_profile_steps1 ( Ww , true);
90                        pmsmsim_step ( Ww );
91                };
92                // simulation via deterministic model
93                ut ( 0 ) = KalmanObs[4];
94                ut ( 1 ) = KalmanObs[5];
95               
96                dt ( 0 ) = KalmanObs[2];
97                dt ( 1 ) = KalmanObs[3];
98       
99                //ESTIMATE
100                Efix.bayes(concat(dt,ut));
101                //
102                M.bayes(concat(dt,ut));
103               
104                //LOG
105                L.logit(X_log,  vec(x,4)); //vec from C-array
106                L.logit(E_log, Efix._epdf().mean()); 
107                L.logit(M_log, M._epdf().mean()); 
108               
109                L.step();
110        }
111
112        L.finalize();
113        //L.itsave("sim_var.it");       
114       
115
116        return 0;
117}
Note: See TracBrowser for help on using the browser.