﻿1
00:00:00,420 --> 00:00:01,150
‫Welcome back.

2
00:00:01,620 --> 00:00:12,210
‫And so, as discussed before, the rest of the code after these inner and outer loops is about animation

3
00:00:12,480 --> 00:00:13,440
‫and plotting.

4
00:00:14,100 --> 00:00:16,980
‫So you can see it here as well, animation and then plotting.

5
00:00:18,090 --> 00:00:25,770
‫Now, if we look at plotting first, then plotting starts here after the end of the animation.

6
00:00:26,610 --> 00:00:34,920
‫And notice that here you have this no plots variable that you could assign a value to in the init function.

7
00:00:35,730 --> 00:00:42,240
‫So if you don't want to see plots, then in the next function you assign this value to be one and then

8
00:00:42,240 --> 00:00:43,620
‫you will exit the program.

9
00:00:44,310 --> 00:00:54,480
‫But if this values zero or actually any other value, then you will enter this block here and then it

10
00:00:54,480 --> 00:00:56,640
‫will start plotting you all kinds of graphs.

11
00:00:57,760 --> 00:01:03,520
‫So this one will plot a three dimensional work for you, this is not an animation.

12
00:01:03,550 --> 00:01:08,650
‫This is the first plot that you see after you close your animation.

13
00:01:09,570 --> 00:01:12,880
‫Then here you plot your X dimensions.

14
00:01:13,660 --> 00:01:19,330
‫Here you plot your Y dimensions, and then here you plot your Z dimensions.

15
00:01:20,200 --> 00:01:30,340
‫Here you plot your five feet on BPCI angles, and then here you plot your control inputs and also your

16
00:01:30,340 --> 00:01:30,550
‫own.

17
00:01:31,780 --> 00:01:35,410
‫So it's going to be a subplot with eight sub windows.

18
00:01:36,390 --> 00:01:45,110
‫So that's plotting and then animation works pretty much like this, that you've got some kind of function

19
00:01:45,600 --> 00:01:54,060
‫and then here you have a variable number, which is a feature of matplotlib, then this num variable,

20
00:01:54,060 --> 00:01:59,920
‫it's going to go from zero to one to two, three, four.

21
00:02:00,660 --> 00:02:08,430
‫You decide how many times you call this update plot function and therefore how many times this variable

22
00:02:08,430 --> 00:02:13,710
‫number gets increased by one every time this function is called.

23
00:02:14,370 --> 00:02:18,390
‫And the decision for that you can make in the end of the animation.

24
00:02:19,170 --> 00:02:21,060
‫So it's this one here.

25
00:02:21,900 --> 00:02:26,130
‫Here you call the animation function from matplotlib.

26
00:02:26,910 --> 00:02:28,390
‫You define your figure.

27
00:02:29,190 --> 00:02:35,250
‫And so here you decide how many times you call this update plot function.

28
00:02:36,090 --> 00:02:43,710
‫And you decided by determining your frame amount here, you're going to put your frame amount and then

29
00:02:43,710 --> 00:02:48,330
‫here you're going to put interval equals, I put it 20 here.

30
00:02:48,750 --> 00:02:52,960
‫So Intervale, it's how fast your frames would change.

31
00:02:53,340 --> 00:02:54,010
‫So 20.

32
00:02:54,120 --> 00:02:55,710
‫Twenty milliseconds.

33
00:02:56,750 --> 00:03:04,700
‫So that means that it's every zero point zero two seconds, then, if you want your information to repeat,

34
00:03:04,700 --> 00:03:13,000
‫you put here through and then blit, it's there to make the animation smoother.

35
00:03:13,820 --> 00:03:21,880
‫And by the way, this update plot, that's the name of this function where you have this non variable.

36
00:03:22,610 --> 00:03:24,560
‫So that's how the program knows that.

37
00:03:24,560 --> 00:03:28,030
‫OK, we're talking about this function here.

38
00:03:28,790 --> 00:03:33,860
‫And then, of course, you have to put Palta dot show here.

39
00:03:33,870 --> 00:03:38,000
‫So this is a function that you have to put here in the end.

40
00:03:38,780 --> 00:03:46,280
‫And then this figure that you define here, well, that's defined right here.

41
00:03:46,340 --> 00:03:48,620
‫You see here I define that figure.

42
00:03:49,520 --> 00:03:51,860
‫I define the grades for that figure.

43
00:03:52,880 --> 00:03:55,280
‫I need that to create some windows.

