Uploaded by Luis Alberto Sanchez Rodas

Clase 05 Introduccion al Simulink

advertisement
Introducción al modelado y
simulacion con Simulink
Luis Sánchez
INTRODUCTION
Simulink, developed by The MathWorks, is a commercial tool
for modeling, simulating and analyzing dynamic systems. Its
primary interface is a graphical block diagramming tool and a
customizable set of block libraries. It offers tight integration with
the rest of the MATLAB environment. Simulink is widely used
in control theory and digital signal processing for simulation and
design.
A block diagram is simply a graphical representation of a
process (which is composed of an input, the system, and an
output).
Capabilities of Simulink
• It Simulates Linear and nonlinear systems.
• It Simulates continuous, discrete and hybrid
systems.
• It has a powerful “What if” exploration
capability.
GETTING STARTED IN SIMULINK
To start Simulink, on the
command prompt, type
>>simulink
or
Click here
SIMULINK Library Browser
The Simulink Library
Browser is the library
where you find all the
blocks you may use in
Simulink.
Simulink
software includes an
extensive library of
functions commonly
used in modeling a
system.
SOURCES
Sources library contains
the sources of data
signals to be used in the
dynamic
system
simulation.
E.g. Constant signal,
signal
generator,
sinusoidal waves, step
input,
repeating
sequences like pulse
trains and ramps etc.
SINKS
Sinks library contains
blocks where the signal
terminates. You may
store data in a file,
display it. Use the
terminator
block
to
terminate unused signals.
STOP block is used to
stop the simulation if the
input to the block is nonzero.
CONTINUOUS AND DISCRETE
Analyze your dynamic system as continuous or discrete. Simulink lets you
represent your system using transfer functions, integration blocks, delay blocks etc.
Create a new Model
Click the New icon on the Toolbar in order to create a new
Simulink model:
The following window
appears
Configuration
There are lots of parameters you may want to configure regarding
your simulation. Select “Configuration Parameters…” in the
Simulation menu.
Here you set important parameters such as:
- Start and Stop time for the simulation
- What kind of Solver to be used (ode45, ode23 etc.)
- Fixed-step/Variable-step
SIMPLE EXAMPLE
Modelado y Simulación de sistemas
Lineales e Invariantes en el tiempo LTI
1. Modelado y Simulación a Partir de las EDO
2. Modelado y Simulación a la Función de
Trasferencia.
Ejemplo. Modelo Simple
• Build a Simulink model that solves the
differential equation
x  3 sin 2t 
• Initial condition x(0)  1.
• First, sketch a simulation diagram of this
mathematical model (equation)
(3 min.)
Diagrama de la Simulación
• Input is the forcing function 3sin(2t)
• Output is the solution of the differential
equation x(t)
x(0)  1
3sin(2t)
(input)
x
1
s
x
x(t)
(output)
integrator
• Now build this model in Simulink
Select an input block
Drag a Sine Wave block
from the Sources library to
the model window
Select an operator block
Drag an Integrator block
from the Continuous library
to the model window
Select an output block
Drag a Scope block from the
Sinks library to the model
window
Connect blocks with signals
• Place your cursor on the
output port (>) of the
Sine Wave block
• Drag from the Sine Wave
output to the Integrator
input
• Drag from the Integrator
output to the Scope
input
Arrows indicate the direction
of the signal flow.
Select simulation parameters
Double-click on the
Sine Wave block to
set amplitude = 3
and freq = 2.
This produces the
desired input of
3sin(2t)
Select simulation parameters
Double-click on
the Integrator
block to set
initial condition
= -1.
This sets our IC
x(0) = -1.
Select simulation parameters
Double-click on the
Scope to view the
simulation results
Run the simulation
In the model
window, from the
Simulation pulldown
menu,
select Start
View the output
x(t) in the Scope
window.
Simulation results
To verify that this plot
represents the solution
to the problem, solve
the
equation
analytically.
The analytical result,
x(t )  12  32 cos2t 
matches the plot (the
simulation
result)
exactly.
Ejemplo. EDO 2 orden
• Build a Simulink model that solves the
following differential equation
– 2nd-order mass-spring-damper system
– zero ICs
– input f(t) is a step with magnitude 3
– parameters: m = 0.25, c = 0.5, k = 1
mx  cx  kx  f (t )
mx  cx  kx  f (t )
Create the simulation diagram
• On the following slides:
– The simulation diagram for solving the ODE is
created step by step.
– After each step, elements are added to the
Simulink model.
• Optional exercise: first, sketch the complete
diagram (5 min.)
mx  cx  kx  f (t )
(continue)
• First, solve for the term with highest-order
derivative
mx  f (t )  cx  kx
• Make the left-hand side of this equation the
output of a summing block
mx
summing
block
Drag a Sum block from the
Math library
Double-click to change the
block parameters to
rectangular and + - -
(continue)
• Add a gain (multiplier) block to eliminate
the coefficient and produce the highestderivative alone
mx
summing
block
1
m
x
Drag a Gain block from the
Math library
The gain is 4 since 1/m=4.
Double-click to change the
block parameters.
Add a title.
(continue)
• Add integrators to obtain the desired output
variable
mx
summing
block
1
m
x
1
s
x
1
s
x
Drag Integrator blocks from
the Continuous library
ICs on the integrators
are zero.
Add a scope from the Sinks library.
Connect output ports to input ports.
Label the signals by double-clicking on the leader line.
(continue)
• Connect to the integrated signals with gain blocks
to create the terms on the right-hand side of the
EOM
mx
summing
block
x
1
m
cx
1
s
x
c
kx
k
1
s
x
Drag new Gain blocks
from the Math library
To flip the gain block, select it
and choose Flip Block in the
Format pull-down menu.
 Double-click on gain blocks to
