Changeset 1440
- Timestamp:
- 03/18/12 00:18:17 (13 years ago)
- Location:
- applications/pmsm/simulator_zdenek/ekf_example
- Files:
-
- 2 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/CMakeLists.txt
r1381 r1440 2 2 add_executable (simulmpf pmsm_mod.cpp pwm.cpp regulace.cpp mpf_double.cpp simulmpf.cpp ) 3 3 4 add_executable (test_exp test_exp.c) 5 TARGET_LINK_LIBRARIES( test_exp m ) 6 4 7 include_directories(../../bdm) 5 8 add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp) -
applications/pmsm/simulator_zdenek/ekf_example/mpf_double.cpp
r1439 r1440 2 2 #include "math.h" 3 3 #include <stdio.h> 4 //#include <libconfig/lib/grammar.y> 4 #include "RArandn.h" 5 #include "fast_exp.h" 5 6 6 7 static floatx om[N]; … … 18 19 static floatx r; 19 20 20 21 #define MAXrand 10022 #define MAXrandn 10023 static const floatx RArandu[MAXrand]={0.8147, 0.9058, 0.1270, 0.9134, 0.6324, 0.0975, 0.2785, 0.5469, 0.9575, 0.9649,24 0.1576, 0.9706, 0.9572, 0.4854, 0.8003, 0.1419, 0.4218, 0.9157, 0.7922, 0.9595, 0.6557, 0.0357,25 0.8491, 0.9340, 0.6787, 0.7577, 0.7431, 0.3922, 0.6555, 0.1712, 0.7060, 0.0318, 0.2769, 0.0462,26 0.0971, 0.8235, 0.6948, 0.3171, 0.9502, 0.0344, 0.4387, 0.3816, 0.7655, 0.7952, 0.1869, 0.4898,27 0.4456, 0.6463, 0.7094, 0.7547, 0.2760, 0.6797, 0.6551, 0.1626, 0.1190, 0.4984, 0.9597, 0.3404,28 0.5853, 0.2238, 0.7513, 0.2551, 0.5060, 0.6991, 0.8909, 0.9593, 0.5472, 0.1386, 0.1493, 0.2575,29 0.8407, 0.2543, 0.8143, 0.2435, 0.9293, 0.3500, 0.1966, 0.2511, 0.6160, 0.4733, 0.3517, 0.8308,30 0.5853, 0.5497, 0.9172, 0.2858, 0.7572, 0.7537, 0.3804, 0.5678, 0.0759, 0.0540, 0.5308, 0.7792,31 0.9340, 0.1299, 0.5688, 0.4694, 0.0119, 0.337132 };33 static const floatx *randu_i=&RArandu[0];34 const static floatx *randu_last=&RArandu[MAXrand-1];35 36 static const floatx RArandn[MAXrandn]={37 0.6353, -0.6313, -1.0181, 0.4801, 0.4855, 0.9901, -0.5412, -1.0290, 1.0641, -0.0132,38 -0.6014, -2.3252, -0.1821, 0.6682, -0.0050, 0.2189, -1.3335, 0.2431, -0.2454, -0.5803,39 0.5512, -1.2316, 1.5210, -0.0783, -0.2762, 0.2617, 1.0727, -1.2566, -1.5175, 2.1363,40 -1.0998, 1.0556, -0.0384, 0.8892, 1.2765, 1.2134, -0.7121, -0.3472, 0.0097, -0.2576,41 0.0860, -0.1132, 1.2274, 2.3093, 1.8634, -0.2747, -0.0113, -0.9414, 0.0714, -1.4095,42 -2.0046, 0.3792, -0.6962, 0.5246, -0.5226, -0.1331, -0.0008, -1.1746, 0.3165, 1.7701,43 -0.4931, 0.9442, 0.0075, -0.0118, 0.1034, -1.2705, -0.2494, -1.0211, 0.4998, 0.3255,44 0.4620, -2.1204, -0.7829, 0.9131, -0.8076, -1.6636, 0.3966, -0.4017, 1.2781, -1.1190,45 -0.3210, -0.6447, 0.5869, 0.0559, 0.6804, -0.7036, -0.2640, 0.1737, -0.5478, 0.6204,46 1.2366, -0.7043, -0.2512, -1.1071, -2.3646, 0.2809, -1.6640, -0.1161, 0.2608, 1.269847 };48 static const floatx *randn_i=&RArandn[0];49 const static floatx *randn_last=&RArandn[MAXrandn-1];50 21 51 22 floatx qrandu() { … … 185 156 Kq = *Pt_i*Cq*ro; 186 157 187 (*Pt_i) =(*Pt_i)*( 1.0- ( Kd*Cd+Kq*Cq ) );158 (*Pt_i)*=( 1.0- ( Kd*Cd+Kq*Cq ) ); 188 159 189 160 ypd = Cd**om_i; … … 212 183 213 184 } 214 maxlwi=-1e10;185 /* maxlwi=-1e10; 215 186 lw_i = &lwi[0]; 216 187 for ( i=0;i<N;i++,lw_i++ ) { 217 188 if ( *lw_i>maxlwi ) maxlwi=*lw_i; 218 } 189 }*/ 219 190 lw_i = &lwi[0]; 220 191 w_i = &w[0]; 221 192 for ( i=0;i<N;i++,lw_i++,w_i++ ) { 222 *lw_i-=maxlwi;223 (*w_i)= exp( *lw_i ); // always resample -> wmin=1/n;193 // *lw_i-=maxlwi; 194 (*w_i)=EXP ( *lw_i ); // always resample -> wmin=1/n; 224 195 } 225 196 … … 260 231 void mpf_mean ( floatx *Ecosth, floatx *Esinth, floatx *Eome ) { 261 232 int i; 233 floatx *w_i=&w[0]; 234 floatx *cth_i=&cth[0]; 235 floatx *sth_i=&sth[0]; 236 floatx *om_i=&om[0]; 262 237 *Ecosth=0.0; 263 238 *Esinth=0.0; 264 239 *Eome=0.0; 265 for ( i=0;i<N;i++ ) {266 *Ecosth+=( w[i]*(cth[i]));267 *Esinth+=( w[i]*(sth[i]));268 *Eome+=( w[i]*(om[i]));240 for ( i=0;i<N;i++,w_i++,cth_i++,sth_i++,om_i++ ) { 241 *Ecosth+=(*w_i)*(*cth_i); 242 *Esinth+=(*w_i)*(*sth_i); 243 *Eome+=(*w_i)*(*om_i); 269 244 } 270 245 -
applications/pmsm/simulator_zdenek/ekf_example/mpf_double.h
r1439 r1440 5 5 //#define pi 3.141596 6 6 7 #define N 17 #define N 4 8 8 9 9 #define Lsd Ls*0.9