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.