Stateflow provides graphical and tabular interfaces for modeling system logic using state machines. In a state machine, you model the system's modes of operation as states and represent the logic for switching between modes using transitions and junctions. You can model the different components in your system as states that execute exclusively or in parallel. Stateflow lets you manage the complexity of your design by organizing state diagram objects, functions, and components hierarchically.
Designing logic involves defining conditions to be checked and subsequent actions to be performed. Stateflow enables you to define conditions and actions in MATLAB, Simulink, or C. You can manage the data used in conditions and actions from the Symbols Manager. Stateflow guides you during design creation and notifies you of possible inconsistencies, unused data and events, and invalid transitions.
Stateflow provides an editor and graphical objects for drawing state machines and flow charts. You build a state machine by selecting states, transitions, and junctions from a graphical palette and dragging them into the Stateflow Editor. You can also create functions using flow chart notation, Simulink subsystems, MATLAB, and truth tables. Your Stateflow diagram can be specified as a hybrid of Mealy and Moore machines with extended functionality, a Mealy machine, or a Moore machine.
You can create flow charts by drawing transitions that are connected at junctions and execute based on conditional logic. The Pattern Wizard lets you create commonly used logic flow patterns. Flow charts can be placed in graphical functions for use in many locations in the state diagram and in other state diagrams in the same model. You can use flow charts to design the logic for transitioning between states.
The Stateflow Editor provides edit-time checks to identify syntax and semantic issues such as illegal object placement and invalid transitions.
Explore gallery (2 images)
State transition tables in Stateflow provide a structured environment for modeling state machines. You build a state machine by adding rows for states, and columns for the transitions between states. State transition tables help you create state machines by providing dropdown menus for state names, automatic completion of finite state machine syntax, and other edit-time checks. Before executing your model, you can run static diagnostic tests to detect syntax errors, incomplete transitions, and unreachable states.
The state transition matrix view generated from state transition tables lets you quickly identify conditions and possible destination states from a particular state.
Truth tables in Stateflow let you model logic when the output depends purely on the current input. You build a truth table by entering conditions to be checked followed by combinations of outcomes for those conditions. Actions can then be entered for different outcome combinations. After building the truth table, you can run static diagnostic checks to identify over-specified and under-specified conditions.
You can create reusable components in Stateflow, and you can integrate them with other components to build your state machine algorithm. Stateflow components can contain MATLAB and Simulink functions, custom C code, graphical functions, and truth tables.
Stateflow facilitates component-based modeling and modular design. You can segment your chart into reusable design components that can be saved in a library. Each Stateflow component can be developed, executed, and verified independently, enabling multiple users to work on different parts of the algorithm at the same time.
You can model conditional, event-based, and time-based logic in Stateflow to call Simulink and MATLAB algorithms in a periodic or continuous manner. Stateflow can let you orchestrate the execution of components to simulate the scheduling of your real-time environment.
Stateflow provides event-based and time-based operators (such as after and duration) that let you specify state-transition logic based on event counts, elapsed time, and de-noised signals without having to create and maintain your own timers and counters.
You can analyze the behavior of your system by simulating your model and visualizing the results. You can run what-if scenarios by restarting the simulation from any saved state and analyzing its reaction to different settings and configurations.
In Stateflow you can visualize system behavior during simulation by using state diagram animation to highlight the active states and transitions in your model.
Stateflow debugging capabilities let you step through the simulation in detail. You can set breakpoints, monitor data values, and step through different functions in your state diagrams. Additionally, you can detect run-time errors, including state inconsistencies, data range violations, and potential infinite loops.
During simulation, you can visualize the results by:
Alternatively, you can log diagram and state activity data for post-processing in MATLAB.
By using Stateflow with other Simulink products, you can validate your design against requirements and generate code for implementation on your embedded system.
With Simulink Requirements™, you can link requirements directly to Stateflow objects using drag and drop.
With Simulink Check™, you can check that your state diagrams comply with standards.
With Simulink Coverage™, you can collect model and generated code coverage metrics.
With Simulink Design Verifier™, you can detect design errors and generate test vectors for hard-to-find errors using formal methods.
With Simulink Test™, you can develop, manage, and execute simulation-based tests