﻿1
00:00:00,610 --> 00:00:01,420
‫Welcome back.

2
00:00:02,050 --> 00:00:07,770
‫Now I'm going to give you a general explanation of the code, so let's get started.

3
00:00:08,760 --> 00:00:15,300
‫The code has the same structure, like in the case of the autonomous vehicle, it's just slightly larger.

4
00:00:16,270 --> 00:00:22,450
‫You still have to files, you have the main file and then you have the support file, the main file

5
00:00:22,450 --> 00:00:29,740
‫is called like this main underscore, LPT, underscore, MPAC, underscore that pie and then the support

6
00:00:29,740 --> 00:00:35,470
‫file is this one support on the score files underscore drone that pie.

7
00:00:35,830 --> 00:00:43,330
‫And remember, these two files need to be in the same folder and then remember that you have to run

8
00:00:43,480 --> 00:00:44,750
‫the main file.

9
00:00:45,730 --> 00:00:52,240
‫So even though both of them need to be in the same folder, you have to run the main file, not the

10
00:00:52,240 --> 00:00:53,160
‫support file.

11
00:00:53,950 --> 00:00:56,140
‫You have to run this file here.

12
00:00:56,560 --> 00:01:02,800
‫And then this file will communicate with the support file on its own and again, make sure that they're

13
00:01:02,830 --> 00:01:04,070
‫in the same folder.

14
00:01:04,090 --> 00:01:05,330
‫That's very important.

15
00:01:06,160 --> 00:01:08,270
‫So what's new in the structure?

16
00:01:09,160 --> 00:01:16,000
‫Well, in the support file, you have one more function called porc on this controller.

17
00:01:16,720 --> 00:01:18,250
‫That's for position control.

18
00:01:19,060 --> 00:01:22,860
‫And in the main file, you have one more loop.

19
00:01:23,770 --> 00:01:28,270
‫Remember that we have the outer loop and the inner loop.

20
00:01:29,360 --> 00:01:36,860
‫So the outer loop would be for this for loop here, that happens every zero point four seconds and then

21
00:01:36,860 --> 00:01:43,490
‫the inner loop, which is this one which runs everything open one second, it runs four times per one

22
00:01:43,490 --> 00:01:44,270
‫outer loop.

23
00:01:45,110 --> 00:01:49,840
‫Everything else, even though adapted to a drone, has the same structure.

24
00:01:51,230 --> 00:01:59,570
‫And so let's get started in the meanwhile, we start by importing all the necessary laborers that are

25
00:01:59,570 --> 00:02:00,140
‫here.

26
00:02:01,100 --> 00:02:09,230
‫This one here that's actually part of matplotlib and it comes together with matplotlib and it enables

27
00:02:09,230 --> 00:02:13,040
‫me to animate that drone in 3D.

28
00:02:13,640 --> 00:02:18,220
‫But it did not fully work in matplotlib three point thirty point three.

29
00:02:18,620 --> 00:02:27,860
‫So because of this one here, I had to get my three point two point two, then I have to create an object.

30
00:02:28,250 --> 00:02:29,510
‫That's this one here.

31
00:02:29,510 --> 00:02:39,170
‫I'm creating an object here and then I'm going to load all the initial constants from this init function

32
00:02:39,170 --> 00:02:42,440
‫in the support file, this support file.

33
00:02:42,920 --> 00:02:44,630
‫It's like one big class.

34
00:02:45,560 --> 00:02:52,610
‫So if you look at this here, you have the support file and you see this super file.

35
00:02:52,610 --> 00:02:54,200
‫It's one big class.

36
00:02:54,620 --> 00:02:58,040
‫And in this class you have several functions.

37
00:02:58,990 --> 00:03:06,730
‫You have this innate function, then you have this trajectory generator function, then you have the

38
00:03:06,730 --> 00:03:10,050
‫position controller function and cetera.

39
00:03:10,870 --> 00:03:17,860
‫And so these are all your functions in this class that you have in the support file.

40
00:03:18,670 --> 00:03:27,640
‫And so once the main file creates an object based on this class here, that's when the main file can

41
00:03:27,640 --> 00:03:32,050
‫start using the functions inside this class.

42
00:03:33,000 --> 00:03:39,570
‫And so the first thing that this, meanwhile, is going to do, it's going to take all the initial constants

43
00:03:39,900 --> 00:03:44,130
‫from this init function, it happens here.

44
00:03:44,250 --> 00:03:47,850
‫Konstanz equals support that Constance.

45
00:03:48,780 --> 00:03:55,260
‫And if you look at this in its function here, then these are all your initial constants and they are

46
00:03:55,260 --> 00:03:58,590
‫all stored here in this vector.

47
00:03:58,800 --> 00:04:02,660
‫In this list, you see it's a pretty long list.

48
00:04:02,880 --> 00:04:06,330
‫I think you have either thirty four, thirty five elements here.

49
00:04:07,110 --> 00:04:12,510
‫And in this main file, they will be stored in this variable here constants.

50
00:04:13,590 --> 00:04:20,520
‫It will be a vector from which I can take my initial concerns, for example, if I want the sample time

51
00:04:20,520 --> 00:04:27,830
‫interval interrelates, then it's going to be the seventh element in this constant vector.

52
00:04:28,080 --> 00:04:30,540
‫Why do I say the seventh element?

53
00:04:31,440 --> 00:04:34,260
‫Because in Python you start counting from zero.

