Skip to content
Snippets Groups Projects
Commit 57bea939 authored by Adam Friedrich Schrey's avatar Adam Friedrich Schrey
Browse files

Rewrite code in Python and add interactive widgets in...

Rewrite code in Python and add interactive widgets in V09_zustandsrekonstruktion_mittels_beobachter.ipynb
parent 946ca5c7
Branches
No related tags found
1 merge request!1merge develop into master
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
# <span style='color:OrangeRed'>V9 - Zustandsrekonstruktion mittels Beobachter</span> # <span style='color:OrangeRed'>V9 - Zustandsrekonstruktion mittels Beobachter</span>
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## <span style='color:Gray'>Beispiel #1 </span> ## <span style='color:Gray'>Beispiel #1 </span>
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Für das System: Für das System:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
pkg load control pkg load control
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
A = [-2 1; A = [-2 1;
0 -1]; 0 -1];
   
B = [1; 1]; B = [1; 1];
   
C = [1 0]; C = [1 0];
   
D = 0; D = 0
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
soll ein Beobachter entworfen werden mit den Polen: $s_{1,2}$ = [-10+1j*5 -10-1j*5] soll ein Beobachter entworfen werden mit den Polen: $s_{1,2}$ = [-10+1j*5 -10-1j*5]
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
poles = [-10+1j*5 -10-1j*5] poles = [-10+1j*5 -10-1j*5]
% po = [-5+1j*5 -5-1j*5] % Beobachterpole % po = [-5+1j*5 -5-1j*5] % Beobachterpole
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
So = [C; C*A] So = [C; C*A]
rank(So) rank(So)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Zunächst prüfen wir die Beobachtbarkeit und die Beobachterverstärkung wird berechnet zu: Zunächst prüfen wir die Beobachtbarkeit und die Beobachterverstärkung wird berechnet zu:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
G = place(A',C',poles) G = place(A',C',poles)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Durch die Matrix <code>G</code> ändert sich das dynamische Verhalten des geschlossenen Systems Durch die Matrix <code>G</code> ändert sich das dynamische Verhalten des geschlossenen Systems
mit Beobachter. mit Beobachter.
<br> bestimmen wir die Eigenwerte für das System mit Beobachter: <br> bestimmen wir die Eigenwerte für das System mit Beobachter:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Ao = A-G'*C Ao = A-G'*C
eigs(Ao) eigs(Ao)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Bo = [B G'] Bo = [B G']
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Veranschaulichung durch Simulink: Veranschaulichung durch Simulink:
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
![V9_Update-1.png](attachment:V9_Update-1.png) ![V9_Update-1.png](attachment:V9_Update-1.png)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
% Simulink model A % Simulink model A
% Set the Octave Engine to run the simulation % Set the Octave Engine to run the simulation
% Simulation Parameters % Simulation Parameters
addpath("./Octsim"); addpath("./Octsim");
% Start time % Start time
tini = 0; tini = 0;
% End time % End time
tfinal = 10; tfinal = 10;
% Time Step % Time Step
dt = 0.001; dt = 0.001;
% Number of data flows in the schematic % Number of data flows in the schematic
nflows_1 = 12; nflows_1 = 12;
% Initial conditions % Initial conditions
xo_1 = [2; 1]; xo_1 = [2; 1];
xo_2 = [0; 0]; xo_2 = [0; 0];
   
% Matrices % Matrices
C2 = eye(2); C2 = eye(2);
D2 = [0;0]; D2 = [0;0];
Do = zeros(2,2); Do = zeros(2,2);
   
