0% found this document useful (0 votes)
479 views39 pages

Modeling and Simulation of Using Matlab/Simulink

This document provides an overview of modeling and simulating dynamic systems using Matlab/Simulink. It outlines the goals of feeling comfortable building and analyzing basic models in Simulink. It describes Simulink as a software package that provides a graphical interface for building and analyzing system models using a block diagram approach. It also discusses various Simulink modeling tools and features, such as hierarchical modeling, simulation, analysis tools, and communicating with MATLAB. An example thermodynamic house model is demonstrated.

Uploaded by

svp3761
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
479 views39 pages

Modeling and Simulation of Using Matlab/Simulink

This document provides an overview of modeling and simulating dynamic systems using Matlab/Simulink. It outlines the goals of feeling comfortable building and analyzing basic models in Simulink. It describes Simulink as a software package that provides a graphical interface for building and analyzing system models using a block diagram approach. It also discusses various Simulink modeling tools and features, such as hierarchical modeling, simulation, analysis tools, and communicating with MATLAB. An example thermodynamic house model is demonstrated.

Uploaded by

svp3761
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Modeling and Simulation of

using Matlab/Simulink

Modeling Building
and Simulation with Simulink
Updated for Spring 2001

Raul G. Longoria
University of Texas at Austin
Department of Mechanical Engineering

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Outline for Today
Quick Intro/Demo Analysis Tools in
Physical modeling with Simulink
block diagrams review available solvers
Simulink modeling tools trim
and features Tutorials:
PMDC motor
Angular drive coil

Goal: Feel comfortable building and analyzing


basic models in Simulink.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Description of Simulink
Simulink is a software package that runs within MATLAB, and provides a
graphical user interface for building and analyzing system models.
Simulink can communicate with the MATLAB workspace and functions, as
well as with user-written programs in other languages.
Simulink can be used for modeling, simulating, and analyzing dynamic
systems, and has features that can be used to represent linear and nonlinear
systems with continuous and/or sampled time characteristics. Systems can also
be multirate, i.e., have different parts that are sampled or updated at different
rates.
Simulink uses a block diagram approach to represent mathematical equations.
Numerical integrators
1

x = x + u (t ) u (t) s
Inte g ra to r S co p e

algebra
e.g., u(t) = step Output
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls displays
The University of Texas at Austin
Simulink Description
Models are hierarchical. Model detail can be viewed by diving into blocks.
The block diagram describes the equations, and possibly the interconnection of
components.
You can simulate the model choosing from several integration methods.
Analysis can be conducted in Simulink or from the MATLAB command
window. It depends on whether an interactive or batch mode is desired.
Display functions are available for direct plotting (while simulation runs).
The simulation results can also be sent to the workspace for postprocessing
and visualization using the MATLAB graphical tools.
There are many analysis tools available, and since Simulink is integrated into
MATLAB, you can simulate, analyze, and revise models in either environment
at any point.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Starting Simulink
Simulink can be launched from the command
line:
Open a model
simulink Create
a new
model
Or, use the menu bar
The model browser opens
*.mdl is the extension
used for Simulink models
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
House Demo
Open:
MATLABR11\toolbox\simulink\simdemos
thermo.mdl he a te r
1 /s co st

Do lla r
He a t C os t ($)

blowe r QDot
Te rr cmd Ga in
70 F2 C Mdo t*h a
S e t P oin t Fa hre n he it C2 F
He a te r
to Ce lsius Th e rm o sta t Indoor v s .
Blowe r Ce lsiu s to Outdoor Te m p.
Ho use Fa h re n he it
Th e rm o
50 F2C
Note: model files Avg Ou td o or Tin
P lots
Fa h re n he it
are ASCII, so they Te m p to Ce lsius
can be opened by Da ily Te m p
any text editor, or Va ria tion

sent easily to other Note: this


platforms. Ho use Th e rm od yna m ics ? Do ub le click model file
(Do ub le click o n th e "? " for m o re info) h e re for
S im u lin k He lp pre-loads
To sta rt a n d stop th e sim u la tion , u se the "S ta rt" thermdat.m
se le ction in th e "S im ula tio n" pu ll-d own m e n u
to set parameters.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Whats in the house?
The models are
formulated from
a set of basic
block diagram
elements. These
can be grouped
into subsystems,
building a multilevel
model.
The Simulink environment provides a way to piece together
basic elements with algebraic elements (e.g., summers), and Other
there are calculus functions as well. The physics can either demos
be diagrammed or embedded in function calls.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Block Diagrams
for Computer Simulation:
Not a new idea.

The block diagram descriptions


are effective for modeling F.D. Ezekiel and H.M. Paynter, Computer Representations of
Engineering Systems Involving Fluid Transients, Trans. ASME, Nov. 1957.
dynamic system models.

Example elements:
= summer
= product
= integrator
= function (nonlinear type)

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
What is to be gained?

