PID相关问题仿真

    xiaoxiao2022-07-02  116

    写在前面的话:文章内容来源于但不限于网络、书籍、个人心得体会等,意在总结和方便各位同行快速参考,共同学习进步,记录自己的问题。错误在所难免,有请各位批评斧正。如有侵权,烦请第一时间通知,我会立即删除相关内容,万分感谢!

     

    clc; %target sig,square wave T=1; I=[1,T;0,1]; t=5e2; V=square(2*pi/50*(1:500))*20; l=[0.5*T^2,T]'; KP=5e-1;KI=KP;KD=KP; [sig,u,e] = PIDctrl(c,I,l,KP,KI,KD); figure subplot(4,1,1) plot(u,'-k','linewidth',2) title('u条件曲线','fontsize',15) xlabel('t/s','fontsize',15) ylabel('u') grid on subplot(4,1,2) hold on plot(e,'-k','linewidth',2) title('误差跟随时间','fontsize',15) xlabel('t/s','fontsize',15) ylabel('error') grid on legend({'sig','Y'},'fontsize',15) subplot(4,1,3) plot(signal(1,:),'-k','linewidth',2) title('z信号状态曲线','fontsize',15) xlabel('t/s','fontsize',15) ylabel('x','fontsize',15) grid on subplot(4,1,4) plot(signal(2,:),'-k','linewidth',2) plot(Y,'-r','linewidth',2) title('条件曲线','fontsize',15) xlabel('t/s','fontsize',15) ylabel('Y/x_2') grid on function [sig,S,V] = PIDctrl(c,I,l,KP,KI,KD) S=zeros(1,length(c)); sig=zeros(2,length(c)); V=zeros(1,length(c)); E=1e-2; for k=2:length(c)-1 sig(:,k+1)=I*sig(:,k)+l*Y(:,k); V(k+1)=c(k+1)-sig(2,k+1); if abs(V(k+1))<E S(k+1)=S(k)+KP*(V(k+1)-V(k))+KI*V(k+1)+KD*(V(k+1)+e(k-1)-2*V(k)); else S(k+1)=S(k)+KP*(V(k+1)-V(k))+KD*(V(k+1)+V(k-1)-2*V(k)); end end end

     

     

     

    最新回复(0)