Can not save enumeration created by Stateflow

25 views (last 30 days)
StateFlow can create an enumeration when outputing a monitor port, but can also use a manually created enumeration that match the state names. What I would really like to do is save the StateFlow-created enumeration, and then for future model runs select "Define enumeration type manually". This would a) avoid having to type the enumeration from scratch, and then b) eliminate all the red block highlighting when the model opens (before it builds). Is there a way to do this?
  2 Comments
Andy
Andy on 23 Nov 2024 at 16:11
I worked with the suggestions from other users, and while I learned a lot in the process what I had to do was start with this enum definition template, and then reassign "(0)" to match what the initial state arrow was actually pointing at. I'll now have to manually maintain that enum as the STD grows or changes.
Laurent Royer
Laurent Royer on 23 Nov 2024 at 17:05
I'm surprised you want the initial child state to have the zero value. Once using enumeration type, the actual numerical values should not matter.
I understand your solution, but this again gives me an idea to improve my tool: When importing the state monitoring data, I'll automatically update the existing class file, just as you intend to do manually :)

Sign in to comment.

Accepted Answer

Andy
Andy on 23 Nov 2024 at 16:14
see the self-comment.

More Answers (2)

Ashok
Ashok on 19 Nov 2024
Hey @Andy,
Stateflow does not have a direct feature to output the enumeration definition. here's a workaround that might be useful. In a Stateflow chart where the Enum type 'ModeLogicModeType' is created, the output of the 'Child activity' monitor can be logged using an 'Outport' as shown below.
To gather the enumeration class name, members, and their corresponding numeric values, the following lines of code can be used:
[enumMembers, memberNames] = enumeration(out.yout{1}.Values.Data);
memberValues = double(enumMembers);
enumName = class(out.yout{1}.Values.Data);
This data can then be used to define an enumeration type using the ‘Simulink.defineIntEnumType’ function. More information on this function can be found here:
To list all custom enumerations, present in the current MATLAB session, refer to this MATLAB Answer:
I believe this will assist you!
  1 Comment
Andy
Andy on 23 Nov 2024 at 16:12
This for the suggestions, and I learned a lot trying them, but what I had to end up using in my self-answer. Still, thanks a 1e+6.

Sign in to comment.


Laurent Royer
Laurent Royer on 22 Nov 2024 at 23:24
Thanks for your question about enumerations for states monitoring! It gave me the idea to add a new feature to this Enumeration Manager available in File Exchange.
So this manager now allows to easily generate the enumeration class files corresponding to the enumeration types generated by Stateflow. Hope this helps.
Also note that if by any chance, you're enabling the monitoring feature for 2 distinct states having the same name (possibly located in 2 charts of the same model), you'll have to manually change the name of one of the 2 generated enumeration classes to avoid a conflict. Actually it would be possible to use one single enumeration class for these 2 states, defined as a union of members from both classes. This is something I could add to my manager if needed.
  1 Comment
Andy
Andy on 23 Nov 2024 at 16:14
I downloaded the Enum Manager; looks interesting. Still what I had to end up doing is in my self-answer above. Still, thanks a 1e+6.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!