Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
PID and GPC control systems
subplot(212);stairs(0:Ts:1,u); xlabel('time (s)');ylabel('input u'); hold on Ts=0.05; sys_d = c2d(sys_c,Ts); [b,a] = tfdata(sys_d,'v'); y = filter(b,a,N[zeros(1,0.1/Ts) ones(1,1+0.9/Ts)]); u = filter([Kd/Ts+Kp -Kd/Ts],1,N[zeros(1,0.1/Ts) ones(1,1+0.9/Ts)]-y); subplot(211);plot(0:Ts:1,y); xlabel('time (s)');ylabel('output y'); legend('T_s=0.01s','T_s=0.025s','T_s=0.05s') hold on subplot(212);stairs(0:Ts:1,u); xlabel('time (s)');ylabel('input u'); legend('T_s=0.01s','T_s=0.025s','T_s=0.05s')
clc;clear; Ts=.1; lambda=.001; Ny=10; Nu=2; G=c2d(tf(1,[1 0 0]),Ts,'tustin'); [b,a]=tfdata(G,'v'); n=length(a); m=length(b);
delta=[1 -1]; Aba=conv(a,delta); [E,F]=diophantine(1,Aba,Ny); [G,H]=diophantGH(E,b,1,Ny); G=G(:,1:Nu); A=[0 1;0 0]; B=[0;1]; C=[1 0]; M=(G'G+lambdaeye(Nu))(G'); SimTL=10; % Simulation time Ns=SimTL/Ts; % Sample points x0=[0;0]; x=x0; time=0; u=0; y=x(1); r=[zeros(.1Ns,1);100ones(.9Ns+Ny,1)]; for k=1:Ns if k< du(k)=0; u(k)=0; else del_u=M(r(k:k+Ny-1)-Hdu(k-1:-1:k-1-(m-2))'-Fy(k:-1:k-(n-1))'); du(k)=del_u(1); u(k)=u(k-1)+du(k); end [tt,xx]=ode45(@DbIntdyn,[(k-1)Ts kTs],x,[],u(k),A,B); x=xx(end,:)'; y(k+1)=Cx; time(k+1)=kTs; end u(k+1)=u(k); r(k+1)=r(k); close all figure(1); subplot(211) plot(time,y,'-');title('Non-constrained GPC') hold on stairs(time,r(1:Ns+1),'--r') ylabel('Output y') xlabel('Time (s)') subplot(212) stairs(time,u) ylabel(' Input u') xlabel('Time (s)')
Ns=SimTL/Ts; % Sample points x0=[0;0]; x=x0; time=0; u=0; y=x(1); r=[zeros(.1Ns,1);100ones(.9Ns+Ny,1)]; for k=1:Ns if k< du(k)=0; u(k)=0; else f=Hdu(k-1:-1:k-1-(m-2))'+Fy(k:-1:k-(n-1))'; Fbar=2G'(f-r(k:k+Ny-1)); Aineq=[eye(Nu);-eye(Nu);Lbar;-Lbar]; bineq=[Tsdumaxones(Nu,1); -Tsduminones(Nu,1); (umax-u(k-1))ones(Nu,1); -(umin-u(k-1))ones(Nu,1)]; del_u=quadprog(Hbar,Fbar,Aineq,bineq); du(k)=del_u(1); u(k)=u(k-1)+du(k); end [tt,xx]=ode45(@DbIntdyn,[(k-1)Ts kTs],x,[],u(k),A,B); x=xx(end,:)'; y(k+1)=Cx; time(k+1)=k*Ts; end u(k+1)=u(k); r(k+1)=r(k); close all figure(1); subplot(211) plot(time,y,'-');title('constrained GPC'); hold on stairs(time,r(1:Ns+1),'--r') ylabel('Output y') xlabel('Time (s)') subplot(212) stairs(time,u) ylabel('Input u') xlabel('Time (s)')