1
Stateflow Workshop for System Engineers
Roni Peer
Systems and Applications Engineer
Systematics, Ltd.
ronip@systematics.co.il
2
‫סיסטמטיקס‬–‫נציגת‬MathWorks‫בישראל‬
‫משווקת‬ ‫סיסטמטיקס‬,‫ותומכת‬ ‫מיישמת‬,‫הישראלי‬ ‫לשוק‬ ‫ייעודיים‬ ‫מחשוב‬ ‫בפתרונות‬.
‫קורסים‬ ‫מגוון‬,‫והכשרות‬ ‫הדרכות‬
‫וייעוץ‬ ‫הטמעה‬ ‫פרוייקטי‬
‫מרחוק‬ ‫ובסיוע‬ ‫הלקוח‬ ‫באתר‬ ‫מלאה‬ ‫טכנית‬ ‫תמיכה‬
‫הלקוח‬ ‫לצורכי‬ ‫המוצרים‬ ‫והתאמת‬ ‫מכירה‬ ‫לפני‬ ‫ייעוץ‬
ESRI, ENVI, NAVTEQ
eMap, GeoEye, LizardTech
SolidWorks
MathWorks Oracle Agile PLM
Open Text RightFax
3
Mechanical
Components
MCAD/
MCAE
Electrical
Components
EDA
INTEGRATION AND TEST
SPECIFICATIONS
DESIGN
RESEARCH REQUIREMENTS
Embedded
Software
C/C++
IMPLEMENTATION
Requirement Documents
• Difficult to analyze
• Difficult to manage as they change
Paper Specifications
• Easy to misinterpret
• Difficult to integrate with design
Physical Prototypes
• Incomplete and expensive
• Prevents rapid iteration
• No system-level testing
Manual Coding
• Time consuming
• Introduces defects and variance
• Difficult to reuse
Traditional Testing
• Design and integration issues found late
• Difficult to feed insights back into design
process
• Traceability
Embeddable
Algorithms
Algorithm
Design
Traditional Development
4
DESIGN
Embedded
Software
Control
Algorithms
Mechanical
Components
Electrical
Components
Model-Based Design- Describe the system dynamics
Model-Based Design uses
block diagrams to
mathematically model the
system behavior.
You design the way the system
should perform.
5
Model-Based Design- Design and test using simulation
DESIGN
Environmental Models
Control Algorithms
Mechanical Electrical
Supervisory Logic
Requirements are linked to the
model.
Detail is added from specific
domains to refine the model.
Intellectual property and
engineering data are reused
from existing designs and CAE
tools, such as CAD, FEA, and
SPICE models.
Testing control algorithms
against requirements is done
by simulating the model.
RESEARCH REQUIREMENTS
6
REAL-TIME TESTING
Model-Based Design- Test and validate in real-time
DESIGN
Environmental Models
Control Algorithms
Mechanical Electrical
Supervisory Logic
Automatically generate code
from the simulation model for
real-time testing of the control
algorithms.
RESEARCH REQUIREMENTS
Automatically generate code
from the simulation model for
real-time system simulation of
hardware for testing the real
microcontroller, FPGA, or PLC
MCU DSP FPGA ASIC
Structured
Text
VHDL,
Verilog
C, C++
PLC
7
INTEGRATION
IMPLEMENTATION
TEST&VERIFICATION
Model-Based Design- Implement embedded software
DESIGN
Environmental Models
Control Algorithms
Mechanical Electrical
Supervisory Logic
Automatically generate code
from the simulation model for
implementing directly on
production targets:
• Microcontrollers
• FPGAs
• PLC IDEs
RESEARCH REQUIREMENTS
MCU DSP FPGA ASIC
Structured
Text
VHDL,
Verilog
C, C++
PLC
8
 Provides a CAE solution for
multidomain system-level
development of embedded
controllers
 Uses a simulation model to
mathematically describe the system-
level behavior of complex equipment
 Automatically generates code from
the model to help you with real-time
testing and with implementation
 Lets you test continuously
throughout the development process
Model-Based Design Summary
Design
with
Simulation
Executable
Specifications
Continuous
Test and
Verification
Automatic
Code Generation
Models
9
What is Stateflow?
 Model and simulate decision
logic
 Develop mode-logic using
state machines and flow charts
 See how the logic behaves
