How can i call a state machine which is inside a function.Function is called iteratively?

2 ビュー (過去 30 日間)
Pradeep Murugan
Pradeep Murugan 2018 年 9 月 14 日
回答済み: Muthukumar Ganesan 2022 年 8 月 1 日
Hi ,
I want to call a function inside a loop. The function has a Statemachine in it.
Below is the Pseudo "C" code for which the equivalent stateflow model is required.
for(i=0;i<2;i++)
{
CallStatechart(i);
}
CallStatechart(j)
{
case A:......out[i]=...;
case B:......out[i] =...;
case C:......out[i] =...;
}
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 14 日
State machines in C are usually more like
current_state = 0;
for (i=0; i<2; i++)
{
current_state = CallStatechart(current_state, i);
}
int CallStatechart(int current_state, int statenum)
{
switch(current_state)
{
case A: ....; new_state = ...; break
case B: ....; new_state = ....; break;
...
}
return new_state;
}
This permits reactions to be conditional on the current state, and permits the state to be changed in non-linear ways.
Pradeep Murugan
Pradeep Murugan 2018 年 9 月 14 日
My question is to know if we can have statemachine inside a function.If i am doing it, i am getting an error saying :
"Function 'Fun' contains substate 'A'. This is not allowed"

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

回答 (1 件)

Muthukumar Ganesan
Muthukumar Ganesan 2022 年 8 月 1 日
Hi,
This requirement can be achieved by implementing the statemachine inside the "For Iterator Subsystem" in simulink. Please refer to the attachment.
Thanks.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by