42
3/30/2011 1 Università degli Studi di Modena e Reggio Emilia A utomation R obotics and S ystem CONTROL Modeling and Simulation Cesare Fantuzzi University of Modena and Reggio Emilia 21/03/2011 1 Course syllabus Part 1: Theory of Modeling and Simulation. Part 2: Numerical simulation. Part 3: How develop simulation projects using Matlab and Simulink. Part 4: Case studies. 21/03/2011 2

001 Modeling and simulation - · PDF file3/30/2011 2 Part 1: Theory of Modeling and Simulation 1. Definition and terminology concerning Modeling and Simulation. 2. Model physical system

Embed Size (px)

Citation preview

3/30/2011

1

Università degli Studidi Modena e Reggio Emilia

AutomationRobotics andSystemCONTROL

Modeling and Simulation

Cesare FantuzziUniversity of Modena and Reggio Emilia

21/03/2011

1

Course syllabus

� Part 1: Theory of Modeling and Simulation.� Part 2: Numerical simulation.� Part 3: How develop simulation projects using Matlab

and Simulink.� Part 4: Case studies.

21/03/2011 2

3/30/2011

2

Part 1: Theory of Modeling and Simulation

1. Definition and terminology concerning Modeling and Simulation.

2. Model physical system with static and dynamic equations, linear and nonlinear models, state space model and input-output model. Model with energetic considerations. Physical models, parametric models, models with lumped and distributed parameters. Universal approximates (fuzzy, neural networks, etc.).

3. Model the time: time continuous and time discrete models, discrete event models.

4. System identification

21/03/2011 3

Main concepts

System Model

SimulationExperiments

21/03/2011 4

3/30/2011

3

What is a System?

� A system is an object or collection of objects whose properties we want to study.

� Formal definition: – A System is a real or virtual environment viewed as a source of

observational data or more specifically, behavior.

� A system can contain subsystems which are themselves systems.

� An important property of systems is that they should be observable.– A system has always Inputs and outputs

21/03/2011 5

System

� Controllable systems : we can influence their behavior through inputs.

� Observable systems : we can measure their behavior through outputs

21/03/2011 6

3/30/2011

4

Extract information from Systems

� An experiment is the process of extracting information from a system by exercising its inputs.

� To perform an experiment on a system it must be both controllable (for inputs) and observable (for outputs).

� The system must be also be “stable ” (i.e. our experiment doesn’t destroy the system itself).

� Engineering and physical knowledge help in gathering system information– i.e. derive a model (mathematical, logical, heuristic, etc.)

21/03/2011 7

What is a Model?

� A model of a system is anything an "experiment" can be applied to in order to answer questions about that system.

� This implies that a model can be used to answer questions about a system without doing experiments on the real system.

� A Representation of an object, a system, or an idea in some form other than that of the entity itself (Claude ElwoodShannon) .

21/03/2011 8

3/30/2011

5

What is Simulation?

� A simulation is an experiment performed on a model:– A simulation of an industrial process such as steel or pulp

manufacturing, to learn about the behavior under different operating conditions in order to improve the process.

– A simulation of vehicle behavior, e.g. of a car or an airplane, for the purpose of providing realistic operator training.

� It is important to realize that the experiment description and model description parts of a simulation are conceptually separate entities.

� Analytical techniques usually apply only under a set of simplifying assumptions. Simulation is considered as a different approach from analytical techniques.

� The value of the simulation results is dependent on how well the model represents the system

21/03/2011 9

Why Simulation?

� Experiments are too expensive, too dangerous, or the system to be investigated does not yet exist.

� The time scale of the dynamics of the system is not compatible with that of the experimenter.

� Variables may be inaccessible in real system.– In simulation all variables can be controlled.

� Easy manipulation of models.� Suppression of disturbances and Suppression of

second-order effects. – This can allow us to isolate particular effects and thereby gain a

better understanding of those effects.

21/03/2011 10

3/30/2011

6

But, be aware of….

� Falling in love with a model– the Pygmalion effect (who falls in love with one of his sculpture

works).

� Forcing reality into the constraints of a model– the Procrustes effect (who forces victims to fit into a torturing

bed)

� Forgetting the model's level of accuracy. – All models have simplifying assumptions and we have to be

aware of those in order to correctly interpret the results.

21/03/2011 11

21/03/2011 12

3/30/2011

7

Modeling is a Challenging Task

� Modeling is to develop an abstraction of a system. � A good model should capture only the relevant

information, ignore the irreverent information. � What is relevant (or irreverent) depends on your

modeling goal.

21/03/2011 13