with diagram animation and
integrated debugger
10
How does Stateflow work with Simulink?
Simulink is used to respond to
continuous changes in
dynamic systems.
Stateflow is used to respond to
instantaneous changes in
dynamic systems.
Real-world systems have to respond to both continuous and
instantaneous changes.
suspension dynamics
gear changes
propulsion system
liftoff stages
robot kinematics
operation modes
Use both Simulink and Stateflow so that you can
use the right tool for the right job.
11
What Can You Do with Stateflow® Software?
Truth table
State machineComplex decision flow
12
Why use Stateflow?
 Model modes of operation clearly
with state machines in Stateflow
 Represent complex conditional and
event based logic with flow charts
in Stateflow
 Understand behavior of logic easily
with animation and integrated
debugger in Stateflow
 Test and Verify your design using
Model-Based Design tools before
implementation
13
Stateflow Example
14
Stateflow Review
 STATES represent modes of operation
– Exclusive States (OR)
– Parallel States (AND)
 TRANSITIONS represent paths between states
 Types of functions supported:
– Graphical
– MATLAB
– Simulink
– Truth Tables
15
State Labeling Syntax
State name (mandatory)
State actions (optional)
• entry – Executes upon entering the
state
• exit – Executes upon exiting the
state
• during – Executes when the state
starts out as active and remains
active (no transition occurs)
16
Transition Labeling Syntax
• Comments can be placed
anywhere
• All other sections must
remain in order shown
Enclosed in
/* */
Enclosed in
[ ]
Enclosed in
{ }
Preceded by
/
17
Superstates and Substates
Ungrouped
Grouped
Add states into
a parent state
Double-click border to group contents
of the superstate
18
Parallel State Charts
Failure determination
Mode logic
19
Model Coverage & Automatic Test Cases
 Execution analysis
– Based on the model structure
– Dynamic – data collected during
simulation
 Coverage results
– Displayed directly in the model
– Available in a separate html
report linked with the model
objects
 Supports:
– Simulink
– Stateflow
– MATLAB
Decision coverage
Condition coverage
MC/DC
Lookup table coverage
Signal range coverage
Supported coverage types
20
Summary
 Model-Based Design provides an efficient and smooth
solution to design, test and implement Systems
 State machines and flow charts in Stateflow clearly
represent logic
 With Model-Based Design, you continuously test to
check that the design meets requirements

