introduction to simulink, stateflow, and simscape - matlab€¦ · introduction to simulink,...

21
1 © 2013 The MathWorks, Inc. Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks

Upload: vothuy

Post on 08-Jul-2018

359 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

1 © 2013 The MathWorks, Inc.

Introduction to Simulink, Stateflow,

and Simscape

By Paul Peeling

MathWorks

Page 2: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

2

Key Technologies for Embracing Complexity

Model-Based Design

Multi-Domain Modelling

Code Generation

Page 3: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

3

Two Engineering Challenges

Shift schedule optimisation of an

automatic transmission controller

Modelling and control of an

inverted double pendulum

Page 4: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

4

Modelling Automatic Transmission

Page 5: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

5

Modelling Automatic Transmission in Simulink

Page 6: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

6

Blocks in Simulink

Fundamental blocks

Subsystems

Other Simulink Models

MATLAB Code

DLLs

Stateflow Charts

Simscape Components

Page 7: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

7

Simulation of dynamic systems

Page 8: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

8

Simulink: Key Features

Visual, block-diagram, environment

Hierarchical, component-based

modelling

Extensive and expandable libraries of

pre-defined blocks

Open Application Program Interface

(API)

Full MATLAB® integration

Multi-domain

Page 9: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

9

Stateflow for Complex Logic

When to use Stateflow?

Model instantaneous

changes in dynamic

systems

– Changes in state

– Events

Finite state machines

Flow diagrams

Page 10: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

10

Stateflow Overview

Extend Simulink with a design environment for

developing state machines and flow charts

Design systems containing control, supervisory, and

mode logic

Describe logic in a natural and understandable form

with deterministic execution semantics

Page 11: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

11

Stateflow: Key Features

Defines functions

– Procedurally, using MATLAB

– Graphically, using flow diagrams

– In tabular form, with truth tables

Provides language elements,

hierarchy, and parallelism

Animates Stateflow® charts

Incorporates custom and legacy C

code

Performs static and run-time checks

Page 12: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

12

Conclusions

Simulink and Stateflow provide:

A powerful environment for modelling real processes...

in a modular fashion...

and are fully integrated with the MATLAB environment

for extensive design & analysis capability

Page 13: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

13

Physical Modelling

Physical

Hardware

S1

S2 S3

Software and

Algorithms

P T T

A B

PID + -

if (..)

x = …

else

x =

Inputs and outputs, state

charts, algorithms, …

Physical devices

Page 14: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

14

What does this model represent?

Page 15: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

15

Modelling an electrical circuit in Simulink

Step 1: figure out the equations

Step 2: build the model

Page 16: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

16

Differential equation

Algebraic equation

Differential Algebraic Equation

Page 17: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

17

Constructed by the

Simscape solver

Component equations

Modeling an electrical circuit in Simscape

Page 18: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

18

Mathematical Modelling of Mechanical

Systems

Derivation of the equations of motion

requires extensive knowledge and

great effort.

- -

- - - - - - - - + - =

) ( sin 1

) cos( ) cos( )) sin( ( ) sin( )) sin( ( ) sin( 2

2 2

2 2

g a

g g a a g a g a g g a a a

ne

n ne nw L & & & dg

Page 19: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

19

With SimMechanics

Revolute

Joint1

Revolute

Joint2

Joints Bodies

Fixture

Link1

Link2 +

SimMechanics Model

Page 20: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

20

Physical Systems in Simulink®

Sim

Mechanic

s™

Mechanical dynamics (3-D)

Sim

Drivelin

e™

Drivetrain systems (1-D)

Sim

Hydra

ulic

Fluid power and control Multidomain physical systems

Electrical power systems

Sim

Pow

erS

yste

ms

Sim

Ele

ctr

onic

s™

Electromechanical and

electronic systems

Simscape™

Page 21: Introduction to Simulink, Stateflow, and Simscape - MATLAB€¦ · Introduction to Simulink, Stateflow, and Simscape By Paul Peeling MathWorks . 2 Key Technologies for Embracing Complexity

21

Simscape Key Features

Library of foundation physical modelling

building blocks

– Mechanical, electrical, hydraulic,…

Simscape language source provided

Signals and parameters with units, and

automatic unit conversion

Physical network solver technology

designed for physical systems

Integrated with Simulink to support

complete system modelling (physical

system plus algorithms)

Convert to C code for deployment

P A T B