144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
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";
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));
|
|
>
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
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 = "remote";
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));
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
A_ud = expm(p_c.A_u*dt); # Discrete-time input transition
if (ControlType==2) #
[L, M, P, obs_poles] = dlqe(Ad,G,C,sigma_x,Sigma);
else
L = zeros(n_x,n_y);
obs_poles = eig(Ad);
endif
else
error(sprintf("Observer method ""%s"" unknown", p_o.method));
endif
## Display the poles
obs_poles
|
>
>
>
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
A_ud = expm(p_c.A_u*dt); # Discrete-time input transition
if (ControlType==2) #
[L, M, P, obs_poles] = dlqe(Ad,G,C,sigma_x,Sigma);
else
L = zeros(n_x,n_y);
obs_poles = eig(Ad);
endif
elseif strcmp(p_o.method, "remote")
L = zeros(n_x,n_y);
obs_poles = [];
else
error(sprintf("Observer method ""%s"" unknown", p_o.method));
endif
## Display the poles
obs_poles
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
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 y_new, 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 y_new 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_new'];
e_e = [e_e; e_est'];
endfor
endif
##Control
if ( (p_c.Tau_u==[])&&(p_c.Tau_y==[]) )
U = K_w*w - K_x*x_est;
else
## Input constraints
|
>
>
>
>
|
>
>
>
>
>
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
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
if strcmp(p_o.method, "remote")
[t_i,y_i,X] = ppp_put_get_X(U); # Remote-state interface
u_i = X(3); # Integrated control is third state
else
[t_i,y_i,u_i] = ppp_put_get(U); # Generic interface to real-time
endif
endif
## Observer
if strcmp(p_o.method, "intermittent")
[x_est y_est y_new, 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 y_new 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_new'];
e_e = [e_e; e_est'];
endfor
elseif strcmp(p_o.method, "remote")
## predict from remote state (with zero L)
[x_est y_est y_new e_est] = ppp_int_obs \
(X,y_i,U,A,B,C,D,p_c.A_u,p_c.delta_ol,L);
endif
##Control
if ( (p_c.Tau_u==[])&&(p_c.Tau_y==[]) )
U = K_w*w - K_x*x_est;
else
## Input constraints
|