Overview
Comment: | Simulation and real now compatible! |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2e7eb80963858dc3cbd13a28a91b8500 |
User & Date: | gawthrop@users.sourceforge.net on 2003-10-15 16:21:20 |
Other Links: | branch diff | manifest | tags |
Context
2003-10-16
| ||
07:30:24 | ppp_int_obs now returns corrected as well as predicted output check-in: 4c9bb5509d user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
2003-10-15
| ||
16:21:20 | Simulation and real now compatible! check-in: 2e7eb80963 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
16:14:38 | Correct on current value, predict next value check-in: a8c356c721 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/lib/control/PPP/ppp_lin_run.m from [26fb8a410d] to [66d5fae7bd].
|
| | | | 1 2 3 4 5 6 7 8 9 10 | function [t,y,u,t_e,y_e,e_e] = ppp_lin_run (Name,Simulate,ControlType,w,x_0,p_c,p_o) ## usage: [t,y,u,t_e,y_e,e_e] = ppp_lin_run (Name,Simulate,ControlType,w,x_0,p_c,p_o) ## ## ## Linear closed-loop PPP of lego system (and simulation) ## ## Name: Name of system (in mtt terms) ## Simulate = 0: real thing ## Simulate = 1: simulate |
︙ | ︙ | |||
40 41 42 43 44 45 46 | endif if nargin<5 x_0 = zeros(n_x,1); endif if nargin<6 | | | | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | endif if nargin<5 x_0 = zeros(n_x,1); endif if nargin<6 p_c.N = 50; endif if nargin<7 p_o.sigma = 1e-1; endif if !struct_contains(p_c,"delta_ol") p_c.delta_ol = 0.5; # OL sample interval endif if !struct_contains(p_c,"T") p_c.T = 2.5; # Last time point. endif if !struct_contains(p_c,"augment") p_c.augment = 1; # Augment basis funs with contand endif if !struct_contains(p_c,"Method") |
︙ | ︙ | |||
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | endif if !struct_contains(p_o,"method") ##p_o.method = "continuous"; p_o.method = "intermittent"; endif ## Check w. [n_w,m_w] = size(w); if ( (n_w!=n_y) || (m_w!=1) ) error(sprintf("ppp_lin_run: w must a column vector with %i elements",n_y)); endif ## Initialise x_est = p_o.x_0; | > | | 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 | endif if !struct_contains(p_o,"method") ##p_o.method = "continuous"; p_o.method = "intermittent"; endif ## Check w. [n_w,m_w] = size(w); if ( (n_w!=n_y) || (m_w!=1) ) error(sprintf("ppp_lin_run: w must a column vector with %i elements",n_y)); endif ## Initialise x_est = p_o.x_0; ## Initialise simulation state x = x_0; if ControlType==0 # Step input I = 1; # 1 large sample p_c.delta_ol = p_c.T # I K_w = zeros(p_c.n_U,n_y); K_w(1,1) = 1; |
︙ | ︙ | |||
134 135 136 137 138 139 140 | endif ##Sanity check A_u [p_c.n_U,M_u] = size(p_c.A_u); if (p_c.n_U!=M_u) error("A_u must be square"); endif | < | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | endif ##Sanity check A_u [p_c.n_U,M_u] = size(p_c.A_u); if (p_c.n_U!=M_u) error("A_u must be square"); endif U = K_w*w; # Initial control U ## Checks [ol_zeros, ol_poles] = sys2zp(sys) cl_poles = eig(A - B*k_x) endif |
︙ | ︙ | |||
190 191 192 193 194 195 196 | u = []; t = []; y_e = []; t_e = []; e_e = []; tick = time; i=0; | | < > | < > > < < < < | < | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | u = []; t = []; y_e = []; t_e = []; e_e = []; tick = time; i=0; for j=1:10 for k=1:I tim=time; # Timing i++ if Simulate # Exact simulation t_sim = [1:p_c.N]*dt; # Simulation time points [yi,ui,xsi] = ppp_ystar(A,B,C,D,x,p_c.A_u,U,t_sim); # Simulate x = xsi(:,p_c.N); # Current state (for next time) ti = [(i-1)*p_c.N:i*p_c.N-1]*dt; y_i = yi(1); # Current output t_i = ti(1); else # The real thing [t_i,y_i,u_i] = ppp_put_get(U); # Generic interface to real-time endif ## Observer if strcmp(p_o.method, "intermittent") [x_est y_est e_est] = ppp_int_obs \ (x_est,y_i,U,A,B,C,D,p_c.A_u,p_c.delta_ol,L); elseif strcmp(p_o.method, "continuous") Ui = U; # U at sub intervals for k = 1:p_c.N |
︙ | ︙ | |||
234 235 236 237 238 239 240 | ## Save data if Simulate t = [t;ti']; y = [y;yi']; u = [u;ui']; else t = [t;t_i]; | | | | | | > | > > > > > | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | ## Save data if Simulate t = [t;ti']; y = [y;yi']; u = [u;ui']; else t = [t;t_i]; y = [y;y_i']; u = [u;u_i']; endif if strcmp(p_o.method, "intermittent") y_e = [y_e; y_est']; e_e = [e_e; e_est']; t_e = [t_e; t_i]; endif delta_comp = time-tim; usleep(floor(1e6*(p_c.delta_ol-delta_comp-0.01))); endfor # Main loop w = -w; endfor # Outer loop if !Simulate ppp_put_get(0*U); # Reset to zero endif if strcmp(p_o.method, "continuous") t_e = t; endif sample_interval = (time-tick)/i ## Put data on file (so can use for identification) filename = sprintf("%s_ident_data.dat",Name); eval(sprintf("save -ascii %s t y u",filename)); endfunction |