% Instance of the simulation schematic % Instance of the simulation schematic
sc1 = Schema(tini,tfinal,dt,nflows_1); sc1 = Schema(tini,tfinal,dt,nflows_1);
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
<br><span style='color:Orange'>SquareSignal Function Definition:</span> <br><span style='color:Orange'>SquareSignal Function Definition:</span>
<br><code>SquareSignal(1.argument = output, 2.argument = high, 3.argument = low, 4.argument = frequency , 5.argument = duty cycle )</code> <br><code>SquareSignal(1.argument = output, 2.argument = high, 3.argument = low, 4.argument = frequency , 5.argument = duty cycle )</code>
<br>Der Tastgrad (eng. Duty Cycle) wird als Verhältniszahl mit einem Wertebereich von 0 bis 1 oder 0 bis 100 % angegeben. Hier 50 (default). <br>Der Tastgrad (eng. Duty Cycle) wird als Verhältniszahl mit einem Wertebereich von 0 bis 1 oder 0 bis 100 % angegeben. Hier 50 (default).
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
c1{1} = SquareSignal(1,10,0,1,0.5); %input c1{1} = SquareSignal(1,10,0,1,0.5); %input
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
c1{2} = StateSpace(1,[2 3],A,B,C2,D2,xo_1); % original system c1{2} = StateSpace(1,[2 3],A,B,C2,D2,xo_1); % original system
   
c1{3} = StateSpace(1,[4 5],A,B,C2,D2,xo_2); % erroneous system c1{3} = StateSpace(1,[4 5],A,B,C2,D2,xo_2); % erroneous system
c1{4} = StateSpace([1 8],[6 7],Ao,Bo,C2,Do,xo_2); % observer system c1{4} = StateSpace([1 8],[6 7],Ao,Bo,C2,Do,xo_2); % observer system
   
c1{5} = Gain([2 3],8,C); c1{5} = Gain([2 3],8,C);
   
c1{6} = Sum(2,4,9,1,-1); c1{6} = Sum(2,4,9,1,-1);
c1{7} = Sum(3,5,10,1,-1); c1{7} = Sum(3,5,10,1,-1);
c1{8} = Sum(2,6,11,1,-1); c1{8} = Sum(2,6,11,1,-1);
c1{9} = Sum(3,7,12,1,-1); c1{9} = Sum(3,7,12,1,-1);
sc1.AddListComponents(c1); sc1.AddListComponents(c1);
   
% Run the schematic and plot % Run the schematic and plot
out1 = sc1.Run([1:12]); out1 = sc1.Run([1:12]);
time1 = out1(1,:); time1 = out1(1,:);
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time1,out1(3,:), time1,out1(4,:)); plot(time1,out1(3,:), time1,out1(4,:));
legend('State-Space 1, x_{dot}','State-Space 1, y') legend('State-Space 1, x_{dot}','State-Space 1, y')
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time1,out1(10,:),'r',time1,out1(11,:),'b'); plot(time1,out1(10,:),'r',time1,out1(11,:),'b');
legend('Reale System','System mit falsche Bedingungen vor t0') legend('Reale System','System mit falsche Bedingungen vor t0')
grid on grid on
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time1,out1(12,:),'r',time1,out1(13,:),'b'); plot(time1,out1(12,:),'r',time1,out1(13,:),'b');
legend('Offene Kreis','System mit Beobachter') legend('Offene Kreis','System mit Beobachter')
grid on grid on
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## <span style='color:Gray'>Beispiel #2 </span> ## <span style='color:Gray'>Beispiel #2 </span>
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Für das System der Zustandsraumdarstellung: Für das System der Zustandsraumdarstellung:
<br>$\dot{x}(t)$= $Ax(t)$ + $bu(t)$ <br>$\dot{x}(t)$= $Ax(t)$ + $bu(t)$
<br>$y(t)$=$c^Tx(t)$ <br>$y(t)$=$c^Tx(t)$
<br>Mit Matrizen: <br>Mit Matrizen:
<br> $A$ = $\left[ \begin{array}{rrrr} <br> $A$ = $\left[ \begin{array}{rrrr}
1 & 1 \\ 1 & 1 \\
-2 & -1 \\ -2 & -1 \\
\end{array}\right] $ \end{array}\right] $
<br><br> $B$ = $\left[ \begin{array}{rrrr} <br><br> $B$ = $\left[ \begin{array}{rrrr}
0 \\ 0 \\
1 \\ 1 \\
\end{array}\right] $ \end{array}\right] $
<br><br> $C$ = $\left[ \begin{array}{rrrr} <br><br> $C$ = $\left[ \begin{array}{rrrr}
1 & 0 \\ 1 & 0 \\
\end{array}\right] $ \end{array}\right] $
<br><br> $D$ = $0$ <br><br> $D$ = $0$
<br>vergleichen wir das dynamische Verhalten <br>vergleichen wir das dynamische Verhalten
vom geschlossenen Regelkreis ohne und mit vom geschlossenen Regelkreis ohne und mit
Beobachter. Beobachter.
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
A = [-2 1; A = [-2 1;
0 -1]; 0 -1];
   
