Why are the states not executing properly in the Simulink function?

13 次查看(过去 30 天)
I am using three subsystems: one contains a Stateflow chart with states, and the other two contain Simulink functions, each with its own Stateflow block. I am using nested Simulink functions and calling them through Stateflow. However, the states are not executing properly inside the Simulink functions. Can anyone help me understand why this is happening and what might be causing it?
I have attached some snapshots and the .slx file for your reference and clarification.

回答(1 个)

Epsilon
Epsilon 2025-3-5
编辑:Epsilon 2025-3-6
Hi Kathir,
In the provided model, the execution appears inconsistent due to a mismatch between the desired execution time and the execution order of the blocks. To ensure proper execution, two issues need to be addressed:
  1. The first issue can be resolved by disabling the 'Execute (enter) chart at initialization' parameter for both the 'def_Chart' and 'Fun_Caller' charts. This prevents them from executing at initialization.
  2. The second issue arises when the function named 'Call' is invoked. It executes only one state in 'def_Chart' before execution returns to the 'Fun_Caller' chart, causing a discrepancy. To address this, enable the 'Enable super step semantics' parameter for the 'def_Chart' chart.
These parameters can be found in the advanced section of the property inspector after selecting the respective charts. The property inspector is accessible from the design section of the modeling tab in the toolstrip.
For further reference, the resolved file 'resolved.slx' is attached. Please also refer to the following documentation on Stateflow chart properties: https://www.mathworks.com/help/releases/R2024a/stateflow/ug/specifying-chart-properties.html#:~:text=Stateflow%20API.-,Stateflow%20Chart%20Properties,-You%20can%20set
  3 个评论
Epsilon
Epsilon 2025-5-6
Please excuse the late response, I was away from the community for a while.
In the attached model, function 'Call' is executed only once and then the execution moves to state 'Re_Init'. The execution is not able to exit the 'Re_Init' state and come back to 'Init' as the defined condition 'prev~=in' is never met. Try changing the condition as desired.
I would also recommend you to go through the 'Stateflow Onramp' to gain better understanding of Stateflow. Link to the Onramp: https://matlabacademy.mathworks.com/details/stateflow-onramp/stateflow

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by