How to simulate Stateflow with temporal and event elements

1 回表示 (過去 30 日間)
Matthew Johnson
Matthew Johnson 2020 年 8 月 4 日
回答済み: Altaïr 2025 年 4 月 22 日
I am having trouble simulating Stateflow models that use events. If I use tmeporal elements, alone, transitions occur as expected, but events seem to break things. In fact, I can't successfully simulate the example at:
I am trying to do something similar as in that example: have one system trigger another system, which then proceeds through its state machine. E.g., I want a "test" state machine that sends a "power on" event that starts another state machine, and a "power off" event to shut it down (or send it to an "off" state).
Secondly, when I do have the output and input events connected in Simulink, "after(n,sec)" and other temporal logic doesn't seem to work any more. E.g., the target Stateflow has an "Off" state, waits for "event", then transitions to "on", but subsequent transitions do not take place, whether empty (no logic), or with temporal logic. Once the receiving state has an input event symbol, it seems to functional differently, whether I use the event or not in the Stateflow.
I have tried 2019b and 2020a.

回答 (1 件)

Altaïr
Altaïr 2025 年 4 月 22 日
The example demonstrates how the behavior of a Stateflow chart changes based on whether messages, events, or data are used to control transitions. Without access to your files, here's an explanation based on the general principles illustrated in the example. The following command provides access to the example:
openExample('stateflow/ViewDifferencesBetweenMessagesEventsAndDataExample')
Three key points from the example are:
  1. When data is sent from one Stateflow chart to another, the assigned value persists throughout the simulation.
  2. When an event is sent from one Stateflow chart to another, the event is only valid for a single time step. The receiving chart has one opportunity to respond; otherwise, the event is lost.
  3. When a message is sent from one Stateflow chart to another, it is queued. The receiving chart can respond at any time after the message is sent, but the message is destroyed at the end of the time step if not processed.
If the event is sent under the entry action in the "test" chart as shown above, the second chart (with "off" and "on" states) must be ready to respond immediately; otherwise, the transition opportunity is missed. Broadcasting the event in the during action as well can help ensure the transition occurs in the second chart. In the example, this adjustment helps verify that the transition in the EventReceiver progresses from states A0 to A1 to A2 to A3.
For further reference, the following example illustrates control states in charts enabled by function-call input events:
openExample('stateflow/StatesWhenEnablingExample')

カテゴリ

Help Center および File ExchangeStateflow についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by