44
00:03:56,320 --> 00:04:02,240
‫Here I define the dimensions, the resolution and then the colors for the figure.

45
00:04:02,890 --> 00:04:07,410
‫So in a nutshell, the animation works like this here.

46
00:04:07,420 --> 00:04:11,950
‫You're going to go through some variables that are related to the animation.

47
00:04:13,000 --> 00:04:21,880
‫These are the numbers that I want to use for animation here, I define my frame amount, which is the

48
00:04:21,880 --> 00:04:36,100
‫length of this state's total X vector and this state's tall sub X is states total underscore UNY and

49
00:04:36,100 --> 00:04:38,950
‫then the first column.

50
00:04:39,970 --> 00:04:48,850
‫So if we go into our support file, then if you look at this, states underscore any vector, then you

51
00:04:48,850 --> 00:04:53,590
‫see that it contains information about X, Y, Z, Fifita and Passi.

52
00:04:54,340 --> 00:04:56,710
‫And then essentially here I make them Fleener.

53
00:04:57,430 --> 00:05:11,110
‫So if X goes from zero to 10, then this states up only is five times bigger because it will take this

54
00:05:11,110 --> 00:05:16,380
‫interval from zero to 10 and it will make it into five intervals.

55
00:05:17,230 --> 00:05:23,920
‫So this matrix will then contain information like this zero two four six eight 10.

56
00:05:24,670 --> 00:05:28,060
‫Then I can create an animation that is smooth.

57
00:05:28,600 --> 00:05:37,060
‫Otherwise your drone would move, then stop for a second move and then stop for a second in the move

58
00:05:37,060 --> 00:05:38,250
‫and stop for a second.

59
00:05:39,190 --> 00:05:40,650
‫So that's the purpose of it.

60
00:05:41,470 --> 00:05:47,530
‫And so I take the X dimension of this state's total underscore unny.

61
00:05:48,370 --> 00:05:54,900
‫I take its length and then I am going to say that it's my frame amount and I could have put here states

62
00:05:54,910 --> 00:05:57,160
‫total on the score, Y or Z.

63
00:05:57,160 --> 00:05:57,910
‫Doesn't matter.

64
00:05:58,460 --> 00:05:59,920
‫They all have the same length.

65
00:06:00,610 --> 00:06:04,960
‫Then the program recognizes this animation function.

66
00:06:05,530 --> 00:06:15,760
‫It recognizes this special matplotlib update plot function with this variable NUM that is used to update

67
00:06:15,910 --> 00:06:20,140
‫your feature called Figure in which you have your animations.

68
00:06:20,680 --> 00:06:22,790
‫So first of all, it's going to skip it.

69
00:06:23,500 --> 00:06:25,960
‫Then here you're going to define your figure.

70
00:06:27,080 --> 00:06:34,130
‫Then you're going to define certain objects, like, for example, this drone Body X, that's your red

71
00:06:34,130 --> 00:06:35,140
‫beam, right?

72
00:06:35,190 --> 00:06:42,650
‫Remember, that's your drone and that's the body from X dimension that your red beam and then this one,

73
00:06:42,890 --> 00:06:45,130
‫that's your green beam.

74
00:06:45,710 --> 00:06:47,540
‫You define them as objects.

75
00:06:48,410 --> 00:06:50,720
‫You define how wide they are.

76
00:06:51,710 --> 00:06:53,780
‫And then you have other objects here as well.

77
00:06:53,810 --> 00:07:01,430
‫For example, this one here, that's your reference trajectory line, the blue one, and this is your

78
00:07:01,430 --> 00:07:02,360
‫real trajectory.

79
00:07:02,360 --> 00:07:09,890
‫That's the red line that you see in the animation that shows how the drone actually flies.

80
00:07:10,880 --> 00:07:13,240
‫Then these are some formatting features.

81
00:07:14,060 --> 00:07:18,950
‫And now if you remember then we had two versions for our simulation.

82
00:07:19,670 --> 00:07:28,880
‫If same underscore version equals one, then your Windows showed you the control inputs you want you

83
00:07:28,880 --> 00:07:35,150
‫to use three and four, how they evolved as a function of time and also how your red and green beam,

84
00:07:35,720 --> 00:07:39,770
‫how they tilted, in which direction they tilted.

85
00:07:40,550 --> 00:07:45,920
‫Then you enter into this block here and then all that becomes relevant.

86
00:07:46,340 --> 00:07:56,270
‫However, if your SIM version equals two, then you see how your drone is able to follow your X, Y,

