Stateflow

Getting Started

Preface

System Requirements

Using Stateflow on a Laptop Computer

Related Products

Using This Guide

Typographical Conventions

Installing Stateflow

Starting Stateflow

Stateflow Overview

What Is Stateflow?

Examples of Stateflow Applications

Stateflow Components

Stateflow Works with Simulink and Real-Time Workshop

Stateflow and Simulink Design Approaches

Quick Start

Look at the Power Switch Model

Create a Simulink Model

Create a Stateflow Diagram

Define Input Events

Define the Stateflow Interface

Define Simulink Parameters

Parse the Stateflow Diagram

Run a Simulation

Debug the Model During Simulation

Save the Model

How Stateflow Works

Finite State Machine Concepts

What Is a Finite State Machine?

Finite State Machine Representations

Stateflow Representations

Notation

Semantics

References

Stateflow and Simulink

The Simulink Model and the Stateflow Machine

Stateflow Data Dictionary of Objects

Defining Stateflow Interfaces to Simulink

Stateflow Diagram Objects

Graphical Objects Example Diagram

States

Transitions

Default Transitions

Events

Data

Conditions

History Junction

Actions

Connective Junctions

Stateflow Hierarchy of Objects

Exploring a Real-World Stateflow Application

Overview of the "fuel rate controller" Model

Control Logic of the "fuel rate controller" Model

Simulating the "fuel rate controller" Model

Using Stateflow

Stateflow Notation

Overview of Stateflow Objects

Graphical Objects

Nongraphical Objects

The Data Dictionary

How Hierarchy Is Represented

States

What Is a State?

State Decomposition

State Label Notation

Transitions

What Is a Transition?

Transition Label Notation

Valid Transitions

Transition Connections

Transitions to and from Exclusive (OR) States

Transitions to and from Junctions

Transitions to and from Exclusive (OR) Superstates

Transitions to and from Substates

Self-Loop Transitions

Inner Transitions

Default Transitions

What Is a Default Transition?

Drawing Default Transitions

Labeling Default Transitions

Default Transition Examples

Connective Junctions

What Is a Junction?

Flow Diagram Notation with Connective Junctions

History Junctions

What Is a History Junction?

History Junctions and Inner Transitions

Boxes

Graphical Functions

Action Language

What Is Action Language?

Action Language Categories Example

Action Language Notation

Action Language Semantics

Stateflow Semantics

Executing an Event

Sources for Stateflow Events

Processing Events

Executing a Chart

Executing an Inactive Chart

Executing an Active Chart

Executing a Transition

Transition Flow Graph Types

Executing a Set of Flow Graphs

Ordering Single Source Transitions

Executing a State

Entering a State

Executing an Active State

Exiting an Active State

State Execution Example

Early Return Logic for Event Broadcasts

Semantic Examples

Transitions to and from Exclusive (OR) States Examples

Label Format for a State-to-State Transition Example

Transitioning from State to State with Events Example

Transitioning from a Substate to a Substate with Events Example

Condition Action Examples

Condition Action Example

Condition and Transition Actions Example

Condition Actions in For Loop Construct Example

Condition Actions to Broadcast Events to Parallel (AND) States Example

Cyclic Behavior to Avoid with Condition Actions Example

Default Transition Examples

Default Transition in Exclusive (OR) Decomposition Example

Default Transition to a Junction Example

Default Transition and a History Junction Example

Labeled Default Transitions Example

Inner Transition Examples

Processing Events with an Inner Transition in an Exclusive (OR) State Example

Processing Events with an Inner Transition to a Connective Junction Example

Inner Transition to a History Junction Example

Connective Junction Examples

Label Format for Transition Segments Example

If-Then-Else Decision Construct Example

Self-Loop Transition Example

For Loop Construct Example

Flow Diagram Notation Example

Transitions from a Common Source to Multiple Destinations Example

Transitions from Multiple Sources to a Common Destination Example

Transitions from a Source to a Destination Based on a Common Event Example

Backtracking Behavior in Flow Graphs Example

Event Actions in a Superstate Example

Parallel (AND) State Examples

Event Broadcast State Action Example

Event Broadcast Transition Action with a Nested Event Broadcast Example

Event Broadcast Condition Action Example

Directed Event Broadcasting Examples

Directed Event Broadcast Using send Example

Directed Event Broadcasting Using Qualified Event Names Example

Working with Charts

Creating a Stateflow Chart

Using the Stateflow Editor

Stateflow Diagram Editor Window

Drawing Objects

Displaying the Context Menu for Objects

Specifying Colors and Fonts

Selecting and Deselecting Objects

Cutting and Pasting Objects

Copying Objects

Editing Object Labels

Viewing Data and Events from the Editor

Zooming a Diagram

Undoing and Redoing Editor Operations

Using States in Stateflow Charts

Creating a State

Moving and Resizing States

Creating Substates

Grouping States

Specifying Substate Decomposition

Specifying Activation Order for Parallel States

Changing State Properties

Labeling States

Outputting State Activity to Simulink

Using Transitions in Stateflow Charts

Creating a Transition

Creating Straight Transitions

Labeling Transitions

Moving Transitions

