‫Welcome back.
‫So now, starting from this video, I want to talk about the additions and the modifications that I
‫have made in the code file in order to include NPC constraints here.
‫Now it's important to mention that I'm not explaining the code in this section.
‫The entire code file was explained in Section eight in the previous section in this section.
‫I simply very quickly talk about the additions that I have made to this file in order for you to see
‫how I had also implemented the NPC constraints here.
‫And so it is extremely important that you watch the code explanation videos in the previous section
‫first, because only then what I'm about to explain to here will make sense.
‫OK, so let's get started.
‫You already know that we have two files.
‫The main file and then the support file.
‫And so the main file is the one that you need to run, either in terminal if you use Ubuntu or in command
‫prompt if you use Windows.
‫And then the support file.
‫It consisted of all kinds of different functions that the main file needed to use.
‫And all these functions, they were part of one big class, which is this one here.
‫Support files, the drone and the very first function that we had here was this init function, which
‫is a mandatory function if you work with classes.
‫And so this function, like any other function and also like the main file itself.
‫They are the same like you had in section eight.
‫The only difference is that now you had a bit of more code in order to make the NPC constraints work.
‫So, for example, one addition to the init function is this one here.
‫Over here, I define my omega minimum and omega maximum.
‫So remember this was around 115 radians per second.
‫And then this one was around 900 gradients per second.
‫Essentially, they are these values here.
‫So this is around one hundred and fifteen radians per second.
‫And this one around 900 radians per second.
‫So these were your minimum and maximum bounds.
‫And so I define them here.
‫Then you have this constraint switch here.
‫The purpose of this variable is that here you can choose whether you want to take constraints into account
‫or not.
‫So if you put here a zero, then this entire code file, it's built in such a way that it would behave
‫like the one from section eight.
‫So if you don't want to consider constraints, just put here zero.
‫But if you do want to consider constraints, then you need to put one here.
‫Then this matrix here, it's this one here.
‫It's your see till the star you used it in order to extract your view to zero, you three zero and you
‫for zero, which were part of this augmented predicted state vector X1 Tilde.
‫And then, of course, later on, you used this matrix to extract the you values from this vector here.
‫Still, the two x still the three and still the four as well.
‫So this matrix here, it's this one here.
‫Now there is one modification that I have made in this code file compared to the one in section eight.
‫In Section eight, I used lists.
‫So all these constants, then I had defined in my neat function.
‫I put them here inside this list and then later on when I needed stuff from that list, then I extracted
‫them like this self dot constants.
‫And then I had to put a number here.
‫So six here it would be zero one, two, three, four, five and six.
‫So that's your yes, your sample time interval.
‫Remember, since you're working with Python, then six here means that this is your seventh element
‫because you start counting from zero.
‫And then in the main file you wrote constants equals support constants.
‫And then when you wanted to get your thoughts, then you wrote constants.
‫And then again, you put six here.
‫The problem with these lists is that when you have tens of variables there, then sometimes you might
‫make a mistake with these numbers.
‫And in order to avoid these mistakes, you have to very carefully count these variables so that you
‫would put the right number here.
‫It turns out that there is a better way to do it, and that's why in this version that has the constraints
‫in it, I'm using dictionaries.
‫You still put your initial constants inside your dictionary, but each variable has a special key.
‫And if you name that key in the same way, like you had named your variable itself, then later on,
‫when you need variables from your dictionary, it's very easy to extract them.
‫You just write self doubt constants and then the name of your key, which happens to have the same name,
‫like the name of that variable.
‫And then you do the same thing in your main file.
‫You write constants equals support constants and then you write two equals constants.
‫And then the name of the key, which is also PTS.
‫So that makes the coding process a lot easier.
‫But OK.
‫We have defined our omega omega max.
‫Then whether we want to use constraints or not.
‫And then this till the star matrix.
‫Now they're also part of this dictionary.
‫And so when I go back to my main file, then everything else is pretty much the same like it was before.
‫The only difference are that here I extract my omega minimum and omega maximum from the dictionary.
‫Then my initial omega as all four of them, I will assign omega meant to them.
‫Then I calculate my omega total.
‫Then everything is the same again until we reach here.
‫Here from the Constants Dictionary, I obtained this variable constraint switch, which had to be either
‫one or zero.
‫And so this is also new compared to the previous file in Section eight.
‫Here I write If constraint switch equals one, meaning that you want to include your NPC constraints,
‫then you enter into this block here.
‫If you choose to use NPC constraints, then only then it makes sense to import 2p solvers.
‫Otherwise, you don't need to import it.
‫And then inside this block, I will calculate my minimum and maximum use for all four of them.
‫So these equations, here they are.
‫These ones here.
‫Here we calculated the minimum and maximum your values.
‫And then in the code, we are doing it here.
‫And then here you have y max and women.
‫Essentially, you take your you to Max, U3 Max and you four max and you put them all in one array and
‫you call that array y max and you do the same thing for you.
‫Two men, you three men and you four men.
‫You put them all in one array and you call it y min.
‫Now you might wonder why I don't put my U1 max and you one min here inside these two arrays.
‫Well, that's because we're working with MPAC constraints.
‫But you one had nothing to do with NPC.
‫If you remember, then you one came out of your feedback, unionization block and then it went straight
‫into your planned box and only you to Q3 and Q4 came out of your NPC block.
‫And so this array y max and this one y men, they will be used for NPC constraints.
‫Now it doesn't mean, of course, that we are not going to constrain you one.
‫We're going to do that as well, but in a different way.
‫So here I start with my outer loop and everything is the same like it was in section eight, except
‫that you have this block here.
‫Here you say that if you consider your constraints, then when you get your u one from your position
‫controller from your feedback ionization controller.
‫Here, you say that if your you one is less than you one minimum, then you will simply assign this
‫you one minimal value to your u one variable.
‫You are simply going to send your you one meaning to your planned box.
‫And similarly, if your new one is greater than you one max, then you will simply send you one max
‫to your plan box.
‫So that's how we constrain our you one values.
‫And now we're going to finish with our outer loop and starting from here, we're going to start with
‫our inner loop.