﻿1
00:00:00,420 --> 00:00:01,230
‫Welcome back.

2
00:00:02,130 --> 00:00:11,590
‫But now what's the difference between R and ref signals, which is generated in this blog here?

3
00:00:12,210 --> 00:00:13,350
‫What's the difference?

4
00:00:13,830 --> 00:00:21,990
‫Well, you can see that Ref Signals contains your five three time reference values, and that happens

5
00:00:22,020 --> 00:00:23,700
‫once per outer loop.

6
00:00:24,300 --> 00:00:31,500
‫And then you enter into your inner loop and you have four inner loops per one outer loop.

7
00:00:32,040 --> 00:00:42,600
‫So you can see that in every inner loop, this are variable extracts, something from this ref signals

8
00:00:42,600 --> 00:00:43,170
‫array.

9
00:00:43,770 --> 00:00:45,660
‫This are variable here.

10
00:00:46,260 --> 00:00:50,410
‫That's the reference vector that enters into your NPC controller.

11
00:00:50,760 --> 00:00:55,020
‫This is your NPC cost function and you see this is your AHA.

12
00:00:55,590 --> 00:01:00,360
‫And here you transpose it of course, but this is your R variable.

13
00:01:00,930 --> 00:01:05,640
‫That's what is used for the NPC controller, if you remember.

14
00:01:05,640 --> 00:01:16,530
‫Then this is how we depicted our reference Phi Theta and Passi values for each individual outer loop.

15
00:01:17,160 --> 00:01:18,900
‫That's how it was depicted.

16
00:01:19,500 --> 00:01:29,640
‫So every outer loop, the position controller computes a value for fi R and then theta R and then also

17
00:01:29,640 --> 00:01:34,200
‫it computed you one that went straight into the plant.

18
00:01:34,800 --> 00:01:36,800
‫And so that happens here.

19
00:01:36,960 --> 00:01:37,480
‫Right?

20
00:01:37,770 --> 00:01:43,860
‫So our position controller gave us a value for fire F and Theta ref.

21
00:01:44,400 --> 00:01:53,340
‫Now these are just numbers, but since we had four inor iterations per one outer iteration, we wanted

22
00:01:53,340 --> 00:02:02,930
‫to take this fire F and Theta ref and make them a five element array for both Fire and Sittar.

23
00:02:03,480 --> 00:02:11,240
‫And then we did the same thing for R, but SA was computed by the planner, not by the position controller.

24
00:02:11,850 --> 00:02:20,310
‫And so you can see that fire and theater and PCEHR, they're the same at K K plus one plus two plus

25
00:02:20,310 --> 00:02:21,650
‫three plus four.

26
00:02:22,320 --> 00:02:28,860
‫We put them in this form because we want to give this information to the NPC controller as reference

27
00:02:28,860 --> 00:02:36,960
‫values so that in the first iteration NPC could get closer to this value than in the second iteration

28
00:02:36,960 --> 00:02:44,040
‫so that it could get even closer to the value than in the third iteration, so that it could get even

29
00:02:44,040 --> 00:02:53,430
‫closer and so that by the end of the fourth iteration, it would catch the required value in the same

30
00:02:53,430 --> 00:02:56,300
‫thing for Sittar and PCEHR.

31
00:02:56,880 --> 00:03:06,180
‫And so that's why we put this fire in this form in which all the elements in this vector are equal to

32
00:03:06,180 --> 00:03:06,660
‫each other.

33
00:03:07,230 --> 00:03:11,040
‫And we did the same thing for to R and R.

34
00:03:11,610 --> 00:03:15,390
‫As you can see, you have a straight line here and here.

35
00:03:16,080 --> 00:03:24,930
‫That means that Fire Theatre and CI are they do not change in value when they go from K to plus one

36
00:03:24,930 --> 00:03:27,810
‫to keep plus to keep us three or four plus four.

37
00:03:28,440 --> 00:03:36,600
‫Now before we move on, I need to tell you about a small change in the code and that change relates

38
00:03:36,600 --> 00:03:46,580
‫to CI r it does not relate to Sittar or fire but it relates to CI are and this changes the following.