Changing Transition Arrowhead Size

Creating Self-Loop Transitions

Creating Default Transitions

Setting Smart Behavior in Transitions

What Smart Transitions Do

What Nonsmart Transitions Do

Changing Transition Properties

Using Boxes in Stateflow Charts

Using Graphical Functions in Stateflow Charts

Creating a Graphical Function

Calling Graphical Functions

Exporting Graphical Functions

Specifying Graphical Function Properties

Using Junctions in Stateflow Charts

Creating a Junction

Changing Size

Moving a Junction

Editing Junction Properties

Using Notes in Stateflow Charts

Creating Notes

Editing Existing Notes

Changing Note Font and Color

Moving Notes

Deleting Notes

Using Subcharts in Stateflow Charts

What Is a Subchart?

Creating a Subchart

Manipulating Subcharts as Objects

Opening a Subchart

Editing a Subchart

Navigating Subcharts

Using Supertransitions in Stateflow Charts

What Is a Supertransition?

Drawing a Supertransition

Labeling Supertransitions

Specifying Chart Properties

Checking the Chart for Errors

Creating Chart Libraries

Printing and Reporting on Charts

Printing and Reporting on Stateflow Charts

Generating a Model Report in Stateflow

Printing the Current Stateflow Diagram

Printing a Stateflow Book

Defining Events and Data

Defining Events

Adding Events to the Data Dictionary

Setting Event Properties

Defining Local Events

Defining Input Events

Defining Output Events

Exporting Events

Importing Events

Specifying Trigger Types

Implicit Events

Defining Data

Adding Data to the Data Dictionary

Setting Data Properties

Defining Data Arrays

Defining Input Data

Defining Output Data

Associating Ports with Data

Defining Temporary Data

Exporting Data

Importing Data

Action Language

Types of Action Language

Keyword Identifiers

State Action Type Keywords

Implicit Event Keywords

Special Function Keywords

Operations

Binary and Bitwise Operations

Unary Operations

Unary Actions

Assignment Operations

Pointer and Address Operations

Typecast Operations

Fixed-Point Data

Fixed-Point Arithmetic

How Stateflow Implements Fixed-Point Data

Specifying Fixed-Point Data in Stateflow

Tips and Tricks for Using Fixed-Point Data in Stateflow

Offline and Online Conversions of Fixed-Point Data

Fixed-Point Context-Sensitive Constants

Supported Operations with Fixed-Point Operands

Promotion Rules for Fixed-Point Operations

Assignment (=, :=) and Cast Operations

Overflow Detection for Fixed-Point Types

Sharing Fixed-Point Data with Simulink

Fixed-Point "Bang-Bang Control" Example

Calling C Functions

Calling C Library Functions

Calling min and max Functions

Calling User-Written C Code Functions

MATLAB Functions and Data

ml Namespace Operator

ml Function

ml Expressions

Which ml Should I Use?

ml Data Type

Inferring Return Size for ml Expressions

Data and Event Arguments

Arrays in Action Language

Array Notation

Arrays and Custom Code

Event Broadcasting

Broadcasting Events

Directed Event Broadcasting

Condition Statements

Using Temporal Logic

Rules for Using Temporal Logic Operators

after Temporal Logic Operator

before Temporal Logic Operator

at Temporal Logic Operator

every Temporal Logic Operator

Conditional and Event Notation

Temporal Logic Events

Special Symbols

Defining Stateflow Interfaces

Overview Stateflow Interfaces

Stateflow Interfaces

Typical Tasks to Define Stateflow Interfaces

Where to Find More Information on Events and Data

Setting the Stateflow Block Update Method

Stateflow Block Update Methods

Adding Input or Output Data and Events to Charts

Adding Input Events from Simulink

Adding Output Events to Simulink

Adding Input Data from Simulink

Adding Output Data to Simulink

Implementing Interfaces in Stateflow to Simulink

Defining a Triggered Stateflow Block

Defining a Sampled Stateflow Block

Defining an Inherited Stateflow Block

Defining a Continuous Stateflow Block

Defining Function Call Output Events

Defining Edge-Triggered Output Events

MATLAB Workspace Interfaces

Examining the MATLAB Workspace in MATLAB

Interfacing the MATLAB Workspace in Stateflow

Interface to External Sources

Exported Events

Imported Events

Exported Data

Imported Data

Exploring and Searching Charts

Overview of the Stateflow Machine

The Stateflow Explorer Tool

Opening Stateflow Explorer

Explorer Main Window

Objects in the Explorer

Objects and Properties in the Contents Pane

Targets in the Explorer

Stateflow Explorer Operations

Opening a New or Existing Simulink Model

Editing States or Charts

Setting Properties for Data, Events, and Targets

Moving and Copying Events, Data, and Targets

Changing the Index Order of Inputs and Outputs

Deleting Events, Data, and Targets

Setting Properties for the Stateflow Machine

Transferring Properties Between Objects

The Stateflow Search & Replace Tool

Opening the Search & Replace Tool

Using Different Search Types

Specify the Search Scope

Using the Search Button and View Area

Specifying the Replacement Text

Using the Replace Buttons

