[38] | 1 | /* |
---|
| 2 | Main simulation module |
---|
| 3 | |
---|
| 4 | Simulation of PMSM drive ... floating point |
---|
| 5 | |
---|
| 6 | Illustration demo for object design - project EKF and PF |
---|
| 7 | |
---|
| 8 | Z. Peroutka |
---|
| 9 | |
---|
| 10 | REV. 16.3.2008 |
---|
| 11 | |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
| 15 | #include <math.h> |
---|
| 16 | #include "regulace.h" |
---|
| 17 | #include "simulator.h" |
---|
| 18 | |
---|
| 19 | static double param[7]={0.28,0.003465,0.1989,0.0,4,1.5,0.04}; |
---|
| 20 | // [Rs, Ls, Fmag, Bf, p, kp, J = 0.04?]; |
---|
| 21 | |
---|
| 22 | double h, t, t_end, t_sense, h_disp=0; |
---|
| 23 | |
---|
| 24 | static int print_counter=0; |
---|
| 25 | static double Ww; |
---|
| 26 | |
---|
| 27 | static int k_rampa=1; |
---|
| 28 | static long k_rampa_tmp=0; |
---|
| 29 | |
---|
| 30 | FILE *fw; |
---|
| 31 | |
---|
[1380] | 32 | int main(void) |
---|
[38] | 33 | { |
---|
| 34 | h=1e-6; |
---|
| 35 | |
---|
| 36 | t_end=4.; // profil Isq 5s, rozbeh 12s, rozbeh +/- 20s, reverzace 12s |
---|
| 37 | t_sense=0.0; // 1. |
---|
| 38 | t=0.; |
---|
| 39 | |
---|
| 40 | fw=fopen("data\\graf1.txt","w"); |
---|
| 41 | |
---|
| 42 | set_parameters(*param,*(param+1),*(param+2),*(param+3),*(param+4),*(param+5),*(param+6), 200., 3e-6, h); |
---|
| 43 | |
---|
| 44 | Ww=0.; |
---|
| 45 | |
---|
| 46 | while (t<=t_end) |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | Ww+=k_rampa*2.*M_PI*2e-4; //1000Hz/s |
---|
| 50 | if (Ww>2.*M_PI*150.) {Ww=2.*M_PI*150.; if (k_rampa_tmp<500000) k_rampa_tmp++; else {k_rampa=-1;k_rampa_tmp=0;}} |
---|
| 51 | if (Ww<-2.*M_PI*150.) Ww=-2.*M_PI*150.; /* */ |
---|
| 52 | |
---|
| 53 | eval(Ww); |
---|
| 54 | |
---|
| 55 | if (t>=t_sense) |
---|
| 56 | if (print_counter>199) |
---|
| 57 | { fprintf(fw,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",t,x[0],x[1],x[6],*ladeni_regulace,x[7],*(ladeni_regulace+2),x[4],x[5],x[3],x[2],Ww,*(ladeni_regulace+1),0.95,*(ladeni_regulace+4),*(ladeni_regulace+5),x[10],*(ladeni_regulace+6),200., *(ladeni_regulace+7),0,0,*(ladeni_regulace+8),*(ladeni_regulace+9)); |
---|
| 58 | // t, Isx, Isy, Isd, Isdw, Isq, Isqw, M, Fs, poloha, rychlost, rychlost_w, Urm, Urm_max, |
---|
| 59 | // Fs_model, M_model, zatezny uhel (beta), zatezny uhel vypocteny z napeti (zbeta), Uc |
---|
| 60 | print_counter=0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if (h_disp>0.2) |
---|
| 64 | { printf("%f \n",t); |
---|
| 65 | h_disp=0; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | t+=h; |
---|
| 69 | h_disp+=h; |
---|
| 70 | print_counter++; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | fclose(fw); |
---|
[1380] | 74 | return 0; |
---|
[38] | 75 | } |
---|