1
00:00:00,480 --> 00:00:05,910
In this lesson we will be sending commands to fly the drones in different directions.

2
00:00:05,970 --> 00:00:13,990
We'll be using commands such as Up down left right forward and backwards looking at the API.

3
00:00:14,010 --> 00:00:17,220
You'll find some X's after the command.

4
00:00:17,220 --> 00:00:24,300
These X's can be set with numbers from 20 to 500 which will be the length in centimeters.

5
00:00:24,300 --> 00:00:26,910
This is based on SDK 2.0.

6
00:00:26,910 --> 00:00:33,020
So maybe in the near future there may be changes in the numbers depending on the drone version.

7
00:00:33,090 --> 00:00:39,450
Please revise your numbers in case there are any changes in the SDK for some of you.

8
00:00:39,480 --> 00:00:43,260
You may not be familiar with centimeters in our code.

9
00:00:43,260 --> 00:00:51,180
We will set the drone to measurements and feats also just to give you an idea and measurements one feat

10
00:00:51,300 --> 00:00:54,660
is thirty point four eight centimeters.

11
00:00:54,660 --> 00:00:59,030
Now let's get started with our codes first.

12
00:00:59,060 --> 00:01:06,730
Let's start by setting a default value default distance will be set to zero point three zero.

13
00:01:06,780 --> 00:01:09,630
For those of you who are familiar with centimeters.

14
00:01:09,660 --> 00:01:12,420
This means 30 centimetres.

15
00:01:12,420 --> 00:01:19,470
If I change to 4 0 to a 1 that will mean one meter and 30 centimetres.

16
00:01:19,470 --> 00:01:25,740
I do want to warn you if you are thinking of changing this value you will be flying your drone inside

17
00:01:26,040 --> 00:01:29,490
so you don't want to set the default to a big number.

18
00:01:29,490 --> 00:01:35,730
For those of you who wish to use the centimeter metric you should add a code to the initial settings

19
00:01:36,570 --> 00:01:40,920
you will set is imperial false.

20
00:01:40,920 --> 00:01:44,100
Also we need to set the length as an argument.

21
00:01:44,100 --> 00:01:48,480
We will need to set self is imperial.

22
00:01:48,720 --> 00:01:49,720
Now scroll down.

23
00:01:49,740 --> 00:01:52,790
Let's add this after land.

24
00:01:53,220 --> 00:02:01,260
Define a method named move and set the first argument as direction in this direction argument will be

25
00:02:01,260 --> 00:02:09,690
set to change to command names such as up or left the direction will be followed by distance.

26
00:02:09,870 --> 00:02:17,160
If the distance is set to 30 centimetres the argument will be placed with zero point three zero for

27
00:02:17,160 --> 00:02:20,210
the distance will set it as a float.

28
00:02:20,430 --> 00:02:27,860
If the distance is imperial meaning it's set to FT metrics we need to rounded and multiply by thirty

29
00:02:27,860 --> 00:02:29,990
eight point four eight.

30
00:02:30,120 --> 00:02:35,310
If the distance is not imperial that will mean it set to centimeter metrics.

31
00:02:35,340 --> 00:02:40,680
So we need to rounded up and multiply by hundred.

32
00:02:40,700 --> 00:02:49,550
Now we will return self then command here we will be using f strings in the parentheses we set f followed

33
00:02:49,550 --> 00:02:53,540
by a curly braces with the direction and another curly braces.

34
00:02:53,540 --> 00:03:00,510
With distance Next we need to set the directions in the move method.

35
00:03:00,510 --> 00:03:09,140
Let's take up as an example def up and we set the distance of the default distance we set to return

36
00:03:09,140 --> 00:03:17,700
to self move with the command up and the distance once we make this object we can set the drone manager

37
00:03:18,060 --> 00:03:26,220
up with the distance of 30 centimeters then self move will be returned with the up command and the distance

38
00:03:26,310 --> 00:03:29,380
as zero point three.

39
00:03:29,430 --> 00:03:33,170
These numbers will be set to the move method arguments.