B = [0; 1]; B = [0; 1];
   
C = [1 0]; C = [1 0];
   
D = 0; D = 0;
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Zunächst prüfen wir die Steuerbarkeit: Zunächst prüfen wir die Steuerbarkeit:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Sc = [B A*B] Sc = [B A*B]
rank(Sc) rank(Sc)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Dann wird die Beobachtbarkeit geprüft: Dann wird die Beobachtbarkeit geprüft:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
So = [C; C*A] So = [C; C*A]
rank(So) rank(So)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Gebe nun für den geschlossenen Regelkreis diese zwei Pole vor: Gebe nun für den geschlossenen Regelkreis diese zwei Pole vor:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
pc = [-5+1j*5 -5-1j*5] pc = [-5+1j*5 -5-1j*5]
K = place(A,B,pc) K = place(A,B,pc)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Der Beobachterpol beträgt: Der Beobachterpol beträgt:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
csi = 0.8; csi = 0.8;
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Wähle die Grundfrequenz zu $\omega_0$ = 10: Wähle die Grundfrequenz zu $\omega_0$ = 10:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
omega0 =10; omega0 =10;
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Definition von Beobachterpolen in Bezug auf die Grundfrequenz $\omega_0$ um das dynamische Definition von Beobachterpolen in Bezug auf die Grundfrequenz $\omega_0$ um das dynamische
Verhalten zu ändern: Verhalten zu ändern:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
poles = [-csi*omega0+1j*omega0*sqrt(1-csi*csi) -csi*omega0-1j*omega0*sqrt(1-csi*csi)] poles = [-csi*omega0+1j*omega0*sqrt(1-csi*csi) -csi*omega0-1j*omega0*sqrt(1-csi*csi)]
G = place(A',C',poles) G = place(A',C',poles)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Berechne die Beobachter Eigenwerte: Berechne die Beobachter Eigenwerte:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Ao = A-G'*C Ao = A-G'*C
eigs(Ao) eigs(Ao)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Bo = [B G'] Bo = [B G']
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Wir arbeiten nun mit folgendem Simulink Modell: Wir arbeiten nun mit folgendem Simulink Modell:
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
![V9_Update-2.png](attachment:V9_Update-2.png) ![V9_Update-2.png](attachment:V9_Update-2.png)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
% Simulink model A % Simulink model A
% Set the Octave Engine to run the simulation % Set the Octave Engine to run the simulation
% Simulation Parameters % Simulation Parameters
addpath("./Octsim"); addpath("./Octsim");
% Start time % Start time
tini = 0; tini = 0;
% End time % End time
tfinal = 5; tfinal = 5;
% Time Step % Time Step
dt = 0.01; dt = 0.01;
% Number of data flows in the schematic % Number of data flows in the schematic
nflows_2 = 11; nflows_2 = 11;
% Initial conditions % Initial conditions
xo_1 = [2; 1]; xo_1 = [2; 1];
xo_2 = [0; 0]; xo_2 = [0; 0];
   
% Matrices % Matrices
C2 = eye(2); C2 = eye(2);
D2 = [0;0]; D2 = [0;0];
Do = zeros(2,2); Do = zeros(2,2);
   
% Instance of the simulation schematic % Instance of the simulation schematic
sc2 = Schema(tini,tfinal,dt,nflows_2); sc2 = Schema(tini,tfinal,dt,nflows_2);
   
c2{1} = StateSpace(3,[1 2],A,B,C2,D2,xo_1); c2{1} = StateSpace(3,[1 2],A,B,C2,D2,xo_1);
c2{2} = Gain([1 2],3,-K); c2{2} = Gain([1 2],3,-K);
   
c2{3} = StateSpace(6,[4 5],A,B,C2,D2,xo_1); c2{3} = StateSpace(6,[4 5],A,B,C2,D2,xo_1);
c2{4} = Gain([7 8],6,-K); c2{4} = Gain([7 8],6,-K);
   
