‫Welcome back.
‫And so, as discussed before, the rest of the code after these inner and outer loops is about animation
‫and plotting.
‫So you can see it here as well, animation and then plotting.
‫Now, if we look at plotting first, then plotting starts here after the end of the animation.
‫And notice that here you have this no plots variable that you could assign a value to in the init function.
‫So if you don't want to see plots, then in the next function you assign this value to be one and then
‫you will exit the program.
‫But if this values zero or actually any other value, then you will enter this block here and then it
‫will start plotting you all kinds of graphs.
‫So this one will plot a three dimensional work for you, this is not an animation.
‫This is the first plot that you see after you close your animation.
‫Then here you plot your X dimensions.
‫Here you plot your Y dimensions, and then here you plot your Z dimensions.
‫Here you plot your five feet on BPCI angles, and then here you plot your control inputs and also your
‫own.
‫So it's going to be a subplot with eight sub windows.
‫So that's plotting and then animation works pretty much like this, that you've got some kind of function
‫and then here you have a variable number, which is a feature of matplotlib, then this num variable,
‫it's going to go from zero to one to two, three, four.
‫You decide how many times you call this update plot function and therefore how many times this variable
‫number gets increased by one every time this function is called.
‫And the decision for that you can make in the end of the animation.
‫So it's this one here.
‫Here you call the animation function from matplotlib.
‫You define your figure.
‫And so here you decide how many times you call this update plot function.
‫And you decided by determining your frame amount here, you're going to put your frame amount and then
‫here you're going to put interval equals, I put it 20 here.
‫So Intervale, it's how fast your frames would change.
‫So 20.
‫Twenty milliseconds.
‫So that means that it's every zero point zero two seconds, then, if you want your information to repeat,
‫you put here through and then blit, it's there to make the animation smoother.
‫And by the way, this update plot, that's the name of this function where you have this non variable.
‫So that's how the program knows that.
‫OK, we're talking about this function here.
‫And then, of course, you have to put Palta dot show here.
‫So this is a function that you have to put here in the end.
‫And then this figure that you define here, well, that's defined right here.
‫You see here I define that figure.
‫I define the grades for that figure.
‫I need that to create some windows.
‫Here I define the dimensions, the resolution and then the colors for the figure.
‫So in a nutshell, the animation works like this here.
‫You're going to go through some variables that are related to the animation.
‫These are the numbers that I want to use for animation here, I define my frame amount, which is the
‫length of this state's total X vector and this state's tall sub X is states total underscore UNY and
‫then the first column.
‫So if we go into our support file, then if you look at this, states underscore any vector, then you
‫see that it contains information about X, Y, Z, Fifita and Passi.
‫And then essentially here I make them Fleener.
‫So if X goes from zero to 10, then this states up only is five times bigger because it will take this
‫interval from zero to 10 and it will make it into five intervals.
‫So this matrix will then contain information like this zero two four six eight 10.
‫Then I can create an animation that is smooth.
‫Otherwise your drone would move, then stop for a second move and then stop for a second in the move
‫and stop for a second.
‫So that's the purpose of it.
‫And so I take the X dimension of this state's total underscore unny.
‫I take its length and then I am going to say that it's my frame amount and I could have put here states
‫total on the score, Y or Z.
‫Doesn't matter.
‫They all have the same length.
‫Then the program recognizes this animation function.
‫It recognizes this special matplotlib update plot function with this variable NUM that is used to update
‫your feature called Figure in which you have your animations.
‫So first of all, it's going to skip it.
‫Then here you're going to define your figure.
‫Then you're going to define certain objects, like, for example, this drone Body X, that's your red
‫beam, right?
‫Remember, that's your drone and that's the body from X dimension that your red beam and then this one,
‫that's your green beam.
‫You define them as objects.
‫You define how wide they are.
‫And then you have other objects here as well.
‫For example, this one here, that's your reference trajectory line, the blue one, and this is your
‫real trajectory.
‫That's the red line that you see in the animation that shows how the drone actually flies.
‫Then these are some formatting features.
‫And now if you remember then we had two versions for our simulation.
‫If same underscore version equals one, then your Windows showed you the control inputs you want you
‫to use three and four, how they evolved as a function of time and also how your red and green beam,
‫how they tilted, in which direction they tilted.
‫Then you enter into this block here and then all that becomes relevant.
‫However, if your SIM version equals two, then you see how your drone is able to follow your X, Y,
‫Z, and then Fifita Inside Dimensions and then you can see them separately as a function of time.
‫And then if your SIM version equals two, you entered this block here.
‫And then in both blocs, what you do, you create objects, you create lines for yourself, windows,
‫so you can see that this is green.
‫So that's the green line that represents the tilting of your green beam.
‫And this is for the red one.
‫These are objects for your control input lines you want.
‫Then you to use three and then you have four.
‫And then if you had chosen SIM version two, then you simply enter into this block.
‫But the logic is the same.
‫You create objects here and then you reach this place here.
‫So the programmer knows what figure you're talking about.
‫It knows the function.
‫It knows the amount of frames here.
‫You specify your interval and then you specify if you want to repeat your animation or not and whether
‫you want to be efficient or not.
‫And then he goes here to that show, and then you're going to jump to the beginning of that function,
‫which is you an update plot.
‫And so if your frame amount was 10, then your number will go from zero to nine.
‫And now this number variable is very important because what you're going to do, you're going to take
‫your simulation results from your control engineering part and then you want to go through those results.
‫So, for example, if we take this object here, that's the red line in your animation, real trajectory,
‫then if we go to our update plot function.
‫Then your real trajectory would be here and then you would right here, real trajectory that set X data.
‫And then you take your state's toll suspects that you got from here and then you enter that vector and
‫then you right here from zero column to number.
‫So you can imagine that as you go through this function, your number will go like this zero one to.
‫So in the first iteration, it will take your first element, then it will take your first and second
‫element, because in the second loop it would be from zero to one.
‫Then it will be from zero to two zero to three zero to four.
‫And that's how your red line becomes longer and longer in your animation.
‫So if you want, then you can play around and experiment with these features here and see what you're
‫going to get, and then you're going to learn it very well through experimentation.
‫And then it's very important that you return your objects that you had defined before you return it
‫here or here, depending on your version.
‫If you have a simpler animation, then you would simply have return here and then a bunch of objects.
‫So that's an overview of how this animation works in Python.
‫And well, we have covered pretty much everything here in this coat and also everything in the support
‫file.
‫So at the beginning it looks pretty massive coat.
‫However, these two files, they really follow the theory.
‫Everything that you have learned so far now is just in the coat format and that's it.