Overview
Comment:New defaults
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 764c415db60be34a2c1adaa0d06b000a45293bc9a866510489712f094959f307
User & Date: gawthrop@users.sourceforge.net on 2003-08-19 16:22:36
Other Links: branch diff | manifest | tags
Context
2003-09-07
20:25:09
Fixed [ 790467 ] -oct option broken check-in: 2bf551b4f2 user: geraint@users.sourceforge.net tags: origin/master, trunk
2003-08-19
16:22:36
New defaults check-in: 764c415db6 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
16:21:58
Added ; to prevent output check-in: aefed16f8f user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/lib/control/PPP/ppp_lin_run.m from [b67bec725e] to [fd3d84c38b].

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
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







-
+







-
+













-
+







  if !struct_contains(p_c,"Method")
    p_c.Method = "lq";
  endif

  if struct_contains(p_c,"Method")
    if strcmp(p_c.Method,"lq") 
      p_c.Q = eye(n_y);
      p_c.R = (0.5^2)*eye(n_u);
      p_c.R = (0.25^2)*eye(n_u);
      p_c.n_U = n_x;
    elseif strcmp(p_c.Method,"original");
      if !struct_contains(p_c,"A_w")
	p_c.A_w = 0;
      endif
      if !struct_contains(p_c,"A_u")
	p_c.n_U = n_x;
	a_u = 1.0;
	a_u = 2.0;
	p_c.A_u = laguerre_matrix(p_c.n_U,a_u)
      endif
    else
      error(sprintf("Method %s not recognised", p_c.Method));
    endif
  endif
  
  if !struct_contains(p_o,"x_0")
    p_o.x_0 = zeros(n_x,1);
  endif
  
  if !struct_contains(p_o,"method")
    p_o.method = "continuous";
##    p_o.method = "intermittent";
    ##    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));
186
187
188
189
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
219
220
221


222
223
224
225
226


227
228
229
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
186
187
188
189
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
219
220
221


222
223
224

225


226
227

228
229
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







-
+

-
-
+
+
+



-
+


-
+
+






-
-
-
-
-
-
+
+
+
+
+
+




-
-
+
+

-

-
-
+
+
-






-
-
+
+
-














-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+



  t_e = [];
  e_e = [];
  tick = time;
  for i=1:I
    i
    tim=time;			# Timing
    if Simulate			# Exact simulation 
      t_sim = [0:p_c.N]*dt;	# Simulation time points
      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+1);	# Current state (for next time)
      y_now = yi(:,p_c.N+1);	# Current output
      x = xsi(:,p_c.N);	# Current state (for next time)
      y_now = yi(:,p_c.N);	# Current output
      ti  = [(i-1)*p_c.N:i*p_c.N-1]*dt; 
    else			# The real thing
      to_rt(U');		# Send U
      data = from_rt(p_c.N);	# Receive data
      [yi,ui] = convert_data(data); # And convert from integer format
      [yi,ui,ti] = convert_data(data); # And convert from integer format
      y_now = yi(:,p_c.N);	# Current output
    endif

    sample_time = (time-tim)/p_c.N
    tim = time;
    ## Observer
    if strcmp(p_o.method, "intermittent")
      [x_est y_est e_est] = ppp_int_obs \
	  (x_est,y_now,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
      [x_est y_est e_est] = ppp_int_obs \
	  (x_est,yi(:,k+1),Ui,A,B,C,D,p_c.A_u,dt,L);
      Ui = A_ud*Ui;
      y_e = [y_e; y_est'];
      e_e = [e_e; e_est];
      for k = 1:p_c.N
	[x_est y_est e_est] = ppp_int_obs \
	    (x_est,yi(:,k),Ui,A,B,C,D,p_c.A_u,dt,L);
	Ui = A_ud'*Ui;
	y_e = [y_e; y_est'];
	e_e = [e_e; e_est];
      endfor
    endif
    
    ##Control
    ##U = K_w*w - K_x*x_est;
    U = expm(p_c.A_u*(p_c.delta_ol))*U
    U = K_w*w - K_x*x_est;

    ## Save data
    ti  = [(i-1)*p_c.N:i*p_c.N-1]*dt; 
    t = [t;ti'];
    y = [y;yi(:,1:p_c.N)'];
    u = [u;ui(:,1:p_c.N)'];
    y = [y;yi'];
    u = [u;ui'];
    sample_time = (time-tim)/p_c.N

    if strcmp(p_o.method, "intermittent")
      y_e = [y_e; y_est'];
      e_e = [e_e; e_est];
      t_e = [t_e; (i*p_c.N)*dt];
    endif
    


    overrun = time-tim
    dt
  endfor			# Main loop

  if strcmp(p_o.method, "continuous")
    t_e = t;
  endif
  
  
  sample_interval = (time-tick)/(I*p_c.N)

  ## 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));


  ## Plot
  gset nokey
  title("");
  boxed=0;
  monochrome=1;
  grid;
  xlabel("t");
#   ## Plot
#   gset nokey
#   title("");
#   boxed=0;
#   monochrome=1;
#   grid;
#   xlabel("t");

  ylabel("y");
  figure(1);plot(t,y, t_e,y_e,"+");
#   ylabel("y");
#   figure(1);plot(t,y, t_e,y_e,"+");

  ylabel("u");
  figure(2);plot(t,u);
#   ylabel("u");
#   figure(2);plot(t,u);

  ylabel("e");
  figure(3);plot(t_e,e_e);
#   ylabel("e");
#   figure(3);plot(t_e,e_e);


endfunction


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]