c2{5} = StateSpace([6 9],[7 8],Ao,Bo,C2,Do,xo_2); c2{5} = StateSpace([6 9],[7 8],Ao,Bo,C2,Do,xo_2);
c2{6} = Gain([4 5],9,C); c2{6} = Gain([4 5],9,C);
   
c2{7} = Sum(1,4,10,1,-1); c2{7} = Sum(1,4,10,1,-1);
c2{8} = Sum(2,5,11,1,-1); c2{8} = Sum(2,5,11,1,-1);
   
sc2.AddListComponents(c2); sc2.AddListComponents(c2);
   
% Run the schematic and plot % Run the schematic and plot
out2 = sc2.Run([1:11]); out2 = sc2.Run([1:11]);
time2 = out2(1,:); time2 = out2(1,:);
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time2,out2(2,:),'r',time2,out2(3,:),'b'); plot(time2,out2(2,:),'r',time2,out2(3,:),'b');
legend('State-Space:1','State-Space:2') legend('State-Space:1','State-Space:2')
grid on grid on
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time2,out2(8,:),'r',time2,out2(9,:),'b'); plot(time2,out2(8,:),'r',time2,out2(9,:),'b');
legend('State-Space 2:1','State-Space 2:2') legend('State-Space 2:1','State-Space 2:2')
grid on grid on
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
<b> Aufgabe </b>: Wiederholen Sie nun die Simulation mit $\omega_0$ = 1, d.h. langsamer! <b> Aufgabe </b>: Wiederholen Sie nun die Simulation mit $\omega_0$ = 1, d.h. langsamer!
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
% Update values with new omega % Update values with new omega
omega1 =1; omega1 =1;
poles = [-csi*omega1+1j*omega1*sqrt(1-csi*csi) -csi*omega1-1j*omega1*sqrt(1-csi*csi)]; poles = [-csi*omega1+1j*omega1*sqrt(1-csi*csi) -csi*omega1-1j*omega1*sqrt(1-csi*csi)];
G = place(A',C',poles); G = place(A',C',poles);
Ao = A-G'*C; Ao = A-G'*C;
eigs(Ao); eigs(Ao);
Bo = [B G']; Bo = [B G'];
   
% Start time % Start time
tini = 0; tini = 0;
% End time % End time
tfinal = 5; tfinal = 5;
% Time Step % Time Step
dt = 0.001; dt = 0.001;
% Number of data flows in the schematic % Number of data flows in the schematic
nflows_2 = 11; nflows_2 = 11;
% Initial conditions % Initial conditions
xo_1 = [2; 1]; xo_1 = [2; 1];
xo_2 = [0; 0]; xo_2 = [0; 0];
   
% Matrices % Matrices
C2 = eye(2); C2 = eye(2);
D2 = [0;0]; D2 = [0;0];
Do = zeros(2,2); Do = zeros(2,2);
   
% Instance of the simulation schematic % Instance of the simulation schematic
sc2 = Schema(tini,tfinal,dt,nflows_2); sc2 = Schema(tini,tfinal,dt,nflows_2);
   
c2{1} = StateSpace(3,[1 2],A,B,C2,D2,xo_1); c2{1} = StateSpace(3,[1 2],A,B,C2,D2,xo_1);
c2{2} = Gain([1 2],3,-K); c2{2} = Gain([1 2],3,-K);
   
c2{3} = StateSpace(6,[4 5],A,B,C2,D2,xo_1); c2{3} = StateSpace(6,[4 5],A,B,C2,D2,xo_1);
c2{4} = Gain([7 8],6,-K); c2{4} = Gain([7 8],6,-K);
   
c2{5} = StateSpace([6 9],[7 8],Ao,Bo,C2,Do,xo_2); c2{5} = StateSpace([6 9],[7 8],Ao,Bo,C2,Do,xo_2);
c2{6} = Gain([4 5],9,C); c2{6} = Gain([4 5],9,C);
   
c2{7} = Sum(1,4,10,1,-1); c2{7} = Sum(1,4,10,1,-1);
c2{8} = Sum(2,5,11,1,-1); c2{8} = Sum(2,5,11,1,-1);
   