Quicker modeling
Better communication
Modularity - can connect
subsystems together to make more
complex models

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Exploring the Simulink
Environment
To learn about the Simulink environment, we
will explore the various blocks and features as
we build several simple examples.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Transient Response
Lets build a simple mass-spring-damper or
LRC circuit model responding to a step
response.
Display either:
velocity (for mechanical)
current (for LRC)
Add nonlinear effects

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Simulink Features to Explore
Manipulating Blocks, Lines, and Labels
Block Orientation & Sizing
Changing Block Properties

Display blocks
Output to workspace

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Signal Lines
Drawing lines
Changing line directions
Deleting lines
Vector lines; displaying line widths
Inserting blocks in a line
Line labels (double-click on line)

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Block Orientation & Sizing

Use CTRL-R to
rotate

Grab corner and


drag to size
(no UNDO!)

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Block Properties
For any given block,
for example, an
integrator, open the
Block Properties

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Creating a Subsystem
If a group of elements is to form a
component, you can group them into a
subsystem.
Select components, go to Edit menu and
select Create Subsystem.
Careful, this is hard to UNDO.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Example: Using Subsystems
Example: Create a subsystem for the mass-spring-
damper or LRC system. Illustrate inputs and outputs.

You can use subsystem as a method for loading


parameter data.
Or Callback routines (PreLoadFcn)

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Simulink Analysis

Finding model information


For example,
sizes = bicycle1([ ],[ ],[ ],0)
no. of states (every integrator -> state), etc.
Running Simulation: interactive vs batch
Setting parameters (simset)
Getting parameters (simget)

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Parameters for Simulation
Solver
RelTol Solver
RelTol
AbsTol
AbsTol
Refine Refine
MaxStep MaxStep
InitialStep InitialStep
FixedStep FixedStep
OutputPoints

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Using Command Line

You can use sim to run a model from the


command

[t,x,y] = sim(modelname,tspan,options,ut)
help sim Use simset
SIM Simulate a Simulink model
SIM('model') will simulate your Simulink model using all simulation
parameter dialog settings including Workspace I/O options.

[T,X,Y] = SIM('model',TIMESPAN,OPTIONS,UT)
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Simulation Parameters
Under Simulation
menu (3 panels)
Solver settings
Workspace I/O
Diagnostics

simset can be used to set options from


Command line
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Model Building Tutorial Examples
PMDC Motor

Revisit Driving Coil Example

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Basic PMDC Motor Example

Basic PMDC motor equations

R km
h + v
 Lm Jm
m
h = k B

m m h + TL
Lm Jm
Require:
Load system
fixed field Electrical source model
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Model of PMDC Motor
la m da
1 la m b da
d ot 1
Vin Vm 1/Lm 1
Km s
Curre n t
la m da in t Ga in4
S um
Ga in2

Rm /Lm

Tm
Ga in 3 Km /Lm

h Ga in
h d ot
1
2 1 /J m 2
s
Moto r S pe e d To rqu e Lo a d
Ga in1 h in t S um 1

Bm
Visco us
Ga in 5 Frictio n Vin C urre nt

Torque Loa d Motor S pe e d

P MDC Motor

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
pmdc.mdl
Vin P lo t

Vin C urre nt -K-


Vin (v olts ) Curre nt (m A)
Vin (volts) A2 m A Curre n t

Torque Loa d Motor S pe e d -K-

Ge a r F
Rloa d 0
P MDC Moto r

-K-

Ge a r B
P os ition (de g)
P os ition/Volts S ha f t Motion

P o sition
P osition S e nso r

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Adding Real Effects
in the PMDC Model
Gear-reduction

Backlash

Stiction

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Simulink Modeling of
Driving Coil Example
Recall example from previous session.

Develop a Simulink model of this system, and


compare to m-file version.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Example: Angular Driving-Coil
R
v(t )
L( )
flywheel

bearing

torsion rod

 = 1
h

blade
J
h b2 B
h K R
L() driving
2 L( ) 2 J v coil

J = flywheel inertia = 0.001 kg m 2 Adapted from


S. Nasar, Electric machines and electromechanics
K = 1.0 N m/rad = torsion rod stiffness
B = 0.01 N sec/rad = bearing resistance
R = 100 Drive this system with
L( ) = 1 + 0.5 henry voltage of amplitude
f = 10 Hz 10 volts at frequency f.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Building the Simulink Model
Use a sine wave source as the input
A function block can be used to represent the
dependence of inductance on angle

Assume initial conditions are such that the


blade is sitting outside of the core material, and
the coil pulls the blade into the gap

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Drive coil example
DEMO: Nas ar Example
Dire ct block d ia g ra m im ple m e n ta tion
of the sta te e q ua tio ns.

1
v(t) la m bda dot s la m bda
XY Gra p h
Inte g ra tor

la m bd a /L
Note: there has to be co il re sista n ce
c urre nt
a way to have the actuator 1 00
f(u ) R2 D
always drive the blade into the gap.
0.5 *b i^2 L(th e ta ) Ra dia n s th e ta
This does it. to De g re e s
0 .5 *.5 | u| 2 la m bda dot
Blade position will
The sign is included. curre n t
f(u ) o ffse t be brought to zero when
stiffn e ss
D2 R 5
coil is energized.
sig n
la m b da /L1 K*the ta
.1
De g re e s to
B*the ta dot Ra dia ns1
torque 0 .01

da m p in g
to rq ue 1
50 0 1
hdot s h the ta dot
s
Inte gra to r1 1 /J
Inte gra to r2

0 D2R

initia l a n gle De g re e s to
Ra dia ns

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Equilibrium Point Determination

help trim

TRIM Finds steady state parameters for a system given a set of conditions.
TRIM enables steady state parameters to be found that satisfy
certain input, output and state conditions.

[X,U,Y,DX]=TRIM('SYS') attempts to find values for X, U and Y


that set the state derivatives, DX, of the S-function 'SYS' to
zero. TRIM uses a constrained optimization technique.

[X,U,Y,DX]=TRIM('SYS',X0,U0) sets the initial starting guesses


for X and U to X0 and U0, respectively.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Example: A Pressure-Compensated Pump System
This example is a hydraulic
drive from a printing press.
Ref: E.O. Doebelin, System Response Modeling

If the pressure in the line


is used to change
the yoke angle, the feedback
provides a pressure-compensation.

Lets look at a model of this system to demonstrate


how you can use trim to find steady-states.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Example: The Pressure-Compensated Pump System
Pressure-Compensated Variable-Displacement Pump S ystem
Ou t Ou t1
Loa d To rq u e
1 2
TL
P re ssu re P hi Pm
Co m p e n sa tion Pp
TL
phi phi
Qp Qp om e ga m
Pm Qm Pm Pm Tm Motor Torque
QAL
QAL o m e g a in om e ga in
Ca pa citive Ro ta tio n a l Lo a d
o m e g a in
Pp Line Mo d e l
Pm
om e gam Qm
3

Va r D Hyd P u m p Ou t2
Fixe d D Hyd Mo to r
Om e g a m

R.G. Lo n g o ria
Ma y 1 9 98

P a ra m e te r file : p se tup 2 .m

This model has


multiple levels. We
can find information
on states as shown
next.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Model Information Example
This command will provide information on a system model.

[sizes, x0, xstord] = pcpump([],[],[],0) Using this


call from MATLAB
returns the information
sizes = shown.
x0 =
xstord =
4 (# states) 0.0033 'pcpump/Pressure
0 (discrete) 0 Compensation/phidot'
3 (outputs) 0 'pcpump/Capacitive
0 (inputs) 0 Line Model/Vdot'
0 (discontinuous roots) (block initial conditions) 'pcpump/Rotational Load/hldot'
0 'pcpump/Pressure
Using trim we can Compensation/hidot
2 find the equilibrium
closest to this initial A string containing where to find
ME 379M/397 condition. the integrators.
Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Equilibrium for Pressure-Compensated Pump
Using trim to find steady-states
trim uses a sequential quadratic programming algorithm to find trim points. See the
Optimization Toolbox User's Guide for a description of this algorithm.
[X,U,Y,DX]=TRIM('pcpump')
Yoke Angle (phi) P res s ure in Line
X= 0.5 1200

0.4 1000

P res s ure (P a)
0.2644 System

Angle (rad)
800
0.3
0.9482 600
0.9908 states 0.2
400
0.0000 0.1 200
0 0
0 0.1 0.2 0.3 0.4 0 0.1 0.2 0.3 0.4
time time
U= Motor Angular Velocity
30
Angular Velocity (rad/s ec)

Empty matrix: 0-by-1 Direct simulation


20
System shows the same
Y= 10 SS values for the
outputs outputs (Y) are
0.2644 (radians)
948.2204 (pressure)
0
0 0.1 0.2 0.3 0.4 reached.
time
23.0418 (angular velocity)
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
DEE

help dee DEE offers a direct


way to integrate nonlinear
Differential Equation Editor state-space equations.

Demonstrations.
dee - Simulink system containing DEE and associated demos.
deedemo1 - Van der Pol Equation.
deedemo2 - Lorenz Atractor.
deedemo3 - Mass and Spring.
deedemo4 - Coupled Mass and Spring System with Animation.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
Example: The Classic Van der Pol
Minimize block diagram
construction required.

ME 379M/397 Department of Mechanical Engineering


Vehicle System Dynamics and Controls The University of Texas at Austin
pmdc using DEE

Volts in Current
P MDC Motor
Mode l

Load Speed
torque DEE

Rather than block diagram a


given set of equations, the DEE
allows you to insert them to this
block. Input and output ports
can be defined.
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin
Summary
We took a hands-on approach to learning how
to use Simulink to build basic models.
Some modeling issues were discussed
Some of the basic analysis routines were used
to conduct simple simulation.

Next time: S-functions, model libraries, more complex


examples, difficult simulation cases, toolbox usage
ME 379M/397 Department of Mechanical Engineering
Vehicle System Dynamics and Controls The University of Texas at Austin

You might also like