2
votes

I'm almost new to Simulink and Stateflow. I am trying to model some simple state machines. But when trying to run the model, it shows errors (on the main Matlab screen).

Warning: Input port 1 of 'sample/If' is not connected. 
Warning: Output port 1 of 'sample/If' is not connected. 
Parsing failed for machine: "sample"(#90)

1) Is there anything wrong with this?

2) One more question: How can I add a timer on S2? e.g. we can not stay more than 2 minutes on S2. So as soon as we enter S2, a timer starts, and when it reaches 2 minutes, then should transition to S3.

P.S. For some reasons, the stateflow thumbnail on simulink scheme is not showing the updated model; there is no condition and if_outfput variables anymore! enter image description hereenter image description here

1
Not directly related to your question, but the implementation in your statechart won't work. You've got your 4 states defined as executing in parallel (indicated by the dashed borders and the integers in their top right corners), but the logic clearly shows them needing to be defined as exclusive-or states. - Phil Goddard
@Phil : oh, they should be regular states, serial...not parallel. I just selected the state icon and drew them. How can I fix them? - user1196937
Right click in the statechart outside of any of the states, go down about half way to the Decomposition menu, then select exclusive-or. - Phil Goddard
Thanks! After resolving a couple of error, finally it works. I have two general questions: 1) The speed of running! The model runs too fast. Do you happen to know what are the best configs on the Model Configuration Parameters to make it slower so we can track the transitions? 2) Currently I just have a constant input. How can I set a series of constants, say 0, then after 1 minute 1, after 3 minutes 2, etc ? thanks - user1196937

1 Answers

0
votes

Well, the error message is pretty self-explanatory: you haven't connected the input Condition of your Stateflow chart to anything, hence the error. Connect it to a signal in your Simulink (whatever represents your condition signal). Likewise, you haven't connected the output of the chart to anything either. You say these variables aren't there anymore, but Stateflow doesn't seem to think so. Have you deleted them from the Model Explorer? If not, Stateflow will still think they're part of the chart. See Use the Model Explorer with Stateflow Objects in the documentation for more details.

For the timer, yes it's possible. At the moment, you exit S2 to S3 when input ==1. You can change the transition to be [input == 1] || after(2000,sec) (I think). You may need to enable support for absolute time in the model configuration parameters. See Control Chart Execution Using Temporal Logic in the documentation for more details.