sc2.AddListComponents(c2); sc2.AddListComponents(c2);
   
% Run the schematic and plot, now having omega:=1 % Run the schematic and plot, now having omega:=1
out2 = sc2.Run([1:11]); out2 = sc2.Run([1:11]);
time2 = out2(1,:); time2 = out2(1,:);
plot(time2,out2(8,:),'r',time2,out2(9,:),'b'); plot(time2,out2(8,:),'r',time2,out2(9,:),'b');
legend('State-Space 2:1','State-Space 2:2') legend('State-Space 2:1','State-Space 2:2')
grid on grid on
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Differenz der Systeme: Differenz der Systeme:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time2,out2(11,:),'r',time2,out2(12,:),'b'); plot(time2,out2(11,:),'r',time2,out2(12,:),'b');
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## <span style='color:Gray'>Beispiel #3 </span> ## <span style='color:Gray'>Beispiel #3 </span>
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Nun arbeiten wir mit einem diskreten System. Für das System mit der Zustandsraumdarstellung: Nun arbeiten wir mit einem diskreten System. Für das System mit der Zustandsraumdarstellung:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
A = [-2 1; A = [-2 1;
0 -1]; 0 -1];
   
B = [0; 1]; B = [0; 1];
   
C = [1 0]; C = [1 0];
   
D = 0; D = 0;
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
und der Abtastzeit $T_s=0.1$ wollen wir das dynamische Verhalten vom geschlossenen Regelkreis ohne und mit Beobachter vergleichen. und der Abtastzeit $T_s=0.1$ wollen wir das dynamische Verhalten vom geschlossenen Regelkreis ohne und mit Beobachter vergleichen.
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Zunächst prüfen wir die Steuerbarkeit: Zunächst prüfen wir die Steuerbarkeit:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Sc = [B A*B] Sc = [B A*B]
rank(Sc) rank(Sc)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Das System ist zeitdiskret. Infolgedessen führe folgenden Berechnungen durch: Das System ist zeitdiskret. Infolgedessen führe folgenden Berechnungen durch:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Ts = 0.01; Ts = 0.01;
   
pc = [-5+1j*5 -5-1j*5]; pc = [-5+1j*5 -5-1j*5];
pcd = exp(pc.*Ts); pcd = exp(pc.*Ts);
Ad = expm(A*Ts) Ad = expm(A*Ts)
Bd = (Ad-eye(2))*inv(A)*B Bd = (Ad-eye(2))*inv(A)*B
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Reglerentwurf: Reglerentwurf:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
K = place(Ad,Bd,pcd) K = place(Ad,Bd,pcd)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Die Beobachtbarkeit wird geprüft: Die Beobachtbarkeit wird geprüft:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
So = [C; C*Ad] So = [C; C*Ad]
rank(So) rank(So)
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Beobachter Eigenwerte: Beobachter Eigenwerte:
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
poles = [0 0]; poles = [0 0];
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Es handelt sich um einen <span style='color:OrangeRed'>Deadbeat Beobachter</span>! Es handelt sich um einen <span style='color:OrangeRed'>Deadbeat Beobachter</span>!
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
<div style="font-family: 'times'; font-size: 13pt; text-align: justify"> <div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Beobachterpole: Beobachterpole:
<br><span style='color:Gray'>Hinweis</span>: Verwende Funktion <code>acker</code> anstelle von <code>place</code>! <br><span style='color:Gray'>Hinweis</span>: Verwende Funktion <code>acker</code> anstelle von <code>place</code>!
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
Gd = acker(Ad',C',poles) Gd = acker(Ad',C',poles)
   
Aod = Ad-Gd'*C Aod = Ad-Gd'*C
eigs(Aod) eigs(Aod)
Bod = [Bd Gd']; Bod = [Bd Gd'];
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
![V9_Update-3.png](attachment:V9_Update-3.png) ![V9_Update-3.png](attachment:V9_Update-3.png)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
% Simulink model A % Simulink model A
% Number of data flows in the schematic % Number of data flows in the schematic
% Start time % Start time
tini = 0; tini = 0;
% End time % End time
tfinal = 3; tfinal = 3;
% Time Step % Time Step
dt = 0.001; dt = 0.001;
% Number of data flows in the schematic % Number of data flows in the schematic
nflows_3 = 13; nflows_3 = 13;
% Initial conditions % Initial conditions
xo_1 = [2; 1]; xo_1 = [2; 1];
xo_2 = [0; 0]; xo_2 = [0; 0];
   
% Matrices % Matrices
C2 = eye(2); C2 = eye(2);
D2 = [0;0]; D2 = [0;0];
Do = zeros(2,2); Do = zeros(2,2);
   
% Instance of the simulation schematic % Instance of the simulation schematic
sc3 = Schema(tini,tfinal,dt,nflows_3); sc3 = Schema(tini,tfinal,dt,nflows_3);
   
c3{1} = ZOH(4,1,Ts); %ZOH arguments: in_ID,out_ID,T c3{1} = ZOH(4,1,Ts); %ZOH arguments: in_ID,out_ID,T
c3{2} = StateSpace(1,[2 3],A,B,C2,D2,xo_1); c3{2} = StateSpace(1,[2 3],A,B,C2,D2,xo_1);
c3{3} = Gain([2 3],4,-K); c3{3} = Gain([2 3],4,-K);
   
c3{4} = ZOH(11,5,Ts); c3{4} = ZOH(11,5,Ts);
c3{5} = StateSpace(5,[6 7],A,B,C2,D2,xo_1); c3{5} = StateSpace(5,[6 7],A,B,C2,D2,xo_1);
   
c3{6} = Sum(2,6,12,1,-1); c3{6} = Sum(2,6,12,1,-1);
c3{7} = Sum(3,7,13,1,-1); c3{7} = Sum(3,7,13,1,-1);
   
c3{8} = Gain([6 7],8,C); c3{8} = Gain([6 7],8,C);
   
% Notice, that we introduce the discrete StateSpace Object here: DTStateSpace(in,out,A,B,C,D,T,xo) % Notice, that we introduce the discrete StateSpace Object here: DTStateSpace(in,out,A,B,C,D,T,xo)
c3{9} = DTStateSpace([11 8],[9 10],Aod,Bod,C2,Do,Ts,xo_2); c3{9} = DTStateSpace([11 8],[9 10],Aod,Bod,C2,Do,Ts,xo_2);
   
c3{10} = Gain([9 10],11,-K); c3{10} = Gain([9 10],11,-K);
   
sc3.AddListComponents(c3); sc3.AddListComponents(c3);
   
% Run the schematic and plot % Run the schematic and plot
out3 = sc3.Run([1:13]); out3 = sc3.Run([1:13]);
time3 = out3(1,:); time3 = out3(1,:);
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
**Plot zeitdiskreten Regelkreis ohne Beobachter:** **Plot zeitdiskreten Regelkreis ohne Beobachter:**
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time3,out3(3,:),'r',time3,out3(4,:),'b'); plot(time3,out3(3,:),'r',time3,out3(4,:),'b');
legend('State-Space:1','State-Space:2') legend('State-Space:1','State-Space:2')
grid on grid on
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
**Plot Regelkreis mit Zustandsbeobachter:** **Plot Regelkreis mit Zustandsbeobachter:**
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time3,out3(7,:),'r',time3,out3(8,:),'b'); plot(time3,out3(7,:),'r',time3,out3(8,:),'b');
legend('State-Space 1:1','State-Space 1:2') legend('State-Space 1:1','State-Space 1:2')
grid on grid on
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
**Plot Differenz beider Regelkreise:** **Plot Differenz beider Regelkreise:**
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time3,out3(13,:),'r',time3,out3(14,:),'b'); plot(time3,out3(13,:),'r',time3,out3(14,:),'b');
legend('Discrete State-Space:1','Discrete State-Space:2') legend('Discrete State-Space:1','Discrete State-Space:2')
grid on grid on
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` octave ``` python
plot(time3,out3(10,:),'r',time3,out3(11,:),'b'); plot(time3,out3(10,:),'r',time3,out3(11,:),'b');
legend('Discrete State-Space:1','Discrete State-Space:2') legend('Discrete State-Space:1','Discrete State-Space:2')
grid on grid on
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment