0% found this document useful (0 votes)
4K views10 pages

Stateflow Learning Part 1

Stateflow

Uploaded by

Chadil hiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views10 pages

Stateflow Learning Part 1

Stateflow

Uploaded by

Chadil hiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

STATEFLOW

LEARNING AND PRACTICES

By
- A. MAHENDRAN
TABLE OF CONTENT
S. No Content
1 Introduction to Stateflow
1.1 Defining Chart Behavior by Using State and Transition Actions
1.1.1 State Action Types
1.1.2 Transition Action Types
1.2 Stateflow Working
1.2.1 Creating a Stateflow Chart
1.2.2 Constructing the Stateflow Model
1.2.3 Resolving Undefined Symbols
1.3 Simulating the stateflow Chart as Simulink block - By using constant blocks as inputs.
1 STATEFLOW
➢ Stateflow provides a graphical language that includes state transition diagrams, flow charts, state transition tables, and
truth tables. You can use Stateflow to describe how MATLAB algorithms and Simulink models react to input signals,
events, and time-based conditions.
➢ With Stateflow, you can model combinatorial and sequential decision logic that can be simulated as a block within a
Simulink model or executed as an object in MATLAB. Graphical animation enables you to analyze and debug your logic
while it is executing. Edit-time and run-time checks ensure design consistency and completeness before implementation.

Sample Stateflow Chart

Applications
Stateflow enables you to design and develop supervisory control, task scheduling, fault management / detection,
communication protocols, user interfaces and is used for Control systems logic, Finite state machines.
Simulink is used to respond to continuous changes in Stateflow is used to respond to instantaneous changes
dynamic systems in dynamic systems
1.1 Defining Chart Behavior by Using State and Transition Actions

State actions and transition actions are instructions that


you write inside a state or on a transition, respectively, The square [] bracket is for condition
to define how a Stateflow chart behaves during curly {} brackets are for action.
simulation. In Stateflow transition signals,

Entry actions occur when the state becomes


active and are performed if something
happens on the way into a state.
1.1.1 State Action Types

State actions define what a Stateflow chart During action is performed, when remaining in a
does while a state is active. The most state, during actions occur on a time step when the
common types of state actions state is already active, and the chart does not
are entry, during, and exit actions: transition out of the state.

Exit actions are performed on the way out of a state.


Exit actions occur when the chart transitions out of
the state.
1.1.2 Transition Action Types
Transition actions define what a Stateflow chart does when the
active state changes. The most common types of transition
actions are conditions and condition actions. To specify transition
actions, use a label with this syntax:
➢ [Condition] {ConditionAction}

➢ Condition is a Boolean expression that determines whether the transition occurs. If you do not specify a condition, the
transition occurs one time step after the source state becomes active.
➢ ConditionAction is an instruction that executes when the condition that guards the transition is true. The condition action
takes place after the condition but before any exit or entry state actions.
1.2 Stateflow Working
1.2.1 Creating a Stateflow Chart

➢ The Stateflow Editor is a graphical environment for designing state transition diagrams, flow
charts, state transition tables, and truth tables. Before opening the Stateflow Editor, decide on the
chart execution mode that best meets your needs.

➢ To model conditional, event-based, and time-based logic for periodic or continuous-time Simulink
algorithms, use the sfnew function to create a Stateflow chart that you can simulate as a block in
a Simulink model. At the MATLAB command prompt, enter: >> sfnew motorctrl

➢ A chart has been created with the name motorctrl


➢ To open the Stateflow Editor, double-click the chart block. Simulink creates a model called motorctrl that contains an
empty Stateflow Chart block.

Stateflow chart /
editor / canvas

The Stateflow chart / chart canvas is a drawing area where you create a chart by combining states, transitions, and other
graphical elements.
➢ On the left side of the canvas, the object palette displays a set of tools for adding graphical elements to your chart
➢ On the right side of the canvas, in the Symbols pane, you add new data, events, and messages to the chart and resolve
any undefined or unused symbols.
Step 1 - From the object palette, click the
After opening the state State icon and move the pointer to the
1.2.2 Constructing flow chart, follow these chart window. A state with its default
the stateflow steps to create and transition appears. To place the state, click
Model Simulate the Chart as a the location on the window. At the text
Simulink Block, prompt, enter the state name On and below
state action y = x.

Step 4 - Alternatively, to draw a


Step 2 - Add another state by Step 3 - Realign the two states transition, click and drag from the
right-click and drag the On state. and pause on the space edge of one state to the edge of the
Blue graphical arrows help you to between the two states. Blue other state. Double-click each
align your states horizontally or transition arrows indicate transition and type the appropriate
vertically. The name of the new several ways in which you can transition condition (x<t0 or x>=t0).
state changes to Off. Double-click connect the states. To add The conditions appear inside square
the state and modify the state transitions, click the appropriate brackets. Now we have created a
action to y = 0. arrow signal. stateflow chart with default junction
and condition.
1.2.3 Resolving Undefined Symbols

1. Open the Symbols pane.

➢ If you are building a chart in a Simulink model, in the Modeling tab, under Design
Data, select Symbols Pane.
➢ If you are building a standalone chart for execution in MATLAB, in the State Chart
tab, select Design Data > Symbols Pane.

2. After opening the Symbols pane, click Resolve Undefined Symbols

➢ We can resolve the undefined symbols by giving the variables of inputs & outputs.
For this example, give x & t0 as input data and y as output

➢ Note: The inputs are t0, x and output are y.


1.3 Simulating the stateflow Chart as Simulink block - By using constant blocks as inputs.

• After resolving, come out of the chart, add 2 constant blocks for inputs t0, x and a display block for output y to view results.

Stateflow chart we created

(Note: Based on the input values and transition conditions, the states will execute with respect to each step of stop
time.)
Now we’ll see different set of cases for executing the transition conditions
Case 1: We give both t0, x = 1, which showed in symbols pane. When we simulate, with the transition conditions satisfying
[x>=t0], the On state will execute for the whole stop time and highlights as shown below.
Case 2: If we give t0 as 1 and x as 0, now simulate the model in Step forward to see the states execution at every time
step. The Off state should be executed for the condition, but as we mentioned that On state as default junction, at 1st time
step the state entry will be at On state & will highlight as we seen below.

For further time steps up to the last stop time, the Off will be executed and highlighted.

Note : As we can see the output value in scope blocks, while we executing the transition conditions, parallelly we can view
this data at each time step on symbols pane at right side of window

You might also like