Differences From Artifact [39b3104ab9]:

To Artifact [26fb8a410d]:


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
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
  endif
  
  if nargin<5
    x_0 = zeros(n_x,1);
  endif
  
  if nargin<6
    p_c.N = 10;
  endif

  if nargin<7
    p_o.sigma = 1e-1;
  endif

  if !struct_contains(p_c,"delta_ol")
    p_c.delta_ol = 1.0;	# OL sample interval
  endif
  
  if !struct_contains(p_c,"T")
    p_c.T = 10.0;			# 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")
    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.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 = 2.0;
	p_c.A_u = laguerre_matrix(p_c.n_U,a_u);
	if p_c.augment		# Put in constant term
	  A_u = ppp_aug(0,A_u);
	endif
      endif
    else
      error(sprintf("Method %s not recognised", p_c.Method));
    endif
  endif
  







|







|











|
















|







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
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
  endif
  
  if nargin<5
    x_0 = zeros(n_x,1);
  endif
  
  if nargin<6
    p_c.N = 25;
  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 = 10.0;			# 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")
    p_c.Method = "original";
  endif

  if struct_contains(p_c,"Method")
    if strcmp(p_c.Method,"lq") 
      p_c.Q = eye(n_y);
      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 = 2.0;
	p_c.A_u = laguerre_matrix(p_c.n_U,a_u);
	if p_c.augment		# Put in constant term
	  p_c.A_u = ppp_aug(0,p_c.A_u);
	endif
      endif
    else
      error(sprintf("Method %s not recognised", p_c.Method));
    endif
  endif
  
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
270
271
272
273
274
275
  y = [];
  u = [];
  t = [];
  y_e = [];
  t_e = [];
  e_e = [];
  tick = time;

  for i=1:I

    i
    tim=time;			# Timing
    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)
      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,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),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;

    ## Save data

    t = [t;ti'];
    y = [y;yi'];
    u = [u;ui'];







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

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

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

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


endfunction







>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
>
|
|
|
>
>
>
>
>
|
>
|
|
|
|
|

|
|
>
>












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

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
  y = [];
  u = [];
  t = [];
  y_e = [];
  t_e = [];
  e_e = [];
  tick = time;
  i=0;
  for j=1:20
    for k=1:I
      i++;
      tim=time;			# Timing
      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)
	y_i = 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,ti] = convert_data(data); # And convert from integer format
	[t_i,y_i,u_i] = ppp_put_get(U); # Generic interface to real-time
				#      y_i = 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_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
	  [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;

      ## 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; (i*p_c.N)*dt];
      endif

      overrun = time-tim;
    endfor			# Main loop
    w = -w
  endfor 			# Outer 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));




















endfunction

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