Stateflow outputs a "mux" variable when I want a bus. How can I output a bus or reference specific elements of "mux"?

4 views (last 30 days)
I am using Simulink to model a cyclical process. I am mainly interested in conditions at the end of each operating mode, so I want to store a list of variables each time a stateflow state switches. The system needs to tolerate storing several variables at the end of each state, so I cannot reasonably input and output each variable independently.
In my present solution, in addtion to its other functions, the stateflow block takes one input (a bus containing all the state information I want to save, "present_state") and produces one output for the end of each step in the cycle ("[X]_state"). Each stateflow "arrow" includes a statement that [X]_state=present_state. Thus, the output for [X]_state holds the variables of interest as they were the last time [X]_state ended.
This works well in every respect except that the outputs "[X]_state" turn out to be muxes rather than busses. I can use demux blocks to isolate the variables, but I don't have any reliable way of knowing which demux output corresponds with which bus input. While I can look at the outputs and guess which is which, this presents obvious risks for the robustness of the model as it is modified.
Is there some way I can tell stateflow that "present_state" is a bus, and have its bus characteristics carried through its internal logic so that I can use a bus selector to get specific variables? Are there other established solutions for this sort of problem?

Answers (1)

Mark McBroom
Mark McBroom on 11 Jan 2019
Have you tried creating a Simulink Bus and then in the Stateflow data editor setting the type of present_state to be the Simulink.Bus that you created?
  2 Comments
Bryan Callaway
Bryan Callaway on 11 Jan 2019
I can't find anything about a "Stateflow data editor". In the Stateflow "symbols" window, I can set data as input, output, etc., but I don't see anything about a bus.
Looking for similar solutions elsewhere, I did find an option in the model explorer to make the input or output "bus <data type>", but thus far no matter what I do with the data type field gives me the error:
"Invalid setting in 'Chart' for parameter 'Datatype'"
Could you provide more details around this solution? Thank you.
Mark McBroom
Mark McBroom on 12 Jan 2019
You have found the proper location to enter the bus data type. Do you have a Simulink.Bus defined in the MATLAB workspace? If so, then the syntax for specifying the data type to be a bus is ( assiming your bus is named "myBus") is:
Bus: myBus
Thanks.
Mark.

Sign in to comment.

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!