How to use bus data in Stateflow transition conditions?

12 vues (au cours des 30 derniers jours)
Anantrao
Anantrao le 18 Avr 2025
Commenté : Aabha le 24 Avr 2025
Hello,
I am working with a Stateflow chart with some simple transition conditions. For the input I have a Bus "velocity" consiting of min, max value of velocity.
I want to use these 3 data in the bus in the transition condition to generate another bus of states.
So please could you help me figure out how to use bus elements in the transition conditions?
Thank you in adavance.

Réponses (1)

Aabha
Aabha le 21 Avr 2025
I understand you wish to use data from a Simulink bus object in the transition condition for a Stateflow chart. In order to do this, please follow the below steps:
  • Create a ‘Simulink.Bus’ object in the ‘Base Workspace’ of the model. The name of the bus object in this case would be ‘Velocity’. Add two elements to the ‘Velocity’ bus, and name them as ‘Vmin’ and ‘Vmax’ respectively. For more information on how to create ‘Simulink.Bus’ objects programmatically, please refer to the following documentation link: https://www.mathworks.com/help/releases/r2023b/simulink/ug/create-bus-objects-programmatically.html
  • In the Simulink model, double click on the ‘Bus Creator’ block to open the ‘Block Parameters’ window. In the ‘Output data type’ dialogue, select the ‘Bus: <object name>’ option, and replace it with the name of the respective bus (i.e.Velocity’).
  • Inside the Stateflow chart, open the ‘Symbols Pane’ from the ‘Modeling’ section in the Simulink toolstrip. Right click on the ‘Velocity’ data in the symbols pane, and click on the ‘Inspect’ option. This will open a ‘Property Inspector’ window. Set the data type of the ‘Velocity’ data to ‘Bus’ as mentioned before and specify the name of the corresponding ‘Bus object’ (i.e. ‘Velocity’).
  • Now you can use ‘dot indexing’ to access the elements of the ‘Velocity Bus Object’. The transition conditions can be specified as, for example, ‘Velocity.Vmax > 30’ and ‘Velocity.Vmin < 30’.
Alternatively, you can also access ‘Simulink Bus Objects’ using ‘Stateflow Structures.’ Please refer to the following documentation link for more information regarding the same:
I hope this is helpful to you!
  2 commentaires
Anantrao
Anantrao le 22 Avr 2025
Hello,
Thank you for your kind reply. However, I fear that you misunderstood the question. I know that I can use dot indexing to separate the two components of velocity as you demonstrated. I want to use the velocity as structure to be compared with as shown in my figure. So that it will act as an array comparison giving 2 commands as output (preferrably a strucutre as well).
Could you elaborate on this if it can be done?
Aabha
Aabha le 24 Avr 2025
The conditions that are specified for stateflow transitions, need to evaluate to a boolean value as mentioned in the documentation link:
Additionally, relational operators such as '>', '<' or '==' do not support operands of type 'Simulink.Bus'. As a workaround, you can access individual elements of the 'Simulink.Bus' object, compare them and assign the comparison results to a different 'struct' variable.
I hope this answers your question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Functions 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