[MUSIC] This video show you how to simulate a finite state machine. Notice that simulink, our Cyber Physical Systems section of the Hybrid Equations Toolbox has already has a final state machine block. So what I did here was to actually create that model already for us to reduce the length of this video. And here's a route that I configured to actually simulate the example that we had seen in a previous video. So let me show you that example that we use in a previous video right here. So, in one of these videos that you've seen, there is this finite state machine that has three different modes of operation, A, B, and C. And it initializes at A, and when series applies an input it will remain at A, but if 1 is applied, it will go to B. At B, if series apply will go back to A and if 1 is applied will go back to C, where it will stay. C will be a full invariant mode. This truth table that you see right here is actually how this machine operates. And the transition function that captures that is given by here. Which corresponds to situations where if V = 0 and q = A, or V = 0 and q = B, then we will stay in A. While if B = 1 and Q = A, which is. Right here V = 1, q = A, then it will be transitioned to B. Otherwise whatever happens, will take it to C. So that's the transition function. So that was encoded into this finite state machine, so they jump up. So we see right here it has to be an equivalent between this table and this. Now q = 1 is equal to A. q = 2 corresponds to B, Q = 3 corresponds to C. So that we can deal with numbers. So u, the first input, is the input B here in this table is (u(1) = 0) && ((q = 1) || (q = 2)), which corresponds to q = A or q = B, the transition will be to remain in A. So qplus = 1. And then you can see the other conditions right here. So to run this, we need to provide an input. And let me just say that the JuMP set is essentially change generated in an event whenever a change in the output would happen, correspondent to concurrent state of the state. But that could be just simplified, but let's say that that is the way we trigger the machine. We going to talk about that when we implement FSM later on. So what we are going apply is a signal, which we don't need to worry too much about. And that signal will be something that we will be keeping track of. And according to that signal where 0=1 the machine will iterate along its values, okay? So let me initialize this. Machine or the simulation. Initialization, that's what we usually do. Clears everything and sets initial state, which is corresponds to A. Set the horizon for simulation, the rule and the tolerances. So let's make sure we got the right things, and it seems to be the case. Now we can run this simulation. And as we did it before we create work space copies of the simulation results, including in this case the input applied to the machine, which is VS. So for post-processing, I have prepared a plot that corresponds to first VS, the first input, which is the one that is applied to the finite state machine. And then the value of the discrete digital state on a machine, okay? Okay, so we see it right here and we should compare it to this logic right there. When the machine is at 1, and the input is equal to 0, there is no change in the state of the machine. So therefore it remains at A. Whenever the input becomes 1, the machine will see the change on the input, and it will transition from q = A or q = 1 to q = B or q = 2. So that's the transition that you see right here, that star. As soon as the transition happens, the machine now will be at q = 2 or B = 1, which means that should transition q = C or q =3, and that's what happens. And then no matter what the input does, as we explained in this diagram, the machine will remain at the thermal C = 3, and that's what happens here is invariant or with respect to the input. So that's the simulation of a finite state machine using the Hybrid Equation Toolbox. [MUSIC]