控制对象为:
采样时间为1ms,采用z变换进行离散化,经过z变换后的离散化对象为:
y(k)=-den(2)y(k -1)- den(3)y(k -2)- den(4)y(k-3)+num(2)u(k -1)+ num(3)u(k -2)+ num(4)u(k-3)
设计离散PID控制器。其中,S为信号选择变量,S=1时为阶跃跟踪,S=2时为方波跟踪,S=3时为正弦跟踪。PID阶跃跟踪结果如图所示。
仿真程序:
%PID Controller
clear all;
close all;
ts=0.001;
sys=tf(5.235e005,[1,87.35,1.047004,0]);
dsys=c2d(sys,ts,'z');
[num,den]=tfdata(dsys,'v');
u_1=0.0;u_2=0.0;u_3=0.0;
y1=0.0;y2=0.0;y_3=0.0;
X-[0,0,0);
error_1=0;
for k=1:1:500
time(k)=k *ts;
S=3;
if S==1
kp=0.50;ki=0.001;kd=0.001;
yd(k)=1; %Step Signal
elseif S==2
kp=0.50;ki=0.001:;kd-0.001;
yd(k)=sign(sin(2*2*pi*k*ts)); %Square Wave Signal
elseif S==3
kp=1.5;ki=1.0;kd=0.01; %Sine Signal
yd(k)=0.5*sin(2*2*pi*k*ts);
end
u(k)=kp*x(1)+kd*x(2)+ki*x(3); %PID Controller
%Restricting the output of controller
if u(k)>-10
u(k)=10;
end
ifu(k)<=-10
u(k)=-10;
end
%Linear model
y(k)=-den(2)*y_1-den(3)*y_2-den(4)y_3+num(2)*u_l+num(3)*u_2+num(4)*u_3;
crror(k)=yd(k)-y(k);
%Return of parameters
u_3=u_2;u_2=u_1;u_1=u(k);y_3=y_2;y_2=y_l:y_I=y(k);
x(1)=error(k); %Calculating P
x(2)=(error(k)-error_1)/ts; %Calculating D
X(3)=x(3)+error(k)*ts; %Calculating I
error_1=error(k);
end
figure(1);
plot(time,yd,'r' time,y,'k:1 linewidth',2);xlabel('time(s));ylabel('yd,y');
legend('ldeal position signal','Position tracking');