‫Welcome back.
‫But now what's the difference between R and ref signals, which is generated in this blog here?
‫What's the difference?
‫Well, you can see that Ref Signals contains your five three time reference values, and that happens
‫once per outer loop.
‫And then you enter into your inner loop and you have four inner loops per one outer loop.
‫So you can see that in every inner loop, this are variable extracts, something from this ref signals
‫array.
‫This are variable here.
‫That's the reference vector that enters into your NPC controller.
‫This is your NPC cost function and you see this is your AHA.
‫And here you transpose it of course, but this is your R variable.
‫That's what is used for the NPC controller, if you remember.
‫Then this is how we depicted our reference Phi Theta and Passi values for each individual outer loop.
‫That's how it was depicted.
‫So every outer loop, the position controller computes a value for fi R and then theta R and then also
‫it computed you one that went straight into the plant.
‫And so that happens here.
‫Right?
‫So our position controller gave us a value for fire F and Theta ref.
‫Now these are just numbers, but since we had four inor iterations per one outer iteration, we wanted
‫to take this fire F and Theta ref and make them a five element array for both Fire and Sittar.
‫And then we did the same thing for R, but SA was computed by the planner, not by the position controller.
‫And so you can see that fire and theater and PCEHR, they're the same at K K plus one plus two plus
‫three plus four.
‫We put them in this form because we want to give this information to the NPC controller as reference
‫values so that in the first iteration NPC could get closer to this value than in the second iteration
‫so that it could get even closer to the value than in the third iteration, so that it could get even
‫closer and so that by the end of the fourth iteration, it would catch the required value in the same
‫thing for Sittar and PCEHR.
‫And so that's why we put this fire in this form in which all the elements in this vector are equal to
‫each other.
‫And we did the same thing for to R and R.
‫As you can see, you have a straight line here and here.
‫That means that Fire Theatre and CI are they do not change in value when they go from K to plus one
‫to keep plus to keep us three or four plus four.
‫Now before we move on, I need to tell you about a small change in the code and that change relates
‫to CI r it does not relate to Sittar or fire but it relates to CI are and this changes the following.
‫This is how we did it before we gave prior to the NPC controller in this form in which Sciorra K was
‫equal to Sirat plus one and that was equal to zero plus two etc..
‫So all these values here, they were equal to each other.
‫And then the NPC controller tried to catch this reference value during the four inner iterations.
‫However, that makes your control a little bit not smooth.
‫And that's because if we look at the global picture, then this would be your one outer loop, then
‫this would be your another outer loop.
‫And so we are assuming that we are flying the spiral.
‫So your your reference angle always increases because you go in a spiral like this and then in the next
‫outer loop, you reference your angle is like this and this is the outer loop.
‫Right.
‫So your case here, you K plus four is here.
‫So you have four inner loop iterations per each straight line that you can see here.
‫Then this would be Kate plus eight.
‫And so in the global picture, you reference your angle was like this and then the controller tries
‫to catch it.
‫And what happens is this.
‫It goes something like this and you can see it here in the graph.
‫So this is your BPCI angle and we can try to zoom it.
‫So here it is.
‫So in blue, you have your your reference values and then your NPC controller tries to catch it.
‫And by the way, as you can see in Python, this point would be cabelas for that's the end of one outer
‫loop.
‫And then this would be K plus one, the beginning of the next outer loop.
‫I usually draw like this where I draw this point and then this point, but then Python does not plot
‫this point.
‫And so you can see the pattern.
‫And in order to achieve this pattern, the NPC controller, if you look at this EUFOR control input,
‫it needs to provide mostly a positive your control moment.
‫But since here and literally telling the drone to stop at this value because of that, the NPC controller
‫also calculates some your control moments that are negative in order to slow down this, your motion.
‫And as a result, the rotation about the body frame Z axis is not very smooth.
‫Instead of giving the your reference values to the NPC controller in this form where your reference,
‫your value is equal at K and keep us one and K plus two and keep us three and keep us four.
‫Instead of that, I create a your reference vector that looks like this you see.
‫So this would be at K then.
‫This would be at K plus one, this would be at K plus two, this would be at K plus three and finally
‫this would be at plus four.
‫So no longer I keep my bpci.
‫Are values equal during K, K plus one K plus two plus three and plus four.
‫Now what I do, I give this information to the NPC controller in this form.
‫And so in the global picture, the Passi, our values will look like this, it will increase in a linear
‫fashion.
‫But of course if in the next outer loop I have a very big sigh, ah, then the slope of this yellow
‫line will increase.
‫And then if all of a sudden my PCR is like this, then this yellow line would be like this.
‫But these are straight lines here.
‫All right.
‫This is not a parable or anything.
‫These are straight lines.
‫But of course, the straight lines can have different slopes in every outer loop.
‫But of course, if you have a spiral, then there will simply be a straight line.
‫When I tried that, then the rotation of the drone about the body from Z axis was much smoother.
‫I tried the same thing for fire and theater as well, but that made the results worse so far.
‫And Sittar, they still have this structure where they do not change with K and K plus one and plus
‫two.
‫However, are does change.
‫And remember, zero was generated in the planner.
‫It wasn't computed in the position controller.
‫And so in the code, the change that has happened in order to achieve this behavior is the following.
‫I delete this line here and then I uncommented this piece of code.
‫So this piece of code, it achieves this behavior here you can see that there is a for loop here and
‫essentially was have.
‫Here inside this for Loop is exactly that, so every your step, your SIRF vector gets a different value
‫and it follows this logic.
‫Every outer loop, you either have a positive linear line or a negative linear line.
‫As a result, your drone rotates about the body from the axis in a smoother way.
‫And you can see that when I zoom in now, then in blue, your values increase linearly and that makes
‫tracking of it much better.
‫So that's the change that I want to mention.
‫So essentially, every outer loop, the planner will give me some kind of value, which is CRF.
‫Then I look at the size of value in the previous outer loop.
‫Let's say maybe it was here and then this code here, it will create a vector that will contain this
‫value, then this value, then this value, this one and this one.
‫So my CI, our vector will essentially have these five values.
‫They will not be equal like for example, FAAB or Thi DA.
‫And by the way, all these changes are in the latest downloadable code and now you have all this information
‫and you have to store it in a specific way.
‫You have to create an array in which you store all this, this and this and all that is stored in an
‫array called Reft Signals.
‫And they are not just stored there.
‫All these reference values are stored there in a specific pattern.
‫In this pattern is here five zero zero zero zero zero and then five one theatric, one zero one, etc..
‫So in my red signals array, I will first store this which comes here, then this which comes here and
‫then this which comes here.
‫Then I store this that comes here, this one that comes here, and then this value, which is essentially
‫this value here.
‫Right.
‫So it comes here then the same thing for K plus two plus three and K plus four.
‫This is how Red Signals looks like.
‫And then remember you have for inner loop iterations in one outer loop and your horizon period is four.
‫And so now this are array comes into play in the first inner loop, this array, which is if you go
‫down this one here, you can see that it extracts something from Reft Signals and this is what it extracts
‫in the first inner loop.
‫And then this portion goes into the NPC controller.
‫It comes here in this NPC cost function.
‫So this extraction in the first inner loop, it's this one here, this R so that's your first inner
‫loop.
‫Then in the second inner loop, you're our reference vector will extract this part from Reft Signals
‫and now your horizon period is three and so you extract three five values, then three theta values
‫and then three psi values.
‫And then in the second inner loop this are array, this reference vector again it will go here then
‫in the third inner loop, your horizon period is two and this is what are extracts from reffed signals.
‫And this R then goes into the NPC controller and that's this R and finally in the fourth inner loop,
‫your horizon, these one are extracts only this part from Reft Signals and then this R will go here
‫into this NPC cost function.
‫And then after the fourth inner loop there will be a new outer loop.
‫So the position controller will calculate your new fire R and then you will get a new value from Sciorra.
‫So you will have a new line for fire R, which will be different from this one.
‫And also you will.
‫We have a new line for Sittar, which will be different from the previous one, and you will have a
‫new value for your ah, maybe it will be somewhere here.
‫So let's say that here this is my Kate plus eight and then you compare it with your previous Siwan,
‫which is this one, and then this modification in the code will create this line and then chop it linearly.
‫And so in the new ref signals, you will have this value, this value, this value, this value and
‫this value.
‫And like I said, for fire and Theta are you will also have different lines.
‫And then again, you formulate your signals according to this pattern that I showed you here.
‫And then again, you will have four inner loops in which your ah reference vector will extract some
‫portions from this ref signals and feed it into the NPC controller and this extraction from ref signals.
‫It happens here.
‫The reason why you have an if statement here is because what if your horizon period was two and not
‫four?
‫Then in the first inner loop you're our reference vector would only extract this portion.
‫Then in the second inner loop it would extract this portion here in the third inner loop.
‫It would extract this portion here.
‫And finally in the fourth inner loop, it would extract this portion here.
‫As you can see that in this case, in the first inner loop, your Horizons period was two.
‫In the second inner loop, your horizon period was still two.
‫In the third inner loop, it was still two and only in the fourth inner loop.
‫It became one because you started hitting the wall, right.
‫That was the end of your rift signals.
‫You cannot go out of the rift signals.
‫And so in this case, this piece of code will behave like this in the first inner loop.
‫You come here then in the second inner loop, you come here, then in the third inner loop, you also
‫come here and then in the fourth inner loop because you need to decrease your horizon, period.
‫You come into this block.
‫But in our case, Horizon period equals four.
‫In that case, that would be your first inner loop.
‫When your horizon period equals four, that would be your second inner loop.
‫And now already your horizon power decreases because you're hitting the wall.
‫Then here this would be your third inner loop and horizon period equals two and this would be your fourth
‫inner loop where your horizon equals one.
‫So in our case, you first enter into this block here in the first inner loop and then in the second,
‫third and fourth inner loop, you enter here because you need to decrease your horizon, period, because
‫you're hitting the wall.
‫So this conditional statement, it's to manage this situation when you start hitting the wall of rough
‫signals, because you can imagine that if I keep my horizon period for here, then I will want to extract
‫a lot more from red signals.
‫But there is no more.
‫And that's why I have this conditional statement here.
‫But now you know the difference between R and ref signals.