training tum gs simulink 13a

Upload: anonymous-wkbmwca8m

Post on 04-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Training TUM GS Simulink 13a

    1/70

    Technische Universitt Mnchen

    MATLAB and Simulink Basics

    TUM Graduate School TrainingDipl.-Ing. Markus Hornauer

  • 8/13/2019 Training TUM GS Simulink 13a

    2/70

    TUM Graduate School

    Training on MATLAB and Simulink

    Outline Day 1

    Introduction to MATLAB

    Basics:

    1) Introduction

    2) MATLAB Basics3) 2D and 3D Plots

    4) Data Import and Export

    Advanced:

    1) Programming with MATLAB

    2) Graphical User Interfaces in MATLAB

    Toolboxes:

    1) Symbolic Math Toolbox

    2) Control System Toolbox and Curve Fitting Toolbox

    2

  • 8/13/2019 Training TUM GS Simulink 13a

    3/70

    TUM Graduate School

    Training on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    3

  • 8/13/2019 Training TUM GS Simulink 13a

    4/70

    Technische Universitt Mnchen

    Day 2

    Introduction to Simulink, Stateflow and

    Code Generationbased on slides by Todd Atkins (MathWorks)

    And on the book MATLAB Simulink Stateflow

    (Angermann, Beuschel, Rau, Wohlfarth, Oldenburg Verlag)

    4

  • 8/13/2019 Training TUM GS Simulink 13a

    5/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    5

  • 8/13/2019 Training TUM GS Simulink 13a

    6/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    What is Simulink?6

    Simulink is a software package for modeling,

    simulating, and analyzing dynamical systems

    Graphical programming language

    Block diagram editing

    Nonlinear simulation

    Hybrid (continuous and discrete) models

    Asynchronous (non-uniform sampling) simulation

    Fully integrated with MATLAB, MATLAB toolboxes and

    blocksets

  • 8/13/2019 Training TUM GS Simulink 13a

    7/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    What is Simulink?7

    Accurately design, implement, and test:

    Control systems

    Signal Processing systems

    Communications systems

    Embedded systems Physical systems

    other Dynamic systems

  • 8/13/2019 Training TUM GS Simulink 13a

    8/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    What is Simulink?8

    Modeling and simulation

    Multidomain Dynamic Systems

    Nonlinear Systems

    Continuous-time , Discrete-time, Multi-Rate systems

    Plant and Controller Design

    Rapidly model what-if scenarios

    Communicate design ideas Embody performance specifications

    Select/Optimize control architecture and parameters

    Implementation

    Automatic code generation

    Rapid prototyping for HIL, SIL

    Verification and validation

  • 8/13/2019 Training TUM GS Simulink 13a

    9/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    Launching Simulink9

    Starting Simulink

  • 8/13/2019 Training TUM GS Simulink 13a

    10/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    Simulink Library Browser10

  • 8/13/2019 Training TUM GS Simulink 13a

    11/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    Finding Blocks11

  • 8/13/2019 Training TUM GS Simulink 13a

    12/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    Getting Help12

    1

    2

    3

  • 8/13/2019 Training TUM GS Simulink 13a

    13/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Basics

    Demonstration of Model Elements13

  • 8/13/2019 Training TUM GS Simulink 13a

    14/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    14

  • 8/13/2019 Training TUM GS Simulink 13a

    15/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Modeling Continuous Systems15

    Engine provides variable-step and fixed-step ODE solvers

    Block Diagram representation of dynamic systems

    Blocks define governing equations

    Signals are propagated between blocks over time

    Remeber MuPad: + b + = 0,

    x 0 = 0, 0 = 1, = 10, = 1, = 10

    Exercise: Create a mass-spring-damper system

    in Simulink

  • 8/13/2019 Training TUM GS Simulink 13a

    16/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Algebraic Loops16

    Error because of Direct Feedthrough Block input depends directly on its own output

    E.g.: Gain, Product, Sum/Subtract, Transfer Fcn

    Recommended solution: use Delay, Integrator or

    other history related block

    Alternative, but bad solution:

    reduce diagnostics settings and

    leave solving up to Simulink

    engine (not recommended!!)

    S C S

  • 8/13/2019 Training TUM GS Simulink 13a

    17/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Solver17

    Solver?

    Determines solution at current time step Determines the next simulation time step

    Solver options: Fixed-Step

    Ode1

    Ode2

    Ode3Ode4

    Ode5

    Ode8

    Variable-Step

    Ode45

    Ode23

    Ode113Ode15s

    Ode23s

    Ode23t

    Ode23tb

    Si li k C i S

  • 8/13/2019 Training TUM GS Simulink 13a

    18/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Fixed-step Solver18

    Si li k C ti S t

  • 8/13/2019 Training TUM GS Simulink 13a

    19/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Variable-step Solver19

    Si li k C ti S t

  • 8/13/2019 Training TUM GS Simulink 13a

    20/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Variable-step Size20

    Max step size is the largest

    time step that the solver

    can take (auto means 50

    steps)

    stepstimettsizestepmx startstop

    _

    __

    Si li k C ti S t

  • 8/13/2019 Training TUM GS Simulink 13a

    21/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Demo: Importing and Exporting Data21

    Si li k C ti S t 22

  • 8/13/2019 Training TUM GS Simulink 13a

    22/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Importing Data into Simulink22

    IN

    Requires vector of time along with input values

    input( t, u1un) defined configuration parameters

    CONSTANT

    Changeable on the highest hierarchy level

    Tunable with parameter objects

    FROM WORKSPACE

    Requires vector of time along with input values

    input( t, u1un) defined a workspace variable

    FROM FILE Requires vector of time along with input values

    input( t, u1un) defined in a given mat file

    Sim link Contin o s S stems 23

  • 8/13/2019 Training TUM GS Simulink 13a

    23/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    OUT

    Saves all outputs together in one variable, defined in the

    configuration parameters

    TO WORKSPACE

    Saves the output data in a variable to the workspace,

    defined in the block parameters

    TO FILE

    Saves the output data in a .mat file

    Simulink Continuous Systems

    Exporting Data to MATLAB Workspace23

    Simulink Continuous Systems 24

  • 8/13/2019 Training TUM GS Simulink 13a

    24/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Exchanging Data with MATLAB Workspace24

    For IN and OUT blocks variables must be

    defined in Configuration Parameters

    Simulink Continuous Systems 25

  • 8/13/2019 Training TUM GS Simulink 13a

    25/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    MATLAB Embedded25

    Subset of MATLAB for code generation

    Can be used for direct generation of

    source code out of MATLAB as well as inSimulink MATLAB Function blocks

    Enables user to reuse his MATLAB code

    in Simulink

    To call unsupported functions useeml.extrinsic or coder.extrinsic

    (leads to significantly reduced

    performance!!!)

    Simulink Continuous Systems 26

  • 8/13/2019 Training TUM GS Simulink 13a

    26/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Model and Block Callbacks26

    Simulink Continuous Systems 27

  • 8/13/2019 Training TUM GS Simulink 13a

    27/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Continuous Systems

    Callback Functions27

    Common tasks you can achieve by using callback functions include:

    Loading variables into the MATLAB workspace automatically when you

    open your Simulink model

    Executing a MATLAB script by double-clicking on a block

    Executing a series of commands before starting a simulation

    Executing commands when a block diagram is closed

    Load

    Initialize

    Start

    Continue

    Stop

    Close Help => Callback Functions

    Outline Day 2 28

  • 8/13/2019 Training TUM GS Simulink 13a

    28/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    28

    Simulink Discrete Systems 29

  • 8/13/2019 Training TUM GS Simulink 13a

    29/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Discrete Systems

    Demo: Creating a counter29

    Exercise: Create a Stop Watch Combine counters to a stop watch

    Show tenth seconds, seconds, minutes and hours

    Reduce simulation speed to soft realtime

    Simulink Discrete Systems 30

  • 8/13/2019 Training TUM GS Simulink 13a

    30/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Discrete Systems

    Multirate Systems30

    Systems with signals that are sampled at

    different rates

    Use for discrete or hybrid systems

    To connect system use rate transition blocks

    Specify specific sampling rate by variable ateach in and out port

    Different sample times need to be an

    integer multiple of the highest (global)

    sampling rate

    Sample Time Colors

    -> fastest discrete sampling time is displayed

    in red

    Outline Day 2 31

  • 8/13/2019 Training TUM GS Simulink 13a

    31/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    31

    Simulink Subsystems 32

  • 8/13/2019 Training TUM GS Simulink 13a

    32/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Subsystems

    Subsystems32

    Why? Reduce blocks displayed in a model window

    Keep functionally related block together

    Establish hierarchical block diagram

    SimulinkSubsystems 33

  • 8/13/2019 Training TUM GS Simulink 13a

    33/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    y

    Creating Subsystems33

    Context menu -> Create Subsystem

    Subsystem ports

    Inside a subsystem

    Simulink Subsystems 34

  • 8/13/2019 Training TUM GS Simulink 13a

    34/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Subsystems

    Atomic Subsystems34

    Represent nonvirtual systems within another system

    Have their own sampling rate

    Have their own code generating characteristics

    Have their own execution order number

    Simulink Subsystems 35

  • 8/13/2019 Training TUM GS Simulink 13a

    35/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Subsystems

    Masking Subsystems35

    Mask - Encapsulation with a UI

    Provides

    Mask icon display

    Block description

    Parameter dialog prompt

    Custom block help text

    masking

    mask

    Outline Day 2 36

  • 8/13/2019 Training TUM GS Simulink 13a

    36/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Outline Day 2

    Simulink und Stateflow:

    Basics:

    1) Simulink

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison5) Integrating C Code using the Legacy Code Tool

    6) MATLAB Coder, Simulink Coder, Embedded Coder

    36

    Simulink Libraries and Model Reference 37

  • 8/13/2019 Training TUM GS Simulink 13a

    37/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Libraries and Model Reference

    User Libraries37

    Collection of reusable blocks

    Prototype block vs Reference block

    Propagation of changes to Library

    Discard

    Push

    Library Links

    Disable link

    Restore link

    Break link

    Other features

    Display in Simulink Library Browser

    Add documentation

    Simulink Libraries and Model Reference 38

  • 8/13/2019 Training TUM GS Simulink 13a

    38/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Libraries and Model Reference

    Model Referencing38

    One model in another-parent and referenced model

    Advantages:

    Componentization/Modularization

    IP protection

    Multiple referencing

    Acceleration

    Outline Day 2 39

  • 8/13/2019 Training TUM GS Simulink 13a

    39/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    y

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    39

    Simulink Signals 40

  • 8/13/2019 Training TUM GS Simulink 13a

    40/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    g

    Vectors40

    Matrix and Vector operations possible

    Mux block to compose vector

    Demux block to extract from signal

    Increase simulation performance

    Simulink Signals 41

  • 8/13/2019 Training TUM GS Simulink 13a

    41/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    g

    Busses

    Graphical grouping of signals to a hierarchical bus signal

    Bus creators to create a bus from signal and busses

    Bus selector to select single signals or whole sub-busses

    Bus Objects can be specified

    Simulink Signals 42

  • 8/13/2019 Training TUM GS Simulink 13a

    42/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    g

    Simulink Model Explorer

    Simulink Signals 43

  • 8/13/2019 Training TUM GS Simulink 13a

    43/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    g

    Simulink Data Objects

    Simulink Parameter Object

    >> Var = Simulink.Parameter

    Simulink Signal Object

    >> Var = Simulink.Signal

    Simulink Bus Object

    Use Bus editor

    Simulink Signals 44

  • 8/13/2019 Training TUM GS Simulink 13a

    44/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Signal Logging

    Signal Context

    Menu

    Configuration

    Parameters

    Outline Day 2 45

  • 8/13/2019 Training TUM GS Simulink 13a

    45/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    Stateflow 46

  • 8/13/2019 Training TUM GS Simulink 13a

    46/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Demo: Flow Graph Soda Machine

    Flow Graphs have no action or information in state. Everything is done on

    transitions.

    First condition [a>b], then action {c= 0;}

    Demo: A soda machine provides coke, orange juice and water. The user enters

    the corresponding number. The machine puts out a can with the drink.

    Stateflow 47

  • 8/13/2019 Training TUM GS Simulink 13a

    47/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Basic Elements

    Default

    TransitionTransitions

    Junction

    ConditionAction

    Terminating

    Junction

    Stateflow 48

  • 8/13/2019 Training TUM GS Simulink 13a

    48/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Hints

    First Condition, then Action!

    Double Click keeps buttonspressed

    Stateflow 49

  • 8/13/2019 Training TUM GS Simulink 13a

    49/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Defining Chart Data

    Stateflow 50

  • 8/13/2019 Training TUM GS Simulink 13a

    50/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Guidelines for Creating Flow Charts

    The execution has only one entry point!

    The execution has only one termination point!

    The execution can always reach the termination point!

    The flow never backtracks!

    Stateflow 51

  • 8/13/2019 Training TUM GS Simulink 13a

    51/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    State Charts

    State charts have a internal behavior and

    internal data

    Actions can be performed on entry, during

    residence in the state and on exit

    A state can perform a self transition

    A state can be either active or passive

    Stateflow

    C52

  • 8/13/2019 Training TUM GS Simulink 13a

    52/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Demo: Autopilot Mode Control

    Stateflow

    E i O d53

  • 8/13/2019 Training TUM GS Simulink 13a

    53/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Execution Order

    true falseexecutes

    does not execute

    Stateflow

    P ll l Ch t d Hi hi l Ch t54

  • 8/13/2019 Training TUM GS Simulink 13a

    54/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Parallel Charts and Hierarchical Charts

    Stateflow

    E i El t55

  • 8/13/2019 Training TUM GS Simulink 13a

    55/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Exercise: Elevator

    States: InitialState, Stopped, Up, Down

    Doors may only open when elevator is stopped

    Inputs: Height, Request

    Outputs: Command, Doors

    Doors: close = false, open = true

    Command: up = 1, down = 2, stop = 3

    Height of each floor = 3

    Outline Day 2

    Si li k d St t fl56

  • 8/13/2019 Training TUM GS Simulink 13a

    56/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    Modeling Guidelines

    I i M d l Q lit57

  • 8/13/2019 Training TUM GS Simulink 13a

    57/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Increasing Model Quality

    Help => Simulink => Modeling Guidelines

    Outline Day 2

    Sim link nd Stateflo58

  • 8/13/2019 Training TUM GS Simulink 13a

    58/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    Model Advisor

    Simulink Model Advisor59

  • 8/13/2019 Training TUM GS Simulink 13a

    59/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink Model Advisor

    Outline Day 2

    Simulink und Stateflow:60

  • 8/13/2019 Training TUM GS Simulink 13a

    60/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    Report Generator and Model Comparison

    Automatic Report Generation61

  • 8/13/2019 Training TUM GS Simulink 13a

    61/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Automatic Report Generation

    Report Generator and Model Comparison

    Compare XML Files62

  • 8/13/2019 Training TUM GS Simulink 13a

    62/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Compare XML Files

    Outline Day 2

    Simulink und Stateflow:63

  • 8/13/2019 Training TUM GS Simulink 13a

    63/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    Integrating C Code using the Legacy Code Tool

    Introducing S-Functions64

  • 8/13/2019 Training TUM GS Simulink 13a

    64/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Introducing S-Functions

    S-Functions are used for:

    Hiding information about a models content (IPR)

    Speeding up simulation

    Integrating external functions written in C

    S-Functions can be created by Block Context Menu, by Legacy Code Tool, by

    S-Function Builder or they can be written by hand (template available)

    S-Functions always consist of two elements:

    A .mexw32 file containing the compiled model

    A S-Function Block calling the .mexw32 file

    In most cases S-Function blocks are masked to increase usability

    Integrating C Code using the Legacy Code Tool

    Demo: Legacy Code Tool65

  • 8/13/2019 Training TUM GS Simulink 13a

    65/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Demo:Legacy Code Tool

    LCT only creates a wrapper, which will be

    removed at code generation

    Simple way to integrate C code in Simulink

    In MATLAB use cevalto integrate code

    Help => Integrating Existing C

    Functions into Simulink Models with

    the Legacy Code Tool

    Outline Day 2

    Simulink und Stateflow:66

  • 8/13/2019 Training TUM GS Simulink 13a

    66/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Simulink und Stateflow:

    Basics:

    1) Simulink

    Basics

    Continuous Models

    Discrete Models

    Subsystems

    Signals

    2) Stateflow

    Advanced:

    1) Libraries and Model Reference

    2) Style Guidelines

    3) Model Advisor

    4) Report Generator and Model Comparison

    5) Integrating C Code using the Legacy Code Tool6) MATLAB Coder, Simulink Coder, Embedded Coder

    MATLAB Coder, Simulink Coder, Embedded CoderMATLAB Coder

    67

  • 8/13/2019 Training TUM GS Simulink 13a

    67/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    MATLAB Coder

  • 8/13/2019 Training TUM GS Simulink 13a

    68/70

    Summary69

  • 8/13/2019 Training TUM GS Simulink 13a

    69/70

    TUM Graduate SchoolTraining on MATLAB and Simulink

    Summary

    Simulink is a graphical modeling environmentbased on MATLAB

    Simulink is fully integrated in MATLAB environment

    Simulink can be used to model continuous, discrete and hybrid sytsems

    In addition, Simulink is a graphical programming language for embedded

    systems

    Simulink interacts with real hardware for Hardware In The Loop or

    Procesoor in the Loop setups, as well as for test beds and laboratory

    setups

  • 8/13/2019 Training TUM GS Simulink 13a

    70/70