matlab仿真程序如下:它的输出怎么调都是在1左右,求问大神是什么原因?
clear all;
close all;
ts=0.001;
%sys=tf(50,[0.125,7, 0]);
%dsys=c2d(sys,ts,'z');
%[num,den]=tfdata(dsys,'v');
num=[0 -0.00324 0.003325];
den=[1 -1.982 0.9834];
u_1=0.0;u_2=0.0;
y_1=0.0;y_2=0.0;
x=[0,0,0]';
error_1=0;
error_2=0;
for k=1:1:1000
time(k)=k*ts;
S=1;
if S==1
kp=30;ki=0;kd=0;
rin(k)=4; %Step Signal
elseif S==2
kp=10;ki=0.1;kd=15; %Sine Signal
rin(k)=0.5*sin(2*pi*k*ts);
end
du(k)=kp*x(1)+kd*x(2)+ki*x(3); %PID Controller
u(k)=u_1+du(k);
%Restricting the output of controller
if u(k)>=5
u(k)=5;
end
if u(k)<=-5
u(k)=-5;
end
%Linear model
yout(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2;
error(k)=rin(k)-yout(k);
%Return of parameters
u_2=u_1;u_1=u(k);
y_2=y_1;y_1=yout(k);
x(1)=error(k)-error_1; %Calculating P
x(2)=error(k)-2*error_1+error_2; %Calculating D
x(3)=error(k); %Calculating I
error_2=error_1;
error_1=error(k);
end
figure(1);
plot(time,rin,'b',time,yout,'r');
xlabel('time(s)'),ylabel('rin,yout');
figure(2);
plot(time,error,'r')
xlabel('time(s)');ylabel('error');
没做过,这个不一定非要完全按照PID的方法,实际上能完成你要完成的控制任务就行,思想都是一样的。就跟你扔飞镖原理相同