21/03/2011 14

3/30/2011

8

Kinds of Systems

Production Line

• Very complex system, in which uncertainty is modeled with stochastic theory

Machine

• Complex system that evolves through machine steps

Components

• System formed by the interaction of mechanical and electromechanical components.

21/03/2011 15

Kinds of Mathematical Models

Production Line: Discrete Event Model

• State machine with transition between discrete that is governed by a probabilistic function, who takes in account complexity and poor knowledge on subsystem interaction.

Machine: State machine model.

• States represent current machine behavior. Transition between states is principally deterministic.

Components: Differential equations.

• The behavior of devices is described by equation defining physical laws, possibly multi-domain (electrical, mechanical, chemical, etc.).

21/03/2011 16

•Cooperative simulation (co-simulation)

is necessary when simulation projects

involves different abstraction level (e.g.

machine and component levels) and/or

different physical domains.

•Co-simulation is also mandatory when

homogenous simulation software tools

are used.

3/30/2011

9

Kinds of Mathematical Models

� Static or Dynamic:– A static model can be defined without involving time. Example:

voltage-current relation for a resistor and a capacitor.� Continuous time or Discrete Time:

– Evolve continuously over time or that change at discrete points in time.

� State machine or infinite values:– System variables takes only finite values, and represents logical

conditions instead of physical measurements.� Stochastic or deterministics:

– Some phenomena in nature are conveniently described by stochastic processes and probability distributions, e.g. noisy radio transmissions or atomic-level quantum physics.

– Such models might be labeled stochastic or probability-based models where the behavior can be represented only in a statistic sense, whereas deterministic models allow the behavior to be represented without uncertainty.

21/03/2011 17

An example of Mathematical Model

