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,11 +40,12 @@ ## Closed-loop intermittent solution Delta_ol = 0.5 # Intermittent time disp("Intermittent control simulation"); - [T,y,u] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \ + R=1;P=0; + [T,y,u] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q,R,P, \ [],[],[],[], \ [],[],[],[],W,x_0,Delta_ol); size(T) ## Exact closed-loop disp("Exact closed-loop"); Index: mttroot/mtt/lib/control/PPP/ppp_inflate.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_inflate.m +++ mttroot/mtt/lib/control/PPP/ppp_inflate.m @@ -13,11 +13,11 @@ error("A_v must have at least as many rows as columns"); endif n = N/M; # Number of matrix elements in A_v - if round(n)<>n + if round(n)!=n error("A_v must be a column vector of square matrices"); endif A_m = []; for i = 1:n Index: mttroot/mtt/lib/control/PPP/ppp_lin.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_lin.m +++ mttroot/mtt/lib/control/PPP/ppp_lin.m @@ -167,11 +167,12 @@ J_xx = J_xx + (QQ .* y_x(:,i:n_y:n_yx)') * y_x(:,i:n_y:n_yx); endfor ## Input weighting (scalar for the moment) if (n_u>1) - warning("Sorry, cant do n_u>1 just now"); + warning("Sorry, cant do n_u>1 just now: exiting"); + return endif ## Scale R R = R*dt; # Scale to give correct units for i = 1:m_t Index: mttroot/mtt/lib/control/PPP/ppp_lin_quad.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_lin_quad.m +++ mttroot/mtt/lib/control/PPP/ppp_lin_quad.m @@ -1,16 +1,23 @@ function [k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] = \ - ppp_lin_quad (A,B,C,D,tau,Q,R) + ppp_lin_quad (A,B,C,D,tau,Q,R,A_e) ## usage:[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] = - ## ppp_lin_quad (A,B,C,D,tau,Q,R) + ## ppp_lin_quad (A,B,C,D,tau,Q,R[,A_e]) ## ## ## Steady-state Linear Quadratic solution ## using Algebraic Riccati equation (ARE) + + if nargin<8 + A_e = []; + endif + [P,A_u,A_w] = ppp_are (A,B,C,D,Q,R); + + A_u = ppp_aug(A_u,A_e); ## PPP solution [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,tau,Q,R,P); Index: mttroot/mtt/lib/control/PPP/ppp_open2closed.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_open2closed.m +++ mttroot/mtt/lib/control/PPP/ppp_open2closed.m @@ -16,11 +16,11 @@ ## Check sizes n_o = is_square(A_u); n_c = is_square(A_c); - if (n_o==0)||(n_c==0)||(n_o<>n_c) + if (n_o==0)||(n_c==0)||(n_o!=n_c) error("A_u and A_c must be square and of the same dimension"); endif [n_u,n_x] = size(k_x); 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 @@ -62,12 +62,12 @@ else T_ol = [0,dt]; Delta_ol = dt; endif t_last = t(length(t)); - T_cl = 0:Delta_ol:t_last-Delta_ol; # Closed-loop time vector - T = 0:dt:t_last; # Overall time vector + T_cl = 0:Delta_ol:2*t_last-Delta_ol; # Closed-loop time vector + T = 0:dt:2*t_last; # Overall time vector ## Lengths thereof n_Tcl = length(T_cl); n_ol = length(T_ol); n_T = length(T); @@ -102,11 +102,11 @@ J = []; tick= time; ## disp("Simulating ..."); for t=T_cl # Outer loop at Delta_ol - + printf("%g\r",t); ##disp(sprintf("Time %g", t)); ## Output constraints [Gamma_y,gamma_y] = ppp_output_constraints (A,B,C,D,x,A_u,Tau_y,Min_y,Max_y,Order_y); ## Composite constraints Index: mttroot/mtt/lib/control/PPP/ppp_ystar.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_ystar.m +++ mttroot/mtt/lib/control/PPP/ppp_ystar.m @@ -22,12 +22,18 @@ ## AA The composite system matrix ## Copyright (C) 1999 by Peter J. Gawthrop ## $Id$ - - [n_x,n_u,n_y] = abcddim(A,B,C,D); # System dimensions + if (size(A)>0) + [n_x,n_u,n_y] = abcddim(A,B,C,D); # System dimensions + else + n_x = 0; + n_y = 0; + n_u = 0; + endif + no_system = n_x==0; [n,m] = size(A_u); # Size of composite A_u matrix square = (n==m); # Is A_u square? n_U = m; # functions per input @@ -115,15 +121,20 @@ ## Compute the star variables for t=tau xxt = expm(AA*t)*xx_0; # Composite state xst = xxt(1:n_x); # x star xut = xxt(n_x+1:n_xx); # x star - yst = C*xst; # y star + if length(C)>0 + yst = C*xst; # y star + else + yst = []; + endif + ust = Utilde*xut; # u star xs = [xs xst]; # x star xu = [xu xut]; # x star ys = [ys yst]; # y star us = [us ust]; # u star endfor endfunction