Before You Begin
System Requirements
Using Stateflow on a Laptop Computer
Related Products
MATLAB
Simulink
Real-Time Workshop
Using This Guide
Chapter Quick Reference
Typographical Conventions
Installing Stateflow
Introduction
Overview
What Is Stateflow?
Examples of Stateflow Applications
Stateflow Components
Design Approaches
Finite State Machine Concepts
What Is a Finite State Machine?
FSM Representations
Stateflow Representations
Notations
Semantics
References
Anatomy of a Model and Machine
The Simulink Model and Stateflow Machine
Defining Stateflow Interfaces
Stateflow Diagram Objects
Quick Start
The Power Switch Model
Creating a Simulink Model
Creating a Stateflow Diagram
Defining Input Events
Defining the Stateflow Interface
Defining Simulink Parameters
Parsing the Stateflow Diagram
Running a Simulation
Debugging
Generating Code
Creating Charts
Creating a Chart
Using the Stateflow Editor
Displaying Shortcut Menus
Drawing Objects
Specifying Object Styles
Selecting and Deselecting Objects
Cutting and Pasting Objects
Copying Objects
Editing Object Labels
Exploring Objects in the Editor Window
Zooming a Diagram
Creating States
Moving and Resizing States
Creating Substates
Grouping States
Hiding a State's Contents
Specifying State Decomposition
Specifying Activation Order for Parallel States
Labeling States
Using the State Properties Dialog
Naming States
Defining State Actions
Outputting State Activity to Simulink
Creating Boxes
Creating Transitions
What Is a Default Transition?
Creating Default Transitions
Editing Transition Attach Points
Labeling Transitions
Valid Labels
Changing Arrowhead Size
Moving Transition Labels
Using the Transition Properties Dialog
Creating Junctions
Changing Size
Changing Arrowhead Size
Moving a Junction
Editing Junction Properties
Specifying Chart Properties
Waking Up Charts
Creating Chart Libraries
Stateflow Printing Options
Printing a Stateflow Diagram
Printing a Stateflow Book
Defining Events and Data
Defining Events
Adding Events to the Data Dictionary
Setting Event Properties
Event Properties
Naming Events
Defining Local Events
Defining Input Events
Defining Output Events
Exporting Events
Importing Events
Specifying Trigger Types
Describing Events
Documenting Events
Implicit Events
Defining Data
Adding Data to the Data Dictionary
Setting Data Properties
Data Properties
Defining Data Arrays
Defining Input Data
Defining Output Data
Associating Ports with Data
Defining Temporary Data
Exporting Data
Importing Data
Documenting Data
Defining Stateflow Interfaces
Overview
Interfaces to Stateflow
Typical Tasks to Define Stateflow Interfaces
Where to Find More Information on Events and Data
Defining the Stateflow Block Update Method
Stateflow Block Update Methods
Defining a Triggered Stateflow Block
Defining a Sampled Stateflow Block
Defining an Inherited Stateflow Block
Defining a Continuous Stateflow Block
Defining Output to Simulink Event Triggers
Overview
Defining Function Call Output Events
Defining Edge-Triggered Output Events
Event Inputs from Simulink
Add an Event Choosing a Chart as the Parent
Choose Input from Simulink as the Scope
Select the Trigger
Apply the Changes
Data Inputs from Simulink
Add a Data Object Choosing a Chart as the Parent
Choose Input from Simulink as the Scope
Specify Data Attributes
Apply and Save the Changes
Event Outputs to Simulink
Add an Event Choosing a Chart as the Parent
Choose Output to Simulink as the Scope
Apply the Changes
Data Outputs to Simulink
Add a Data Object Choosing a Chart as the Parent
Choose Output to Simulink as the Scope
Specify Data Attributes
Apply the Changes
MATLAB Workspace
What Is the MATLAB Workspace?
Using the MATLAB Workspace
Defining the Interface to External Sources
What Are External Sources?
Exported Events
Imported Events
Exported Data
Imported Data
Exploring and Searching
Overview
Exploring and Searching
Stateflow Explorer User Interface
Explorer Main Window
Moving Objects/Changing Parent
Moving Objects/Changing Index and Port Order
Deleting Objects
Editing Objects
Stateflow Finder User Interface
Finder Dialog Box
Finder Display Area
Searching for a Wildcard String
Example
Searching for an Exact String Match
Example
Searching for All Objects of a Specified Object Type
Example
Searching Based on Multiple Conditions
Example
Searching for an Object to Edit Properties
Example
Notations
Overview
What Is Meant by Notation?
Motivation Behind the Notation
How Is the Notation Checked?
What Are the Graphical Objects?
What Are the Nongraphical Objects?
What Is the Data Dictionary?
Keywords
How Is Hierarchy Represented?
States
Overview
What Is a State Decomposition?
Active and Inactive States
What Are Combination States?
Labeling a State
Transitions
What Is a Transition?
Labeling a Transition
What Is a Valid Transition?
Types of Transitions
What Is a Default Transition?
Labeling of Default Transitions
What Is an Inner Transition?
What Is a Self Loop Transition?
Connective Junctions
What Is a Connective Junction?
What Is Flow Diagram Notation?
History
What Is a History Junction?
History Junctions and Inner Transitions
Action Language
What Is an Action Language?
Objects with Actions
Transition Action Notation
State Action Notation
Action Language Components
Bit Operations
Binary Operations
Unary Operations
Unary Actions
Assignment Operations
User-Written Functions
ml() Functions
MATLAB Name Space Operator
Choosing Between the ml() Function and the ml Name Space Operator
Data and Event Arguments
Arrays
Pointer and Address Operators
Hexadecimal Notation
Event Broadcasting
Directed Event Broadcasting
Conditions
Time Symbol
Literals
Continuation Symbols
Comments
Use of the Semicolon
Using the Notation Efficiently
Designing for Efficiency
Optimizing for Speed
Optimizing for Code Size
Optimizing for Memory Use
Semantics
Overview
What Are Semantics?
List of Semantic Examples
Event-Driven Effects on Semantics
What Does Event-Driven Mean?
Top-Down Processing of Events
Semantics of Active and Inactive States
Semantics of State Actions
Semantics of Transitions
Transitions to and from Exclusive (OR) States
Condition Actions
Default Transitions
Inner Transitions
Connective Junctions
Event Actions
Parallel (AND) States
Directed Event Broadcasting
Execution Order
Overview
Execution Order Guidelines
Parallel (AND) States
Semantic Rules Summary
Entering a Chart
Executing an Active Chart
Entering a State
Executing an Active State
Exiting an Active State
Executing a Set of Flow Graphs
Executing an Event Broadcast
Tutorial: Entering a Stateflow Diagram
Overview
Objectives
Provided Models for This Chapter
Carousel Tutorial Example
Basic Operation
Designing the Carousel Stateflow Diagram
Overview
The Design Questions
What Are the States?
What Is a State Decomposition?
What Are the State Labels?
Will Junctions Simplify the Design?
What Are the Transitions?
Are There Default Transitions?
Are There Events?
Is There Data?
Procedure
Overview
Create a Simulink Model
Sample Stateflow Diagram
Create and Label the OR States
Create and Label the Superstates
Create and Label the AND States
Create the Transitions
Label the Transitions
Create Default Transitions
Add and Define Event Objects
Add and Define Data Objects
Save the Model
Run the Simulation for the Provided Solution
Overview
Carousel Simulink Model Solution
Carousel Operator's Console
Carousel Solution Stateflow Diagram
Procedure
Run the Carousel Demo
Overview
Carousel Operator's Console
Procedure
Building Targets
Overview
Target Types
Building a Target
How Stateflow Builds Targets
Setting Up Target Build Tools
Setting Up Build Tools on UNIX
Setting Up Build Tools on Windows
Starting a Build
Starting from a Target Builder Dialog Box
Configuring a Target
Specifying Code Generation Options
Specifying Custom Code Options
Parsing
Parser
Parse the Machine or the Stateflow Diagram
Error Messages
Parser Error Messages
Code Generation Error Messages
Compilation Error Messages
Debugging
Overview
Debugging
Typical Debugging Tasks
Including Debugging in the Target Build
Breakpoints
Runtime Debugging
Stateflow Debugger User Interface
Debugger Main Window
Status Display Area
Break On Controls
Debugger Action Control Buttons
Animation Controls
Display Controls
MATLAB Command Field
Debugging Runtime Errors
Example Stateflow Diagram
Typical Scenario to Debug Runtime Errors
Create the Model and Stateflow Diagram
Define the sfun Target
Invoke the Debugger and Choose Debugging Options
Start the Simulation
Debug the Simulation Execution
Resolve Runtime Error and Repeat
Solution Stateflow Diagram
Debugging State Inconsistencies
What Is a State Inconsistency?
Causes of State Inconsistency
Detecting State Inconsistency
Debugging Conflicting Transitions
What Is a Conflicting Transition?
Detecting Conflicting Transitions
Debugging Data Range Violations
What Is a Data Range Violation?
Detecting Data Range Violations
Debugging Cyclic Behavior
What Is Cyclic Behavior?
Detecting Cyclic Behavior
Reference
Commands
sfnew
sfexit
sfsave
stateflow
sfprint
sfhelp
Glossary