Overview
| Comment: | Revised to work with LQ on alnalogue circuit example with integration |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | origin/master | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
b4a88aed89c459b852ea2f693bb060f5 |
| User & Date: | gawthrop@users.sourceforge.net on 2003-10-21 09:30:24.000 |
| Other Links: | branch diff | manifest | tags |
Context
|
2003-10-21
| ||
| 09:55:02 | Make time horizon tau part of p_c struct check-in: fa74b12eb3 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
| 09:30:24 | Revised to work with LQ on alnalogue circuit example with integration check-in: b4a88aed89 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
|
2003-10-20
| ||
| 17:10:31 | Link ancestry of version-0-1 to it's source branch check-in: 538bbd8286 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/lib/control/PPP/ppp_lin_quad.m
from [2ba9cc3698]
to [b791777adb].
1 | function [k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] = \ | | < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function [k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] = \
ppp_lin_quad (A,B,C,D,tau,Q,R)
## usage:[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] =
## ppp_lin_quad (A,B,C,D,tau,Q,R)
##
##
## Steady-state Linear Quadratic solution
## using Algebraic Riccati equation (ARE)
[P,A_u,A_w] = ppp_are (A,B,C,D,Q,R);
## PPP solution
[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww] = \
ppp_lin(A,B,C,D,A_u,A_w,tau,Q,R,P);
endfunction
|
Modified mttroot/mtt/lib/control/PPP/ppp_lin_run.m
from [96369350d9]
to [fdb48937ab].
| ︙ | ︙ | |||
52 53 54 55 56 57 58 |
endif
if !struct_contains(p_c,"delta_ol")
p_c.delta_ol = 0.5; # OL sample interval
endif
if !struct_contains(p_c,"T")
| | | > > > > > > > > > > > > > > > > > | | | | 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 92 93 94 95 96 97 |
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; # Last time point.
endif
if !struct_contains(p_c,"augment")
p_c.augment = 0; # Augment basis funs with constant
endif
if !struct_contains(p_c,"integrate")
p_c.integrate = 0; # Augment basis funs with constant
endif
if !struct_contains(p_c,"Tau_u")
p_c.Tau_u = [];
p_c.Min_u = [];
p_c.Max_u = [];
endif
if !struct_contains(p_c,"Tau_y")
p_c.Tau_y = [];
p_c.Min_y = [];
p_c.Max_y = [];
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.1^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;
|
| ︙ | ︙ | |||
115 116 117 118 119 120 121 |
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;
K_w(2,1) = -1;
K_x = zeros(p_c.n_U,n_x);
| < > | | | < > > > > | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
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;
K_w(2,1) = -1;
K_x = zeros(p_c.n_U,n_x);
else
I = ceil(p_c.T/p_c.delta_ol) # Number of large samples
if strcmp(p_c.Method, "original")
tau = [10:0.1:11]*(2/a_u); # Time horizons
[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww] =\
ppp_lin(A,B,C,D,p_c.A_u,p_c.A_w,tau); # Design
elseif strcmp(p_c.Method, "lq") # LQ design
tau = [0:0.1:2]; # Time horizons
[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww,A_u] \
= ppp_lin_quad (A,B,C,D,tau,p_c.Q,p_c.R);
p_c.A_u = A_u;
else
error(sprintf("Control method %s not recognised", p_c.Method));
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
## Checks
[ol_zeros, ol_poles] = sys2zp(sys)
cl_poles = eig(A - B*k_x)
endif
## Initial control U
U = zeros(p_c.n_U,1);
## Short sample interval
dt = p_c.delta_ol/p_c.N;
## Observer design
G = eye(n_x); # State noise gain
sigma_x = eye(n_x); # State noise variance
|
| ︙ | ︙ | |||
176 177 178 179 180 181 182 | endif ## Display the poles obs_poles ## Write the include file for the real-time function ## Use double length to allow for overuns | < | > > > > > > > | | | 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 |
endif
## Display the poles
obs_poles
## Write the include file for the real-time function
## Use double length to allow for overuns
overrun = 2;
Ustar = ppp_ustar (p_c.A_u, n_u, [0:dt:overrun*p_c.delta_ol], 0,0);
if p_c.integrate # Integrate Ustar
disp("Integrating Ustar");
Ustar = cumsum(Ustar)*dt;
endif
disp("Writing Ustar.h");
ppp_ustar2h(Ustar);
## Control loop
y = [];
u = [];
t = [];
y_e = [];
t_e = [];
e_e = [];
tick = time;
i=0;
for j=1:4
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);
|
| ︙ | ︙ | |||
221 222 223 224 225 226 227 |
Ui = A_ud'*Ui;
y_e = [y_e; y_new'];
e_e = [e_e; e_est'];
endfor
endif
##Control
| > | > > > > > > > > > > > > > > > > > | | | > > < | 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 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 |
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
[Gamma_u, gamma_u] = \
ppp_input_constraints(p_c.A_u,p_c.Tau_u,p_c.Min_u,p_c.Max_u);
## Output constraints
[Gamma_y,gamma_y] = \
ppp_output_constraints(A,B,C,D,x_est,p_c.A_u,\
p_c.Tau_y,p_c.Min_y,p_c.Max_y);
## Composite constraints - t=0
Gamma = [Gamma_u; Gamma_y];
gamma = [gamma_u; gamma_y];
[u_qp,U] = ppp_qp (x_est,w,J_uu,J_ux,J_uw,Us0,Gamma,gamma,1e-6,1);
endif
## 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_new'];
e_e = [e_e; e_est'];
t_e = [t_e; t_i];
endif
if !Simulate
delta_comp = time-tim;
usleep(floor(1e6*(p_c.delta_ol-delta_comp-0.01)));
endif
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;
|
| ︙ | ︙ |