Hybrid systems use modal logic to transition from one mode to another in response to physical events and conditions. In these systems, continuous-time dynamics govern each mode. A simple example of this type of hybrid system is a bouncing ball. The ball moves continuously through the air until it hits the ground, at which point a mode change or discontinuity occurs. As a result, the ball suddenly changes direction and velocity. For more information, see Model a Bouncing Ball in Continuous Time.
Simulate hybrid systems that respond to continuous and discrete mode changes by configuring Stateflow® charts for continuous-time modeling. In a Stateflow chart, you can represent modal logic succinctly and intuitively as a series of states, transitions, or flow charts. You can also represent state information as continuous local variables with automatic access to time derivatives.
Continuous-time simulation is supported only in Stateflow charts in Simulink® models. If your continuous system does not contain modal logic, consider using a Simulink model. For more information, see Model a Continuous System.
Continuous updating is a Stateflow chart property.
Right-click inside a chart and select Properties from the context menu.
In the Chart Properties dialog box, set the Update
method field to
you select this option:
The Enable zero-crossing detection check box is selected.
The Enable super step semantics check box is unavailable.
(Optional) By default, zero-crossing detection is enabled. To disable this option, clear the Enable zero-crossing detection check box. For more information, see Disable Zero-Crossing Detection.
You cannot use Moore charts for continuous-time modeling.
During continuous-time simulation, a Stateflow chart updates its mode only in major time steps. In a minor time step, the chart computes outputs based on the state of the chart during the last major time step. For more information, see Continuous Sample Time.
When you define local continuous variables, the Stateflow chart provides programmatic access to their derivatives. The Simulink solver computes the continuous state of the chart at the current time step based on the values of these variables and their derivatives at the previous time step. For more information, see Continuous Versus Discrete Solvers.
To determine when a state transition occurs, a Stateflow chart registers a zero-crossing function with the Simulink solver. When Simulink detects a change of mode, the solver searches forward from the previous major time step to detect when the state transition occurred. For more information, see Zero-Crossing Detection.
Zero-crossing detection on state transitions can present a tradeoff between accuracy and performance. When detecting zero crossings, a Simulink model accurately simulates mode changes without unduly reducing step size. For systems that exhibit chattering, or frequent fluctuations between two modes of continuous operation, zero-crossing detection can potentially impact simulation time. Chattering requires a Simulink model to check for zero crossings in rapid succession, which can slow simulation. In these situations, you can:
Disable zero-crossing detection.
Choose a different zero-crossing detection algorithm for your chart.
Modify parameters that control the frequency of zero crossings in your Simulink model.
You can choose from different zero-crossing detection algorithms on the Solver pane in the Model Configuration Parameters dialog box. For more information, see Zero-Crossing Detection.
To maintain the integrity and smoothness of the results of a continuous-time simulation, constrain your charts to a restricted subset of Stateflow chart semantics. By restricting the semantics, the inputs do not depend on unpredictable factors such as:
The number of minor intervals that the Simulink solver uses in each major time step.
The number of iterations required to stabilize the integration and zero-crossings algorithms.
By minimizing these side effects, a Stateflow chart can maintain its state at minor time steps and update its state only during major time steps. Therefore, a Stateflow chart can compute outputs based on a constant state for continuous time.
During continuous-time simulation, a chart updates its outputs at minor time
steps corresponding to the
during actions of the active
state. A chart with no states produces no output. To mimic the behavior of a
stateless chart in continuous time, create a single state that calls a graphical
function in its
exit, and Transition Actions
To maintain precision in continuous-time simulation, update discrete and continuous local data only during major time steps corresponding to state transitions. During state transitions, only these types of actions occur:
exit actions, which occur before leaving
the state at the beginning of the transition.
entry actions, which occur after entering
the new state at the end of the transition.
Transition actions, which occur during the transition.
Condition actions on a transition, but only if the transition
directly reaches a state. For example, this chart executes the
n++ even when conditions
c3 are false.
Because there is no state transition, the condition action updates
n in a minor time step and results in an
Do not write to local continuous data in state
during actions because these actions occur in minor time
In minor time steps, a continuous-time chart executes only state
during actions. Because Simulink models read continuous-time derivatives during minor time steps,
compute derivatives in
during actions to provide the most
duringActions or in Transition Conditions
In minor time steps, it is possible that outputs and derivatives do not reflect their most current values. To provide smooth outputs, compute values from local discrete data, local continuous data, and chart inputs.
duringActions or in Transition Conditions
You cannot call Simulink functions during minor time steps. Instead, call Simulink functions only in actions that occur during major time steps:
exit actions and transition
actions. Calling Simulink functions in state
during actions or in
transition conditions results in an error during simulation. For more
information, see Reuse Simulink Components in Stateflow Charts.
To prevent mode changes between major time steps, conditions that affect
control flow in
during actions depend on discrete variables.
Discrete variables do not change value between major time steps.
The presence of input events makes a chart behave like a triggered subsystem and unable to simulate in continuous time. For example, this model generates an error if the chart uses a continuous update method.
To mimic the behavior of an input event, pass the input signal through a Hit Crossing block as an input to the continuous-time chart.
When a mode change occurs during continuous-time simulation, the
entry action of the destination state indicates to the
Simulink model that a state transition occurred. With an inner transition,
the chart never executes the
entry action. For more
information, see Inner Transitions.
Do not use event-based temporal logic because in continuous-time simulation, there is no concept of a tick. Use only absolute-time temporal logic for continuous-time simulation. For more information, see Control Chart Execution by Using Temporal Logic.
To implement change detection, Stateflow buffers variables in a way that affects the behavior of charts between a minor time step and the next major time step.
Modifying the operating point of a continuous-time chart is not supported. If you load the operating point for a continuous-time chart, you cannot modify the activity of states or any values of local or output chart data. For more information, see Rules for Using the Operating Point of a Chart.