‫Welcome back.
‫Now I'm going to give you a general explanation of the code, so let's get started.
‫The code has the same structure, like in the case of the autonomous vehicle, it's just slightly larger.
‫You still have to files, you have the main file and then you have the support file, the main file
‫is called like this main underscore, LPT, underscore, MPAC, underscore that pie and then the support
‫file is this one support on the score files underscore drone that pie.
‫And remember, these two files need to be in the same folder and then remember that you have to run
‫the main file.
‫So even though both of them need to be in the same folder, you have to run the main file, not the
‫support file.
‫You have to run this file here.
‫And then this file will communicate with the support file on its own and again, make sure that they're
‫in the same folder.
‫That's very important.
‫So what's new in the structure?
‫Well, in the support file, you have one more function called porc on this controller.
‫That's for position control.
‫And in the main file, you have one more loop.
‫Remember that we have the outer loop and the inner loop.
‫So the outer loop would be for this for loop here, that happens every zero point four seconds and then
‫the inner loop, which is this one which runs everything open one second, it runs four times per one
‫outer loop.
‫Everything else, even though adapted to a drone, has the same structure.
‫And so let's get started in the meanwhile, we start by importing all the necessary laborers that are
‫here.
‫This one here that's actually part of matplotlib and it comes together with matplotlib and it enables
‫me to animate that drone in 3D.
‫But it did not fully work in matplotlib three point thirty point three.
‫So because of this one here, I had to get my three point two point two, then I have to create an object.
‫That's this one here.
‫I'm creating an object here and then I'm going to load all the initial constants from this init function
‫in the support file, this support file.
‫It's like one big class.
‫So if you look at this here, you have the support file and you see this super file.
‫It's one big class.
‫And in this class you have several functions.
‫You have this innate function, then you have this trajectory generator function, then you have the
‫position controller function and cetera.
‫And so these are all your functions in this class that you have in the support file.
‫And so once the main file creates an object based on this class here, that's when the main file can
‫start using the functions inside this class.
‫And so the first thing that this, meanwhile, is going to do, it's going to take all the initial constants
‫from this init function, it happens here.
‫Konstanz equals support that Constance.
‫And if you look at this in its function here, then these are all your initial constants and they are
‫all stored here in this vector.
‫In this list, you see it's a pretty long list.
‫I think you have either thirty four, thirty five elements here.
‫And in this main file, they will be stored in this variable here constants.
‫It will be a vector from which I can take my initial concerns, for example, if I want the sample time
‫interval interrelates, then it's going to be the seventh element in this constant vector.
‫Why do I say the seventh element?
‫Because in Python you start counting from zero.
‫So zero one, two, three, four, five and six.
‫So it's it's the seventh element because you start counting from zero.
‫So if you go from zero to six, actually you have seven elements here and they define the sample time
‫interval value right here.
‫T equals zero point one seconds.
‫And now let's look at the initial constants more closely just for you to know all these parameters.
‫They belong to a movie called Aztec Hummingbird.
‫You have the mass moments of inertia here.
‫You have the mass.
‫You have the gravity acceleration.
‫You also have the Mars moment of inertia of the propeller.
‫You have the sample time interval.
‫You have the NPC wait Matrixes, Q, s and R, as you can see, they are now three by three diagonal
‫weight matrixes.
‫You have the trust factor here, you have the drag factor here, and then you have the length and that's
‫the length from the center of the drone to the center of any of the propeller's.
‫So if you remember then, the trust factor was this one here, you used it in you one, you two and
‫you three in those equations, were you related the control inputs with the angular velocity of the
‫drone and then your drag factor is here where you related your EUFOR with your Omega's.
‫So see, Sabeti, that was your trust factor and then see subcu, that was your drag factor and then
‫your length was from the center of the drone right here where my mouth is up until the center of any
‫of the propellers.
‫That was your length then?
‫I have this variable here, controlled states.
‫So basically here for the NPC purposes, I'm saying that the number of my added to the outputs Phi Theta
‫and BPCI, their amount is three because you have five Seeta and three edited outputs.
‫I will use that later to formulate a reference value vector, then this is my horizon period, which
‫is for then I also have this viable inner dynamics length inner DAINE and then on the skirt length,
‫which also equals four.
‫So that essentially tells me how many inner control loop interactions I have per one outer loop iteration.
‫Then I define my polls here, so polls for the X, Y and Z dimensions, respectively, and these are
‫the real polls.
‫And then here I can also uncommented the complex polls that contain the imaginary part as well.
‫And then these variables here, therefore, the trajectories, for example.
‫This is the radius of the spiral that you have seen before then the frequency which pretty much determines
‫how many rotations in the spiral on the X Y plane you're going to have in one hundred seconds because
‫our simulation length will be one hundred seconds.
‫So right now my spiral looks like this.
‫But if I increase my frequency and I multiply it, for example, by one point five, then I will have
‫more rotations in that spiral.
‫You see, in total, the simulation length is one hundred seconds, so you go from zero to one hundred
‫seconds.
‫But during those one hundred seconds, you will have more circles made on the X Y plane.
‫And then this is the initial height of your spiral and then this is the final height of your spiral.
‫So even though my drone starts from the zero meter altitude, then my spiral starts from the five meter
‫altitude and it finishes at the twenty five meter altitude.
‫You see, this is my Z dimension and I start from here.
‫The Z equals zero meters, but then the reference value for the Z dimension starts from five meters
‫and it ends at twenty five meters.