39
00:03:47,160 --> 00:03:56,850
‫This is how we did it before we gave prior to the NPC controller in this form in which Sciorra K was

40
00:03:56,850 --> 00:04:03,510
‫equal to Sirat plus one and that was equal to zero plus two etc..

41
00:04:03,510 --> 00:04:07,740
‫So all these values here, they were equal to each other.

42
00:04:08,280 --> 00:04:17,060
‫And then the NPC controller tried to catch this reference value during the four inner iterations.

43
00:04:17,610 --> 00:04:23,340
‫However, that makes your control a little bit not smooth.

44
00:04:33,790 --> 00:04:40,780
‫And that's because if we look at the global picture, then this would be your one outer loop, then

45
00:04:40,780 --> 00:04:43,170
‫this would be your another outer loop.

46
00:04:43,720 --> 00:04:46,820
‫And so we are assuming that we are flying the spiral.

47
00:04:47,470 --> 00:04:56,590
‫So your your reference angle always increases because you go in a spiral like this and then in the next

48
00:04:56,590 --> 00:05:01,450
‫outer loop, you reference your angle is like this and this is the outer loop.

49
00:05:01,450 --> 00:05:01,760
‫Right.

50
00:05:02,320 --> 00:05:06,210
‫So your case here, you K plus four is here.

51
00:05:06,400 --> 00:05:12,730
‫So you have four inner loop iterations per each straight line that you can see here.

52
00:05:13,330 --> 00:05:15,040
‫Then this would be Kate plus eight.

53
00:05:15,520 --> 00:05:22,900
‫And so in the global picture, you reference your angle was like this and then the controller tries

54
00:05:22,900 --> 00:05:23,490
‫to catch it.

55
00:05:24,070 --> 00:05:26,200
‫And what happens is this.

56
00:05:26,830 --> 00:05:30,920
‫It goes something like this and you can see it here in the graph.

57
00:05:30,940 --> 00:05:36,000
‫So this is your BPCI angle and we can try to zoom it.

58
00:05:36,610 --> 00:05:37,420
‫So here it is.

59
00:05:38,020 --> 00:05:44,610
‫So in blue, you have your your reference values and then your NPC controller tries to catch it.

60
00:05:45,160 --> 00:05:53,890
‫And by the way, as you can see in Python, this point would be cabelas for that's the end of one outer

61
00:05:53,890 --> 00:05:54,210
‫loop.

62
00:05:54,760 --> 00:05:59,560
‫And then this would be K plus one, the beginning of the next outer loop.

63
00:06:00,100 --> 00:06:07,990
‫I usually draw like this where I draw this point and then this point, but then Python does not plot

64
00:06:08,200 --> 00:06:09,030
‫this point.

65
00:06:09,520 --> 00:06:11,100
‫And so you can see the pattern.

66
00:06:11,740 --> 00:06:18,640
‫And in order to achieve this pattern, the NPC controller, if you look at this EUFOR control input,

67
00:06:19,210 --> 00:06:24,900
‫it needs to provide mostly a positive your control moment.

68
00:06:25,450 --> 00:06:34,240
‫But since here and literally telling the drone to stop at this value because of that, the NPC controller

69
00:06:34,450 --> 00:06:43,500
‫also calculates some your control moments that are negative in order to slow down this, your motion.

70
00:06:44,080 --> 00:06:50,460
‫And as a result, the rotation about the body frame Z axis is not very smooth.

71
00:06:50,920 --> 00:06:58,570
‫Instead of giving the your reference values to the NPC controller in this form where your reference,

72
00:06:58,570 --> 00:07:04,840
‫your value is equal at K and keep us one and K plus two and keep us three and keep us four.

73
00:07:05,470 --> 00:07:12,300
‫Instead of that, I create a your reference vector that looks like this you see.

74
00:07:12,880 --> 00:07:15,640
‫So this would be at K then.

75
00:07:15,640 --> 00:07:23,950
‫This would be at K plus one, this would be at K plus two, this would be at K plus three and finally

76
00:07:23,950 --> 00:07:25,630
‫this would be at plus four.