Simulink Stateflow workshop

  • 1.
    1 Stateflow Workshop forSystem Engineers Roni Peer Systems and Applications Engineer Systematics, Ltd. ronip@systematics.co.il
  • 2.
    2 ‫סיסטמטיקס‬–‫נציגת‬MathWorks‫בישראל‬ ‫משווקת‬ ‫סיסטמטיקס‬,‫ותומכת‬ ‫מיישמת‬,‫הישראלי‬‫לשוק‬ ‫ייעודיים‬ ‫מחשוב‬ ‫בפתרונות‬. ‫קורסים‬ ‫מגוון‬,‫והכשרות‬ ‫הדרכות‬ ‫וייעוץ‬ ‫הטמעה‬ ‫פרוייקטי‬ ‫מרחוק‬ ‫ובסיוע‬ ‫הלקוח‬ ‫באתר‬ ‫מלאה‬ ‫טכנית‬ ‫תמיכה‬ ‫הלקוח‬ ‫לצורכי‬ ‫המוצרים‬ ‫והתאמת‬ ‫מכירה‬ ‫לפני‬ ‫ייעוץ‬ ESRI, ENVI, NAVTEQ eMap, GeoEye, LizardTech SolidWorks MathWorks Oracle Agile PLM Open Text RightFax
  • 3.
    3 Mechanical Components MCAD/ MCAE Electrical Components EDA INTEGRATION AND TEST SPECIFICATIONS DESIGN RESEARCHREQUIREMENTS Embedded Software C/C++ IMPLEMENTATION Requirement Documents • Difficult to analyze • Difficult to manage as they change Paper Specifications • Easy to misinterpret • Difficult to integrate with design Physical Prototypes • Incomplete and expensive • Prevents rapid iteration • No system-level testing Manual Coding • Time consuming • Introduces defects and variance • Difficult to reuse Traditional Testing • Design and integration issues found late • Difficult to feed insights back into design process • Traceability Embeddable Algorithms Algorithm Design Traditional Development
  • 4.
    4 DESIGN Embedded Software Control Algorithms Mechanical Components Electrical Components Model-Based Design- Describethe system dynamics Model-Based Design uses block diagrams to mathematically model the system behavior. You design the way the system should perform.
  • 5.
    5 Model-Based Design- Designand test using simulation DESIGN Environmental Models Control Algorithms Mechanical Electrical Supervisory Logic Requirements are linked to the model. Detail is added from specific domains to refine the model. Intellectual property and engineering data are reused from existing designs and CAE tools, such as CAD, FEA, and SPICE models. Testing control algorithms against requirements is done by simulating the model. RESEARCH REQUIREMENTS
  • 6.
    6 REAL-TIME TESTING Model-Based Design-Test and validate in real-time DESIGN Environmental Models Control Algorithms Mechanical Electrical Supervisory Logic Automatically generate code from the simulation model for real-time testing of the control algorithms. RESEARCH REQUIREMENTS Automatically generate code from the simulation model for real-time system simulation of hardware for testing the real microcontroller, FPGA, or PLC MCU DSP FPGA ASIC Structured Text VHDL, Verilog C, C++ PLC
  • 7.
    7 INTEGRATION IMPLEMENTATION TEST&VERIFICATION Model-Based Design- Implementembedded software DESIGN Environmental Models Control Algorithms Mechanical Electrical Supervisory Logic Automatically generate code from the simulation model for implementing directly on production targets: • Microcontrollers • FPGAs • PLC IDEs RESEARCH REQUIREMENTS MCU DSP FPGA ASIC Structured Text VHDL, Verilog C, C++ PLC
  • 8.
    8  Provides aCAE solution for multidomain system-level development of embedded controllers  Uses a simulation model to mathematically describe the system- level behavior of complex equipment  Automatically generates code from the model to help you with real-time testing and with implementation  Lets you test continuously throughout the development process Model-Based Design Summary Design with Simulation Executable Specifications Continuous Test and Verification Automatic Code Generation Models
  • 9.
    9 What is Stateflow? Model and simulate decision logic  Develop mode-logic using state machines and flow charts  See how the logic behaves with diagram animation and integrated debugger
  • 10.
    10 How does Stateflowwork with Simulink? Simulink is used to respond to continuous changes in dynamic systems. Stateflow is used to respond to instantaneous changes in dynamic systems. Real-world systems have to respond to both continuous and instantaneous changes. suspension dynamics gear changes propulsion system liftoff stages robot kinematics operation modes Use both Simulink and Stateflow so that you can use the right tool for the right job.
  • 11.
    11 What Can YouDo with Stateflow® Software? Truth table State machineComplex decision flow
  • 12.
    12 Why use Stateflow? Model modes of operation clearly with state machines in Stateflow  Represent complex conditional and event based logic with flow charts in Stateflow  Understand behavior of logic easily with animation and integrated debugger in Stateflow  Test and Verify your design using Model-Based Design tools before implementation
  • 13.
  • 14.
    14 Stateflow Review  STATESrepresent modes of operation – Exclusive States (OR) – Parallel States (AND)  TRANSITIONS represent paths between states  Types of functions supported: – Graphical – MATLAB – Simulink – Truth Tables
  • 15.
    15 State Labeling Syntax Statename (mandatory) State actions (optional) • entry – Executes upon entering the state • exit – Executes upon exiting the state • during – Executes when the state starts out as active and remains active (no transition occurs)
  • 16.
    16 Transition Labeling Syntax •Comments can be placed anywhere • All other sections must remain in order shown Enclosed in /* */ Enclosed in [ ] Enclosed in { } Preceded by /
  • 17.
    17 Superstates and Substates Ungrouped Grouped Addstates into a parent state Double-click border to group contents of the superstate
  • 18.
    18 Parallel State Charts Failuredetermination Mode logic
  • 19.
    19 Model Coverage &Automatic Test Cases  Execution analysis – Based on the model structure – Dynamic – data collected during simulation  Coverage results – Displayed directly in the model – Available in a separate html report linked with the model objects  Supports: – Simulink – Stateflow – MATLAB Decision coverage Condition coverage MC/DC Lookup table coverage Signal range coverage Supported coverage types
  • 20.
    20 Summary  Model-Based Designprovides an efficient and smooth solution to design, test and implement Systems  State machines and flow charts in Stateflow clearly represent logic  With Model-Based Design, you continuously test to check that the design meets requirements