‫Welcome back.
‫And so now that we have our control inputs, we have our new one that came from the position controller
‫and then now we have our YouTube, Q3 and Q4.
‫And now what we need to do, we need to find our omega's, our angular velocities for our propeller's.
‫If you remember then, these were the relationships between you want you to Q3 and Q4 and then Omega
‫one, omega to omega three and Omega four, and then what we did, we divided.
‫You want you to use three or four by these concerns here, the trust factor, the trust factor times
‫the length here as well, and then the drag factor.
‫And so after having done that, we put it in this vector and then we called the new star.
‫And in the code, that's this part here.
‫You see here I perform the divisions and then here I put it in the vector, then this one here, that's
‫this matrix.
‫So all these operations where I first define a four by four zero matrix and then I assign some ones
‫and minus ones in certain elements.
‫I'm doing that in order to create this matrix.
‫Then the next step was to find the inverse of this matrix, which is this one here.
‫And then once I had my inverse matrix, then I could find my Omega squared like this with this equation.
‫And so it looks like this here and in the code.
‫That's this part here.
‫And then once I have my omega squared, then I can take a square root of them and then I get my omega
‫one, omega two, omega three and Omega four.
‫And then in order to find the total omega, then we use this formula for that.
‫So Omega one minus Omega two plus omega three minus omega four.
‫Remember that you have had your minus signs here because Omega two and Omega four, they had negative
‫rotation.
‫And in the code it's this one here.
‫So you see I first check if at least one of them is less than zero, that means that there is no real
‫solution for that.
‫However, if all of them are bigger than zero, then I use these equations here and then I have my omega
‫one, omega two, omega three and Omega four.
‫And then I put them all here into this variable.
‫So I collect them all throughout the simulation in this matrix.
‫And then I can use this vector later to graph my Omega's as a function of time.
‫And then here I compute my Omega total, you see with this formula here and then I enter into my last
‫function in the support file.
‫So now I'm here planned integration and now I'm entering into this function, open loop new states.
‫So let's see how it looks like it starts here.
‫And then I take in the existing states, then my omega total.
‫There's this one here.
‫This is my omega total.
‫Then I also take in my existing you one, you two, you three and you for my latest control inputs from
‫the init function.
‫I take the constants that I need.
‫Then remember the states.
‫It's a twelfth element vector.
‫So I take all my 12 states out of this vector right here you see.
‫I go from U v, w, eqr to X, Y, Z and five feet up sigh So that's this block here.
‫These three lines are for the animation purposes to make the movie smoother.
‫Then in case I want to use the drag force version, then I also take some of the values from the net
‫function related to drag.
‫And remember that in this course we used wrong Akutan method to integrate our plans.
‫So this here, this was like our summary for Runga Kutta, this schematics showed us in a nutshell how
‫the procedure worked, how you calculate it for different slopes, and then you assigned some weights
‫to them and then you had your weighted average slope and then you use that in this integration.
‫So this entire procedure, that's this entire block here.
‫So this entire code, that's wrong.
‫Kutta, up until here, end of Runga Cutter method.
‫So here I define some of the variables and then I say that they have to be my origin variables, meaning
‫that these are the variables at K, not K plus one and not in the middle between K and K plus one.
‫But these variables here.
‫They are these variables here, you see, except this one, that's where you are right now, that's
‫your present state.
‫And then I call them like this, for example, w underscore or so it's like Origin, then I will need
‫this variable to be equal to to here I choose if I want the drag force or not.
‫These are my state's basic equations here.
‫This is where I compute my slope's.
‫And since I have to compute for then all that is in this for loop you see for J in range from zero to
‫four.
‫So J would be zero one, two and three.
‫Python will not count for here four here does not mean that J has to go to four for here means that
‫you need to have four iterations and you start counting from zero.
‫So it's going to be zero, one, two and three.
‫And here I have my rotation matrix.
‫Then here I compute my latest x y and see that using the latest you the end W.
‫Then I do the same thing with the attitude values, so I have my transfer matrix here and then I use
‫that transfer matrix to take my latest, pick your values and convert them into my latest FIDA theatergoer,
‫then decide that values.
‫And then remember, in Guta, we had to compute for Slope's and so I save them here.
‫My first slope's, they are saved here when J equals zero.
‫So you can imagine that these are my state base equations and then I take my newest states that I get
‫from here.
‫And then I put them in this equation and then I get my first slope's.
‫You write V that W dot and then P that Q Dot and our dot.
‫And then I use the rotation and transfer matrices in order to obtain my X, Y and Z dot and then find
‫Citadel, then decide that.
‫And so these are my 12 slope's that are the first slope's and then I save them here.
‫Then I skip the other blocks because it's an if statement.
‫Then I entered this blog here.
‫That's when I compute my new status, but remember, when I compute my new status in the first iteration,
‫then I don't go from K to K plus one.
‫I compute my new status in the middle, right in the middle between K and K plus one.
‫And that's why in this equation I say you equals USIP or which is my present state.
‫Plus you dot my first slope times the sample time interval, which is zero point one seconds divided
‫by this RTS suppos and this time suppose that's this one here.
‫So that means that instead of zero point one seconds I will have a zero point one divided by two.
‫So I will have zero point zero five seconds here.
‫Then I will compute my new status here in the middle between K and K plus one.
‫And that's how I compute my all new 12 states and then I skip this block because I've already been in
‫this block here and then I go to the beginning of my loop.
‫Now, my J equals one, not zero anymore, but one.
‫I take my new states that I have just computed, and then I'm going to put them here in this equation
‫and then I'm going to get my second slope's.
‫And then thanks to my rotation and transfer matrices, I'm going to be able to get my new X, Y and
‫Z dots and then Fifita and Dots.
‫And then I'm going to enter into this block here because my G equals one now.
‫And in this block I'm going to save my second slope's, then I'm going to skip the other blocks.
‫Then I will again enter this block here.
‫I'm going to compute my new states, but now using my second slope.
‫But still this person needs to be to because these new state values, they will be between K and K plus
‫one.
‫And then again I will skip the other block, then I will go back to the beginning of my loop and now
‫my G equals two.
‫I have my new state value so I can put them here and compute my third slope's.
‫And thanks to the rotation and transfer matrices, I can get my new slope's in the inertia frame as
‫well.
‫So I will have my 12 third slope's, then I check, OK, JQ zero, no, I skipped this block.
‫Jake was one.
‫I skipped this block, Jake was two.
‫I enter here, so I save my third slope's here and then I make my two supposed one.
‫Why?
‫Well, that's because since they now enter in this block again and then I want to compute my new state
‫values using the third slope.
‫But remember, when you have a third slope, then you want to go from K to K plus one.
‫So now when you use the third slope, you want your new state values to be computed at K plus one not
‫in the middle, but at K plus one.
‫So not here anymore, but literally here.
‫And so now I shouldn't divide my ties by two anymore, I should divide it by one because then this thing
‫becomes zero point one seconds.
‫And then I compute my new state value set, Kate plus one, I skipped this block again.
‫I go back to my loop and now J equals three, the last loop.
‫Using my existing state values to compute my fourth slope's in the body frame and also in the inertial
‫frame, I check the JS Jake zero no G equals one no equals two no else.
‫Yes.
‫So I enter into this block and that's where I save my fourth slope's.
‫So since I have four slope's now, then I can stop with the process.
‫I'm not going to enter this block any more.
‫I'm going to skip it because now my Jake was three, so I will skip this block because I would only
‫enter this block if Jake was a number that is less than three since my Jake was three.
‫Then I will enter this block here in this block here.
‫Well, that's this one here.
‫It's this equation, this entire equation.
‫So you see, if you look at this one here, then this is your weighted average slope.
‫You see one over six times and then your four slopes.
‫And then for the second and third slope, you put two here and here because they have stronger weights
‫and then you take your original state value plus the weighted average slope times.
‫Yes.
‫And then you get your states that leave the plant.
‫So these states here, they leave the plant and that's it.
‫We're done with that for loop and then this one here, that's for the animation purposes.
‫The same thing here, again, just to make the movie smoother.
‫So that's the end of the wrong method.
‫Then these states get from here.
‫I'm going to store them in this new states vector like this.
‫And then this new states vector along with states underscore unny and you underscore Arny, they will
‫go to the main file.
‫And so in the main file, I get them here.
‫States, states, underscore and underscore UNY.
‫And then what I do, I take my state's total matrix and then I add my new states vector to the states
‫total matrix, you see, I put it here, I concatenated that's how I keep track of all my states throughout
‫time.
‫And then I do the same thing with states total underscore scrutiny and Yuto underscore Arnie.
‫And in fact, that's the end of the simulation.
‫Everything that follows next is about animation and plotting.
‫But control engineering ends here because now what happens next is that you go back to the beginning
‫of your inner loop, which is here, and then you run the entire loop again.
‫And then again.
‫And when you have run of four times, then you go to the beginning of your outer loop and then you run
‫your outlook again up until here and once you have run your outlook, then again you will run your inner
‫loop four times.
‫And so all that ends when you reach your time equals one hundred seconds.