振动系统的PID控制
%%%PID g跟踪控制,关键是控制确定Kp和Kd以及Kcclear all
clc
num=;
den=;
=tf2ss(num,den);
%系统参数
Tao=0.02;T=0.01;Umin=0.07;Umax=0.7;
Kp=5;Kd=0.1;Kc=0.01;Tmax=5;
X=;e=0;de=0;ie=0;
%R=1*ones(1,Tmax/T);
h=T;Nd=Tao/T;
for n=1:1:Tmax/T
uu=-(Kp*e+Kd*de+Kc*ie); %PID控制器
K1=A*X+B*uu;K2=A*(X+h*K1/2)+B*uu;K3=A*(X+h*K2/2)+B*uu; K4=A*(X+h*K3)+B*uu; %龙格计算
X=X+(h/6)*(K1+K2*2+2*K3+K4);
y=C*X+D*uu;
yy(n)=y;TT(n)=n*T-T; %输出保存
e1=e;e=y-1.5;de=(e-e1)/T;ie=ie+e*T; %误差跟踪——1.5
end
plot(TT,yy);grid on;
function a=single_PI()
clc
clear all
%%%%%%%%PID控制%%%%%%%%%%%%%
de=0;ie=0; e=0; u=0;
Kc=28;Kp=25;Kd=0.82; %PID控制参数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=1;h=0.01; x10=; u=0; t=0; Tmax=2; %计算程序用得初始值
while t<=Tmax
u=Kp*e+Kc*ie+Kd*de; %控制规律
%%%%%%%%%%%%%%%%%%%%%四阶龙格计算%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=derives(t,x10,u);
m1=h*dX; t=t+0.5*h;X=x10+0.5*m1; %更新导数
=derives(t,X,u);
m2=h*dX; X=x10+0.5*m2; %更新导数
=derives(t,X,u);
m3=h*dX; t=t+0.5*h; X=x10+m3; %更新导数
=derives(t,X,u);
m4=h*dX;
x10=x10+(1/6)*(m1+2*m2+2*m3+m4);
C=; %振动函数输出
y=C*x10;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rink=0; %跟踪对象,或者比较对象
e1=e; e=rink-y; de=(e-e1)/h;ie=ie+e; %比列积分和微分积分多注意
XX(n)=y;RR(n)=rink;Time(n)=t; %用于保存
n=n+1;
end
plot(Time,XX,'b',Time,RR,'r');grid on;
end
%求导数
function =derives(t,X,u)
fi=10*exp(-0.5*t).*cos(3*t); %振动系统对象
A=[-14.6254 0;1 0]; B=; f=u+fi;
dX=A*X+B*f;
end
页:
[1]