- Timestamp:
- 05/07/08 13:59:56 (17 years ago)
- Location:
- pmsm
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pmsm/pmsm.h
r91 r94 7 7 8 8 //TODO hardcoded RVs!!! 9 RV rx ( "1 2 3 4", "{ia , ib, om, th}", ones_i ( 4 ), zeros_i ( 4 ));10 RV ru ( "5 6", "{ua , ub}", ones_i ( 2 ) ,zeros_i ( 2 ));11 RV ry ( "7 8", "{oia , oib}", ones_i ( 2 ) ,zeros_i ( 2 ));9 RV rx ( "1 2 3 4", "{ia ib om th }", ones_i ( 4 ), zeros_i ( 4 )); 10 RV ru ( "5 6", "{ua ub }", ones_i ( 2 ) ,zeros_i ( 2 )); 11 RV ry ( "7 8", "{oia oib }", ones_i ( 2 ) ,zeros_i ( 2 )); 12 12 13 13 class uipmsm : public uibase{ -
pmsm/sim_var.cpp
r81 r94 19 19 #include "simulator.h" 20 20 21 #include "iopom.h"21 #include <stat/loggers.h> 22 22 23 23 using namespace itpp; … … 81 81 int Nsimstep = 125; 82 82 83 mat Xt=zeros ( Ndat ,9 ); //true state from simulator 84 mat XtM=zeros ( Ndat ,4 ); //true state from simulator 85 mat XtF=zeros ( Ndat ,4 ); //true state from simulator 86 mat XtO=zeros ( Ndat ,4 ); //true state from simulator 87 mat Dt=zeros ( Ndat,4 ); //observation 88 mat Qrec=zeros ( Ndat, 4*4 ); //full covariance matrix 89 83 dirfilelog L("exp/sim_var",1000); 84 90 85 // SET SIMULATOR 91 86 pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); … … 96 91 vec xdif=zeros ( 4 ); 97 92 vec xt ( 4 ); 93 vec ddif=zeros(2); 98 94 IMpmsm fxu; 99 95 // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz) … … 101 97 OMpmsm hxu; 102 98 mat Qt=zeros ( 4,4 ); 99 mat Rt=zeros ( 2,2 ); 103 100 104 101 // ESTIMATORS … … 116 113 Eop.set_parameters ( &fxu,&hxu,Q,R); 117 114 115 EKFfull Edi ( rx,ry,ru ); 116 Edi.set_est ( mu0, 1*eye ( 4 ) ); 117 Edi.set_parameters ( &fxu,&hxu,Q,R); 118 118 119 epdf& Efix_ep = Efix._epdf(); 119 120 epdf& Eop_ep = Eop._epdf(); 121 epdf& Edi_ep = Edi._epdf(); 120 122 123 //LOG 124 RV rQ("10", "{Q }", "16","0"); 125 RV rR("11", "{R }", "4","0"); 126 int X_log = L.add(rx,"X"); 127 int Efix_log = L.add(rx,"XF"); 128 int Eop_log = L.add(rx,"XO"); 129 int Edi_log = L.add(rx,"XD"); 130 int Q_log = L.add(rQ,""); 131 int R_log = L.add(rR,""); 132 L.init(); 121 133 122 134 for ( int tK=1;tK<Ndat;tK++ ) { … … 133 145 134 146 xt = fxu.eval ( xtm,ut ); 135 136 147 //Results: 137 148 // in xt we have simulaton according to the model 138 149 // in x we have "reality" 139 140 150 xtm ( 0 ) =x[0];xtm ( 1 ) =x[1];xtm ( 2 ) =x[2];xtm ( 3 ) =x[3]; 141 xdif =xtm-xt;151 xdif = xtm-xt; 142 152 if ( xdif ( 3 ) >pi ) xdif ( 3 )-=2*pi; 143 153 if ( xdif ( 3 ) <-pi ) xdif ( 3 ) +=2*pi; 154 155 ddif = hxu.eval(xtm,ut) - dt; 144 156 145 157 //Rt = 0.9*Rt + xdif^2 146 Qt*=0.0 ;158 Qt*=0.01; 147 159 Qt += outer_product ( xdif,xdif ); //(x-xt)^2 148 Qrec.set_row ( tK, vec ( Qt._data(),16 ) ); 160 Rt*=0.01; 161 Rt += outer_product ( ddif,ddif ); //(x-xt)^2 149 162 150 163 //ESTIMATE 151 164 Efix.bayes(concat(dt,ut)); 152 165 // 153 Eop.set_parameters ( &fxu,&hxu,(Qt+1e-16*eye(4)),( 1*eye(2)));166 Eop.set_parameters ( &fxu,&hxu,(Qt+1e-16*eye(4)),(Rt+1e-3*eye(2))); 154 167 Eop.bayes(concat(dt,ut)); 168 // 169 Edi.set_parameters ( &fxu,&hxu,(diag(diag(Qt))+1e-16*eye(4)),(diag(diag(Rt))+1e-3*eye(2))); 170 Edi.bayes(concat(dt,ut)); 155 171 156 Xt.set_row ( tK,vec ( x,9 ) ); //vec from C-array 157 XtM.set_row ( tK,xt ); //vec from C-array 158 XtF.set_row ( tK,Efix_ep.mean() ); 159 XtO.set_row ( tK,Eop_ep.mean() ); 160 Dt.set_row ( tK, concat ( dt,ut ) ); 172 //LOG 173 L.logit(X_log, vec(x,4)); //vec from C-array 174 L.logit(Efix_log, Efix_ep.mean() ); 175 L.logit(Eop_log, Eop_ep.mean() ); 176 L.logit(Edi_log, Edi_ep.mean() ); 177 L.logit(Q_log, vec(Qt._data(),16) ); 178 L.logit(R_log, vec(Rt._data(),4) ); 179 180 L.step(false); 161 181 } 162 182 163 char tmpstr[200]; 164 sprintf ( tmpstr,"%s/%s","variance/","format" ); 165 ofstream form ( tmpstr ); 166 form << "# Experimetal header file"<< endl; 167 dirfile_write ( form,"variance/",Xt,"X","{isa isb om th }" ); 168 dirfile_write ( form,"variance/",XtM,"Xsim","{isa isb om th }" ); 169 dirfile_write ( form,"variance/",XtO,"XO","{isa isb om th }" ); 170 dirfile_write ( form,"variance/",XtF,"XF","{isa isb om th }" ); 171 dirfile_write ( form,"variance/",Dt,"D","{isa isb usa usb }" ); 172 dirfile_write ( form,"variance",Qrec,"Q","{ }" ); 183 L.step(true); 173 184 174 185 return 0;