Overview
Comment: | Time-varying set point W |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9d59aab3cbda99b98d0fc54cfa12970d |
User & Date: | gawthrop@users.sourceforge.net on 2002-09-11 14:19:28 |
Other Links: | branch diff | manifest | tags |
Context
2002-09-11
| ||
14:21:22 | large limits set to inf or -inf check-in: 0187760d62 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
14:19:28 | Time-varying set point W check-in: 9d59aab3cb user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
14:17:36 | Modified for new qp_mu algorithms check-in: a6445e6499 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/lib/control/PPP/ppp_qp_sim.m from [3b08bbc64d] to [9bb563078b].
|
| | > > > | 1 2 3 4 5 6 7 8 9 10 11 | function [T,y,u,X,Iterations] = 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,movie) ## usage: [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,movie) ## Needs documentation - see ppp_ex11 for example of use. ## OUTPUTS ## T: Time vector ## y,u,J output, input and cost |
︙ | ︙ | |||
26 27 28 29 30 31 32 | [n_x,n_u,n_y] = abcddim(A,B,C,D); [n_x0,m_x0] = size(x_0); if (n_x0 != n_x)||(m_x0 != 1) error(sprintf("Initial state x_0 must be %ix1 not %ix%i",n_x,n_x0,m_x0)); endif | | < < < | < < < | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | [n_x,n_u,n_y] = abcddim(A,B,C,D); [n_x0,m_x0] = size(x_0); if (n_x0 != n_x)||(m_x0 != 1) error(sprintf("Initial state x_0 must be %ix1 not %ix%i",n_x,n_x0,m_x0)); endif ## Input constraints [Gamma_u, gamma_u] = ppp_input_constraints(A_u,Tau_u,Min_u,Max_u); ## Output constraints [Gamma_y,gamma_y] = ppp_output_constraints(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"); |
︙ | ︙ | |||
58 59 60 61 62 63 64 | if Delta_ol>0 # Intermittent control T_ol = 0:dt:Delta_ol; # Create the open-loop time vector else T_ol = [0,dt]; Delta_ol = dt; endif | > | > > > > | > > > > > > > > > | > | > > > | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | if Delta_ol>0 # Intermittent control T_ol = 0:dt:Delta_ol; # Create the open-loop time vector else T_ol = [0,dt]; Delta_ol = dt; endif t_last = 2*t(length(t)); T_cl = 0:Delta_ol:t_last-Delta_ol; # Closed-loop time vector T = 0:dt:t_last; # Overall time vector ## Lengths thereof n_Tcl = length(T_cl); n_ol = length(T_ol); n_T = length(T); ## Expand W with constant last value or truncate [n_W,m_W] = size(W); if m_W>n_T W = W(:,1:n_T); else W = [W W(:,m_W)*ones(1,n_T-m_W+1)]; endif ## Compute U* Ustar_ol = ppp_ustar(A_u,n_u,T_ol); # U* in the open-loop interval [n,m] = size(Ustar_ol); n_U = m/length(T_ol); # Determine size of each Ustar # ## Discrete-time system # csys = ss2sys(A,B,C,D); # dsys = c2d(csys,dt); # [Ad, Bd] = sys2ss(dsys) x = x_0; # Initialise state ## Initialise the saved variable arrays X = []; u = []; Iterations = []; du = []; J = []; tick= time; ## disp("Simulating ..."); for t=T_cl # Outer loop at Delta_ol ##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 Gamma = [Gamma_u; Gamma_y]; gamma = [gamma_u; gamma_y]; ## Current Setpoint value w = W(:,floor(t/dt)+1); ## Compute U(t) via QP optimisation [uu, U, iterations] = ppp_qp (x,w,J_uu,J_ux,J_uw,Us0,Gamma,gamma,mu); # Compute U ## Compute the cost (not necessary but maybe interesting) # [J_t] = ppp_cost (U,x,W,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww); # cost # J = [J J_t]; ## OL Simulation (exact) [ys,us,xs] = ppp_ystar (A,B,C,D,x,A_u,U,T_ol); |
︙ | ︙ | |||
123 124 125 126 127 128 129 | u = [u ut]; # Save input Iterations = [Iterations iterations]; # Save iteration count tock = time; Elapsed_Time = tock-tick; y = C*X + D*u; # System output | < | 138 139 140 141 142 143 144 145 146 147 148 149 | u = [u ut]; # Save input Iterations = [Iterations iterations]; # Save iteration count tock = time; Elapsed_Time = tock-tick; y = C*X + D*u; # System output endfunction |