﻿1
00:00:00,750 --> 00:00:01,650
‫Welcome back.

2
00:00:02,190 --> 00:00:09,510
‫So now, starting from this video, I want to talk about the additions and the modifications that I

3
00:00:09,510 --> 00:00:15,480
‫have made in the code file in order to include NPC constraints here.

4
00:00:16,050 --> 00:00:20,880
‫Now it's important to mention that I'm not explaining the code in this section.

5
00:00:21,570 --> 00:00:28,140
‫The entire code file was explained in Section eight in the previous section in this section.

6
00:00:28,530 --> 00:00:37,470
‫I simply very quickly talk about the additions that I have made to this file in order for you to see

7
00:00:37,800 --> 00:00:41,550
‫how I had also implemented the NPC constraints here.

8
00:00:42,090 --> 00:00:49,950
‫And so it is extremely important that you watch the code explanation videos in the previous section

9
00:00:49,950 --> 00:00:55,680
‫first, because only then what I'm about to explain to here will make sense.

10
00:00:56,310 --> 00:00:57,870
‫OK, so let's get started.

11
00:00:58,470 --> 00:01:00,540
‫You already know that we have two files.

12
00:01:01,080 --> 00:01:04,330
‫The main file and then the support file.

13
00:01:04,950 --> 00:01:12,510
‫And so the main file is the one that you need to run, either in terminal if you use Ubuntu or in command

14
00:01:12,510 --> 00:01:14,280
‫prompt if you use Windows.

15
00:01:14,910 --> 00:01:16,530
‫And then the support file.

16
00:01:16,710 --> 00:01:23,670
‫It consisted of all kinds of different functions that the main file needed to use.

17
00:01:24,270 --> 00:01:30,680
‫And all these functions, they were part of one big class, which is this one here.

18
00:01:30,690 --> 00:01:38,610
‫Support files, the drone and the very first function that we had here was this init function, which

19
00:01:38,610 --> 00:01:42,000
‫is a mandatory function if you work with classes.

20
00:01:42,600 --> 00:01:49,440
‫And so this function, like any other function and also like the main file itself.

21
00:01:50,070 --> 00:01:53,550
‫They are the same like you had in section eight.

22
00:01:54,270 --> 00:02:02,370
‫The only difference is that now you had a bit of more code in order to make the NPC constraints work.

23
00:02:02,940 --> 00:02:08,430
‫So, for example, one addition to the init function is this one here.

24
00:02:09,090 --> 00:02:14,160
‫Over here, I define my omega minimum and omega maximum.

25
00:02:14,790 --> 00:02:19,440
‫So remember this was around 115 radians per second.

26
00:02:20,070 --> 00:02:24,630
‫And then this one was around 900 gradients per second.

27
00:02:25,230 --> 00:02:28,560
‫Essentially, they are these values here.

28
00:02:29,100 --> 00:02:33,210
‫So this is around one hundred and fifteen radians per second.

29
00:02:33,840 --> 00:02:36,660
‫And this one around 900 radians per second.

30
00:02:37,260 --> 00:02:39,870
‫So these were your minimum and maximum bounds.

31
00:02:40,500 --> 00:02:42,120
‫And so I define them here.

32
00:02:42,720 --> 00:02:45,420
‫Then you have this constraint switch here.

33
00:02:45,990 --> 00:02:53,190
‫The purpose of this variable is that here you can choose whether you want to take constraints into account

34
00:02:53,190 --> 00:02:53,760
‫or not.

35
00:02:54,330 --> 00:03:03,060
‫So if you put here a zero, then this entire code file, it's built in such a way that it would behave

36
00:03:03,570 --> 00:03:05,670
‫like the one from section eight.

37
00:03:06,150 --> 00:03:10,050
‫So if you don't want to consider constraints, just put here zero.

38
00:03:10,680 --> 00:03:14,970
‫But if you do want to consider constraints, then you need to put one here.

39
00:03:15,660 --> 00:03:19,980
‫Then this matrix here, it's this one here.

40
00:03:20,250 --> 00:03:28,230
‫It's your see till the star you used it in order to extract your view to zero, you three zero and you

