Azzera filtri
Azzera filtri

Resetting only a section of my state during event driven ode45 simulation

20 visualizzazioni (ultimi 30 giorni)
Hello,
I'm trying to write a code that simulates a closed loop event driven LTI system (with a poleplacement controller u(t) = -K*x(t)). I'm using the following event formulation:
where the ξ stands for the actual state and the ϵ stands for the error between the current state and the state measured during an event trigger. So:
So I want to trigger an event the moment the value becomes 0.
Now, the problem I'm having is that I want the ϵ value (so the error) to reset to 0 upon an event but the ξ part of the state should not reset. I'm having trouble coming up with a way to exactly program this. I'm currently just simulating the system dynamics for the augmented system, so for . For now I have the following in matlab:
a = 4;
b = 6;
c = 9;
poles = [-1+2i; -1-2i];
A = [0.3+a-b, 0.5-c; 0, 1];
B = [0; 1];
C = eye(2);
D = [0; 0];
K = place(A, B, poles);
A_aug = [A-B*K -B*K;
-A+B*K B*K];%Defining augmented CL A-matrix for augmented state x_augmented = [x;error]//[xi;epsilon]
tspan = [0,10];
x0 = [1;1;0;0];
Q = eye(2);
P = 2*eye(2);
sig = 0.1;
options = odeset('Events', @(t,x) myEventsFcn(t,x,sig,Q,P,B,K));
[t,y,te,ye,ie] = ode45(@(t,x) LTIaug_fun(t,x,A_aug),tspan,x0,options)
t = 25x1
1.0e+00 * 0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0002
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y = 25x4
1.0000 1.0000 0 0 0.9999 1.0000 0.0001 -0.0000 0.9999 1.0000 0.0001 -0.0000 0.9998 1.0000 0.0002 -0.0000 0.9998 1.0000 0.0002 -0.0000 0.9995 1.0000 0.0005 -0.0000 0.9993 1.0000 0.0007 -0.0000 0.9990 1.0000 0.0010 -0.0000 0.9988 1.0000 0.0012 -0.0000 0.9975 1.0001 0.0025 -0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
te = 0.0514
ye = 1x4
0.4953 1.0120 0.5047 -0.0120
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ie = 1
Where the LTIaug_fun and myEventsFcn are defined as follows:
function dxdt = LTIaug_fun(~,x,A_aug)
dxdt = A_aug*x;
end
function [value,isterminal,direction] = myEventsFcn(t,x,sig,Q,P,B,K)
Th = [(1-sig)*Q P*B*K;
(B*K)'*P zeros(2,2)];
Th_e = x'*Th*x;
value = Th_e;
isterminal = 1;
direction = 0;
end
So how do I set my ϵ part of my augmented state to 0 after/during an event trigger?

Risposte (1)

Torsten
Torsten il 25 Mag 2024 alle 17:53
Spostato: Torsten il 25 Mag 2024 alle 17:54
After the event has been triggered, control is returned to the calling program.
If you want to continue integration with the epsilon part set to 0, you can just call ode45 anew with the initial x0-vector set to x0 = [ye(1:2),0,0].

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by