Index: mttroot/mtt/lib/control/PPP/ppp_ex11.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex11.m +++ mttroot/mtt/lib/control/PPP/ppp_ex11.m @@ -31,15 +31,15 @@ A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions Q = ones(n_y,1);; - ## Constaints + ## Constraints Gamma = []; gamma = []; - ## Constaints - u + ## Constraints - u Tau_u = [0:0.5:2]; one = ones(size(Tau_u)); limit = 1.5; Min_u = -limit*one; Max_u = limit*one; @@ -74,32 +74,34 @@ ## Unconstrained OL simulation disp("Computing unconstrained ol response"); [uu,Uu] = ppp_qp (x_0,W,J_uu,J_ux,J_uw,Us0,[],[]); [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T); - title("Constained and unconstrained y*"); + title("Constrained and unconstrained y*"); xlabel("t"); grid; - plot(T,ys,T,ysu) + figure(1); + plot(T,ys,"-;y*: constrained;", T,ysu, "--;y*: unconstrained;") ## Non-linear - closed-loop disp("Computing constrained closed-loop response"); [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ Tau_u,Min_u,Max_u,Order_u, \ Tau_y,Min_y,Max_y,Order_y,W,x_0); - title("y,y*,u and u*"); + title("Constrained closed-loop response"); xlabel("t"); grid; - plot(T,y,T,u,T,ys,T,us); + figure(2); + plot(T,y,"-;y;", T,u,"--;u;"); - ## Compute derivatives. - dt = t(2)-t(1); - du = diff(u)/dt; - dus = diff(us)/dt; - T1 = T(1:length(T)-1); +# ## Compute derivatives. +# dt = t(2)-t(1); +# du = diff(u)/dt; +# dus = diff(us)/dt; +# T1 = T(1:length(T)-1); ##plot(T1,du,T1,dus); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_ex12.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex12.m +++ mttroot/mtt/lib/control/PPP/ppp_ex12.m @@ -20,11 +20,11 @@ B = [1 0 0]; C = [0 -0.5 1]; D = 0; - [n_x,n_u,n_y] = abcddim(A,B,C,D) + [n_x,n_u,n_y] = abcddim(A,B,C,D); ## Controller t = [4:0.02:5]; # Time horizon A_w = 0; # Setpoint A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions @@ -54,11 +54,11 @@ [],[],[],[], W,x_0); title("y,y*,u and u*"); xlabel("t"); grid; - plot(T,y,T,u,T,ys,T,us); + plot(T,y,"1;y;", T,u,"2;u;", T,ys,"3;y*;", T,us,"4;u*;"); ## Compute derivatives. dt = t(2)-t(1); du = diff(u)/dt; dus = diff(us)/dt; Index: mttroot/mtt/lib/control/PPP/ppp_ex15.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex15.m +++ mttroot/mtt/lib/control/PPP/ppp_ex15.m @@ -40,22 +40,24 @@ ## Closed-loop intermittent solution Delta_ol = 0.5 # Intermittent time disp("Intermittent control simulation"); - [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ + [T,y,u] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ [],[],[],[], \ [],[],[],[],W,x_0,Delta_ol); - +size(T) ## Exact closed-loop disp("Exact closed-loop"); - [k_x,k_w] = ppp_lin (A,B,C,D,A_u,A_w,t,Q); + [k_x,k_w] = ppp_lin (A,B,C,D,A_u,A_w,t,Q) [ye,Xe] = ppp_sm2sr(A-B*k_x, B, C, D, T, k_w*W, x_0); # Compute Closed-loop control - ue = k_w*ones(size(T))*W - k_x*Xe'; + + ue = k_w*ones(size(T))*W - k_x*Xe; title("y and u, exact and intermittent"); xlabel("t"); grid; - plot(T,y,T,u,T,ye,T,ue); + plot(T,y,"1;y (intermittent);", T,u,"2;u (intermittent);",\ + T,ye,"3;y (exact);", T,ue,"4;u (exact);"); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_ex17.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex17.m +++ mttroot/mtt/lib/control/PPP/ppp_ex17.m @@ -71,23 +71,24 @@ [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T); title("Constained and unconstrained y*"); xlabel("t"); grid; - plot(T,ys,T,ysu) + figure(1); + plot(T,ys,"-;y* (constrained);", T,ysu,"--;y* (unconstrained);") ## Non-linear - closed-loop - delta_ol = 0.1; + delta_ol = 0.1; mu = 1e-4; [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ Tau_u,Min_u,Max_u,Order_u, \ - Tau_y,Min_y,Max_y,Order_y,W,x_0,delta_ol); + Tau_y,Min_y,Max_y,Order_y,W,x_0,delta_ol,mu); - title("y,y*,u and u*"); + title("y and u"); xlabel("t"); grid; - plot(T,y,T,u,T,ysu,T,usu); + plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);"); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_ex19.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex19.m +++ mttroot/mtt/lib/control/PPP/ppp_ex19.m @@ -81,24 +81,25 @@ [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T); title("Constrained and unconstrained y*"); xlabel("t"); grid; - plot(T,ys,T,ysu) + plot(T,ys,"-;y* (constrained);", T,ysu,"--;y* (unconstrained);"); ## Non-linear - closed-loop disp("Closed-loop simulation"); [T1,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ Tau_u,Min_u,Max_u,Order_u, \ Tau_y,Min_y,Max_y,Order_y,W,x_0); - title("y,y*,u and u*"); + title("y and u"); xlabel("t"); grid; - plot(T1,y,T,ys,T1,u,T,us); + plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);"); + endfunction Index: mttroot/mtt/lib/control/PPP/ppp_ex6.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ex6.m +++ mttroot/mtt/lib/control/PPP/ppp_ex6.m @@ -36,20 +36,20 @@ ## Simulation W=1; x_0 = 0; ## Linear - [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w] = ppp_lin_plot (A,B,C,D,A_u,A_w,t); + ppp_lin_plot (A,B,C,D,A_u,A_w,t); ## Non-linear movie = 0; [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, Tau,Min,Max,Order, \ [],[],[],[], W,x_0); title("y,u_1,u_2"); xlabel("t"); grid; - plot(T,y,T,u); + plot(T,y,"-;y;", T,u(1,:),"--;u_1;", T,u(2,:),".-;u_2;"); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_lin_plot.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_lin_plot.m +++ mttroot/mtt/lib/control/PPP/ppp_lin_plot.m @@ -1,8 +1,8 @@ function [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w,cond_uu] = ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0) - ## usage: [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w] = ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0) + ## usage: [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w,cond_uu] = ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0) ## ## Linear PPP (Predictive pole-placement) computation with plotting ## INPUTS: ## A,B,C,D: system matrices ## A_u: composite system matrix for U* generation @@ -38,11 +38,11 @@ [n_t,m_t] = size(t); ## Default Q if nargin<8 - Q = ones(n_y,1); + Q = ones(n_y,1) endif ## Default W if nargin<9 W = ones(n_W,1) Index: mttroot/mtt/lib/control/PPP/ppp_qp.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_qp.m +++ mttroot/mtt/lib/control/PPP/ppp_qp.m @@ -45,14 +45,15 @@ ##U = qp(J_uu,(J_ux*x - J_uw*W),Gamma,gamma); # QP solution for weights U ##U = pd_lcp04(J_uu,(J_ux*x - J_uw*W),Gamma,gamma); # QP solution for weights U u = Us0*U; # Control signal else # Do the unconstrained solution ## Compute the open-loop gains + iterations = 0; K_w = J_uu\J_uw; K_x = J_uu\J_ux; ## Closed-loop control U = K_w*W - K_x*x; # Basis functions weights - U(t) u = Us0*U; # Control u(t) endif endfunction Index: mttroot/mtt/lib/control/PPP/ppp_qp_sim.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_qp_sim.m +++ mttroot/mtt/lib/control/PPP/ppp_qp_sim.m @@ -45,11 +45,11 @@ ## Composite constraints - t=0 Gamma = [Gamma_u; Gamma_y]; gamma = [gamma_u; gamma_y]; ## Design the controller - disp("Designing controller"); + ## disp("Designing controller"); [k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww] = ppp_lin (A,B,C,D,A_u,A_w,t,Q); ## Set up various time vectors dt = t(2)-t(1); # Time increment @@ -85,11 +85,11 @@ Iterations = []; du = []; J = []; tick= time; i = 0; - disp("Simulating ..."); + ## disp("Simulating ..."); for t=T_cl # Outer loop at Delta_ol ##disp(sprintf("Time %g", t)); ## Output constraints [Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x,A_u,Tau_y,Min_y,Max_y,Order_y); @@ -122,14 +122,14 @@ X = [X x]; # Save state u = [u ut]; # Save input Iterations = [Iterations iterations]; # Save iteration count tock = time; - Elapsed_Time = tock-tick + Elapsed_Time = tock-tick; y = C*X + D*u; # System output T = 0:dt:t+Delta_ol; # Overall time vector endfunction