Basic Simulink Stateflow Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to a small tutorial how to use simulating state flow so let's start when you are in the regular Simulink environment you can just click in here and type charge and a small yellow window will pop-up if you go in there you will notice that the environment the background changes to yellow to show you that you are now in the chart this is basically where we will do all our logic for the state flow we're going to create and you will also notice that on the left a lot more icons are visible than before in the regular Simulink environment we will go through some of those icons on the left the most important ones so first of all the most important block in state flow in my opinion is probably the state itself and if you click if you make the first state here you already have two blocks created because you immediately create a default transition which you can draw from here which is basically very discharge will start this is like the initial condition for this charge so these are the states that you can wire together and you can jump from state to state depending on various conditions and these states can have names you can just I don't know call this states first for example so this is just the name of the state and in here you can basically program everything you want for example X is 1 or something like that but first of all you can have 3 different times when you can do something in the States itself so you can have you can do something on entry you can do something during a state and you can sue something when you exit a state so I actually only used entry so far so on entry of the state you do something so an entry you can just type in what you want to do for example set the value X to 1 simple as that if we go to here you can see that if you have for example a finished similan simulation or a similar link control and similar link or something like that you want to move that into something like state flow you make that we want to use it in a step-by-step environment you have to somehow convert your Simulink simulation into this state flow environment you can use for example the Simulink function that you can draw from here or you can use the MATLAB function that you can draw from here and these are used differently in here for example you can name these for example you can call this Simulink test for example and if you go in here you will notice that you're in another environment once again you can go in and out with these arrows here so in here you are back in a regular Simulink environment so you can do things like creating and adding various data or something like that for example with sums you can have inputs like if you do subsystems in regular Simulink you can have outputs and you for example we can make a small symbolic function that adds just the one to the input and you can name these for example I don't know you can name this input and you can name this one output this is just to show that this is a function block and if you go out again you will notice that this automatically are actual ices and refreshes and you can see that these names are already refreshed and is already saving as in here which is kind of neat because now for example we can use our similar link test function here for example we can say ok we set X to zero but now we say X is similar link test and we want to input X for example so this should basically increment X by one when the same goes with MATLAB functions you can go in here and you can have in regular metal functions and you can program them like you're used to so this is going to need so when we have States let's delete this and delete this so this is basically how you can implement functions both in MATLAB and Simulink environment in here but usually if you want to do something in stateflow you have more than one state so you can create more states here and do stuff with them so if you go to the edge of one of these states yeah you should name them - I don't know state 2 and state 3 here if we go to the edge you will notice that your mouse pointer becomes a small crosshair and you can pull it and you see an arrow and if you go to another state or to the state itself where you're started you will notice that it snaps to the object see I can go down to this state so this is not a transition by now the transition that the transition has no specific condition but you can add one by clicking on it and you will see that there is a question mark and in here you can type your condition for example we set X to zero in the first state here so for example we can ask in the transition if X is zero delete this in here and you will see that it asks now like in an if Clause if X is zero and if that's the case it goes down the state but what is really nice in this environment you can also do things like it can go to the state and type in after two seconds so it will go to this state after two seconds have passed which is really nice you can also because this works just like an F you can also combine these statements and say if X is 1 again it's simple as that if you have multiple like for example if this one wiring down here but you have another one and you say I want this state to repeat itself so you can now see our numbers on these transitions here one here at two this means this is the priority so if you would make this Priority One it will always repeat itself and even if this state if this condition is true it will never go down here because this could this this wire has priority one so for example if you have like something this this could happen to you so in here you use I don't know some some sort of function where you ask your status but you want to know the status over and over again you have to repeat the function in itself so repeat the state in itself and as soon as X has met some certain criteria for example you go to the next state and I don't know go on entry and do some more stuff with X exactly be advised if you start this simulation it which you should usually change this to infinite and if you click on play it will this will not be two seconds because usually the Similan simulation time it simulates as fast as it can go so will see down here that it bill will be at I don't know 200,000 seconds in like two seconds in so it will be very fast another thing if you go once out up to the irregular Simulink environment once more you can see this is more or less an isolated charge but it doesn't have to be because if we delete these faulty states in here and say okay let's make a very simple state it just makes X to 0 and we click play here we will see an error which is okay because it asks what X is it wants to know what is it is it data event or a message usually you want data and here and the scope you can determine what it is is it just a local variable where you want to play inside the char vivid and change the value of this or is it an input or is it an output for example you can set it to input click OK and you will see now on the outside that X you can you can viro-ex in here so for example you can put constant here but it counts it here now X is in here so setting it zero here would be useless but you can say if X is one this one big it should repeal itself until 2x being a constant a that is one it should do that if you were if you want to change things like that you can go up here in the model Explorer and you can see all the the variables you can have here you have here and you have the scope and for example similarly catch some problems with data size data type and data size and initial value can set all of these here this cope which poured it is to change the order which size it is for example if if just a single number you can put it like this or you can just say minus one to inherit the size yeah and here the type usually it's inherited but you can also set it to all the things that Simulink can handle another thing if you click on here you can see a period a small callback function where you can initialize Rena if you you can initialize with functions that you have for example you have an init function you can call it like this here so if you start the simulation it gets initialized with this function by itself and yeah they initialize if you start it if you pause it if you stop it if you close it everything is here so this is basically all the basic stuff that you have to know about state flow and yeah if these tools you can basically create bigger state flows like this and yeah so if you look at ever look at this it's basically only the things we just learned for example here you have values in it which is just a metal of function which initializes some some variables and then you ask if lockdown is zero any go down here and there's a lot more stuff but it's all these basic functions it's just wiring around if this is true then go there then repeat itself so this is very basic and I hope I could give you some insights on how to use similar state flow
Info
Channel: TheMuglug
Views: 24,512
Rating: 4.80198 out of 5
Keywords: Matlab, Simulink, Stateflow, Basic, Tutorial, MCI, Chart
Id: wRNbvW9tTZQ
Channel Id: undefined
Length: 11min 20sec (680 seconds)
Published: Mon Jun 26 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.