-
大小: 7KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-14
- 语言: Matlab
- 标签: S-Function PID控制器
资源简介
使用S-Function函数实现离散PID控制器,并建立simulink仿真模型。
代码片段和文件信息
function [sysx0strts] = dPID(txuflagkpkikd)
%SFUNTMPL General M-file S-function template
switch flag
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0
[sysx0strts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1
sys=mdlDerivatives(txu);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2
sys=mdlUpdate(txu);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3
sys=mdlOutputs(txukpkikd);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4
sys=mdlGetTimeOfNextVarHit(txu);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9
sys=mdlTerminate(txu);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
DAStudio.error(‘Simulink:blocks:unhandledFlag‘ num2str(flag));
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes initial conditions and sample times for the S-function.
%=============================================================================
%
function [sysx0strts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 4;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [0;0;0;0];
str = [];
ts = [-2 0];
% end mdlInitializeSizes
function sys=mdlDerivatives(txu)
sys = [];
% end mdlDerivatives
%=============================================================================
% mdlUpdate
% Handle discrete state updates sample time hits and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(txu)
x(3)=x(2);
x(2)=x(1);
x(1)=u;
x(4)=u+x(4);
sys =x;
% end mdlUpdate
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(txukpkikd)
sys=kp*x(1)+ki*0.01*x(4)+kd*(x(2)-x(3))/0.01;
% 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(txu)
sampleTime = 0.01;% Example set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%============
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 20563 2012-11-05 16:52 unti
文件 3132 2012-11-05 16:49 dPID.m
----------- --------- ---------- ----- ----
23695 2
相关资源
-
太阳能电池MPPT研究用simuli
nk仿真模 - PID控制器与状态反馈控制器MATLAB教学
- Small Unmanned Aircraft:Theory and Practice 源
- 恒压频比交流调速MATLAB仿真
-
simuli
nk仿真三相异步电动机的起动过 -
Simuli
nk单向感应电动机仿真模型 -
基于SIMUli
nk的F-14俯仰轴仿真程序代 - 双dq锁相环 算法matlab仿真
-
柴油机SIMUli
nk模型.rar - 大规模DFIG风电场的模型
-
工程用光伏电池 matlab simuli
nk 仿真模 -
直流电机制动simuli
nk仿真 - 模型预测控制MPC模型预测电流控制,
- 基于matlab的单相半波可控整流电路的
- 双馈风式风力发电机仿真.slx
- 双PWM调速系统的仿真模型.rar
- 电机pwm仿真模型
- SAR ADC模型
- MATLAB实现SVPWM
- 车辆ABS系统滑移率Bang-Bang、PID控制模
- matlab整流电路
-
基于simuli
nkpq检测STATCOM的三角波控制 -
基于simuli
nk无锁相环检测STATCOM的三 - fuzzy-pid(模糊PID控制器)matlab simuli
-
qpsk调制解调器simuli
nk仿真 -
buck电路simuli
nk仿真(参数调好直接 -
BCH编码与解码的simuli
nk仿真 - 神经网络控制,有s模块源码及simuli
-
数字基带调制解调 simuli
nk仿真 -
QPSK调制与解调的simuli
nk仿真
评论
共有 条评论