77
00:07:26,200 --> 00:07:29,440
‫So no longer I keep my bpci.

78
00:07:29,440 --> 00:07:36,510
‫Are values equal during K, K plus one K plus two plus three and plus four.

79
00:07:37,180 --> 00:07:43,960
‫Now what I do, I give this information to the NPC controller in this form.

80
00:07:44,500 --> 00:07:52,330
‫And so in the global picture, the Passi, our values will look like this, it will increase in a linear

81
00:07:52,330 --> 00:07:52,900
‫fashion.

82
00:07:53,470 --> 00:08:03,070
‫But of course if in the next outer loop I have a very big sigh, ah, then the slope of this yellow

83
00:08:03,070 --> 00:08:04,630
‫line will increase.

84
00:08:05,170 --> 00:08:11,050
‫And then if all of a sudden my PCR is like this, then this yellow line would be like this.

85
00:08:11,650 --> 00:08:13,350
‫But these are straight lines here.

86
00:08:13,360 --> 00:08:13,740
‫All right.

87
00:08:14,290 --> 00:08:16,240
‫This is not a parable or anything.

88
00:08:16,930 --> 00:08:18,760
‫These are straight lines.

89
00:08:19,330 --> 00:08:24,970
‫But of course, the straight lines can have different slopes in every outer loop.

90
00:08:25,600 --> 00:08:31,750
‫But of course, if you have a spiral, then there will simply be a straight line.

91
00:08:32,350 --> 00:08:39,730
‫When I tried that, then the rotation of the drone about the body from Z axis was much smoother.

92
00:08:40,300 --> 00:08:48,160
‫I tried the same thing for fire and theater as well, but that made the results worse so far.

93
00:08:48,160 --> 00:08:56,440
‫And Sittar, they still have this structure where they do not change with K and K plus one and plus

94
00:08:56,440 --> 00:08:56,740
‫two.

95
00:08:57,160 --> 00:09:00,100
‫However, are does change.

96
00:09:00,670 --> 00:09:04,260
‫And remember, zero was generated in the planner.

97
00:09:04,270 --> 00:09:06,970
‫It wasn't computed in the position controller.

98
00:09:07,510 --> 00:09:16,240
‫And so in the code, the change that has happened in order to achieve this behavior is the following.

99
00:09:16,840 --> 00:09:22,720
‫I delete this line here and then I uncommented this piece of code.

100
00:09:23,140 --> 00:09:31,600
‫So this piece of code, it achieves this behavior here you can see that there is a for loop here and

101
00:09:31,600 --> 00:09:33,090
‫essentially was have.

102
00:09:33,430 --> 00:09:45,600
‫Here inside this for Loop is exactly that, so every your step, your SIRF vector gets a different value

103
00:09:46,170 --> 00:09:47,790
‫and it follows this logic.

104
00:09:48,360 --> 00:09:55,020
‫Every outer loop, you either have a positive linear line or a negative linear line.

105
00:09:55,590 --> 00:10:02,250
‫As a result, your drone rotates about the body from the axis in a smoother way.

106
00:10:02,700 --> 00:10:11,940
‫And you can see that when I zoom in now, then in blue, your values increase linearly and that makes

107
00:10:12,450 --> 00:10:15,070
‫tracking of it much better.

108
00:10:15,660 --> 00:10:18,450
‫So that's the change that I want to mention.

109
00:10:19,020 --> 00:10:26,940
‫So essentially, every outer loop, the planner will give me some kind of value, which is CRF.

110
00:10:27,600 --> 00:10:32,550
‫Then I look at the size of value in the previous outer loop.

111
00:10:33,100 --> 00:10:41,520
‫Let's say maybe it was here and then this code here, it will create a vector that will contain this

112
00:10:41,520 --> 00:10:48,290
‫value, then this value, then this value, this one and this one.

113
00:10:48,810 --> 00:10:55,370
‫So my CI, our vector will essentially have these five values.

114
00:10:55,920 --> 00:11:00,450
‫They will not be equal like for example, FAAB or Thi DA.