41
00:03:28,230 --> 00:03:35,370
‫for zero, which were part of this augmented predicted state vector X1 Tilde.

42
00:03:36,000 --> 00:03:42,920
‫And then, of course, later on, you used this matrix to extract the you values from this vector here.

43
00:03:43,150 --> 00:03:47,310
‫Still, the two x still the three and still the four as well.

44
00:03:47,880 --> 00:03:51,120
‫So this matrix here, it's this one here.

45
00:03:51,750 --> 00:03:59,610
‫Now there is one modification that I have made in this code file compared to the one in section eight.

46
00:04:00,270 --> 00:04:03,120
‫In Section eight, I used lists.

47
00:04:03,510 --> 00:04:07,710
‫So all these constants, then I had defined in my neat function.

48
00:04:08,340 --> 00:04:16,980
‫I put them here inside this list and then later on when I needed stuff from that list, then I extracted

49
00:04:16,980 --> 00:04:20,310
‫them like this self dot constants.

50
00:04:20,970 --> 00:04:22,950
‫And then I had to put a number here.

51
00:04:23,580 --> 00:04:31,680
‫So six here it would be zero one, two, three, four, five and six.

52
00:04:32,340 --> 00:04:35,820
‫So that's your yes, your sample time interval.

53
00:04:36,420 --> 00:04:43,680
‫Remember, since you're working with Python, then six here means that this is your seventh element

54
00:04:43,980 --> 00:04:45,750
‫because you start counting from zero.

55
00:04:46,350 --> 00:04:52,260
‫And then in the main file you wrote constants equals support constants.

56
00:04:52,920 --> 00:04:57,510
‫And then when you wanted to get your thoughts, then you wrote constants.

57
00:04:57,870 --> 00:04:59,820
‫And then again, you put six here.

58
00:05:00,430 --> 00:05:08,380
‫The problem with these lists is that when you have tens of variables there, then sometimes you might

59
00:05:08,380 --> 00:05:10,450
‫make a mistake with these numbers.

60
00:05:11,080 --> 00:05:18,930
‫And in order to avoid these mistakes, you have to very carefully count these variables so that you

61
00:05:18,930 --> 00:05:20,440
‫would put the right number here.

62
00:05:21,010 --> 00:05:28,780
‫It turns out that there is a better way to do it, and that's why in this version that has the constraints

63
00:05:28,780 --> 00:05:31,270
‫in it, I'm using dictionaries.

64
00:05:31,810 --> 00:05:39,400
‫You still put your initial constants inside your dictionary, but each variable has a special key.

65
00:05:40,000 --> 00:05:48,460
‫And if you name that key in the same way, like you had named your variable itself, then later on,

66
00:05:48,460 --> 00:05:53,650
‫when you need variables from your dictionary, it's very easy to extract them.

67
00:05:53,980 --> 00:06:01,900
‫You just write self doubt constants and then the name of your key, which happens to have the same name,

68
00:06:02,290 --> 00:06:04,000
‫like the name of that variable.

69
00:06:04,600 --> 00:06:07,210
‫And then you do the same thing in your main file.

70
00:06:07,810 --> 00:06:15,460
‫You write constants equals support constants and then you write two equals constants.

71
00:06:16,030 --> 00:06:19,030
‫And then the name of the key, which is also PTS.

72
00:06:19,600 --> 00:06:22,660
‫So that makes the coding process a lot easier.

73
00:06:23,200 --> 00:06:23,860
‫But OK.

74
00:06:24,460 --> 00:06:27,340
‫We have defined our omega omega max.

75
00:06:27,970 --> 00:06:30,550
‫Then whether we want to use constraints or not.

76
00:06:31,120 --> 00:06:33,760
‫And then this till the star matrix.

77
00:06:34,420 --> 00:06:37,330
‫Now they're also part of this dictionary.

78
00:06:37,990 --> 00:06:44,530
‫And so when I go back to my main file, then everything else is pretty much the same like it was before.

79
00:06:45,190 --> 00:06:53,500
‫The only difference are that here I extract my omega minimum and omega maximum from the dictionary.

80
00:06:54,190 --> 00:07:01,150
‫Then my initial omega as all four of them, I will assign omega meant to them.

