| Stateflow |  |
Design Considerations for Continuous-Time Modeling in Stateflow
www.kxcad.net Home > CAE Software Index > MATLAB Index >
Rationale for Design Considerations
To guarantee the integrity — or smoothness —
of the results in continuous-time modeling, you must constrain your Stateflow
charts to a restricted subset of Stateflow semantics. The restricted semantics
ensure that inputs do not depend on unpredictable factors — or side
effects — such as:
By minimizing side effects, Stateflow can maintain the state
of the chart at minor time steps and, therefore, update state only during
major time steps when mode changes occur. Using this heuristic, Stateflow
can always compute outputs based on a constant state for continuous time.
Stateflow generates informative errors to help you correct semantic
violations.
Back to Top
Summary of Rules for Continuous-Time Modeling
Here are the rules for modeling continuous-time Stateflow charts:
Update local data only in transition, entry,
and exit actions
To maintain precision in continuous-time simulation, you should update
local data (continuous or discrete) only during physical events at major time
steps.
In Stateflow charts, physical events cause state transitions. Therefore,
write to local data only in actions that execute during transitions, as follows:
State exit actions, which execute before
leaving the state at the beginning of the transition
Transition actions, which execute during the transition
State entry actions, which execute after
entering the new state at the end of the transition
Condition actions on a transition, but only if the transition
directly reaches a state
Consider this Stateflow chart:

In this example, the action {n++} executes even when
conditions c2 and c3 are false. In this
case, n gets updated in a minor time step because there
is no state transition.
Do not write to local continuous data in during actions
because these actions execute in minor time steps.
Compute derivatives only in during actions
Simulink reads continuous time derivatives during minor time steps.
The only part of a Stateflow chart that executes during minor time steps is
the during action. Therefore, you should compute derivatives
in during actions to give Simulink the most current calculation.
Do not read outputs and derivatives in states or transitions
This restriction ensures smooth outputs in a major time step because
it prevents Stateflow from using values that may no longer be valid in the
current minor time step. Instead, Stateflow always computes outputs from local
discrete data, local continuous data, and chart inputs.
Use discrete variables to govern conditions in during actions
This restriction prevents mode changes from occurring between major
time steps. When placed in during actions, conditions that
affect control flow should be governed by discrete variables because they
do not change between major time steps.
Do not use input events in continuous-time Stateflow charts
The presence of input events makes Stateflow behave like a triggered
subsystem and therefore unable to simulate in continuous time. For example,
the following model generates an error if the Stateflow chart uses a continuous
update method:

To model the equivalent of an input event, pass the input signal through
a Hit Crossing block as an input to the continuous chart, as in this example:

Do not use inner transitions
When a mode change occurs during continuous-time simulation, the entry action
of the destination state indicates to Simulink that a state transition occurred.
If inner transitions are taken, the entry action is never
executed.
Do not use temporal logic
Temporal logic has no meaning because there is no concept of a tick
during a continuous-time simulation.
The chart must have at least one substate
In continuous-time simulation, the during action
of a state updates the outputs. If the chart has no states, it produces no
output. To simulate the behavior of a stateless chart in continuous-time,
create a single state which calls a graphical function in its during action.
Do not use change detection operators in continuous charts
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.
Back to Top
| Modeling a Bouncing Ball in Continuous-Time | | Using Fixed-Point Data in Stateflow |  |
© 1984-2007 The MathWorks, Inc.
Terms of Use Patents Trademarks Acknowledgments