‫Welcome back.
‫So now that we have covered the prediction formula, let's go to the heart of the embassy controller.
‫The cost function, the cost function has the same format, like in the previous course, it's quadratic.
‫You see, this one was what we had in the previous course here.
‫And this is our cost function here.
‫You see, it's the same format.
‫The only difference now is that instead of the steering wheel angle instead of Delta, we have this
‫control input vector here.
‫And also in our case, the horizon period is four.
‫So that means that this and here this N equals four.
‫And so from the previous course, the steering wheel angle that control input was a scalar.
‫But in our case, in the other case, our control input is a vector.
‫It's a three by one vector.
‫And that's how this three by one control input vector looks like.
‫You have your you two and K plus i you three at kapos I and you for at Kaplans I.
‫And here we are back with our original notation.
‫So now if I write X Sub K, there is the state vector now.
‫OK, so that's your present state.
‫If I write X Sub K plus one, then it's a state vector 0.1 seconds later x k plus two.
‫That's the state vector, 0.2 seconds later and etc. And so let's draw a small time line here.
‫Well, actually, it's a sample time line.
‫You have your key here.
‫Then this is Kate plus one, Kate plus two K plus three.
‫And finally, Kate plus four.
‫So again, this is your present here.
‫This is your sample time interval, which is TTS equals 0.1 seconds.
‫And so the first term in the cost function, which is this one here.
‫This term is for this part here.
‫So if you're an equals four, then it would be K plus four since your horizon period is four, then
‫it would cover K plus one K plus two, K plus three and K plus four.
‫So again, the first term in the cost function is for the errors in the last time sample at K Plus four,
‫and the rest of the cost function is for the time samples from K up until K plus three.
‫So if I take this entire term here.
‫This entire term in purple will be for this from K.
‫Up until K plus three.
‫And you can see it as I in the summation sign will go from I equals to zero to I equals two and minus
‫one, which is four minus one, which is three.
‫Then in the autonomous vehicle case, the error vectors where two by one vectors two rows one column.
‫And so you had two rows because you had a CI variable.
‫And then the initial Y variable, they were also your outputs.
‫Remember, you had four states, however, out of those four states, you chose two outputs, so your
‫error vector, let's say at Cape Plus, I would look like this.
‫Error sigh at K plus I.
‫An error inertial wye at Cape Plus I, and since an error is reference value minus the true output value,
‫then this vector can also be rewritten like this.
‫CI are at Cape Plus I minus sy at K Plus I also the inertial Y reference at K plus i minus the true
‫Y output, the inertial y at K plus I.
‫So this vector here that you can also rewrite in this form.
‫That's how it looks like here and here.
‫It would simply be transposed.
‫You see you have a your transpose sign.
‫So here this vector would be one row and two columns.
‫And of course, if instead of I, you had here and then we would be talking about this vector here in
‫the first term and therefore our weight matrices Q and S.
‫They were two by two diagonal matrices.
‫So, Q was Q1, Q2 and then you had the zero here and here, and the same thing with S S1, S2 and then
‫zero and zero.
‫Also, you only had one control input, you had your steering wheel angle, your delta.
‫Therefore, you are was simply a scalar.
‫So in this term here in the previous course, it was like this, you had your steering wheel input,
‫which was a scalar.
‫Then you had your scalar.
‫Ah, and then you had the same scalar steering wheel input.
‫This transpose sine didn't matter there because if you have scalar transpose, well, that equals the
‫same scalar.
‫So that was our autonomous vehicle.
‫However, in the UAV case, the dimensions are different.
‫The error vectors are three by one vectors.
‫Remember, we had six states and out of these six states we would choose three outputs Phi Theta and
‫CI, because we have to compare them to the reference values of PHI, our CTA, R and R.
‫So the error vector that we have here at Kate plus I, that we have here in our cost function, it will
‫look like this.
‫Error fi at K Plus I error SETA at Cape Plus AI and error CI at Cape Plus AI and in the same way, like
‫here you can rewrite it.
‫Like this fly R at K plus AI minus the true fi as the output at K plus ai seta r at K plus ai minus
‫true seta at K plus ai ci are at Cape Plus AI minus the true CI at K plus AI.
‫So that's how the vector can be rewritten.
‫Then this here would be your control input vector.
‫And again, this is a three by one vector, three rows one column that means that the weight matrices
‫que se and are.
‫They are all three by three diagonal mattresses.
‫There will be a queue matrix.
‫That would be your SE matrix.
‫And this year, our matrix here, they can all be different, but they're all three by three diagonal
‫matrices.
‫And of course, the reason why we had one half in the cost function here and also here you see you have
‫your one half in this term and in this term, the reason for that was that in the cost function, when
‫we took its gradient, then you would end up with a constant to over to.
‫Which you could cancel out, because it would be one.
‫So you see in the previous course this was your cost function here.
‫And when you took the gradient of it, then you managed to have it in this form that you have one here
‫and one here in front of these two terms.
‫And of course, these ones, you don't have to write them here.
‫So it makes this expression easier.
‫And here I would simply like to show you the cost function terms again.
‫So let's start with this one.
‫If we take this term here, then if you write it out, it looks like this.
‫So this one would be the error vector at Cape Bliss End, but transposed.
‫This would be the error vector at Cape Plus End.
‫And this would be your best weight matrix, so you can choose different weights here for S1 S2 in this
‫three.
‫Then this term here it's this one.
‫So the error vector transposed at Cape Plus I this would be your error vector at Cape Plus I this would
‫be your cue weight matrix.
‫Again, you can choose different weights for your cu weight matrices.
‫And finally, this term here looks like this one.
‫That's your control input vector transposed, this is your control input vector and this is your arm
‫matrix here.
‫And of course, you can choose your different are one or two and are three.
‫So these two terms here, in other words, these two here they are for I equals zero, I equals one,
‫I equals two and I equals three, and I'm talking about this.
‫I hear this.
‫I goes from zero to three and minus one four minus one.
‫That's three.
‫And then finally, this term, here is this one.
‫And that's for when and equals four.
‫That's for this one here.