Call a Function in a statemachine

3 次查看(过去 30 天)
Svenh
Svenh 2023-10-27
回答: Poorna 2023-12-6
I have two reference subsystems. In the first one is my statemachine. In the second reference subsystem is another subsystem and within that is my simulink function.
I want to call that function in the statemachine in an insert state. For that i wanted to use the convetion
reference_subsystem_name.subsystem_name.function_name()
unfortunatly i receive the error message: undefined function, errors occurred during parsing of ...
I'm sure that the spelling and name is correct.
In a previous version of my model I had one subsystem less so I only had to use subsystem_name.function_name() and that worked.
Thank you for your help
  2 个评论
Svenh
Svenh 2023-10-28
So to further demonstrate my situation
The function block is called Heute() and is in the following subsystems:
So if the statemachine is on the same level as t2 everything works
but if the statemachine is on the same lever as "test" it doesnt work anymore
i hope this makes it more clear
Svenh
Svenh 2023-10-28
and of course i adjustet the function calling in the statmachine to: test.t2.Heute()

请先登录,再进行评论。

回答(1 个)

Poorna
Poorna 2023-12-6
Hi Svenh,
I understand that you are trying to call a Simulink function from inside your Stateflow chart. I also understand that you are wondering why putting Simulink function inside a subsystem at the same level as the chart works, while placing the grandparent subsystem of the Simulink function at the same level as the chart does not work.
The behaviour you are seeing is expected. The Simulink function you're using is a "scoped" function residing inside a virtual subsystem. A scoped function within a virtual subsystem can be called within the containing subsystem block hierarchy simply by using its name, like "function_name()". It can also be called from outside the subsystem but within the subsystem hierarchy by qualifying the function name with the subsystem block name, like "subsystem_name.function_name()".
Because the subsystem "subsystem_name" is not within the subsystem hierarchy of the chart (while "referenced_subsystem_name" is in the hierarchy, "subsystem_name" is not), you cannot use its Simulink function.
To still access the Simulink function, you can consider changing the scope of the Simulink function to "global". In this case, a simple call like "function_name()" should work across the model, as long as the Simulink Function is inside a virtual subsystem hierarchy.
To can find the option to change the function’s scope in the Block properties of the trigger port of the Simulink function block.
To know more about accessing Scoped Simulink function blocks in subsystems refer to the following documentation:
For an overview of different scopes of a Simulink function block, please refer to the following documentation:
Hope this Helps!
Best regards,
Poorna.

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by