| 1 | %simulator PMSM for PCRB, choice: Ls/Ldq & correct/incorrect expectation | 
|---|
| 2 | clear all; | 
|---|
| 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
|---|
| 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
|---|
| 5 |  | 
|---|
| 6 | %for experiments | 
|---|
| 7 |     %ctrl.> 2,5,9,10 | 
|---|
| 8 |     %model> {1},{7},{4,6,10},{12} - {eq.} sort from worst | 
|---|
| 9 |  | 
|---|
| 10 | %   settings | 
|---|
| 11 |     % ON/OFF  MODEL    IS CORR. E   INDUCT. L | 
|---|
| 12 | model(1) = 1; % alpha-beta    nE      Ls | 
|---|
| 13 | model(2) = 0; % d-q           nE      Ls | 
|---|
| 14 | model(3) = 0; % 5sc           nE      Ls | 
|---|
| 15 |  | 
|---|
| 16 | model(4) = 0; % alpha-beta    E       Ls | 
|---|
| 17 | model(5) = 0; % d-q           E       Ls | 
|---|
| 18 | model(6) = 0; % 5sc           E       Ls | 
|---|
| 19 |  | 
|---|
| 20 | model(7) = 1; % alpha-beta    nE      Ldq | 
|---|
| 21 | model(8) = 0; % d-q           nE      Ldq | 
|---|
| 22 | model(9) = 0; % 5sc           nE      Ldq | 
|---|
| 23 |  | 
|---|
| 24 | model(10) = 0; % alpha-beta   E       Ldq | 
|---|
| 25 | model(11) = 0; % d-q          E       Ldq | 
|---|
| 26 | model(12) = 0; % 5sc          E       Ldq | 
|---|
| 27 |  | 
|---|
| 28 |     % CONTROL | 
|---|
| 29 |     % 1 -   ome = ref_ome, the = integral(ome), ial = ibe = 0 | 
|---|
| 30 |     % 2 -   PI control     | 
|---|
| 31 |     % 3 -   PI + injection (sin -> dq) | 
|---|
| 32 |     % 4 -   PI + injection (rect. -> dq) | 
|---|
| 33 |     % 5 -   PI + injection (const. -> ud) *J4 ~ 3e-6 for all exc. dq | 
|---|
| 34 |     % 6 -   PI + rnd error (ref_ome) *J4: dq bad; ab,5sc Ls ~ 4e-4; ab,5sc Ldq ~5e-6   | 
|---|
| 35 |     % 7 -   PI + injection (sin -> al-be) | 
|---|
| 36 |     % 8 -   PI + injection (rect. -> al-be) | 
|---|
| 37 |     % 9 -   PI + bicrit. (sign) *J4 ~ 1e-3 for all exc. dq | 
|---|
| 38 |     % 10 -  PI + rnd bicrit. selection (5)  | 
|---|
| 39 |      | 
|---|
| 40 | % control = 2; | 
|---|
| 41 | % control = 5; | 
|---|
| 42 | % control = 8; %high frekq. | 
|---|
| 43 | % control = 9; | 
|---|
| 44 | control = 10; | 
|---|
| 45 |     % param. amp*phi(injom*dt*t) //phi = sin,cos,sign(sin),sing(cos) | 
|---|
| 46 |      | 
|---|
| 47 | amp = 10.0; | 
|---|
| 48 | injom = 5000; | 
|---|
| 49 |  | 
|---|
| 50 |     %cov Q, R matrices | 
|---|
| 51 | %         %noise | 
|---|
| 52 | % Q = diag([0.0013 0.0013 5.0e-6 1.0e-10]); | 
|---|
| 53 | % R = diag([0.0006 0.0006]); | 
|---|
| 54 | %         %EKF | 
|---|
| 55 | % Q = diag([0.1 0.1 0.1 0.001]); | 
|---|
| 56 | % R = diag([0.05 0.05]); | 
|---|
| 57 | %         %test | 
|---|
| 58 | Q = diag([0.1 0.1 0.1 10]); | 
|---|
| 59 | R = diag([0.5 0.5]); | 
|---|
| 60 |  | 
|---|
| 61 | %horizont | 
|---|
| 62 | T = 120000;  | 
|---|
| 63 |  | 
|---|
| 64 | %reference signal  | 
|---|
| 65 | % ref_profile = [1, 10, 50, 200, 200, 30, 0, 0, -1, -10, -50, -200, -200, -30, 0]; | 
|---|
| 66 | ref_profile = [0, -1, 3, 6, 9, 6, 3, 0, 0, 0, 0, 0,0,-3, -6, -3]; | 
|---|
| 67 | % ref_profile = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | 
|---|
| 68 | % ref_profile = ones(1,16); | 
|---|
| 69 |  | 
|---|
| 70 | [var_ome, var_th, var_th2] = fpcrb(model, control, amp, injom, Q, R, T, ref_profile); | 
|---|
| 71 |  | 
|---|
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
|---|
| 73 | %   plot | 
|---|
| 74 |  | 
|---|
| 75 | %axis | 
|---|
| 76 | xax = 1:T-1; | 
|---|
| 77 | dt = 0.000125; | 
|---|
| 78 | timex = (xax)*dt; | 
|---|
| 79 | cmp = lines(sum(model)); | 
|---|
| 80 | for i=1:sum(model) | 
|---|
| 81 |     figure(1); | 
|---|
| 82 |     hold on; | 
|---|
| 83 |     plot(timex, var_ome(xax,i),'Color',cmp(i,:)); | 
|---|
| 84 |      | 
|---|
| 85 |     figure(2); | 
|---|
| 86 |     hold on; | 
|---|
| 87 |     plot(timex, var_th(xax,i),'Color',cmp(i,:)); | 
|---|
| 88 |      | 
|---|
| 89 |     figure(3); | 
|---|
| 90 |     hold on; | 
|---|
| 91 |     plot(timex, var_th2(xax,i),'Color',cmp(i,:)); | 
|---|
| 92 | end | 
|---|
| 93 |  | 
|---|
| 94 | sound(chirp(0:0.001:2,0,1,150)); | 
|---|