Simulink, how to do conditional execution inside stateflow

58 ビュー (過去 30 日間)
Lennart Vedin
Lennart Vedin 2017 年 7 月 3 日
コメント済み: Lee 2025 年 9 月 15 日
Our team want to conditional execute code inside one single state. To be executed every execution. I found no applicable examples.
Such as following does not compile:
% code
entry:
x = y;
during:
if a == 12
b = c;
end
Junctions with conditional inside one single state does compile, but will default only execute at entry. To be executed every execution, an arrow outside the state is required and cause all other entry-code to be executed, that is not wanted. It need to be easy-read visible code, not hidden in function call:
In c-code this is simple and common to write. What is the technique in simulink, without creating "fake-states" that is not functionally required states ?
  1 件のコメント
Lee
Lee 2025 年 9 月 15 日
Create a sub-state with a self loop arrow and copy you junctions and conditionals into the sub-state. Delete the self loop arrow from the super state. The entry condition on the super state will no longer get run on every iteration. This worked for me.

サインインしてコメントする。

回答 (1 件)

Akhilesh Mishra
Akhilesh Mishra 2017 年 7 月 10 日
編集済み: Akhilesh Mishra 2017 年 7 月 10 日
From my understanding of the question, it seems that you wish to execute some specific conditional code inside a state chart. For your workflow, you can try using sub-states within your main state. This will not require you to run the entire state again for one conditional code. The details on sub-states can be found in the following link -
To understand the transitions in the substates you can refer to the following documentation link- https://www.mathworks.com/help/releases/R2017a/stateflow/ug/moving-between-different-levels-of-hierarchy-with-supertransitions.html#f9-58101
A relevant example can be found in the link mentioned below, where inside the state 'powerOn', there are two sub-states 'up' and 'down'. The state 'powerOn' can have its own code different from the code in sub-states. https://www.mathworks.com/help/stateflow/examples/modeling-a-dc-motor-in-stateflow.html

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by