2

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 here enter 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 Nov 15 '14 at 21:29
  • @Phil : oh, they should be regular states, serial...not parallel. I just selected the state icon and drew them. How can I fix them? –  Nov 15 '14 at 21:41
  • 1
    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 Nov 17 '14 at 02:24
  • 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 –  Nov 17 '14 at 03:56

1 Answers1

0

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.

am304
  • 13,758
  • 2
  • 22
  • 40
  • Thanks for the good info, but as you see there is no `condition` input on my Stateflow anymore! It was there, but I deleted it. I don't know why it still shows it. I will check your timer code. –  Nov 15 '14 at 15:21
  • 1
    You don't understand: if they're still showing on your chart, it means they're still there as far as Stateflow is concerned. You need to delete them from the Model Explorer. Until you sort out this problem, you won't be able to run your model. – am304 Nov 15 '14 at 15:36
  • Oh, ok. I was checking your answer on my smartphone, and did not fully read your answer above! –  Nov 15 '14 at 21:44
  • 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 –  Nov 17 '14 at 04:15
  • 1
    Glad it helped. Please accept the answer if it solved your problem, to help other people who have a similar issue find a solution. For your other questions, yes you can slow down the animation. You need to go in the Stateflow debugger and put a delay of x seconds in the animation section. In the latest release, the interface is slightly different, but it's the same idea (see http://uk.mathworks.com/help/stateflow/ug/animate-stateflow-charts.html). – am304 Nov 17 '14 at 09:21
  • Finally, to change your constant input, you can use the Repeating Sequence Stair block (http://uk.mathworks.com/help/simulink/slref/repeatingsequencestair.html) or there are a variety of other source blocks in Simulink which you can configure to do the same (Signal Builder, From Workspace, etc...) – am304 Nov 17 '14 at 09:21