MATLAB时间最优PID控制算法
function [ output_args ] = Untitled3( input_args )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
clear all;
close all;
ts=20;
sys=tf([1],[60,1],'inputdelay',80);
dsys=c2d(sys,ts,'zoh');
[num,den]=tfdata(dsys,'v');
u1=0;u2=0;u3=0;u4=0;u5=0;
y1=0;y2=0;y3=0;
error1=0;error2=0;
ei=0;
for k=1:1:200
time(k)=k*ts;
yd(k)=1.0;
y(k)=-den(2)*y1+num(2)*u5;
error(k)=yd(k)-y(k);
kp=0.45;kd=12;ki=0.0048;
A=0.4;B=0.6;
ei=ei+(error(k)+error1)/2*ts;
M=1;
if M==1
if abs(error(k))<=B
f(k)=1;
elseif abs(error(k))>B&abs(error(k))<=A+B
f(k)=(A-abs(error(k))+B)/A;
else f(k)=0;
end
elseif M==2
f(k)=1;
end
u(k)=kp*error(k)+kd*(error(k)-error1)/ts+ki*f(k)*ei;
if u(k)>=10
u(k)=10;
end
if u(k)<=-10
u(k)=-10;
end
u5=u4;u4=u3;u3=u2;u2=u1;u1=u(k);