21/03/2011 18

)()()()( tvtvtvtv CRLi ++=

∫++=t

i diC

Ridt

diLtv

0

)(1

)( ττ

)(1)(

2

2

tiCdt

diR

dt

idL

dt

tvd i ++=

)()( :Input tutvi =

)()( :Output tyti =

3/30/2011

10

In general

21/03/2011 19

Systemu(t) y(t)

∑∑==

=n

jj

j

j

m

jj

j

j dt

tudb

dt

tyda

00

)()(

Intuitive description of derivative in continuous systems

� One can imagine a derivative term in a system as a reservoir that stores energy . Whatever is put into the reservoir is accumulated – with a negative input value meaning outflow.

� The state of the reservoir is its current contents, represented by a variable.

� This is our state variable y. � The current input x represents the rate of current change

of the contents which we express by equation

21/03/2011 20

3/30/2011

11

Differential Equations

21/03/2011 21

)()(

tudt

tdy = ∫=

=t

uty0

)()(τ

τ

Systemu(t) y(t)

∫=

t

u0

)(τ

τ

Transfer function

� A transfer function (also known as the system function or network function) is a mathematical representation, in terms of spatial or temporal frequency, of the relation between the input and output of a linear time-invariant system.

21/03/2011 22

∑∑==

=n

j

jj

m

j

jj sUsbsYsa

00

)()()()(

ssYdt

tdy⇒

∑∑==

=n

jj

j

j

m

jj

j

j dt

tudb

dt

tyda

00

)()(

3/30/2011

12

In general

21/03/2011 23

Systemu(t) y(t)

=

==⇔ m

j

jj

n

j

jj

sa

sb

sU

sYsF

0

0

)(

)()(

∑∑==

=n

j

jj

m

j

jj sUsbsYsa

00

)()(TRANSFER

FUNCTION F(S)

Space-State realization

� The internal state variables are the smallest possible subset of system variables that can represent the entire state of the system at any given time.

� The minimum number of state variables required to represent a given system n, is usually equal to the order of the system defining differential equation.

� If the system is represented in transfer function form, the minimum number of state variables is equal to the order of the transfer function denominator after it has been reduced to a proper fraction.

21/03/2011 24

3/30/2011

13

Space-State realization

� It is important to understand that converting a state space realization to a transfer function form may lose some internal information about the system , and may provide a description of a system which is stable, when the state-space realization is unstable at certain points.

� In a real system the number of state variables is often, though not always, the same as the number of energy storage elements .

21/03/2011 25

A Circuit Example

21/03/2011 26

3/30/2011

14

Implicit Differential Algebraic Equation (DAE) Model

21/03/2011 27

Explicit DAE Model

21/03/2011 28

3/30/2011

15

Ordinary Differential Equation (ODE) Model

21/03/2011 29

Linear State-space Model

21/03/2011 30

3/30/2011

16

MATLAB Simulation Program

21/03/2011 31

MATLAB Simulation Program

21/03/2011 32

3/30/2011

17

Continuous system mathematical model in Simulink

21/03/2011 33

Observing inner states.

� From manipulation of eq:

� We might obtain the Transfer Function

� or:

21/03/2011 34

)()()(

)(2

2

tKdt

tdF

dt

tdJtCm ϑϑϑ ++=

)(1

)(2

sCmkFsJs

s++

)()()()( 2 ss

J

sFssKsCm ϑϑϑ =+−

3/30/2011

18

21/03/2011 35

Capture system complexity

� Mathematical models analyzed up to now feature global behavior described using linear differential equationwith constant coefficients.

� Such a models assume that physical parameters and variables (mass, springs, position, temperature, etc.) are “concentrate” in single point in the system.

� However some physical phenomenon in real machines feature “local” behavior, which required more complex mathematical model:– Non-linear behavior => Non-Linear Models.– Distributed variables and parameters => Finite

Element Models

21/03/2011 36

3/30/2011

19

Non-Linear Models

� A linear system is a mathematical model of a system based on the use of a linear operator .

� Linear systems satisfy the properties of superposition and scaling: given two valid inputs x1(t) and x2(t) as well as their respective outputs

y1(t) = H(x1(t)), y2(t) = H(x2(t))� then a linear system must satisfy, for any scalar values a

and b: a*y1(t) + b*y2(t) = H(a*x1(t)+b*x2(t))

� Mathematical models that does not fulfill the above relationship are called “Non-Linear Models ”

21/03/2011 37

Non linear effects: Friction

Viscous Friction Dry Friction Coulomb Friction

21/03/2011 38

3/30/2011

20

Non linear effects: Actuator Saturation

21/03/2011 39

Non linear effects: Hysteresis

21/03/2011 40

0 0.5 1 1.5 2 2.5 3 3.5 4−1

−0.5

0

0.5

1Ingresso − Uscita (dash)

−1 0 1−1

−0.5

0

0.5

1Isteresi (d = 0.6)

3/30/2011

21

Non linear effects: Dead Zone

21/03/2011 41

Non linear models in Simulink

21/03/2011 42

3/30/2011

22

Handle saturation in Simulink

� In case of saturation, all the integrals must be limited (saturate).� It is wrong to insert a saturation block right after an integral to

model a saturated integral phenomenon.� The correct way is, in the integral block, select the Limit output

check box and enter the limits in the appropriate parameter fields.

� This action causes the block to function as a limited integrator: When the output reaches the limits, the integral action is turned off to prevent integral wind up.

� The block determines output as follows:– When the integral is less than or equal to the Lower saturation limit ,

the output is held at the Lower saturation limit .– When the integral is between the Lower saturation limit and the

Upper saturation limit , the output is the integral.– When the integral is greater than or equal to the Upper saturation

limit , the output is held at the Upper saturation limit .

21/03/2011 43

An example

21/03/2011 44

3/30/2011

23

Modeling Non-Linear system with local bases functions (approximants)

� Piecewise approximants are used in– Neural Networks and Fuzzy Logic models.

– Finite Elements Methods (FEM).

� Complex nonlinear systems are approximate locally with basis functions.

21/03/2011 45

Artificial Neural Network

� An artificial neural network (ANN), usually called neural network (NN), is a mathematical model or computational model that is inspired by the structure and/or functional aspects of biological neural networks.

� A neural network consists of an interconnected group of simple computational units , and it processes information using a connectionist approach to computation.

� In most cases an ANN is an adaptive system that changes its structure based on external or internal information that flows through the network during the learning phase.

� Neural networks are non-linear statistical data modeling tools. They are usually used to model complex relationships between inputs and outputs or to find patterns in data .

21/03/2011 46

3/30/2011

24

ANN Mathematical model

21/03/2011 47

Universal Approximation Theorem

� In mathematics, the universal approximation theorem states that the standard multilayer feed-forward network with a single hidden layer that contains finite number of hidden neurons, and with arbitrary activation function are universal approximators on a compact subset of

� The ANN F(x) can approximate any continuous function f(x), that is:

21/03/2011 48

3/30/2011

25

Capturing discrete time behavior

� Difference Equation.� Discrete time.� Discrete event.� State Machine.

21/03/2011 49

Difference Equation

� Dynamical system featuring dependence to discrete time instead of continuous can be described using difference equation– equivalent to differential equation in continuous time

� Difference equation is an equation involving differences.

� We can see difference equation from two points of views: – as sequence of number (system without input)– discrete dynamical system (system with input)

21/03/2011 50

3/30/2011

26

Sequence of numbers

� Difference equation is a sequence of numbers that generated recursively using a rule to relate each number in the sequence to previous numbers in the sequence.

� Example: Fibonacci sequence: {1,1,2,3,5,8,13,21,…}.

21/03/2011 51

1)0(),()1()2( =++=+ ykykyky

Fibonacci sequence

21/03/2011 52

3/30/2011

27

Discrete dynamical System

� Difference equation is a discrete dynamical system that takes some discrete input signal and produces output signal.

� Example: Dynamical system

� takes unit step input:

21/03/2011 53

0)0(

),(5.1)1(2)(

=−−=

y

kukyky

=−−−=

=,...3,2,1,0for 0

,...3,2,1for 0)(

k

kku

)21(2

3)(outpu theproduce will 1+−= kky

Discrete dynamical system

21/03/2011 54

3/30/2011

28

Discrete dynamical system

� The difference equations might represents:1. A real system that evolves at each discrete and fixed time

interval. 2. A discrete time representation of a real system that evolve

at continuous time (Discretization)

� Discretization: the process of transferring continuous models and equations into discrete counterparts.

� This process is usually carried out as a first step toward making them suitable for numerical evaluation, simulation and implementation on digital computers.

� In order to be processed on a digital computer another process named quantization is essential

21/03/2011 55

Discretization

21/03/2011 56

)()())1((

kTuT

kTyTky =−+)(

)(tu

dt

tdy =

∫=

=t

uty0

)()(τ

τ

Systemu(t) y(t)

∑=

n

k

kTu0

)(

∑=

=n

k

kTuty0

)()(

TkTukTyTky )()())1(( +=+

3/30/2011

29

Z-Trasform

21/03/2011 57

� The z-transform of sequence x(n) is defined by

∑∞

−∞=

−=n

nznxzX )()(

� Let z = e−jω.

( ) ( )j j n

n

X e x n eω ω∞

=−∞

= ∑

Fourier Serie

Shift Theorem

xRzzXnx ∈= ),()]([Z

xn RzzXznnx ∈=+ )()]([ 0

0Z

21/03/2011 58

3/30/2011

30

Nth-Order Difference Equation

∑∑==

−=−M

rr

N

kk rnxbknya

00

)()(

∑∑=

=

− =M

r

rr

N

k

kk zbzXzazY

00

)()(

∑∑==

=

− N

k

kk

M

r

rr zazbzH

00)(

21/03/2011 59

Discretization

21/03/2011 60

3/30/2011

31

Discretization

� The main problem is to choose the correct time interval T

� The goal is to assure that continuous and discrete behave the same

� This reflects on simulation, as all the continuous models are discretized to be solved

� The discretization in simulation might be at fixed time or variable time.

� The correct time interval T must be chosen with respect the system dynamics– Short T for fast systems, large T for slow systems.

21/03/2011 61

Sampling Theorem

� In order for a band-limited (i.e., one with a zero power spectrum for frequencies f>B) baseband ( f>0) signal to be reconstructed fully, it must be sampled at a rate f>2B.

� A signal sampled at is said to be Nyquist sampled , and is called the Nyquist frequency.

� No information is lost if a signal is sampled at the Nyquist frequency, and no additional information is gained by sampling faster than this rate.

21/03/2011 62

3/30/2011

32

Sampling Theorem

21/03/2011 63

Discrete time in Simulink

21/03/2011 64

3/30/2011

33

An example

>> J=1;F=1;K=1;>> Gs=tf(1,[J,F,K])Transfer function:

1-----------s^2 + s + 1

>> bode(Gs)>> grid

21/03/2011 65

Bode Diagram

� We choose a Nyquistfreq. of 10 Hz.

� So that we choose a sampling frequency of 20 Hz, i.e. 50 mS.

>> Ts = 0.05>> Gz=c2d(Gs,Ts,'zoh')Transfer function:0.001229 z + 0.001209----------------------z^2 - 1.949 z + 0.9514

21/03/2011 66

3/30/2011

34

21/03/2011 67

Discrete Event

� A discrete event system evolves only at the occurrence of certain events

21/03/2011 68

3/30/2011

35

Discrete Event vs Discrete Time

�Discrete Event systems and Discrete Time Systems are often confused.

�Actually they might be described by similar equations, but:– The instant of discrete time system evolution

is forced by the elapsing of the time interval T.– The instant of discrete event system evolution

is forced by the arrival of an event.

21/03/2011 69

Discrete time system example

21/03/2011 70

3/30/2011

36

System Cardinality

� Variable might takes infinite (“large”) values.– Differential and Discrete time equations (Note: Variables in

discrete time takes infinite values as well, as only time is discrete!)

� Finite number of values or logical value for system variable (e.g. “system on”, “system off”)– State machine.

� State machine are implemented in time or eventsynchronization time scale.– Time: the state machine evolution takes place at defined time

interval T.– Event: the state machine evolution takes place immediately on

event arrival.� In PLC with scheduled time interval events are synchronized with

program scheduling.

21/03/2011 71

State Machine

� A finite-state machine (FSM) or finite-state automaton(plural: automata), or simply a state machine , is a mathematical abstraction sometimes used to design digital logicor computer programs.

� It is a behavior model composed of a finite number of states, transitions between those states, and actions, similar to a flow graph in which one can inspect the way logic runs when certain conditions are met.

� It has finite internal memory, an input feature that reads symbols in a sequence, one at a time without going backward; and an output feature, which may be in the form of a user interface, once the model is implemented.

� The operation of an FSM begins from one of the states (called a start state), goes through transitions depending on input to different states and can end in any of those available, however only a certain set of states mark a successful flow of operation (called accept states).

21/03/2011 72

3/30/2011

37

State Machine Formal definition

� A deterministic finite state machine or acceptor deterministic finite state machine is a quintuple(Σ,S,s0,δ,F), where:

� Σ is the input alphabet (a finite, non-empty set of symbols).� S is a finite, non-empty set of states.� s0 is an initial state, an element of S.� δ is the state-transition function: (in a nondeterministic

finite state machine it would be , i.e., δ would return a set of states).

� F is the set of final states, a (possibly empty) subset of S.

21/03/2011 73

State machine

21/03/2011 74

3/30/2011

38

State machine in Simulink

21/03/2011 75

Represent Stochastic behavior

� State machines might present probabilistic behavior .

� The transition between states is always triggered by the occurrence of an event.

� However, the event is not certain, but is generated by a probabilistic function .

� It models our partial knowledge about the underlying physical phenomenon (because uncertainty or complexity).

21/03/2011 76

3/30/2011

39

Deterministic and non-deterministic state machine

� D-SMs have at most one trace for any given input string� N-SMs may have many alternative traces for a given input

string.� The behavior of the N-SM can be described as a random

process which will generate a random trace for any given input sequence.

� E.g.: If q1 is a state which has two possible transitions a and b, those two transitions has a probability associated with it.

� Each probability is a nonnegative real number between 0 and 1, and the collection of probabilities for a given state and input event must sum to 1.

21/03/2011 77

An example: a packaging machine

21/03/2011 78

Machine

Run

Machine

Jammed

Event= “Machine can run” with Probability = 1-Pf

Event= “Machine stops” with Probability = Pf

Event= “Machine still Jammed” with Probability = Pr

Event= “Machine has been repaired” with Probability = 1-Pr

3/30/2011

40

Model stochastic behavior

� Many commercial discrete event simulators (Flexsim, Simul8, Arena, etc.)

� SimEvents Matlab toolbox.

21/03/2011 79

Hybrid Systems – Mix continuous and discrete event systems

� A hybrid system is a dynamic system that exhibits both continuous and discrete dynamic behavior

� It’s a system that can both flow (described by a differential equation) and jump (described by a difference equation or control graph).

21/03/2011 80

3/30/2011

41

Main issues in Hybrid Systems

� A system behave as “hybrid”, if its describing differential equations may changes depending on some event.

� In the previous example: an object that accelerates vertically up until it reaches the speed of Vmax (event that changes the continuous behavior) and then falls under the impact of gravity until it touches the ground (y <= 0), where it ceases to exist.

� As system energy (i.e. mechanical energy) can’t changes abruptly, variables linked to system energy (e.g. velocity) must fulfill continuity during state transition.

21/03/2011 81

System Identification

� The field of system identification uses statistical methods to build mathematical models of dynamical systems from measured data.

� Three methodology are mainly reported:– White Box model , in which the equations are derived by physical

laws and parameters are directly measured or estimated.– Grey Box model, in which the system are not entirely known, a

certain model based on both insight into the system and experimental data is constructed. This model does however still have a number of unknown free parameters which can be estimated using system identification. Grey box modeling is also known as semi-physical modeling.

– Black box model , in which no prior information on the model is available. In such a case general universal approximators as neural networks and ARX models are used, and then parameters are identified using data analysis.

21/03/2011 82

3/30/2011

42

END OF PART 121/03/2011

83