Call a Function in a statemachine

2 vues (au cours des 30 derniers jours)
Svenh
Svenh le 27 Oct 2023
Réponse apportée : Poorna le 6 Déc 2023
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 commentaires
Svenh
Svenh le 28 Oct 2023
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 le 28 Oct 2023
and of course i adjustet the function calling in the statmachine to: test.t2.Heute()

Connectez-vous pour commenter.

Réponses (1)

Poorna
Poorna le 6 Déc 2023
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.

Catégories

En savoir plus sur Subsystems dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by