54
00:04:34,260 --> 00:04:40,760
‫So zero one, two, three, four, five and six.

55
00:04:41,220 --> 00:04:46,090
‫So it's it's the seventh element because you start counting from zero.

56
00:04:46,800 --> 00:04:54,240
‫So if you go from zero to six, actually you have seven elements here and they define the sample time

57
00:04:54,390 --> 00:04:57,180
‫interval value right here.

58
00:04:57,180 --> 00:04:59,880
‫T equals zero point one seconds.

59
00:05:00,720 --> 00:05:08,430
‫And now let's look at the initial constants more closely just for you to know all these parameters.

60
00:05:08,760 --> 00:05:13,230
‫They belong to a movie called Aztec Hummingbird.

61
00:05:14,070 --> 00:05:16,710
‫You have the mass moments of inertia here.

62
00:05:17,340 --> 00:05:18,630
‫You have the mass.

63
00:05:19,740 --> 00:05:21,660
‫You have the gravity acceleration.

64
00:05:22,740 --> 00:05:26,580
‫You also have the Mars moment of inertia of the propeller.

65
00:05:27,630 --> 00:05:29,400
‫You have the sample time interval.

66
00:05:30,430 --> 00:05:38,650
‫You have the NPC wait Matrixes, Q, s and R, as you can see, they are now three by three diagonal

67
00:05:38,650 --> 00:05:39,670
‫weight matrixes.

68
00:05:40,660 --> 00:05:48,550
‫You have the trust factor here, you have the drag factor here, and then you have the length and that's

69
00:05:48,550 --> 00:05:54,730
‫the length from the center of the drone to the center of any of the propeller's.

70
00:05:55,760 --> 00:06:03,740
‫So if you remember then, the trust factor was this one here, you used it in you one, you two and

71
00:06:03,740 --> 00:06:12,050
‫you three in those equations, were you related the control inputs with the angular velocity of the

72
00:06:12,050 --> 00:06:19,430
‫drone and then your drag factor is here where you related your EUFOR with your Omega's.

73
00:06:20,530 --> 00:06:28,570
‫So see, Sabeti, that was your trust factor and then see subcu, that was your drag factor and then

74
00:06:28,570 --> 00:06:38,110
‫your length was from the center of the drone right here where my mouth is up until the center of any

75
00:06:38,110 --> 00:06:39,280
‫of the propellers.

76
00:06:39,830 --> 00:06:42,700
‫That was your length then?

77
00:06:42,700 --> 00:06:45,600
‫I have this variable here, controlled states.

78
00:06:46,030 --> 00:06:55,120
‫So basically here for the NPC purposes, I'm saying that the number of my added to the outputs Phi Theta

79
00:06:55,120 --> 00:07:02,770
‫and BPCI, their amount is three because you have five Seeta and three edited outputs.

80
00:07:03,860 --> 00:07:12,200
‫I will use that later to formulate a reference value vector, then this is my horizon period, which

81
00:07:12,200 --> 00:07:20,390
‫is for then I also have this viable inner dynamics length inner DAINE and then on the skirt length,

82
00:07:20,390 --> 00:07:21,850
‫which also equals four.

83
00:07:22,310 --> 00:07:33,920
‫So that essentially tells me how many inner control loop interactions I have per one outer loop iteration.

84
00:07:35,210 --> 00:07:43,970
‫Then I define my polls here, so polls for the X, Y and Z dimensions, respectively, and these are

85
00:07:43,970 --> 00:07:45,070
‫the real polls.

86
00:07:45,620 --> 00:07:54,380
‫And then here I can also uncommented the complex polls that contain the imaginary part as well.

87
00:07:55,160 --> 00:08:00,710
‫And then these variables here, therefore, the trajectories, for example.

88
00:08:01,220 --> 00:08:09,470
‫This is the radius of the spiral that you have seen before then the frequency which pretty much determines

89
00:08:09,710 --> 00:08:18,860
‫how many rotations in the spiral on the X Y plane you're going to have in one hundred seconds because

90
00:08:18,860 --> 00:08:22,210
‫our simulation length will be one hundred seconds.

91
00:08:23,180 --> 00:08:26,600
‫So right now my spiral looks like this.

92
00:08:27,650 --> 00:08:36,350
‫But if I increase my frequency and I multiply it, for example, by one point five, then I will have

93
00:08:36,350 --> 00:08:38,840
‫more rotations in that spiral.

94
00:08:38,930 --> 00:08:46,550
‫You see, in total, the simulation length is one hundred seconds, so you go from zero to one hundred

95
00:08:46,550 --> 00:08:47,210
‫seconds.

96
00:08:48,020 --> 00:08:55,850
‫But during those one hundred seconds, you will have more circles made on the X Y plane.

97
00:08:56,750 --> 00:09:03,770
‫And then this is the initial height of your spiral and then this is the final height of your spiral.

98
00:09:04,640 --> 00:09:13,430
‫So even though my drone starts from the zero meter altitude, then my spiral starts from the five meter

99
00:09:13,430 --> 00:09:18,110
‫altitude and it finishes at the twenty five meter altitude.

100
00:09:18,890 --> 00:09:22,820
‫You see, this is my Z dimension and I start from here.

101
00:09:23,030 --> 00:09:29,900
‫The Z equals zero meters, but then the reference value for the Z dimension starts from five meters

102
00:09:29,900 --> 00:09:32,090
‫and it ends at twenty five meters.

