Setting Events in Matlab/Simulink Stateflow

4.4k Views Asked by At

How can I set an event in a Simulink Stateflow (statechart) based on some value. What I mean is this. I have a variable called "choice". This "choice" comes in as an input from a simulink block.The value of choice is between 1 and 4. So all I want to do is this:

if choice == 1 then trigger/set eventBlue
if choice == 2 then trigger/set eventRed
if choice == 3 then trigger/set eventWhite
if choice == 4 then trigger/set eventGreen
else trigger/set eventYellow

So how do i do that? what is the command?

2

There are 2 best solutions below

0
On BEST ANSWER

I suggest you take a look to the stateflow webinars: http://www.mathworks.com/products/stateflow/ . There are also many examples of stateflow that may help you understanding how to use the library. Check this help webpage: http://www.mathworks.com/help/stateflow/examples/index.html

It is difficult to know exactly what you want to do, but you can draw the arrows that indicate state changes and add a function that checks the value of the variable choice. First you have to configure your statechart to admit 'choice' as input from simulink. Define the states and in the arrow transitions put '[choice == 1]', '[choice == 2]', etc (without the '').

You should obtain a model like this: enter image description here enter image description here

The pulse generator is configured to create a sequence of zeros and ones, to activate the transitions.

Hope this helps,

0
On

For the problem that you are describing, I would suggest you look at inner transitions in Stateflow. Using inner transitions you can avoid creating transitions from each state to every other state with conditions like [x==1] etc...

The example on the doc page linked about should give you an idea of how to implement this.