⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motor.m

📁 这是我参考做的模型其中有三个文件:一个是初始化文件
💻 M
字号:
function [sys,x0,str,ts] = motor5ab(t,x,u,flag)

%the induction motor model in alfa-beta coordinates


% The following outlines the general structure of an S-function.
%
switch flag,

  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes;

  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
    sys=mdlDerivatives(t,x,u);

  %%%%%%%%%%
  % Update %
  %%%%%%%%%%
  case 2,
    sys=mdlUpdate(t,x,u);

  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys=mdlOutputs(t,x,u);

  %%%%%%%%%%%%%%%%%%%%%%%
  % GetTimeOfNextVarHit %
  %%%%%%%%%%%%%%%%%%%%%%%
  case 4,
    sys=mdlGetTimeOfNextVarHit(t,x,u);

  %%%%%%%%%%%%%
  % Terminate %
  %%%%%%%%%%%%%
  case 9,
    sys=mdlTerminate(t,x,u);

  %%%%%%%%%%%%%%%%%%%%
  % Unexpected flags %
  %%%%%%%%%%%%%%%%%%%%
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);

end

% end sfuntmpl

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes

%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%



sizes = simsizes;

sizes.NumContStates  = 5;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 4;
sizes.NumInputs      = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);

%
% initialize the initial conditions
%
% the states are [ids;iqs;phidr;phiqr;wr]wr 为转子机械转速
%
%global Lm
x0  = [0 0 0.01 0 0];%转子磁链d分量(励磁分量)有初始值为0.01

%
% str is always an empty matrix
%
str = [];

%
% initialize the array of sample times
%
ts  = [0 0];

% end mdlInitializeSizes

%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)

%
%the state variables are [ids;iqs;phidr;phiqr;wr];
%
 
global Rs  Rr Lm  Ls  Lr
global np J b lo
%三相额定电压 =200V,额定频率 =50Hz,额定功率 =2.2kW,额定转速 =1430r/min,
% 额定负载 =14.6Nm,Rs=0.877?; Rr=1.47?; Ls=165.142e-3H;
%  Lr=Ls; Lm=160.8e-3H; np=2; J=0.015 kgm2
lo=1/(Ls*Lr-Lm^2);
alfa=Rr/Lr;
mu=np*Lm/(J*Lr);


sys(1)=lo*((-Rs*Lr-alfa*Lm^2)*x(1)+Lm/Lr*Rr*x(3)+Lm*x(4)*np*x(5)+Lr*u(1));
sys(2)=lo*((-Rs*Lr-alfa*Lm^2)*x(2)-Lm*np*x(5)*x(3)+Lm/Lr*Rr*x(4)+Lr*u(2));
sys(3)=lo*(Lm*alfa/lo*x(1)-alfa/lo*x(3)-np*x(5)/lo*x(4));
sys(4)=lo*(Lm*alfa/lo*x(2)+np*x(5)/lo*x(3)-alfa/lo*x(4));
sys(5)=mu*(x(2)*x(3)-x(1)*x(4))-u(3)/J;
 % end mdlDerivatives

%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)

sys = [];

% end mdlUpdate

%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)

%
% outputs are the rotor speed,the square of rotor flux and electric torque
%
global Rs Rr Lm Lr Ls
global np J b lo

mu=np*Lm/(J*Lr);


sys(1)=x(1);
sys(2)=x(2);
sys(3)=x(5);
sys(4)=mu*J*(x(2)*x(3)-x(1)*x(4));


% end mdlOutputs

%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block.  Note that the result is
% absolute time.  Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)

sampleTime = 1;    %  Example, set the next hit to be one second later. 
sys = t + sampleTime;

% end mdlGetTimeOfNextVarHit

%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)

sys = [];

% end mdlTerminate

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -