[MUSIC] In this video, I will outline how to simulate a complete cyber physical system model correspondent to sample and hold control. In a sample and hold control architecture, what we are doing is interconnecting the plant with a sampler to the controller, and the controller to the plant with another sampler. Now the samplers are of different nature. The first sampler that interfaced the plant to the controller is an analog to digital converter, and the sampler that interconnects from the controller to the plant is a digital to analog converter. But as we saw in previous videos, a reasonable first cut model is essentially zero-order hold type model. So essentially we have two different types of events, one for sampler and another one for holding that are governed by different timers. So let's take a look at the model that we have here prepared for this particular sample and hold interconnection, defining a complete CPS. So what we have here is a plant, which is a continuous [INAUDIBLE] system, who's state is sample by analog to digital converter. So that's this sampler. And actually, a function of this state, so that's the output. And when that sample is being used to compute the feedback law, which in this case is [INAUDIBLE] feedback law. Just a gain, like proportional control. And that signal is used to drive the plant, but that's been done through a converter from digital to analog, which is the zero-order hold model. So we're going to, Look at this model. What we have here is essentially a, Sampling parameter for the analog to digital converter. So that's one-eighth of a second. And then a holding device, which is a little slower, so one-fifth. This K, k1 and k2 correspond to the feedback this feedback that defines the A and K. The plant is a second order system as you see right here. We have only from this second state. So it's as if it was a point mask with force activation. And then the measurements are given by the entire state, okay? So this is state feedback. And we pick initial conditions, which probably is not very relevant to this because what they are, but they're here. And then assimilation horizon and the tolerance is role choice as we would typically. So let's initialize this system and see whether everything ended up being correct. And this looks correct. And now we are going to simulate this system. Notice that we keep track of the state of each block and also the time that is generated by each block because this might be different for each particular block due to the resets and how singling implements innorators with state boards. Anyhow, here's assimilation. And that is finished. So now we can plot these signals. In the following plot, what you see is, in the top plot, the components, Of the plan, the second order plan x1 and x2 or z1 and z2. And the sample versions which are here denoted as zs1, zs2. One thing that I would like you to realize and see is that these occur at certain events, okay? So this is the sampler. So this is the output of the analog to digital converter, which is provided to the feedback law. And as you see, because of the controller and the choices of the gains, we have convergence of the first state and the second state to zero. Now the input which is updated at a different rate, is a slightly slower rate. As you see the rates occur at different times, like for instance, instead of 0.5 we have here an update of the input, but no update on the measurements of the state of the plot, okay? So these are the associated events. And as you see here, phase one, two, three, and four events, while here we have one, two, three, and a little bit more information done on the output. And this line is almost the same, the rates are very, very close but we can change that. And in this case we have convergence to zero the input, because the zero input actually this [INAUDIBLE] of the origin for the plant. And we can change these, so let's do that, let's go here and make this rate four. Holding a little bit smaller on this, see the effect of that. I'll just run this initialization again, and let's run the, Whole simulation. And then we can plot. So we got similar results. Let's make sure that this is the thing we expect. There are some plots here that we don't need, okay? They should be gone and these should be gone. All right, so what is this Th? Okay. So, let's see. Right. So that's an error in my coding. I'm glad we found it. This should be Th, because it should use a different parameter, okay? And that will need to also be updated in the flow set. Let's do that. So it should be Th. And here we have Th, Th. Okay, so let's put this back to one-fifth. And that's why the difference between the events wasn't that clear, so now that we have changed this, we might be able to see them better. Actually, they might not be any difference in the previous simulation, so let's fix that. Okay, because we changed some of the functions, this needs to be recompiled. It didn't take us long, the code for compilation is optimized. And now we got results so let's compare these. So this in principle was with the same rate of TS equal to one-eighth, but with different initial conditions of the timer. Because initial conditions here are for, let's see, the sample starts at one-half of the period, which makes sense according to this picture, one-half. While the whole device starts at zero, and that makes sense with this picture right here. Let's see what happened with the fixed objects. Okay, so now we see this correctly. So we have one, two, three, four events over 0.5 seconds, and here we have one and two events. So the rate of holding and updating the input to the plant is much slower than the measurement rate. And one could analytically figure out what these maximums will be, up to some conservatism. Or numerically play with these numbers and guarantee that for that particular simulation, everything works. So this is how to simulate a full CPS. Even by the interconnection of four plugs, one is the plant, the other one is the ADC. The other one is the controller, and the other one is the zero-order hold. [MUSIC]