simulink basics - hochschule augsburgwohlfart/download/folien_simulink_grund_e.pdf · simulink...

24
Simulink Basics SIMULINK Basics Matlab/Simulink Dipl.-Ing. U. Wohlfarth

Upload: nguyennhu

Post on 06-Feb-2018

240 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

Simulink Basics

SIMULINK

Basics

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth

Page 2: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

Simulink Basics

Content

• What’s SIMULINK?

• SIMULINK–Libraries Sources, Sinks und Math

• Simulation parameters

• Algorithm’s for numerical integration

• SIMULINK–Libraries Signals&Systems, Subsystems

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth

Page 3: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

What’s Simulink?

• Graphical modelling of dynamic systems by signal flow

graphs

• Addition to MATLAB (Toolbox)

• Simulink–Additions: Blocksets (SimPower-Systems,

SimMechanics)

gedaempfteSinusschwingung

Sine Wave

Product3

Product2Product1

Mux

eu

MathFunction −1

Gain1

−1

Gain

80

Constant

Clock

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 1

Page 4: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Starting SIMULINK

• Blocks are basic elements

• Blocks characterized by input, output, name, icon

• Double click opens

Block Parameters dialog

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 3

Page 5: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

SIMULINK block libraries Sources and Sinks

Block library Sources:

• Generation of signals

• Import data from MATLAB

workspace

• Import of data from files

StepSine WaveSignal

Generator

RepeatingSequence

Ramp PulseGenerator

untitled.mat

From File

simin

FromWorkspace

1

Constant

1In1

Block library Sinks:

• Graphical display of signals

• Write data to MATLAB

workspace

• Write data to files

1Out1

XY Graphsimout

To Workspace

untitled.mat

To File

Scope

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 4

Page 6: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Example for Sources and Sinks

Signal 1

Signal 2

Signal Builder

Scope

1s

Integrator

Signal Builder : bsp sigbuild.mdl

Signal Builder Dialog box for group of three signals

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 5

Page 7: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

SIMULINK block library Math Opertions

Block library Math:

• Arithmetic, logical and relational operators

• Mathematical and trigonometric functions

sin

TrigonometricFunction

Sum

1

SliderGain <=

RelationalOperator

Product

K*u

MatrixGain

eu

MathFunction

AND

LogicalOperator

1

Gain

Dot Product

etc.

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 6

Page 8: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Examples for Math Operations

Simulink model bspmath.mdl of equation

f(t) = 80 · e− 1

80t· sin (0.25t + π

3)

gedaempfteSinusschwingung

Sine Wave

Product3

Product2Product1

Mux

eu

MathFunction −1

Gain1

−1

Gain

80

Constant

Clock

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 7

Page 9: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Simulation: parameters and solvers

Configuration

Parameters

dialog box

Solver pane:

• Specify start and stop time of simulation

• Solvers for numerical integration

• Output options

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 8

Page 10: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Numerical integration of ODE

Inhomogeneous linear ordinary differential equation:

DGL y(t)u(t) y(t) = f(u(t), y(t))

Integration: yn+1 = yn +

tn+1∫

tn

f(u(t), y(t))dt

Numerous methods:

• Euler method• Heun’s method• Other Runge–Kutta–methods• Adams–Bashforth methods• · · ·

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 9

Page 11: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Numerical integration of ODE

Euler method (explicit)

y0

y0

hy0y(t)

t0

h

t1t

y1

y

dyy(t1)

y1 = y0 + h · y0

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 10

Page 12: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Numerical integration of ODE

Runge–Kutta method

y0

y0

y1 P3(t)

P3 2 2(t ) = yP

t0

h

t1 t2t

y1

y

y2 = y0 +2h

6· [y0 + 4y1 + f(u2, yP

2 )]

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 11

Page 13: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Numerical integration of ODE

Adams–Bashforth method

yn-2

P2(t)

P2 n+1(t )

tn-2 tn-1 tn tn+1

t

yn-1

yn

y

h

yn+1 = yn +h

12· [23yn − 16yn−1 + 5yn−2]

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 12

Page 14: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Solver: integration algorithms in MATLAB

Variable–step solver:

• use variable step size

• allow error control & detection of zero crossings

• for continuous-time, non-stiff systems:

⇒ ode45 (first try), ode23, ode113

• for continuous-time, stiff systems:

⇒ ode15s, ode23s, ode23t,ode23tb

• for discrete-time systems:

⇒ discrete (Variable–step)

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 13

Page 15: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Solver: integration algorithms in MATLAB

Fixed–step solver:

• use fixed step size

• no error control

• no detection of zero crossings

• for continuous-time systems:

⇒ ode5, ode4, ode3, ode2, ode1

• for discrete-time systems:

⇒ discrete (Fixed–step)

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 17

Page 16: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Simulation: parameters and solver methods

Configuration

Parameters

dialog box

Data Import/Export pane:

• Initialization

• Load data from Workspace

• Write data to Workspace

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 18

Page 17: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Simulation: parameters and solver methods

Configuration

Parameters

dialog box

Diagnostics pane:

• Control of warning and error messages

• Set simulation options

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 19

Page 18: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Simulation

Start and stop of simulation

• from SIMULINK window

• from MATLAB Command Window

– set_param(’sys’, ’SimulationCommand’, ’cmd’)

get_param(’sys’, ’SimulationStatus’)

– [t,x,y] = sim(’model’, timespan, options, ut)

options = simset(property, value, ...)

newopts = simset(oldopts, property, value, ...)

struct = simget(’model’)

Example:[t,x,y] = sim(’m1’,[],simset(simget(’m1’),’Solver’,’ode23’,’MaxStep’,0.01))

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 20

Page 19: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Error handling

Simulation

Diagnostics

Viewer

• upper part: error information

• lower part: complete text of error message

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 23

Page 20: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

SIMULINK block library Signal Routing

Block library Signal Routing:

• Date saving

A

Data StoreWrite

A

Data StoreRead

A

Data StoreMemory

• Connect and selection of signals

SelectorMux

[1]

ICHit Crossing

[A]

Goto

[A]

From

Demux

Demux

BusSelector

etc.

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 24

Page 21: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Subsystems

Subsystems:

• Structural order of complex models

• Combining blocks of similar function

• hierarchic structuring

• Creation by

1. menue item Edit/Create Subsystem

2. block library Subsystems

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 25

Page 22: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

SIMULINK block library Subsystems

Block library Subsystems:

while { ... }In1

ICOut1

While IteratorSubsystem

In1 Out1

TriggeredSubsystem

In1 Out1

Subsystem

ActionIn1 Out1

If ActionSubsystem

u1if(u1 > 0)

else

If

function()

In1 Out1

Function−CallSubsystem

In1 Out1

EnabledSubsystem

In1 Out1

Atomic Subsystem

etc.

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 26

Page 23: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Conditionally executed subsystems / Masking

Conditionally Executed Subsystems

• Execution controlled by control signal

• comprise Enable or Trigger

Masking of subsystems

• building a new block from a subsystem

• easier parametrization of complex subsystems

• Setting up of user defined libraries

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 27

Page 24: SIMULINK Basics - Hochschule Augsburgwohlfart/download/folien_simulink_grund_e.pdf · SIMULINK Basics Starting SIMULINK † Blocks are basic elements † Blocks characterized by input,

SIMULINK Basics

Masking of subsystems

Example bspmask.mdl

b y−Achsenabschnitt

m

Steigung

yx

⇒y=mx+b

Matlab/Simulink

Dipl.-Ing. U. Wohlfarth 28