Design Considerations for Moore Charts
Moore machines are finite state machines in which output is modified at clock edges. In Moore charts, output is a function of the current state only. At every time step, a Moore chart wakes up, computes its output, and then evaluates its input to reconfigure itself for the next time step. For example, after evaluating its input, the chart can transition to a new configuration of active states. The chart computes its output before evaluating its input and updating its state. Moore semantics are not supported in standalone Stateflow® charts in MATLAB®.
To ensure that output is a function only of the current state, Moore state machines enforce these semantics:
Outputs do not depend on inputs.
Outputs do not depend on previous outputs.
Outputs do not depend on temporal logic.
Design Rules for Moore Charts
To conform to the Moore definition of a state machine, ensure that every time that a Moore chart wakes up, it computes outputs from the current set of active states without regard to inputs.
Restrictions on State Actions
To ensure that outputs depend solely on the current state, you can compute outputs in state actions, subject to these restrictions:
Combine Actions. In Moore charts, you can include only one action per state. The action can consist of multiple command statements. Stateflow evaluates states in Moore charts from the top level down. Active states in Moore charts execute the state action before evaluating the transitions. Therefore, outputs are computed at each time step whether an outer transition is valid or not.
Do Not Label State Actions. Do not label state actions in Moore charts with any keywords, such as
exit. By default, Moore charts execute the actions in the active states before evaluating inputs and updating state.
Restrictions on Transition Actions
Transitions in Moore charts can contain condition and transition actions if
these actions do not introduce a dependency between output values and input
values. For example, in this chart, each transition tests the input
u in a condition and modifies the output
y in a condition action. Because the output value depends
on the value of the input, this construct violates Moore semantics and triggers
Do Not Use Inputs to Compute Outputs
In Moore charts, outputs cannot depend on inputs. Using an input to contribute directly or indirectly to the computation of an output triggers an error.
Restrict Data Scope
In Moore charts, these data restrictions apply:
Restrict Machine-Parented Data. Machine-parented data is data that you define for a Stateflow machine. The Stateflow machine is the highest level of the Stateflow hierarchy. When you define data at this level, every chart in the machine can read and modify the data. To ensure that Moore charts do not access data that can be modified unpredictably outside the chart, do not use machine-parented data.
Do Not Define Data Store Memory. You cannot define data store memory (DSM) in Moore charts because objects external to the chart can modify DSM objects. A Stateflow chart uses data store memory to share data with a Simulink® model. Data store memory acts as global data. In the Simulink hierarchy that contains the chart, other blocks and models can modify DSM. Moore charts must not access data that can change unpredictably.
Do Not Use
coder.extrinsic to Call Extrinsic Functions
You cannot call extrinsic functions with
Moore charts because it is not possible to enforce that the outputs of extrinsic
functions depend only on the current state. Calling an extrinsic function with
coder.extrinsic in a Moore chart triggers an
Do Not Call Custom Code Functions
You cannot call custom code functions in Moore charts because it is not possible to enforce that the outputs of custom code functions depend only on the current state. Calling a custom code function in a Moore chart triggers an error.
Do Not Use Simulink Functions
You cannot use Simulink functions in Moore charts. This restriction prevents violations of Moore semantics during chart execution.
Do Not Export Functions
You cannot export functions in a Moore chart.
Do Not Disable Inlining
Moore chart semantics require inlining.
Do Not Enable Super Step Semantics
You cannot use super step semantics in a Moore chart.
Do Not Use Messages
You cannot use messages in a Moore chart.
Restrict Use of Events
Limit the use of events in Moore charts:
Use only one input event to trigger the chart.
Use event-based temporal logic to guard transitions.
The change in value of a temporal logic condition behaves like an event that the Moore chart schedules internally. At each time step, the number of ticks before the temporal event executes depends only on the state of the chart. For more information, see Temporal Logic Operators.
In Moore charts, the base event for temporal logic operators must be a predefined event such as
tick(see Implicit Events Based on Data and States).
You cannot broadcast an event of any type.
You cannot use local events to guard transitions. Local events violate Moore semantics because they are not deterministic and can occur while the chart computes its outputs.
You cannot use implicit events such as
Do Not Use Moore Charts for Modeling Continuous-Time Systems
In Moore charts, you cannot set the update method to
Continuous. For modeling systems with continuous time in
Stateflow, use Classic or Mealy charts.