Comment: | Updated for new ppp_qp (using qp_mu from Will Heath/Adrian Wills |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
63e8024414b5ff08f4c7862914ab3dc7 |
User & Date: | gawthrop@users.sourceforge.net on 2002-08-27 17:34:36 |
Other Links: | branch diff | manifest | tags |
2002-08-28
| ||
15:48:01 | Updated mttrc to make standalone C++ compilation configuration clearer. check-in: 7654be3275 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
2002-08-27
| ||
17:34:36 | Updated for new ppp_qp (using qp_mu from Will Heath/Adrian Wills check-in: 63e8024414 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
16:09:01 | Added port_name to error message when multiple bonds are near a port. check-in: c7b42b1371 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
Modified mttroot/mtt/lib/control/PPP/ppp_ex11.m from [8afbccc82d] to [b816bab9e6].
︙ | ︙ | |||
29 30 31 32 33 34 35 | t = [6:0.02:7]; # Time horizon A_w = 0; # Setpoint A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions Q = ones(n_y,1);; | | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | t = [6:0.02:7]; # Time horizon A_w = 0; # Setpoint A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions Q = ones(n_y,1);; ## Constraints Gamma = []; gamma = []; ## Constraints - u Tau_u = [0:0.5:2]; one = ones(size(Tau_u)); limit = 1.5; Min_u = -limit*one; Max_u = limit*one; Order_u = 0*one; |
︙ | ︙ | |||
72 73 74 75 76 77 78 | [ys,us] = ppp_ystar (A,B,C,D,x_0,A_u,U,T); ## 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); | | > | | > | | | | | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | [ys,us] = ppp_ystar (A,B,C,D,x_0,A_u,U,T); ## 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("Constrained and unconstrained y*"); xlabel("t"); grid; 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("Constrained closed-loop response"); xlabel("t"); grid; 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); ##plot(T1,du,T1,dus); endfunction |
Modified mttroot/mtt/lib/control/PPP/ppp_ex12.m from [4b9ce5134a] to [03125b8f94].
︙ | ︙ | |||
18 19 20 21 22 23 24 | 1 0 0 0 1 0]; B = [1 0 0]; C = [0 -0.5 1]; D = 0; | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1 0 0 0 1 0]; B = [1 0 0]; C = [0 -0.5 1]; D = 0; [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 Q = ones(n_y,1);; |
︙ | ︙ | |||
52 53 54 55 56 57 58 | [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,y*,u and u*"); xlabel("t"); grid; | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | [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,y*,u and u*"); xlabel("t"); grid; 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; T1 = T(1:length(T)-1); ##plot(T1,du,T1,dus); |
︙ | ︙ |
Modified mttroot/mtt/lib/control/PPP/ppp_ex15.m from [a26d3cfd27] to [d1ae59f7c7].
︙ | ︙ | |||
38 39 40 41 42 43 44 | x_0 = zeros(n_x,1); # Initial state ## Closed-loop intermittent solution Delta_ol = 0.5 # Intermittent time disp("Intermittent control simulation"); | | | | > | | > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | x_0 = zeros(n_x,1); # Initial state ## 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, \ [],[],[],[], \ [],[],[],[],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) [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; title("y and u, exact and intermittent"); xlabel("t"); grid; plot(T,y,"1;y (intermittent);", T,u,"2;u (intermittent);",\ T,ye,"3;y (exact);", T,ue,"4;u (exact);"); endfunction |
Modified mttroot/mtt/lib/control/PPP/ppp_ex17.m from [0cc0c0d748] to [fd73fba900].
︙ | ︙ | |||
69 70 71 72 73 74 75 | ## Unconstrained OL simulation [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*"); xlabel("t"); grid; | > | | | | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ## Unconstrained OL simulation [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*"); xlabel("t"); grid; figure(1); plot(T,ys,"-;y* (constrained);", T,ysu,"--;y* (unconstrained);") ## Non-linear - closed-loop 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,mu); title("y and u"); xlabel("t"); grid; plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);"); endfunction |
Modified mttroot/mtt/lib/control/PPP/ppp_ex19.m from [667d1947d8] to [8863f79b17].
︙ | ︙ | |||
79 80 81 82 83 84 85 | ## Unconstrained OL simulation [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("Constrained and unconstrained y*"); xlabel("t"); grid; | | | > | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | ## Unconstrained OL simulation [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("Constrained and unconstrained y*"); xlabel("t"); grid; 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 and u"); xlabel("t"); grid; plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);"); endfunction |
Modified mttroot/mtt/lib/control/PPP/ppp_ex6.m from [ba0ffb029f] to [2c0684bb49].
︙ | ︙ | |||
34 35 36 37 38 39 40 | i_u = 1; ## Simulation W=1; x_0 = 0; ## Linear | | | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | i_u = 1; ## Simulation W=1; x_0 = 0; ## Linear 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,"-;y;", T,u(1,:),"--;u_1;", T,u(2,:),".-;u_2;"); endfunction |
Modified mttroot/mtt/lib/control/PPP/ppp_lin_plot.m from [e00d3bd973] to [460292101c].
1 2 | 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) | | | 1 2 3 4 5 6 7 8 9 10 | 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,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 ## one square matrix (A_ui) row for each system input ## each A_ui generates U*' for ith system input. |
︙ | ︙ | |||
36 37 38 39 40 41 42 | endif [n_t,m_t] = size(t); ## Default Q if nargin<8 | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | endif [n_t,m_t] = size(t); ## Default Q if nargin<8 Q = ones(n_y,1) endif ## Default W if nargin<9 W = ones(n_W,1) endif |
︙ | ︙ |
Modified mttroot/mtt/lib/control/PPP/ppp_qp.m from [519bc8a390] to [3e26f7769e].
︙ | ︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 | [U,iterations] = qp_mu(J_uu,(J_ux*x - J_uw*W),Gamma,gamma,mu); # QP solution for weights U ##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 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 | > | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | [U,iterations] = qp_mu(J_uu,(J_ux*x - J_uw*W),Gamma,gamma,mu); # QP solution for weights U ##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 |
︙ | ︙ |
Modified mttroot/mtt/lib/control/PPP/ppp_qp_sim.m from [3484a100c1] to [3b08bbc64d].
︙ | ︙ | |||
43 44 45 46 47 48 49 | [Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x_0,A_u,Tau_y,Min_y,Max_y,Order_y); ## Composite constraints - t=0 Gamma = [Gamma_u; Gamma_y]; gamma = [gamma_u; gamma_y]; ## Design the controller | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | [Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x_0,A_u,Tau_y,Min_y,Max_y,Order_y); ## Composite constraints - t=0 Gamma = [Gamma_u; Gamma_y]; gamma = [gamma_u; gamma_y]; ## Design the 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 ## Make sure Delta_ol is multiple of dt Delta_ol = floor(Delta_ol/dt)*dt; |
︙ | ︙ | |||
83 84 85 86 87 88 89 | X = []; u = []; Iterations = []; du = []; J = []; tick= time; i = 0; | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | X = []; u = []; Iterations = []; du = []; J = []; tick= time; i = 0; ## 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); ## Composite constraints Gamma = [Gamma_u; Gamma_y]; |
︙ | ︙ | |||
120 121 122 123 124 125 126 | ## Save the last values X = [X x]; # Save state u = [u ut]; # Save input Iterations = [Iterations iterations]; # Save iteration count tock = time; | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | ## Save the last values X = [X x]; # Save state u = [u ut]; # Save input Iterations = [Iterations iterations]; # Save iteration count tock = time; Elapsed_Time = tock-tick; y = C*X + D*u; # System output T = 0:dt:t+Delta_ol; # Overall time vector endfunction |