81
00:07:01,780 --> 00:07:04,570
‫Then I calculate my omega total.

82
00:07:05,260 --> 00:07:09,880
‫Then everything is the same again until we reach here.

83
00:07:10,360 --> 00:07:18,040
‫Here from the Constants Dictionary, I obtained this variable constraint switch, which had to be either

84
00:07:18,040 --> 00:07:18,940
‫one or zero.

85
00:07:19,540 --> 00:07:25,720
‫And so this is also new compared to the previous file in Section eight.

86
00:07:26,320 --> 00:07:34,330
‫Here I write If constraint switch equals one, meaning that you want to include your NPC constraints,

87
00:07:35,050 --> 00:07:38,320
‫then you enter into this block here.

88
00:07:38,950 --> 00:07:46,360
‫If you choose to use NPC constraints, then only then it makes sense to import 2p solvers.

89
00:07:47,020 --> 00:07:48,730
‫Otherwise, you don't need to import it.

90
00:07:49,330 --> 00:07:57,550
‫And then inside this block, I will calculate my minimum and maximum use for all four of them.

91
00:07:58,120 --> 00:08:01,060
‫So these equations, here they are.

92
00:08:01,060 --> 00:08:02,230
‫These ones here.

93
00:08:02,560 --> 00:08:05,980
‫Here we calculated the minimum and maximum your values.

94
00:08:06,580 --> 00:08:08,920
‫And then in the code, we are doing it here.

95
00:08:09,250 --> 00:08:12,010
‫And then here you have y max and women.

96
00:08:12,640 --> 00:08:21,280
‫Essentially, you take your you to Max, U3 Max and you four max and you put them all in one array and

97
00:08:21,280 --> 00:08:25,840
‫you call that array y max and you do the same thing for you.

98
00:08:25,840 --> 00:08:29,470
‫Two men, you three men and you four men.

99
00:08:30,070 --> 00:08:34,210
‫You put them all in one array and you call it y min.

100
00:08:34,960 --> 00:08:43,360
‫Now you might wonder why I don't put my U1 max and you one min here inside these two arrays.

101
00:08:43,960 --> 00:08:46,870
‫Well, that's because we're working with MPAC constraints.

102
00:08:47,530 --> 00:08:50,020
‫But you one had nothing to do with NPC.

103
00:08:50,680 --> 00:08:57,190
‫If you remember, then you one came out of your feedback, unionization block and then it went straight

104
00:08:57,190 --> 00:09:03,700
‫into your planned box and only you to Q3 and Q4 came out of your NPC block.

105
00:09:04,300 --> 00:09:11,110
‫And so this array y max and this one y men, they will be used for NPC constraints.

106
00:09:11,770 --> 00:09:17,150
‫Now it doesn't mean, of course, that we are not going to constrain you one.

107
00:09:17,840 --> 00:09:21,460
‫We're going to do that as well, but in a different way.

108
00:09:22,120 --> 00:09:30,670
‫So here I start with my outer loop and everything is the same like it was in section eight, except

109
00:09:30,670 --> 00:09:33,100
‫that you have this block here.

110
00:09:33,600 --> 00:09:41,590
‫Here you say that if you consider your constraints, then when you get your u one from your position

111
00:09:41,590 --> 00:09:44,650
‫controller from your feedback ionization controller.

112
00:09:45,190 --> 00:09:54,790
‫Here, you say that if your you one is less than you one minimum, then you will simply assign this

113
00:09:54,790 --> 00:09:58,900
‫you one minimal value to your u one variable.

114
00:09:59,750 --> 00:10:03,830
‫You are simply going to send your you one meaning to your planned box.

115
00:10:04,430 --> 00:10:12,050
‫And similarly, if your new one is greater than you one max, then you will simply send you one max

116
00:10:12,050 --> 00:10:13,130
‫to your plan box.

117
00:10:13,760 --> 00:10:17,360
‫So that's how we constrain our you one values.

118
00:10:17,990 --> 00:10:24,350
‫And now we're going to finish with our outer loop and starting from here, we're going to start with

119
00:10:24,350 --> 00:10:25,220
‫our inner loop.