87
00:07:56,450 --> 00:08:03,170
‫Z, and then Fifita Inside Dimensions and then you can see them separately as a function of time.

88
00:08:03,650 --> 00:08:07,970
‫And then if your SIM version equals two, you entered this block here.

89
00:08:08,930 --> 00:08:15,650
‫And then in both blocs, what you do, you create objects, you create lines for yourself, windows,

90
00:08:15,950 --> 00:08:18,600
‫so you can see that this is green.

91
00:08:18,980 --> 00:08:25,810
‫So that's the green line that represents the tilting of your green beam.

92
00:08:26,510 --> 00:08:28,150
‫And this is for the red one.

93
00:08:29,150 --> 00:08:35,030
‫These are objects for your control input lines you want.

94
00:08:35,030 --> 00:08:39,110
‫Then you to use three and then you have four.

95
00:08:40,070 --> 00:08:46,860
‫And then if you had chosen SIM version two, then you simply enter into this block.

96
00:08:46,880 --> 00:08:48,770
‫But the logic is the same.

97
00:08:48,950 --> 00:08:54,450
‫You create objects here and then you reach this place here.

98
00:08:55,130 --> 00:08:59,390
‫So the programmer knows what figure you're talking about.

99
00:09:00,140 --> 00:09:02,420
‫It knows the function.

100
00:09:02,780 --> 00:09:05,630
‫It knows the amount of frames here.

101
00:09:05,630 --> 00:09:13,130
‫You specify your interval and then you specify if you want to repeat your animation or not and whether

102
00:09:13,130 --> 00:09:14,750
‫you want to be efficient or not.

103
00:09:15,700 --> 00:09:25,870
‫And then he goes here to that show, and then you're going to jump to the beginning of that function,

104
00:09:25,870 --> 00:09:27,490
‫which is you an update plot.

105
00:09:28,440 --> 00:09:35,460
‫And so if your frame amount was 10, then your number will go from zero to nine.

106
00:09:36,420 --> 00:09:42,000
‫And now this number variable is very important because what you're going to do, you're going to take

107
00:09:42,000 --> 00:09:50,790
‫your simulation results from your control engineering part and then you want to go through those results.

108
00:09:51,810 --> 00:09:59,520
‫So, for example, if we take this object here, that's the red line in your animation, real trajectory,

109
00:10:00,240 --> 00:10:03,540
‫then if we go to our update plot function.

110
00:10:04,550 --> 00:10:13,130
‫Then your real trajectory would be here and then you would right here, real trajectory that set X data.

111
00:10:14,130 --> 00:10:24,360
‫And then you take your state's toll suspects that you got from here and then you enter that vector and

112
00:10:24,360 --> 00:10:28,560
‫then you right here from zero column to number.

113
00:10:29,010 --> 00:10:39,520
‫So you can imagine that as you go through this function, your number will go like this zero one to.

114
00:10:40,440 --> 00:10:47,940
‫So in the first iteration, it will take your first element, then it will take your first and second

115
00:10:47,940 --> 00:10:52,260
‫element, because in the second loop it would be from zero to one.

116
00:10:52,830 --> 00:10:58,230
‫Then it will be from zero to two zero to three zero to four.

117
00:10:58,470 --> 00:11:03,000
‫And that's how your red line becomes longer and longer in your animation.

118
00:11:04,040 --> 00:11:10,760
‫So if you want, then you can play around and experiment with these features here and see what you're

119
00:11:10,760 --> 00:11:14,930
‫going to get, and then you're going to learn it very well through experimentation.

120
00:11:16,120 --> 00:11:24,910
‫And then it's very important that you return your objects that you had defined before you return it

121
00:11:25,450 --> 00:11:30,610
‫here or here, depending on your version.

122
00:11:31,710 --> 00:11:39,390
‫If you have a simpler animation, then you would simply have return here and then a bunch of objects.

123
00:11:40,510 --> 00:11:44,590
‫So that's an overview of how this animation works in Python.

124
00:11:45,600 --> 00:11:54,840
‫And well, we have covered pretty much everything here in this coat and also everything in the support

125
00:11:54,840 --> 00:11:55,340
‫file.

126
00:11:56,040 --> 00:11:58,830
‫So at the beginning it looks pretty massive coat.

127
00:11:58,830 --> 00:12:05,190
‫However, these two files, they really follow the theory.

128
00:12:05,880 --> 00:12:11,220
‫Everything that you have learned so far now is just in the coat format and that's it.

