?? pid.m
字號:
% ***************************************************************************\
% PID Function
%
% This program has been written by the Technical Support Staff at Z-World in
% response to several customer requests. As such, it has NOT had the testing and
% validation procedures which our "standard" software products have. It is being
% made available as a sample. There is no warranty, implied or otherwise.
%
% The PID (Proportional Integral Derivative) function is used in mainly
% control applications. PIDCalc performs one iteration of the PID
% algorithm.
%
% While the PID function works, main is just a dummy program showing
% a typical usage.
%***************************************************************************/
% function ISE = PID(Proportion,Integral,Derivative)
clc;
clear;
Proportion = 4.8269;%2.591; % Proportional Const
Integral = 4.0806;%1.4079; % Integral Const
Derivative = 3.899;%1.1921; % Derivative Const
dt = 0.01; % 每一次迭代時間
Epock = 2000; % 所用時間20秒
PlantOut(1) = 0; % 初始輸出 0
for i =1:Epock
% 參考輸入
input(i) = 1;
% 傳感器輸出
if i==1
output(1) = 0;
else
output(i) = PlantOut(i);
end
% 計算偏差
Error(i) = input(i) - output(i);
% 指標(biāo)計算誤差累積
CumulateError(i) = Error(i)^2*dt;
% PID計算 用面積法近似積分 用變化量近似微分
ErrorArea(i) = Error(i)*dt;
if i == 1
dError = Error(i);
else
dError = Error(i) - Error(i-1);
end
PIDout(i) = Proportion * Error(i) + Integral * sum(ErrorArea) + Derivative * dError;
% 裝置輸出計算
gs(i) = 2/5*exp(-1/5*i*dt)*dt;
PlantOut(i+1) = PIDout*fliplr(gs)';
end
ISE = sum(CumulateError);
% 輸出響應(yīng)曲線
plot((0:dt:20),PlantOut);
hold on
plot((0:dt:20),1,':')
xlabel('t/s')
axis([0 20 0 1.4])
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -