folien simulink systeme - eal.ei.tum.de · pdf filesimulink systeme inhalt •...
Post on 06-Feb-2018
221 Views
Preview:
TRANSCRIPT
SIMULINK Systeme
SIMULINK
Lineare und nichtlineare
Systeme
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14
SIMULINK Systeme
Inhalt
• SIMULINK–Bibliothek Continuous
• Von der DGL zum Continuous-Block
• Linearisierung von Blockdiagrammen
• SIMULINK–Bibliothek Discrete und Abtastsysteme
• SIMULINK–Bibliotheken Discontinuities,
Look Up Tables und User–Defined Functions
• SIMULINK–Bibliotheken Model Verification und
Model–Wide Utilities
• S–Funktionen
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14
SIMULINK Systeme
SIMULINK-Bibliothek Continuous
• Elemente zur Modellierung zeitkontinuierlicher
Systeme
• Totzeiten
Zero−Pole
(s−1)
s(s+1)Transport
Delay
Transfer Fcn
1
s+1
State−Space
x’ = Ax+Bu y = Cx+Du
PID Controller
PID(s)
Integrator,Second−Order
1
s 2ux
dxIntegrator
1/s
Derivative
du/dt
uvm.
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 1
SIMULINK Systeme
Von der DGL zum Continuous-Block (1)
Beispiel: Feder–Masse–Schwinger ohne Gewicht
L0L0k
k: Federkonstante
m
m: Masse
x
x: Auslenkung ausRuhelage
Homogene DGL:
m · x(t)︸ ︷︷ ︸
Beschleunigende Kraft
+ κ · x(t)︸ ︷︷ ︸
Ruckstellkraft der Feder
= 0︸︷︷︸u(t)=0 ⇒keine Anregung
Losung der homogenen DGL im Zeitbereich:
x(t) = x0 cos (ω0t) +v0ω0
sin (ω0t) mit
ω0: Eigenfrequenz, ω0 =√
κm
x0 = x(t = 0): Anfangsauslenkungv0 = x0: Anfangsgeschwindigkeit
Problem: Fur jede Anregung u(t) 6= 0 musseine eigene spezielle Losung der inhomoge-nen DGL berechnet werden!
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 2
SIMULINK Systeme
Von der DGL zum Continuous-Block (2)
L0L0k
k: Federkonstante
m
m: Masse
x
x: Auslenkung ausRuhelage
Daher Ubergang in den Frequenzbereichdurch Laplacetransformation der Impuls-antwort
L { x(t) + κm
· x(t) = δ(t)}︸ ︷︷ ︸
Laplacetransformation︸ ︷︷ ︸
Anregung mit Dirac-Impuls
Anwendung des Additions- und Differentia-tionssatzes (siehe z.B. Bronstein) ergibt mitx0 = 0, x0 = 0:
s2 ·X(s) + κm
·X(s) = 1
⇒ Ubertragungsfunktion:
H(s) =X(s)
U(s)
(U(s)=1)
= X(s) =1
s2 + ω20
In SIMULINK (z.B.): 1
s +22
Transfer Fcn(with initial states)
Scope
0
Constant
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 3
SIMULINK Systeme
Zeitkontinuierliche Systeme und Continuous-Blocke
Beispiele zeitkontinuierlicherSysteme
Zustandsdarstellung(
x1
x2
)
=
[
−10 50.1 −10
]
·
(
x1
x2
)
+
[
10.1
]
· u1
y1 =[10 −1
]·
(
x1
x2
)
+ 0 · u1
Ubertragungsfunktion (Polynomform)
H(s) =Y (s)
U(s)=
4s3 +5s2 + 2s+1
s4 + 8s3 +5s2 +4s+ 1
Ubertragungsfunktion (faktorisierte Form)
H(s) =Y (s)
U(s)= 1.5 ·
(s+0.75)
s(s+ 3.1)(s+0.1)
Zusammengesetzte Ubertragungsfunktionen
H(s) = H1(s) ·H2(s) =1
3s+ 1·
(s+0.7)
s(s+3.1)
Realisierung in SIMULINK
x’ = Ax+Bu y = Cx+Du
State−Space
4s +5s +2s+13 2
s +8s +5s +4s+14 3 2
Transfer Fcn
1.5(s+0.75)
s(s+3.1)(s+0.1)
Zero−Pole
(s+0.7)
s(s+3.1)Zero−Pole
1
3s+1Transfer Fcn
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 4
SIMULINK Systeme
Beispiel zu Continuous
Scope>=
RelationalOperator
1s
xo
Integrator 2
Constant1
0.5
Constant
Anfangswert
bsp continuous.slx,
S. 348 (6. Auflage), S. 358 (7. Auflage)
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 5
SIMULINK Systeme
Linearisierung / Berechnung der Zustandsdarstellung (1)
• Linearisierung von nichtlinearen Simulinkmodellen anbeliebigem Arbeitspunkt
• Berechnung der Zustandsdarstellung von linearenSimulinkmodellen
• aus Matlab / zeitkontinuierlich:
Zustandsdarstellung: [A,B,C,D] = linmod(’sys’, x, u, para)
Ubertragungsfunktion: [num, den] = linmod(’sys’, x, u, para)
Struktur: sys lin = linmod(’sys’, x, u, para)
bzw.
Zustandsdarstellung: [A,B,C,D] = linmod2(’sys’, x, u, para)
Ubertragungsfunktion: [num, den] = linmod2(’sys’, x, u, para)
Struktur: sys lin = linmod2(’sys’, x, u, para)
mit x, u, para optional
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 6
SIMULINK Systeme
Linearisierung / Berechnung der Zustandsdarstellung (2)
• aus Matlab / zeitdiskret:
Zustandsdarstellung:[Ad,Bd,Cd,Dd] = dlinmod(’sys’, Ts, x, u, para)
Ubertragungsfunktion: [numd, dend] = dlinmod(’sys’, Ts, x, u, para)
Struktur: sysd lin = dlinmod(’sys’, Ts, x, u, para)
mit x, u, para optional, Ts: Abtastzeit
• aus Simulink: Blocke
Time–Based/Trigger–Based Linearization
• Zuordnung Block ⇔ Zustand
[sizes,x0,xstring] = sys oder
sys lin.StateName
• Weitere Matlab–Befehle zur Analyse anwendbar(ss, tf, zpk, bode, lsim)
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 7
SIMULINK Systeme
Beispiel zur Linearisierung
Out22
Out11
Strecke
1
2s +1.5s+0.12
Scope
Rückführpfad
1
s+1
Anregung
In11
bsp linmod.slx,
S. 353 (6. Auflage), S. 362 (7. Auflage)
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 8
SIMULINK Abtastsysteme
SIMULINK Bibliothek Discrete
• Elemente zur Modellierung zeitdiskreter Systeme
• Abtast- und Halteglieder
Unit Delayz
1
Discrete−TimeIntegrator
K Ts
z−1
Discrete State−Space
y(n)=Cx(n)+Du(n)x(n+1)=Ax(n)+Bu(n)
Discrete PID Controller
PID(z)
Discrete Filter
1
1+0.5z −1
DiscreteZero−Pole
(z−1)
z(z−0.5)
DiscreteTransfer Fcn
1
z+0.5Difference
z−1
z
uvm.
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 9
SIMULINK Abtastsysteme
Von der Differenzengleichung zum Discrete–Block
L0L0k
k: Federkonstante
m
m: Masse
x
x: Auslenkung ausRuhelage
Differenzengleichung des Feder-Masse-
Schwingers:(
1
T2+
κ
m
)
· xk −2
T2· xk−1 +
1
T2· xk−2 = 0
z-Transformation der zeitdiskreten Impuls-
antwort ergibt z-Ubertragungsfunktion:
X(z) =1
(
1
T2+
κ
m
)
−2
T2z−1 +
1
T2· z−2
⇒ in SIMULINK (z.B.):Step Scope
1
12−20z +10z −1 −2
Discrete FilterT = 0.1
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 10
SIMULINK Abtastsysteme
Allgemeines
• Zeitdiskrete Blocke:
– Abtaster am Eingang (intern)
– Zero-Order Hold am Ausgang (intern)
– vom Benutzer muß zugehorige Abtastzeit manuell
eingetragen werden
• Abtastzeit:
– sample time = [T offset] ⇒ t = k · T + offset
– Vererbung: sample time = −1
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 11
SIMULINK Abtastsysteme
Simulationsparameter
• rein zeitdiskrete Systeme
– discrete Solver (fuhren keine Integration durch)
– variable Schrittweite: discrete (Variable Step)
– feste Schrittweite: discrete (Fixed Step), zero crossings
werden nicht erkannt
• gemischt kontinuierliche und zeitdiskrete Systeme
– bekannte Solver (−→ SIMULINK Grundlagen) konnen verwen-
det werden
– ode15s und ode113 werden nicht empfohlen
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 12
SIMULINK Abtastsysteme
Gemischte Abtastzeiten (multirate systems)
• Simulationsmodell enthalt Blocke mit unterschiedlichen
Abtastzeiten
• discrete (Variable Step) Solver: alle Blocke werden zu
ihrer jeweiligen Abtastzeit ausgewertet
• discrete (Fixed Step) Solver:
– Abtastzeiten mussen ganzzahlige Vielfache der festen Schritt-
weite sein
– Ubergange zwischen Blocken mit unterschiedlichen Abtastzei-
ten mussen beachtet werden
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 13
SIMULINK Abtastsysteme
Simulation von Multitasking–Systemen(1)
Multitasking: Blocke mit unterschiedlicher Abtastzeit haben unter-
schiedliche Prioritaten, Blocke (= Tasks) mit hoherer Prioritat konnen
Blocke mit niedrigerer Prioritat unterbrechen.
Default: Kurzere Abtastzeit = hohere Prioritat!
Beispiel: Ubergang von großer zu kleiner Abtastzeit
In Simulink:
In Echtzeit:Slower
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 14
SIMULINK Abtastsysteme
Simulation von Multitasking–Systemen(2)
• Bei Verwendung eines Fixed-step Solver und Wahl von Tasking
mode for periodic sample times zu Auto oder MultiTasking: Feh-
lermeldung bei direkter Verbindung von (zeitdiskreten) Blocken
mit unterschiedlicher Abtastzeit.
• Abhilfe: Einfugen eines Rate Transition-Blocks oder Aktivierung
der Checkbox Automatically handle rate transition for data transfer
im Solver-Register der Model Configuration Parameters Dialog-
box.
• Hinweis: beide Abhilfemaßnahmen gelten nicht nur fur periodische
Tasks (d.h. fur Blocke mit konstanter Abtastzeit), sondern auch
fur asynchrone Tasks (z.B. Interrupts durch Function-call
Subsystem-Blocke).
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 15
SIMULINK Abtastsysteme
Simulation von Multitasking–Systemen(3)
In Echtzeit mit RT:
Beispiel:
Langsamer Block Schneller Block
Scope
1/z
Rate Transition
(z−1)
z(z−0.5)Discrete
Zero−PoleTs=1sec.
1
z+0.5Discrete
Transfer FcnTs=2sec.
1
Constant
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 16
SIMULINK Abtastsysteme
Beispiel zu zeitdiskreten Systemen
Zero−Order HoldSample time =0.5sec.
Transfer Fcn
1
s +0.5s+12
Step
Sample time =0sec.
Sine WaveSample time =0sec.
Scope
Discrete Transfer Fcn1Sample time =0.5sec.
0.05263z +0.1053z+0.052632
z −1.579z+0.78952
Discrete Transfer FcnSample time =0.5sec.
0.1129z+0.1038
z −1.562z+0.77882 pt2_diskret_zoh
kontinuierlich
pt2_diskret_tustin
abgetastet
Anregung
bsp hybrid.slx,
S. 387 (6. Auflage), S. 400 (7. Auflage)
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 17
SIMULINK Systeme
Discontinuities: Bibliothek und Beispiel
Unterbibliothek Discontinuities:
Elemente zur Modellierung physika-
lischer Nichtlinearitaten
Saturation
Rate Limiter Quantizer
Hit Crossing
Dead Zone
Coulomb &Viscous Friction
Backlashuvm.
ausgabe
To WorkspaceSignal
GeneratorRate Limiter
1
Constant
Backlash
u
y
bsp backlash.slx,
S. 360 (6. Auflage), S. 369 (7. Auflage)
Deadband width
u (Stift)
u = -0,5 u = 0,5u = 0
y (Werkstück)Werkstück
Stift
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 18
SIMULINK Systeme
SIMULINK Bibliotheken Verification und Utilities
Model Verification: Prufblocke
Check Static Lower Bound
min
sig
Check Dynamic Lower Bound
Check Static Gap
maxminsig
Check Dynamic Gap
CheckDiscrete Gradient
Assertionuvm.
Model–Wide Utilities: Hilfreiche Modell–Erganzungen
Trigger−BasedLinearization
T=1
Timed−BasedLinearization
Model Info
DOCText
Block SupportTable
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 19
SIMULINK Systeme
SIMULINK Bibliotheken Tables und Functions
Lookup Tables: Modellierung von wertdiskreten,
n-dimensionalen Kennfeldern
n−D LookupTable
3−D T(u)u1
u2
u3
Prelookup
f
uk k
f
InterpolationUsing Prelookup
2−DT(k,f)
k1f1k2f2
Direct LookupTable (n−D)
2−D T[k]
2−D LookupTable
2−D T(u)u1
u2
1−D LookupTable
1−D T(u)
uvm.
User-Defined Functions: programmierbare Funktionen
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 20
SIMULINK Systeme
System Objects in Simulink - Der MATLAB System-Block (1)
• MATLAB System-Block: Einbinden von System Ob-
jects in Simulink-Modelle.
• System Objects: Systemobjekte in Form von m-Files
zur Modellierung dynamischer Systeme, Klassentyp:
matlab.system, Sprache: MATLAB
• Verwendbar in MATLAB, SIMULINK und vielen ande-
ren ’System’ Toolboxen.
• ,,Rahmenprogramm” entnehmen aus Template, dazu
im Toolstrip HOME des Matlab-Command-Window
New/System Object wahlen: Template offnet sich im
Editor.
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 21
SIMULINK Systeme
System Objects in Simulink - Der MATLAB System-Block (2)
• Weitere Beispiele unter Simulink Examples/Modeling
Features/’Custom Blocks with S-functions, System Ob-
jects and Legacy Code Tool’
pt1fun sysobj.slx
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 22
SIMULINK Systeme
S–Funktionen
• selbst–programmierbare Funktionen
• Ausfuhrung innerhalb eines SIMULINK–Modells durch
S–Function/S–Function Builder–Blocke
• programmierbar in
– Matlab (M–Files), C, C++, Fortran (MEX Files)
• Einbringen bereits vorhandenen Programm–Codes
• Compiler-Suche mit mex -v -setup
wichtig: der Matlab-interne Compiler lcc wird nicht
mehr unterstutzt!
• Compilieren der MEX Files mit mex name des MEXFiles.c
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 23
SIMULINK Systeme
Beispiel zu S–Funktionen (1)
PT1:
Y (s) =1
1+ sT· U(s) oder
x = −1
T· x+
1
T· u
y = x
Step
Scope3
Scope2
Scope1
Scope
S−Function1
pt1sfun_m
S−Function Builder
pt1sfun_csfbu0 y0
S−Function
pt1sfun_c
Level−2 MATLABS−Function
pt1sfun_m2
pt1fun.slx,S. 374 (6. Auflage),S. 384 (7.Auflage)
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 24
SIMULINK Systeme
Beispiel zu S–Funktionen (2)
Quellcode der Level-2 M-File S-Funktion pt1sfun m2.m
% Quellcode der Level-2 MATLAB S-Funktion pt1sfun_m2.m,
% fur das MATLAB-Release R2011a (Matlab 7.12, Simulink 7.7) und hoher
function pt1sfun_m2(block)
% PT1SFUN_M2 modelliert das Verhalten eines PT1-Gliedes. Die Zeit-
% konstante T wird als Parameter ubergeben
setup(block);
%endfunction
function setup(block)
%%%% Beginn Block-Info %%%%
% Eigenschaften (Anzahl I/Os, Dimension, Datentyp, Komplexitat,
% Direct Feedthrough Y/N etc.) sollen dynamisch bezogen werdenblock.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Anzahl der ubergebenen Parameterblock.NumDialogPrms = 1; % Nur T wird ubergeben
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 25
SIMULINK Systeme
Beispiel zu S–Funktionen (3)
Quellcode pt1sfun m2.m Fortsetzung
block.DialogPrmsTunable = {’Nontunable’}; % T soll wahrend der Simulation
% nicht verstellbar sein
% Anzahl der kontinuierlichen Zustandsgroßen (kann nicht dynamisch
% bezogen werden)block.NumContStates = 1;
% Abtastzeit und Offset werden zu Null gesetzt, da System
% zeitkontinuierlich gerechnet wird (konnte auch dynamisch bezogen werden)
block.SampleTimes = [0 0];
%%%% Ende Block-Info %%%%
% Benotigte Callback Methoden in dieser S-Funktion
block.RegBlockMethod(’CheckParameters’, @CheckPrms);
block.RegBlockMethod(’PostPropagationSetup’, @DoPostPropSetup);
block.RegBlockMethod(’InitializeConditions’, @InitializeConditions);block.RegBlockMethod(’Outputs’, @Outputs);
block.RegBlockMethod(’Derivatives’, @Derivatives);
%endfunction
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 26
SIMULINK Systeme
Beispiel zu S–Funktionen (4)
Quellcode pt1sfun m2.m Fortsetzung
% Uberprufe ubergebenen Parameterfunction CheckPrms(block)
if block.DialogPrm(1).Data <= 0error(’Die Zeitkonstante T muss großer Null gewahlt werden’);
end
%endfunction
% Definiere den Data Type Work Vector DWork als "globale" (d.h. von% allen Funktionen)lesbare Variable; DWork dient als Speicher fur die% System-Matrizen.function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = ’Systemmmatrizen’;% muss angegeben werdenblock.Dwork(1).Dimensions = 4; % A,B,C,Dblock.Dwork(1).DatatypeID = 0; % doubleblock.Dwork(1).Complexity = ’Real’; % reell
%endfunction
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 27
SIMULINK Systeme
Beispiel zu S–Funktionen (5)
Quellcode pt1sfun m2.m Fortsetzung
% Definiere System-Matrizen als Elemente von DWork% und setze Anfangswert der Zustandsgroßefunction InitializeConditions(block)
% Zustandsmatrix A (hier skalar)block.Dwork(1).Data(1) = [-1/block.DialogPrm(1).Data];% Eingangsmatrix B (hier skalar)block.Dwork(1).Data(2) = [ 1/block.DialogPrm(1).Data];% Ausgangsmatrix C (hier skalar)block.Dwork(1).Data(3) = [ 1 ];% Durchschaltmatrix D (hier skalar und gleich Null, da sich beim PT1% der Eingang nicht direkt auf den Ausgang auswirkt)block.Dwork(1).Data(4) = [ 0 ];
block.ContStates.Data(1) = zeros(size(block.Dwork(1).Data(1),1),1);
%endfunction
% Berechne Systemausgang zu y = C*x+D*ufunction Outputs(block)
x = block.ContStates.Data(1);u = block.InputPort(1).Data;
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 28
SIMULINK Systeme
Beispiel zu S–Funktionen (6)
Quellcode pt1sfun m2.m Fortsetzung
C = block.Dwork(1).Data(3); % Ausgangsmatrix C
D = block.Dwork(1).Data(4); % Durchschaltmatrix D
block.OutputPort(1).Data = C*x + D*u;
%endfunction% Berechne Zustandsableitung zu x’ = A*x+B*u
function Derivatives(block)
x = block.ContStates.Data(1);
u = block.InputPort(1).Data;
A = block.Dwork(1).Data(1); % Zustandsmatrix AB = block.Dwork(1).Data(2); % Eingangsmatrix B
block.Derivatives.Data(1) = A*x + B*u;
%endfunction
Lehrstuhl fur Elektrische Antriebssysteme und Leistungselektronik
Simulation mit Simulink/Matlab WS13/14 29
top related