getting started with simulink - university of victoriamech459/controlled materials...

50
Getting Started with Simulink Overview of MATLAB Modeling/ Simulation Environment Orientation 2008 | Jamie Cassels, QC, Vice-President Academic and Provost Greater Victoria Chamber of Commerce | March 2008 | David H. Turpin, PhD, FRSC

Upload: truongminh

Post on 06-Feb-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Getting Started with Simulink

Overview of MATLAB Modeling/ Simulation gEnvironment

Orientation 2008 | Jamie Cassels, QC, Vice-President Academic and Provost

Greater Victoria Chamber of Commerce | March 2008 | David H. Turpin, PhD, FRSC

MATLAB/Simulink ApplicationsMATLAB/Simulink Applications

Mechanical System Mechanical System Automotive Controls Controls Robotics Aerospace and DefenseAerospace and Defense Communications Electronics and Signal ProcessingElectronics and Signal Processing Medical Instrumentation

Model-Based DesignModel Based Design

Faster, more cost-effective development of dynamic systems (e.g. control systems, vehicles, etc.)

A system model is at the center of the development process from requirements development throughprocess, from requirements development, through design, implementation, and testing.

Model - an executable specification (MATLAB codes, or p (a block diagram and specified parameters) that is continually refined (optimized) throughout the development.

Simulation test whether the model works correctly and Simulation – test whether the model works correctly, and obtain results.

Software and hardware implementation – automatic code generation

MATLAB Codes – Simulink Block & Block Parameters

Modeling ProcessModeling Process

On Paper:On Paper:1 Defining the System2 Identifying System Components2 Identifying System Components3 Modeling the System with Equations

Using MATLAB/Simulink:4 Building the Simulink Block Diagram5 Running the Simulation6 Validating the Simulation Results

The leading environment forThe leading environment fortechnical computing

• The de facto industry-standard,f yhigh-level programming language for algorithm development

• Numeric computation• Data analysis and visualization• Toolboxes for signal and image

processing, statistics, optimization,symbolic math and other areassymbolic math, and other areas

• Foundation of MathWorks products

from Bryan Zocco & Doug Eastman’s Presentation

The leading environment for system-levelmodeling, simulation, and verification ofcommunications and electronic systems

• Multidomain system-level design and verification• Digital, analog, and mixed-signal simulation

using discrete-time, continuous-time, statemachine, and discrete event modeling

• Floating- and fixed-point algorithm developmentusing MATLAB, Simulink blocks,or existing C code

• Blocksets for signal processing, videoprocessing, communications, and RF

Object Detection

p g, ,• Open architecture with links to third-party tools

and development boards, and instrumentation• C and HDL code generation for DSPs,

embedded processors and FPGAsembedded processors, and FPGAsfrom Bryan Zocco & Doug

Eastman’s Presentation

From Research to Development and TestFrom Research to Development and TestFrom Research to Development and TestFrom Research to Development and Test

SYSTEM-LEVEL DESIGNDATA ANALYSIS VALIDATION/VERIFICATION

DataAnalysis, Data I/O

SystemModeling, Hardware-in-

Test andVerification

y ,Modeling &

Visualization

Data I/O

AlgorithmDevelopment& Simulation

EmbeddedSoftware

AutomaticCode Generation

g,Simulation and

Partitioning

EnvironmentEffects

Embedded

Hardware inthe-Loop Test

IMPLEMENTATION

MathematicalModeling

EmbeddedHardware

SystemComponents

EmbeddedAlgorithms

OtherD iDesignFlows

from Bryan Zocco & Doug Eastman’s Presentation

Graphical Layout of Functional ModulesGraphical Layout of Functional Modules

Complex System Model from Basic Building Blocksp y g

Vehicle and ControlVehicle and Control

Simulink Library (blocks)Simulink Library (blocks)

Key Multiphysics Modeling ToolboxKey Multiphysics Modeling Toolbox

Stateflow™ Design and simulate state machines andStateflow Design and simulate state machines andcontrol logic.

SimMechanics™ Model and simulate mechanical systems.Si P S t ™ M d l d i l t l t i l tSimPowerSystems™ Model and simulate electrical power systems.

Simulink® Control Design™

Design and analyze control systems inSimulink.

SimScape™ Provides expanded capabilities for modeling physical systems (mechanical, electrical, hydraulic, and other physical domains as physical networks)

SimDriveline™ Modeling and simulating the mechanics of driveline (drivetrain) systems

Modeling Dynamic Systems in SimulinkModeling Dynamic Systems in SimulinkModeling Dynamic Systems in SimulinkModeling Dynamic Systems in Simulink

Modeling Approaches

Data-Driven ModelingFirst Principles Modeling

Modeling Approaches

Neural NetworkT lb

SimscapeSimMechanicsSimDriveline

SystemIdentification

T lb

SimulinkDesign

O ti i ti

Simulink

ToolboxSimDrivelineSimHydraulics

SimPowerSystems

ToolboxOptimization

Tools for Modeling Dynamic SystemsADVISOR

PSAT/AutonomieSimDriveline

Tools for Modeling Vehicle Po ertrainsModified from Bryan Zocco & Doug Eastman’s Presentation

Tools for Modeling Vehicle Powertrains

SimDriveline™ ModelSimDriveline Model

Simulink Online HelpSimulink Online Help

Simulink Getting Started Guide Simulink Getting Started Guide Simulink User’s Guide Simulink Reference Writing S-Functions Simulink Release Notes

Other Posted References

Homework: build the Simulink models following the Homework: build the Simulink models following the model building examples

Getting started with Simulink

An introductory tutorialAn introductory tutorial

ES205 Analysis and Design of Engineering SystemsES205 Analysis and Design of Engineering SystemsRose-Hulman Institute of Technology

© R. Layton 2001

Launch SimulinkIn the MATLAB command window,at the >> prompt, type simulinkat the >> prompt, type simulinkand press Enter

Create a new model Click the new-model

icon in the upper left corner to start a new Simulink file

Select the Simulink icon to obtain elements of theelements of the model

Your workspaceLibrary of elements Model is created in this window

Save your model You might create a new folder, like the one

shown below, called simulink_files Use the .mdl suffix when saving

Example 1: a simple model Build a Simulink model that solves the

differential equation q

Initial condition tx 2sin3

1)0( x Initial condition First, sketch a simulation diagram of

thi th ti l d l ( ti )

.1)0( x

this mathematical model (equation)(3 min.)

Simulation diagram Input is the forcing function 3sin(2t) Output is the solution of the differentialOutput is the solution of the differential

equation x(t) 1)0( x

xxs1

3sin(2t) x(t)s(input) (output)

integrator

Now build this model in Simulink

Select an input blockDrag a Sine Wave block from the Sources library to the model window

Select an operator blockDrag an Integrator block from the Continuous library yto the model window

Select an output block

Drag a Scope block from the Sinks library to the modelSinks library to the model window

Connect blocks with signals

Place your cursor on the output port (>) of p p ( )the Sine Wave block

Drag from the Sine Wave output to the Integrator input

f h Drag from the Integrator output to the Scope input Arrows indicate the p p

direction of the signal flow.

Select simulation parameters

Double-click on the Sine Wavethe Sine Waveblock to set amplitude = 3 and freq = 2.

This p od ces theThis produces the desired input of 3sin(2t)3sin(2t)

Select simulation parameters

Double-click on the Integratorthe Integratorblock to set initial condition = -1.

This sets our IC x(0) = -1.

Select simulation parameters

Double-click on the Scope to viewthe Scope to view the simulation results

Run the simulation

In the model window from thewindow, from the Simulation pull-down menu, ,select Start

View the output x(t) in the Scopewindowwindow.

Simulation results

To verify that this plot represents the p psolution to the problem, solve the equation analyticallyequation analytically.

The analytical result,

matches the plot

ttx 2cos)( 23

21

p(the simulation result) exactly.

Example 2 Build a Simulink model that solves the

following differential equation (ODE)g q ( ) 2nd-order mass-spring-damper system zero ICs zero ICs input f(t) is a step with magnitude 3 parameters: m = 0 25 c = 0 5 k = 1 parameters: m 0.25, c 0.5, k 1

)(tfkxxcxm

Create the simulation diagram On the following slides:

The simulation diagram for solving the The simulation diagram for solving the ODE is created step by step.

After each step, elements are added to theAfter each step, elements are added to the Simulink model.

Optional exercise: first, sketch the Optional exercise: first, sketch the complete diagram (5 min.)

)(tfk )(tfkxxcxm

(continue) First, solve for the term with highest-

order derivative

Make the left hand side of this equationkxxctfxm )(

Make the left-hand side of this equation the output of a summing block

xm

summing block

Drag a Sum block from the Math libraryt e at b a y

Double-click to change the block parameters to rectangular and +rectangular and + - -

(continue) Add a gain (multiplier) block to

eliminate the coefficient and produce pthe highest-derivative alone

xm

m1 x

summing block

Drag a Gain block from the Math libraryt e at b a y

The gain is 4 since 1/m=4.

Double-click to change the block parameters.Add a titleAdd a title.

(continue) Add integrators to obtain the desired

output variablep

xm 1 1 1x xxm

summing block

s s

block

Drag Integrator blocks from the Continuous librarythe Continuous library

Initial Conditions (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

xm 1 1 1x x xxmm1

summing

s1

s1x x x

xcsumming block c

k

xc

kx k

Drag new Gain blocks from the Math libraryo t e at b a y

To flip the gain block, select it and choose Flip Block in theand choose Flip Block in the Format pull-down menu.

c=0 5 Double-click on gain blocks to

set parameters

c=0.5

Connect from the gain block input backwards up to the branch point. k=1.0branch point.

Re-title the gain blocks.

Complete the model Bring all the signals and inputs to the

summing block. Check signs on the summer.

xm

m1

s1

s1x xf(t)

input+--

x x(t)output

cxc

k

-x

output

kkx x

Double-click on Step block to set parameters For ato set parameters. For a step input of magnitude 3, set Final value to 3

Final Simulink model

Run the simulation

Results

Underdamped response.Overshoot of 0.5.Final value of 3 (gain = 1).(g )Is this expected?System design – adjust m, c, k values to get different system response

Paper and pencil analysisPaper-and-pencil analysis based on the equations of motion

Standard form )(1 tfk

xxkc

mkx

Nat’l freq. 0.2mk

n

Damping ratio 5.02

kc

m

Static gain

kn

11K Static gain 1

kK

Check simulation results Damping ratio of 0.5 is less than 1.

Expect the system to be underdamped.p y p Expect to see overshoot.

Static gain is 1.Static gain is 1. Expect output magnitude to equal input

magnitude. Input has magnitude 3, so does output.

Simulation results conform to expectations.