一个完整的PID程序,希望对大家有帮助
elseif M==2 %Using Simple PID
u(k)=kc*error(k)+kd*(error(k)-error_1)+ki*ei; end
%Restricting the output of controller
if u(k)>=10
u(k)=10;
end
if u(k)<=-10
u(k)=-10;
end
u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k); y_3=y_2;y_2=y_1;y_1=yout(k);
error_1=error(k);
end
figure(1);
plot(time,rin,'b',time,yout,'r');
xlabel('time(s)');ylabel('rin,yout');
title('PID仿真结果图');