0:01

In this video, we will like to simulate a complete CPS system corresponding to,

Â perhaps quite simple model of a temperature which changes

Â over the time according to whether a heater is on or off,

Â and a finite-state machine that changes mode according

Â to the temperature value relative to thresholds.

Â We already simulated each of individual systems in previous videos.

Â In this video, we're going to simulate the entire system, the entire CPS.

Â This was presented in a previous video,

Â and here is a snapshot where we have a CPS given by the following physics.

Â This is the evolution of temperature over the time,

Â and the cyber component corresponds to

Â a finite-state machine which has a GA function where

Â the changes of the logic state correspond

Â to values of the temperature hitting certain thresholds,

Â and those thresholds were defined as Tmin and Tmax.

Â In order to simulate this system,

Â we will need to implement the physics and the cyber into the same simulation,

Â and this is what I've done right here in this Simulink file.

Â You will see the interconnection,

Â direct interconnection between the physical part,

Â which is the temperature,

Â and the finite-state machine,

Â which is the cyber part.

Â In case you didn't see previous videos,

Â the physical part implements directly the differential

Â equation that you saw in a previous video for the change of temperature over the time,

Â where is the key rate TR is the effect of

Â other variables that affect temperature of

Â the room until they'll take the capacity of the heater.

Â You can be zero or one,

Â zero meaning that is off,

Â and one meaning that is on.

Â These are the parameters that are being used for this map.

Â The flow set, operator will always be equal to one,

Â meaning that there are always flows and there are never

Â a chance because these equal to zero.

Â The other piece of this system is the cyber component,

Â and you also saw it in a previous video,

Â the jump map essentially toggles the value of the finite-state machine from 0-1 and 1-0.

Â Zero meaning that the heater is off,

Â and one meaning that the heater is on.

Â And those events are triggered whenever the input to the system,

Â which in this case is the input equal to

Â the temperature of the room is smaller than Tmin if the heater is off,

Â or if it is larger equal than Tmax if the heater is on.

Â And with that, we're ready to simulate this by initializing the system.

Â Now, this initialization file that I created here not

Â only initializes all the parameters which now is the fifth dimension vector,

Â but it initializes both of the systems for which one is to set different labels for

Â the initial conditions in order for the simulator to craft the right things,

Â values for the initial conditions.

Â So, for the temperature is going to be,

Â initialized at 55, for the finite-state machine,

Â it's going to initialized at zero.

Â This set_param that you see right here

Â resolves the algebraic loop that will appear due to having this interconnection here.

Â And then we're ready to go. The temperature of

Â the plant is being fed to the finite-state machine.

Â The finite-state machine will execute this logic,

Â and that will generate a Q value which is 01,

Â and that Q value will drive the temperature of the system.

Â Remember that this starts at 55 and this starts at zero,

Â natural environment. So, let's simulate.

Â First thing that you will do is to initialize the system by writing this file,

Â and then checking that things doing the right way.

Â So, x0P with a 55, x0FSM, 0,

Â horizon remains a constant,

Â and it's never enough to check

Â these things multiple times to make sure that we are simulating the right thing.

Â Okay, it looks like everything is in place.

Â And now, we can now try again.

Â It's time to compile, generate the code.

Â And once the code is generated,

Â calling the max compiler,

Â now we can probably start seeing the simulator run.

Â And there it goes. We're simulating for 10 seconds with 20 jumps,

Â 5:45

and it seems like it expire after 10 seconds.

Â Now, we can plot several things.

Â And what we're going to plot is the temperature,

Â and also the input applied to the physical system which is essentially the state,

Â or the finite-state machine.

Â So, let's do that. So, what we see here is that the temperature initializes at 55,

Â and the input which is the logic state of machine initializes at zero,

Â because 55 is smaller than the lower threshold which is 70,

Â there is an automatic jump from zero to one of the finite-state machine,

Â and the temperature start increasing because logic state of the machine equal to one,

Â means that we're going to apply heat into the system.

Â It turns out that the temperature start growing,

Â you should grow all the way to 85.

Â But as soon it hits to 80,

Â what's going to happen is that the other threshold,

Â the higher threshold is heat,

Â and the finite-state machine transitions from

Â one to zero were now the temperature decays.

Â Once the temperature hit 70,

Â there's another transition from 0-1 of the finite-state machine.

Â And this keeps occurring over and over unless you

Â see the range of temperatures that we're interested,

Â which is between 70 and 80,

Â which is defined by the thresholds,

Â is an attractive set and actually invariant for the system.

Â So, that's a simulation of a full CPS corresponding

Â to the control of temperature of a room using a finite-state machine.

Â