Index: mttroot/mtt/lib/control/PPP/ppp_nlin_run.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin_run.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin_run.m @@ -58,20 +58,22 @@ T_ol_0 = simpar.last; # The initial specified interval n_t = round(simpar.last/simpar.dt); # Corresponding length x_0 = eval(sprintf("%s_state(par);", system_name)); x_0_model = x_0; [n_x,n_y,n_u] = eval(sprintf("%s_def;", system_name)); - + [n_par,m_par] = size(i_par); if nargin<8 Q = ones(n_y,1); endif ## Sensitivity system details -- defines moving horizon simulation simpars = eval(sprintf("%s_simpar;", s_system_name)); pars = eval(sprintf("%s_numpar;", s_system_name)); x_0s = eval(sprintf("%s_state(pars);", s_system_name)); x_0_models = x_0s; + + p = []; # Initialise saved parameters ## Times ## -- within opt horizon n_Tau = round(simpars.last/simpars.dt); dtau = simpars.dt; @@ -85,14 +87,12 @@ y = []; x = []; u = []; t = []; - p = []; t_last = 0; - UU = []; UU_l =[]; UU_c =[]; t_ppp = []; t_est = []; @@ -102,10 +102,13 @@ x_nexts = zeros(2*n_x,1); ## Initial U is zero [n_U,junk] = size(A_u); U = zeros(n_U,1); + + ## Initialise saved U + UU = []; ## Create input basis functions u_star_tau = ppp_ustar(A_u,1,Tau',0,0,n_u-n_U); ## Reverse time to get "previous" U @@ -123,10 +126,18 @@ T_total = simpar.last; endif for i = 0:N_ol # Main loop printf("%i",i); + UU = [UU; U']; # Save control U + + if n_par>0 + par_est = pars(i_par(:,1)); + p = [p; par_est']; # Save up the estimated parameters + endif + + if (extras.simulate==1) [y_ol,u_ol] = ppp_RT_sim(U); # Simulate else [y_ol,u_ol] = ppp_RT(U); # Real thing endif @@ -145,13 +156,10 @@ ## Generate input to actual system u_star_t = ppp_ustar(A_u,1,t_ol',0,0,n_u-n_U); ## Tune parameters/states if (estimating_parameters==1) - ## Save up the estimated parameters - par_est = pars(i_par(:,1)); - p = [p; par_est']; ## Set up according to interval length if (T_ol>T_ol_0) ## Truncate data simpar_est.last = T_ol_0; y_est = y_ol(1:n_t+1,:); @@ -243,11 +251,10 @@ ## Save up data y_ol = y_ol(1:n_ol,:); y = [y; y_ol]; u = [u; u_ol]; - UU = [UU; U']; t = [t; t_ol+t_last*ones(n_ol,1) ]; t_last = t_last + T_ol; endif