Commit 7d734cf0 authored by Martin Vítek's avatar Martin Vítek

Fixes and experiments

parent 3e3cc9bd
......@@ -55,28 +55,28 @@ dsys.D = zeros(size(dsys.B));
% Simulate system (open loop)
i = 1;
i0 = 0.75;
u0 = 170;
delta0 = 0.9;
tmax = 0.1;
sim.vars(:,1) = [i0, u0, delta0];
sim.t(i) = 0;
for t=dssm.Ts:dssm.Ts:tmax
sim.vars(:, i+1) = dsys.A*sim.vars(:, i) + dsys.B*[1-d; Uin; uc_req];
sim.t(i+1) = t;
i = i+1;
end
% i = 1;
% i0 = 0.75;
% u0 = 170;
% delta0 = 0.9;
% tmax = 0.1;
%
% sim.vars(:,1) = [i0, u0, delta0];
% sim.t(i) = 0;
%
% for t=dssm.Ts:dssm.Ts:tmax
% sim.vars(:, i+1) = dsys.A*sim.vars(:, i) + dsys.B*[1-d; Uin; uc_req];
% sim.t(i+1) = t;
%
% i = i+1;
% end
% Plot it
%plot_sim(sim, "Open loop response", 1);
% Regulator
Q = diag([0.5, 0, 1]);
Q = diag([0, 0.01, 0.5]);
R = 1;
N = zeros(3);
L = dlqr(dsys.A, dsys.B, Q, R, N);
......@@ -90,10 +90,11 @@ K = inv(-Cw * p * dsys.B);
% Simulate system (regulator)
i = 1;
i0 = 0.75;
u0 = 170;
delta0 = 0.9;
u0 = 12;
delta0 = 0;
delta_max = 180;
d0 = 0.95;
tmax = 0.6;
tmax = 5;
sim_reg.vars(:,1) = [i0, u0, delta0];
sim_reg.t(i) = 0;
......@@ -111,6 +112,11 @@ 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.vars(:, i+1) = dsys.A*sim_reg.vars(:, i) + dsys.B*[sim_reg.d(1,i+1); Uin; uc_req];
if (abs(sim_reg.vars(3, i+1)) > delta_max)
sim_reg.vars(3, i+1) = sign(sim_reg.vars(3, i+1)) * delta_max;
end
sim_reg.t(i+1) = t;
i = i+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