115
00:11:00,930 --> 00:11:09,780
‫And by the way, all these changes are in the latest downloadable code and now you have all this information

116
00:11:10,410 --> 00:11:13,500
‫and you have to store it in a specific way.

117
00:11:14,070 --> 00:11:24,450
‫You have to create an array in which you store all this, this and this and all that is stored in an

118
00:11:24,450 --> 00:11:27,450
‫array called Reft Signals.

119
00:11:27,870 --> 00:11:29,780
‫And they are not just stored there.

120
00:11:30,420 --> 00:11:34,320
‫All these reference values are stored there in a specific pattern.

121
00:11:34,890 --> 00:11:44,550
‫In this pattern is here five zero zero zero zero zero and then five one theatric, one zero one, etc..

122
00:11:45,120 --> 00:11:56,760
‫So in my red signals array, I will first store this which comes here, then this which comes here and

123
00:11:56,760 --> 00:11:59,910
‫then this which comes here.

124
00:12:00,480 --> 00:12:09,600
‫Then I store this that comes here, this one that comes here, and then this value, which is essentially

125
00:12:09,810 --> 00:12:11,280
‫this value here.

126
00:12:11,770 --> 00:12:12,240
‫Right.

127
00:12:12,870 --> 00:12:19,880
‫So it comes here then the same thing for K plus two plus three and K plus four.

128
00:12:20,520 --> 00:12:23,570
‫This is how Red Signals looks like.

129
00:12:24,150 --> 00:12:32,060
‫And then remember you have for inner loop iterations in one outer loop and your horizon period is four.

130
00:12:32,700 --> 00:12:42,780
‫And so now this are array comes into play in the first inner loop, this array, which is if you go

131
00:12:42,780 --> 00:12:52,530
‫down this one here, you can see that it extracts something from Reft Signals and this is what it extracts

132
00:12:52,950 --> 00:12:54,300
‫in the first inner loop.

133
00:12:54,810 --> 00:12:58,230
‫And then this portion goes into the NPC controller.

134
00:12:58,800 --> 00:13:02,110
‫It comes here in this NPC cost function.

135
00:13:02,640 --> 00:13:10,740
‫So this extraction in the first inner loop, it's this one here, this R so that's your first inner

136
00:13:10,740 --> 00:13:11,000
‫loop.

137
00:13:11,580 --> 00:13:20,280
‫Then in the second inner loop, you're our reference vector will extract this part from Reft Signals

138
00:13:20,730 --> 00:13:30,360
‫and now your horizon period is three and so you extract three five values, then three theta values

139
00:13:30,510 --> 00:13:33,420
‫and then three psi values.

140
00:13:33,870 --> 00:13:42,690
‫And then in the second inner loop this are array, this reference vector again it will go here then

141
00:13:42,690 --> 00:13:50,100
‫in the third inner loop, your horizon period is two and this is what are extracts from reffed signals.

142
00:13:50,550 --> 00:13:58,530
‫And this R then goes into the NPC controller and that's this R and finally in the fourth inner loop,

143
00:13:59,040 --> 00:14:07,230
‫your horizon, these one are extracts only this part from Reft Signals and then this R will go here

144
00:14:07,230 --> 00:14:09,840
‫into this NPC cost function.

145
00:14:10,410 --> 00:14:15,510
‫And then after the fourth inner loop there will be a new outer loop.

146
00:14:16,020 --> 00:14:25,230
‫So the position controller will calculate your new fire R and then you will get a new value from Sciorra.

147
00:14:25,830 --> 00:14:31,350
‫So you will have a new line for fire R, which will be different from this one.

148
00:14:31,950 --> 00:14:32,760
‫And also you will.

149
00:14:32,770 --> 00:14:39,630
‫We have a new line for Sittar, which will be different from the previous one, and you will have a

150
00:14:39,630 --> 00:14:45,230
‫new value for your ah, maybe it will be somewhere here.

151
00:14:45,810 --> 00:14:55,320
‫So let's say that here this is my Kate plus eight and then you compare it with your previous Siwan,

152
00:14:55,320 --> 00:15:04,670
‫which is this one, and then this modification in the code will create this line and then chop it linearly.

