Commit 3e3cc9bd authored by Martin Vítek's avatar Martin Vítek

Add regulator

parent ecadbe2d
......@@ -310,4 +310,26 @@ U_{in}
\end{bmatrix}
\end{align}
\section{Regulátor}
\begin{align}
d &= -\boldsymbol{L}x_t - \boldsymbol{K}w \\
d &= -\boldsymbol{L}
\begin{bmatrix}
i_{l,t} \\ u_{c,t} \\ \Delta_{t}
\end{bmatrix}
- \boldsymbol{K}
\begin{bmatrix}
D \\ U_{in} \\ u_{c,t}^*
\end{bmatrix} \\
\boldsymbol{L} &= dlqr(\boldsymbol{A}, \boldsymbol{B}, \boldsymbol{Q}, \boldsymbol{N}, \boldsymbol{R}) \\
\boldsymbol{K} &= \{-\boldsymbol{C_w}[\boldsymbol{I}-(\boldsymbol{A}-\boldsymbol{BL})]^{-1}\boldsymbol{B}\}^{-1} \\
\boldsymbol{C}_w &= \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
\end{align}
\end{document}
......@@ -72,7 +72,7 @@ for t=dssm.Ts:dssm.Ts:tmax
end
% Plot it
plot_sim(sim, "Open loop response");
%plot_sim(sim, "Open loop response", 1);
% Regulator
......@@ -81,34 +81,66 @@ R = 1;
N = zeros(3);
L = dlqr(dsys.A, dsys.B, Q, R, N);
reg.A = dsys.A - dsys.B*L;
reg.B = zeros(3);
% Cw = eye(3);
Cw = [1, 0, 0 ; 0, 1, 0; 0, 0, 1];
p = inv(eye(3) - (dsys.A - dsys.B*L));
K = inv(-Cw * p * dsys.B);
% Simulate system (open loop)
% Simulate system (regulator)
i = 1;
i0 = 0.75;
u0 = 170;
delta0 = 0.9;
tmax = 0.2;
d0 = 0.95;
tmax = 0.6;
sim_reg.vars(:,1) = [i0, u0, delta0];
sim_reg.t(i) = 0;
sim_reg.d(:,i) = [1-d0; Uin; uc_req];
for t=Ts:Ts:tmax
sim_reg.vars(:, i+1) = reg.A*sim_reg.vars(:, i) + reg.B*[1-d; Uin; uc_req];
sim_reg.d(:,i+1) = -L*sim_reg.vars(:, i) - K*[sim_reg.d(1,i); Uin; uc_req];
if(sim_reg.d(1,i+1) > 0.99)
sim_reg.d(1,i+1) = 0.99;
end
if(sim_reg.d(1,i+1) < 0)
sim_reg.d(1,i+1) = 0;
end
%sim_reg.vars(:, i+1) = reg.A*sim_reg.vars(:, i) + reg.B*[1-d; Uin; uc_req];
sim_reg.vars(:, i+1) = dsys.A*sim_reg.vars(:, i) + dsys.B*[sim_reg.d(1,i+1); Uin; uc_req];
sim_reg.t(i+1) = t;
i = i+1;
end
% Plot it
plot_sim(sim_reg, "Regulator");
%plot_sim(sim_reg, "Regulator", 2);
figure(3);
sgtitle(sprintf("LQ regulator"));
subplot(1,4,1);
plot(sim_reg.t, sim_reg.vars(1,:));
title("il");
subplot(1,4,2);
plot(sim_reg.t, sim_reg.vars(2,:));
title("uc");
subplot(1,4,3);
plot(sim_reg.t, sim_reg.vars(3,:));
title("delta");
subplot(1,4,4);
plot(sim_reg.t, sim_reg.d(1,:));
title("d");
function plot_sim(sim, what)
% figure(1);
figure;
function plot_sim(sim, what, num)
figure(num);
sgtitle(sprintf("%s", what));
subplot(1,3,1);
plot(sim.t, sim.vars(1,:));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment