1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
function [sys,x0,str,ts]=sm_out(t,x,u,flag)
%description of the machine with s-function
switch flag,
case 0 % System initialization
sizes.NumContStates = 5; %Number of continuous states
sizes.NumDiscStates = 0; %Number of discrete states
sizes.NumOutputs = 5; %Number of outputs
sizes.NumInputs = 6; %Number of inputs
sizes.DirFeedthrough = 0; %Flag for direct feedthrough
sizes.NumSampleTimes = 1; %Number of sample times
sys = simsizes(sizes);
ts=[0 0];
str=[];
x0=zeros(5,1);
case 1 %Calculation of derivatives
parameters;
Rc1=Rin;%outside resistance
%v=Ri+Ma*di/dt
R=[-Rs,Lq*p*u(6),0,0,-p*u(6)*MsQ ;
-Ld*p*u(6),-Rs,p*u(6)*Msfi,p*u(6)*MsD,0;
0,0,Rf,0,0;
0,0,0,RD,0;
0,0,0,0,RQ]; %stator and rotor resistances matrix
Ma=[-Ld 0 Msfi MsD 0;
0 -Lq 0 0 MsQ;
-Msfi 0 Lf MfD 0;
-MsD 0 MfD LD 0;
0 -MsQ 0 0 LQ ];
BB1=inv(Ma);
BB=BB1;%*B1;
AA=-BB1*R;%-1e-5*eye(5);%
sys=[AA*x(1:5)+BB*[u(1);u(2);u(3);0;0]];
case 3 % the outputs
parameters;
sys=[x];
otherwise
sys=[];
end
% Initialization
% mdlInitializeSizes
% flag = 0
%
% Calculation of next sample hit (variable sample time block only)
% mdlGetTimeOfNextVarHit
% flag = 4
%
% Calculation of outputs
% mdlOutputs
% flag = 3
%
% Update of discrete states
% mdlUpdate
% flag = 2
%
% Calculation of derivatives
% mdlDerivatives
% flag = 1
%
% End of simulation tasks
% mdlTerminate
% flag = 9
% Call of parameters which are necessary to make calculation |
Partager