What Is State-flow?
- State flow is a graphical design and development tool for control and supervisory logic used in conjunction with Simulink.
- It provides clear, concise descriptions of complex system behavior using finite state machine theory, flow diagram notations, and state-transition diagrams all in the same Stateflow diagram and verify how the system reacts to events, time-based conditions, and external input signals.
- State-flows can used to design application logics such as supervisory control, task scheduling, and fault management.
Building state Flow chart?
- Before we start building a chart, we need to identify system attributes by answering following:
- What are the interfaces?
- What are the event triggers to which the system reacts?
- What are the inputs to the system?
- What are the outputs from the system?
2. Does the system have any operating modes?
- If the answer is yes, what are the operating modes?
- Between which modes can transitions occur? Are there any operating modes that can run in parallel?
- Following is a basic workflow for building Stateflow charts to model event-driven systems:
- Define the interface to Simulink.
- Define the states for modeling each mode of operation.
- Define state actions and variables.
- Define the transitions between states.
- Decide how to trigger the chart.
- Simulate the chart.
- Debug the chart.
State Flow – Features
- “State-flow Is Part of Simulink” — State-flow integrates with its Simulink environment to model, simulate, and analyze the system.
- “State-flow Is a Finite State Machine” — State-flow visually models and simulates the complex reactive control and simulation based on finite state machine theory. One can design and develop deterministic, supervisory control systems in a graphical environment.
- “State-flow Adds Flow Diagrams to the State Machine” — Flow diagram notation creates decision-making logic such as for loops and if-then-else constructs without the use of states. In some cases, using flow diagram notation provides a closer representation of the required system logic that avoids the use of unnecessary states.
- “State-flow Simulates its State Machine” — Easily modify the design, evaluate the results, and verify the system’s behavior at any stage of the design.
- “State-flow Generates Code” — State-flow automatically generates integer, floating-point, or fixed-point code directly from your design (using State-flow Coder)
Stateflow Is Part of Simulink
- State-flow is a product that is part of Simulink. In Simulink, State-flow blocks are referred to as State-flow Chart blocks. The following diagram shows a simple Simulink model that has a State-flow Chart block in it:
Stateflow Is a Finite State Machine
- If you double-click the Stateflow block in the preceding Simulink model, its Stateflow diagram appears in the Stateflow diagram editor window.
- Stateflow is an example of a finite state machine. A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system makes a transition from one state (mode) to another, if the condition defining the change is true.
Stateflow Adds Flow Diagrams to the State Machine
- While states and transitions are the basic building blocks of a state machine, Stateflow also adds the feature of flow diagrams that provide decision points in transitions. Stateflow implements flow diagrams with junctions, that provide an alternative path for transitions.
- Stateflow data are variables or constants that you define for Stateflow diagrams that apply locally or outside the diagram
Stateflow Simulates its State Machine
- The State Flow chart Simulation allows one to see an animated Stateflow chart while it responds to events and changes states. In the animated chart, active states, when events occur and transitions are taken are highlighted, as shown in the following example:
Stateflow Generates Code
- Stateflow generates its own C-code to simulate Stateflow charts during simulation. When you generate code During the State flow chart simulation an auto code is generated, this is referred to as generating a simulation target whose name is sfun.
- Using the Stateflow Coder, one can generate code for applications that you build in other environments, such as an embedded environment.
- One can even include a custom code, that Stateflow uses to build the target with.