Changeset 62 for tests/pmsm_sim2.cpp
- Timestamp:
- 04/06/08 20:14:56 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tests/pmsm_sim2.cpp
r60 r62 19 19 #include "simulator.h" 20 20 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" 40 22 41 23 using namespace itpp; … … 54 36 void set_simulator_t(double &Ww) { 55 37 56 if (t>0. 0) x[8]=1.2; // 1A //0.2ZP38 if (t>0.2) x[8]=1.2; // 1A //0.2ZP 57 39 if (t>0.4) x[8]=10.8; // 9A 58 40 if (t>0.6) x[8]=25.2; // 21A … … 99 81 if (t>8.3) x[8]=10.8; // 9A 100 82 if (t>8.5) x[8]=25.2; // 21A 83 84 // x[8]=0.0; 101 85 } 102 86 103 87 int main() { 104 88 // Kalman filter 105 int Ndat = 30000;89 int Ndat = 90000; 106 90 double h = 1e-6; 107 91 int Nsimstep = 125; … … 113 97 // internal model 114 98 IMpmsm fxu; 115 // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz)99 // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz) 116 100 fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 117 101 // observation model … … 119 103 120 104 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" 123 108 chmat Q ( Qdiag ); 124 109 chmat R ( Rdiag ); 125 110 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); 128 113 129 114 RV rQ ( "100","{Q}","4","0" ); 130 115 EKF_unQ KFEp ( rx,ry,ru,rQ ); 116 KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) ); 131 117 KFEp.set_parameters ( &fxu,&hxu,Q,R ); 132 KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) );133 118 134 119 mgamma_fix evolQ ( rQ,rQ ); … … 139 124 epdf& pfinit=evolQ._epdf(); 140 125 M.set_est ( pfinit ); 141 evolQ.set_parameters ( 100000.0, Qdiag, 0.5);126 evolQ.set_parameters ( 5000.0, Qdiag, 0.9999 ); 142 127 143 128 // … … 190 175 //Exit program: 191 176 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 192 186 //////////////// 193 187 // Just Testing 194 NcFile nc ( "pmsm_sim.nc", NcFile::Replace ); // Create and leave in define mode188 /* NcFile nc ( "pmsm_sim2.nc", NcFile::Replace ); // Create and leave in define mode 195 189 if ( ! nc.is_valid() ) { std::cerr << "creation of NCFile failed."<<endl;} 196 190 197 191 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 }" ); 199 193 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 }" );*/ 201 195 return 0; 202 196 }