153
00:15:05,250 --> 00:15:13,650
‫And so in the new ref signals, you will have this value, this value, this value, this value and

154
00:15:13,650 --> 00:15:14,330
‫this value.

155
00:15:14,790 --> 00:15:21,060
‫And like I said, for fire and Theta are you will also have different lines.

156
00:15:21,480 --> 00:15:28,170
‫And then again, you formulate your signals according to this pattern that I showed you here.

157
00:15:28,770 --> 00:15:38,130
‫And then again, you will have four inner loops in which your ah reference vector will extract some

158
00:15:38,130 --> 00:15:46,710
‫portions from this ref signals and feed it into the NPC controller and this extraction from ref signals.

159
00:15:47,100 --> 00:15:48,260
‫It happens here.

160
00:15:48,900 --> 00:15:56,910
‫The reason why you have an if statement here is because what if your horizon period was two and not

161
00:15:56,910 --> 00:15:57,360
‫four?

162
00:15:57,990 --> 00:16:06,240
‫Then in the first inner loop you're our reference vector would only extract this portion.

163
00:16:06,870 --> 00:16:13,830
‫Then in the second inner loop it would extract this portion here in the third inner loop.

164
00:16:14,370 --> 00:16:16,740
‫It would extract this portion here.

165
00:16:17,340 --> 00:16:22,950
‫And finally in the fourth inner loop, it would extract this portion here.

166
00:16:23,490 --> 00:16:30,720
‫As you can see that in this case, in the first inner loop, your Horizons period was two.

167
00:16:31,350 --> 00:16:35,220
‫In the second inner loop, your horizon period was still two.

168
00:16:35,820 --> 00:16:40,620
‫In the third inner loop, it was still two and only in the fourth inner loop.

169
00:16:41,190 --> 00:16:44,760
‫It became one because you started hitting the wall, right.

170
00:16:45,360 --> 00:16:47,190
‫That was the end of your rift signals.

171
00:16:47,400 --> 00:16:49,500
‫You cannot go out of the rift signals.

172
00:16:49,980 --> 00:16:56,760
‫And so in this case, this piece of code will behave like this in the first inner loop.

173
00:16:57,300 --> 00:17:04,830
‫You come here then in the second inner loop, you come here, then in the third inner loop, you also

174
00:17:04,830 --> 00:17:10,770
‫come here and then in the fourth inner loop because you need to decrease your horizon, period.

175
00:17:11,400 --> 00:17:12,770
‫You come into this block.

176
00:17:13,260 --> 00:17:16,440
‫But in our case, Horizon period equals four.

177
00:17:16,980 --> 00:17:20,100
‫In that case, that would be your first inner loop.

178
00:17:20,640 --> 00:17:25,350
‫When your horizon period equals four, that would be your second inner loop.

179
00:17:25,920 --> 00:17:30,780
‫And now already your horizon power decreases because you're hitting the wall.

180
00:17:31,410 --> 00:17:40,080
‫Then here this would be your third inner loop and horizon period equals two and this would be your fourth

181
00:17:40,080 --> 00:17:43,120
‫inner loop where your horizon equals one.

182
00:17:43,740 --> 00:17:52,590
‫So in our case, you first enter into this block here in the first inner loop and then in the second,

183
00:17:52,800 --> 00:17:59,670
‫third and fourth inner loop, you enter here because you need to decrease your horizon, period, because

184
00:17:59,670 --> 00:18:00,610
‫you're hitting the wall.

185
00:18:01,140 --> 00:18:09,240
‫So this conditional statement, it's to manage this situation when you start hitting the wall of rough

186
00:18:09,280 --> 00:18:17,310
‫signals, because you can imagine that if I keep my horizon period for here, then I will want to extract

187
00:18:17,430 --> 00:18:20,520
‫a lot more from red signals.

188
00:18:21,030 --> 00:18:22,260
‫But there is no more.

189
00:18:22,800 --> 00:18:25,740
‫And that's why I have this conditional statement here.

190
00:18:26,310 --> 00:18:30,360
‫But now you know the difference between R and ref signals.

