How initialise Output before a stateflow call

29 views (last 30 days)
Good morning everyone,
I experience some trouble with working with Stateflow and outputs initialisation.
I have a stateflow with two outputs bool_Signal_1_Available and bool_Signal_2_Available. The first thing I do when the chart is called is to initialise these signals to the value true.
But before I call this statechart (I have a enable trigger on it), both values of this two outputs are set to "false" (initial value for boolean signal).
I have another chart in a different bloc that reads the outputs on the first one and detects an error when signals bool_Signal_1_Available or bool_Signal_2_Available are equals to false. Due to the bad initialisation, he detect the error before I will call my chart for the first time.
I would like to init these to "true" and not the default value of "false".
Do you have any ideas to fixe this ?
Thanks for helping me ! Have a good day

Answers (1)

Navdeep Singh
Navdeep Singh on 2 Aug 2017
You can initialize the Stateflow chart variable using Property Inspector. Chart's data properties can be set to get the desired model behavior. One of them is 'Initial Value' that can be set to a default value. This may help your case.
  1 Comment
Paul Rancuret
Paul Rancuret on 27 Apr 2023
@Navdeep Singh sorry to bring up a really old post, but I do have a further question about this. In my case, the data type I'm using for an Output item is a bus object. I'm using Matlab R2020b for right now, and I am using a 'Mealy' chart with the matlab action language.
For some reason, the 'Initial value' dialog box is greyed out and says "Not Needed". However, I really do want to specify the initial value. Many fields of the output struct get updated for various reasons at runtime. However, there are some fields which may not get written on a given update step. I would like these to remain at their previous value (using the initial value if they haven't been set at all yet). The default values I would like to use come from a model workspace parameter argument with the same bus object data type.
For now, I have worked around this by adding a statement in the chart which sets the entire output bus value equal to the default output parameter value on the first pass of the chart. I would really have preferred this copy operation to occur in the generated <modelName>_Initialize() function instead of on the first chart pass at run-time, because I really don't want the first pass to have this extra operation time compared to all subsequent passes.
Do you know why the 'Initial value' dialog box is greyed out and says "Not needed" in my case? I can't figure out how to enable it. I've also tried using a Simulink.Signal object for the output data item, but it still won't make use of that initial value when the 'auto' storage class is used for the Simulink.Signal object. It won't let me use any other storage class besides 'auto' if that signal object is in the model workspace (which it needs to be so that the default initial value is in the same context).
Please let me know if you have any further advice on what to do in this situation!
Thanks!

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!