Search and Replace Messages

The Search & Replace Tool Is a Product of Stateflow

The Stateflow Finder Tool

Opening Stateflow Finder

Using Stateflow Finder

Finder Display Area

Building Targets

Overview of Stateflow Targets

Target Types

Building a Target

How Stateflow Builds Targets

Setting Up the Target Compiler

Configuring a Target

Adding a Target to a Stateflow Machine

Accessing the Target Builder Dialog for a Target

Specifying Build Options for a Target

Specifying Code Generation Options

Integrating Custom Code with Stateflow Diagrams

Specifying Custom Code Options

Specifying Path Names in Custom Code Options

Calling Graphical Functions from Custom Code

Starting the Build

Starting a Simulation Target Build

Starting an RTW Target Build

Parsing Stateflow Diagrams

Calling the Stateflow Parser

Parsing Diagram Example

Resolving Event, Data, and Function Symbols

Error Messages

Parser Error Messages

Code Generation Error Messages

Compilation Error Messages

Generated Files

DLL Files

Code Files

Makefiles

Debugging and Testing

Overview of the Stateflow Debugger

Typical Debugging Tasks

Including Error Checking in the Target Build

Breakpoints

Run-Time Debugging

Stateflow Debugger User Interface

Debugger Main Window

Status Display Area

Breakpoint Controls

Debugger Action Control Buttons

Error Checking Options

Animation Controls

Display Controls

Debugging Run-Time Errors Example

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 Run-Time Error and Repeat

Debugged Stateflow Diagram

Debugging State Inconsistencies

Causes of State Inconsistency

Detecting State Inconsistency

State Inconsistency Example

Debugging Conflicting Transitions

Detecting Conflicting Transitions

Conflicting Transition Example

Debugging Data Range Violations

Detecting Data Range Violations

Data Range Violation Example

Debugging Cyclic Behavior

Cyclic Behavior Example

Flow Cyclic Behavior Not Detected Example

Noncyclic Behavior Flagged as a Cyclic Example

Stateflow Chart Model Coverage

Making Model Coverage Reports

Specifying Coverage Report Settings

Cyclomatic Complexity

Decision Coverage

Condition Coverage

MCDC Coverage

Coverage Reports for Stateflow Charts

Summary Report Section

Details Sections

Chart as Subsystem Report Section

Chart as Superstate Report Section

State Report Section

Transition Report Section

API Guide and Reference

Stateflow API

Overview of the Stateflow API

What Is the Stateflow API?

Stateflow API Object Hierarchy

Getting a Handle on Stateflow API Objects

Using API Object Properties and Methods

API References to Properties and Methods

Quick Start for the Stateflow API

Create a New Model and Chart

Access the Machine Object

Access the Chart Object

Create New Objects in the Chart

Accessing the Properties and Methods of Objects

Naming Conventions for Properties and Methods

Using Dot Notation with Properties and Methods

Using Function Notation with Methods

Displaying Properties and Methods

Displaying the Names of Properties

Displaying the Names of Methods

Displaying Property Subproperties

Displaying Enumerated Values for Properties

Creating and Destroying API Objects

Creating Stateflow Objects

Establishing an Object's Parent (Container)

Destroying Stateflow Objects

Accessing Existing Stateflow Objects

Finding Objects

Finding Objects at Different Levels of Containment

Getting and Setting the Properties of Objects

Copying Objects

Accessing the Clipboard Object

copy Method Limitations

Copying by Grouping (Recommended)

Copying Objects Individually

Using the Editor Object

Accessing the Editor Object

Changing the Stateflow Display

Entering Multiline Labels

Creating Default Transitions

Making Supertransitions

Creating a MATLAB Script of API Commands

API Properties and Methods by Use

Reference Table Column Descriptions

Categories of Use

Properties by Use

Structural Properties

Behavioral Properties

Deployment Properties

Utility and Convenience Properties

Graphical Properties

Methods by Use

Structural Methods

Behavioral Methods

Deployment Methods

Utility and Convenience Methods

Graphical Methods

API Properties and Methods by Object

Reference Table Columns

Properties by Object

Editor Properties

Machine Properties

Chart Properties

State Properties

Box Properties

Function Properties

Note Properties

Transition Properties

Junction Properties

Data Properties

Event Properties

Target Properties

Methods by Object

All Object Methods

Editor Methods

Clipboard Methods

Root Methods

Machine Methods

Chart Methods

State Methods

Box Methods

Function Methods

Note Methods

Transition Methods

Junction Methods

Data Methods

Event Methods

Target Methods

Objectless Methods

API Methods Reference

Description of Method Reference Fields

Methods -- Alphabetical List

build

classhandle

copy

defaultTransitions

delete

dialog

disp

find

findDeep

findShallow

generate

get

getCodeFlag

help

innerTransitions

make

methods

outerTransitions

outputData

parse

pasteTo

rebuildAll

regenerateAll

set

setCodeFlag

sfclipboard

sfexit

sfhelp

sfnew

sfprint

sfroot

sfsave

sfversion

sourcedTransitions

stateflow

struct

view

zoomIn and zoomOut

Glossary

Glossary


 Stateflow