PID算法实现该系统控制

2025-01-03 05:41:05
推荐回答(1个)
回答1:

增量式PID控制程序:
%Increment PID Controller
clear all
close all
ts=0.005;
sys=tf([0.1,10],[0.0004,0.0454,0.555,1.51,11],'inputdelay',0.2);
dsys=c2d(sys,ts,'z');
[num den]=tfdata(dsys,'v');
for k=1:44
yout(k)=0;
end
u_1=0;u_2=0;u_3=0;u_4=0;
y_1=0.0;y_2=0.0;y_3=0.0;y_4=0.0;
x=[0,0,0];error_1=0,error_2=0;
kp=0.016;ki=0.056;kd=1
for k=45:1000
time(k)=k*ts;
kp=0.55,ki=0,kd=0;
rin(k)=1.0;
du(k)=kp*x(1)+kd*x(2)+ki*x(3);
u(k)=u_1+du(k);
yout(k)=-den(2)*y_1-den(3)*y_2-den(4)*y_3-den(5)*y_4+num(1)*u_1+num(2)*u_2+num(3)*u_3+num(4)*u_4
error=rin(k)-yout(k);
u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k);
y_4=y_3;y_3=y_2;y_2=y_1;y_1=yout(k);
x(1)=error-error_1; %calculating p
x(2)=error-2*error_1+error_2; %calculating d
x(3)=error; %calculating i
error_2=error_1;error_1=error;
end
figure(1);
plot(time,rin,'b',time,yout,'r');
xlabel('time(s)'),ylabel('rin,yout');
title('单位阶跃响应曲线')

Z-N法整定:
clear all
close all
ts=0.005;
sys=tf([0.1,10],[0.0004,0.0454,0.555,1.51,11],'inputdelay',0.2);
dsys=c2d(sys,ts,'z');
rlocus(dsys)