40
00:03:33,600 --> 00:03:35,970
The distance will be calculated as float.

41
00:03:37,380 --> 00:03:43,590
If the distance is set to fit metrics we will need to change the number and centimeters by multiplying

42
00:03:43,590 --> 00:03:45,180
with thirty point four eight

43
00:03:48,030 --> 00:03:50,830
if the distance is set to centimeter metrics.

44
00:03:50,850 --> 00:03:56,160
It will be multiplied by a hundred as we are using round.

45
00:03:56,250 --> 00:04:00,510
The number will be round off and set as an integer.

46
00:04:00,510 --> 00:04:01,990
Then the process will return.

47
00:04:02,010 --> 00:04:10,980
Self command as this is at f string direction will be set up and distance will be set to 30.

48
00:04:11,040 --> 00:04:18,900
If you're not familiar with F strings I'll rewrite this in a format style with curly braces 0 come a

49
00:04:18,900 --> 00:04:20,730
one point format

50
00:04:22,960 --> 00:04:26,260
parenthesis direction and distance.

51
00:04:26,260 --> 00:04:31,540
For those of you who are familiar with Python 2 we used to use them.

52
00:04:31,540 --> 00:04:34,240
Percentage marks like this.

53
00:04:34,600 --> 00:04:37,070
All three codes mean the same thing.

54
00:04:37,120 --> 00:04:43,060
F string started from Python three point six so I'll be using the first code style.

55
00:04:43,060 --> 00:04:47,190
Feel free to use what you are familiar with.

56
00:04:47,290 --> 00:04:49,540
We've completed the up method.

57
00:04:49,540 --> 00:04:51,820
The rest will be very easy.

58
00:04:51,910 --> 00:04:54,670
Copy the up method and paste 5 times

59
00:04:57,460 --> 00:04:59,500
we need to set down.

60
00:04:59,500 --> 00:05:01,810
Remember to change the command name also.

61
00:05:02,290 --> 00:05:06,880
Then left and left right and right.

62
00:05:06,880 --> 00:05:13,090
Forward and forward back and back.

63
00:05:13,090 --> 00:05:15,310
We've completed all the methods.

64
00:05:15,310 --> 00:05:18,010
Let's prepare to fly the drone.

65
00:05:18,010 --> 00:05:22,030
The drone will take off and sleep for 10 seconds.

66
00:05:22,030 --> 00:05:23,190
Let's use the drone.

67
00:05:23,210 --> 00:05:26,810
Manage your forward method to move forward.

68
00:05:26,830 --> 00:05:29,800
The default is set to 30 centimetres.

69
00:05:29,800 --> 00:05:34,560
Make sure you have plenty of room and not set the numbers too high.

70
00:05:34,570 --> 00:05:37,470
Now let's sleep for another 5 seconds.

71
00:05:37,580 --> 00:05:40,330
Next fly to the right.

72
00:05:40,330 --> 00:05:41,560
Then we fly back

73
00:05:46,040 --> 00:05:51,350
flied to the left and go up last.

74
00:05:51,380 --> 00:05:55,080
We go down and land.

75
00:05:55,670 --> 00:05:59,900
We're all set so let's run this code.

76
00:06:00,100 --> 00:06:03,950
Here you see the drone received the takeoff command.

77
00:06:04,450 --> 00:06:12,490
Here we are waiting for the 10 seconds.

78
00:06:12,670 --> 00:06:18,560
Now it flies forward for 30 centimetres hovers for five seconds.

79
00:06:18,970 --> 00:06:24,480
Then it flies right hovers five seconds again not flies back and hovers.

80
00:06:24,480 --> 00:06:25,450
Five seconds

81
00:06:30,150 --> 00:06:33,990
then it flies left and hovers five seconds.

82
00:06:33,990 --> 00:06:35,370
Next we go up

83
00:06:40,790 --> 00:06:45,470
and down and now the drone lands.

84
00:06:47,510 --> 00:06:51,780
I hope you were able to fly your drone and all the different directions.

85
00:06:51,890 --> 00:06:54,740
I'll be looking forward to seeing you in our next lesson.