set parameters
 Connect from the gain block
input backwards up to the branch
point.
 Re-title the gain blocks.
c=0.5
k=1.0
Complete the model
• Bring all the signals and inputs to the summing
block.
• Check signs on the summer.
f(t)
input
+
-
mx 1
m
x
cx
kx
x
1
s
1
s
x
x
c
k
x
x(t)
output
Double-click on Step block to
set parameters. For a step
input of magnitude 3, set Final
value to 3
Final Simulink model
Run the simulation
Results
Simulación del péndulo de Foucault
En 1851 Jean Leon Foucault colgó un péndulo de 67 metros de largo de la cúpula de los
Inválidos en Paris. Un recipiente que contenía arena estaba sujeto al extremo libre, el hilo
de arena que caía del cubo mientras oscilaba el péndulo señalaba la trayectoria. Demostró
experimentalmente que el plano de oscilación del péndulo giraba 11º 15’ cada hora.
Modeling a Foucault Pendulum
The physics of the problem can be described by the system of
coupled equations given below. The x and y coordinates specify
the position of the pendulum bob as seen by an observer on Earth.
Condiciones Iniciales
Modelado y Simulación de sistemas
Lineales e Invariantes en el tiempo LTI
1. Modelado y Simulación a Partir de las EDO
2. Modelado y Simulación a la Función de
Trasferencia.
Cruise Control: Matlab Modeling
The model of the cruise control system is relatively simple. If it is assumed that rolling
resistance and air drag are proportional to the car's speed, then the problem is reduced to
the simple mass and damper system shown below
Using Newton's 2nd law, the governing equation for this system
.
becomes:
m v  u  bv
(1)
where u is the force applied. For this example, let's assume that
m = 1000 kg; b = 50 N.sec/m; u = 500 N
Transfer function model
Taking the Laplace transform of the governing differential equation
and assuming zero initial conditions, we find the transfer function
of the cruise control system to be:
V ( s)
1
P( s) 

U ( s) ms  b
We enter the transfer function model into MATLAB using the
following commands:
Building the model in simulink
This system will be modeled by summing the forces acting on the mass and integrating the
acceleration to give the velocity. Open Simulink and open a new model window. First, we will
model the integral of acceleration.
dv
 dt dt  v
•Insert an Integrator Block (from the Continuous library) and draw lines to and from its input
and output terminals.
•Label the input line "vdot" and the output line "v" as shown below. To add such a label,
double click in the empty space just above the line.
Since the acceleration (dv/dt) is equal to the sum of the forces divided by mass, we
will divide the incoming signal by the mass.
•Insert a Gain block (from the Math Operations library) connected to the Integrator
block input line and draw a line leading to the input of the Gain block.
•Edit the Gain block by double-clicking on it and change its value to "1/m".
•Change the label of the Gain block to "inertia" by clicking on the word "Gain"
underneath the block.
•Attach a Sum block (from the Math Operations library) to the line leading to the inertia Gain
block.
•Change the signs of the Sum block to "+-".
•Insert a Gain block below the Inertia block, select it by single-clicking on it, and select Flip
from the Format menu (or type Ctrl-F) to flip it left-to-right.
•Set the block's value to "b" and rename this block to "damping".
•Tap a line (hold Ctrl while drawing) off the Integrator block's output and connect it to the
input of the damping Gain block.
•Draw a line from the damping Gain block output to the negative input of the Sum Block.
The second force acting on the mass is the control input, u. We will apply a step input.
•Insert a Step block (from the Sources library) and connect it with a line to the positive input
of the Sum Block.
•To view the output velocity, insert a Scope block (from the Sinks library) connected to the
output of the Integrator.
To provide an appropriate step input of 500 at time equal zero, double-click the Step block and
set the Step Time to "0" and the Final Value to "u".
Run the simulation (hit Ctrl-T or select Start from the
Simulation menu). When the simulation is finished,
double-click on the Scope and hit its autoscale button.
You should see the following output.
Download
Random flashcards
Arab people

15 Cards

Radiobiology

39 Cards

Pastoralists

20 Cards

Marketing

46 Cards

Create flashcards