被控对象为一电机模型传递函数:
式中,J = 0.0067;B=0.10。
采用M函数的形式,利用ODE45的方法求解连续对象方程,输入指令信号为yd(k)=0.50sin(2*3.14*t),采用PID控制方法设计控制器,其中kp=20.0 ,kd=0.50。PID正弦跟踪结果如图所示。
控制主程序;
%Discrete PID control for continuous plant
clear all;
close all;
ts=0.001;%Sampling time
xk=zeros(2,1);
e_1=0;
u_1=0;
for k=1:1:2000
time(k)=k*ts;
yd(k)=0.50*sin(1*2*pi*k*ts);
para=u_l;
tSpan=[0 ts];
[tt,xx]=ode45(chapl_6plant ,tSpan, xk,[],para);
xk=xx(length(xx),:);
y(k)=xk(1);
e(k)=yd(k)-y(k);
de(k)=(e(k)-e_1)/ts;
u(k)-20.0*e(k)+0.50*de(k);%Control limit
if u(k)>10.0
u(k)=10.0;
end
if u(k)<-10.0
u(k)=-10.0;
end
u_l=u(k);
e_I=e(k);
end
figure(1);
plot(time,yd,'r, time,y,'k:' linewidth',2);
xlabel('time(s)');ylabel('yd,y);
legend('Tdeal position signal','Position tracking');
figure(2);
plot(time,yd-y,'r,linewidth',2);
xlabel('time(s)'),ylabel('error);
连续控制对象子程序:chap1_6plant.m
u=para;
J=0.0067;B-0.1;
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=-(B/J)*y(2)+(1/J)*u;