5
5
from inspect import signature
6
6
7
7
tello = Tello ()
8
- tello .connect ()
9
- tello .streamon ()
10
8
11
9
school_distance = 359 # distance to the school building in cm from helipad
12
10
back_bridge_distance = 620 # distance from helipad to back of bridge line in cm
13
- back_to_middle_bridge_distance = 190 # distance from the back of the bridge to the middle where color square is (needs to be calibrated)
14
- manual_commands = { # I could've used match statement, but IDK, I just felt like using this instead.
11
+ # ToDo: Calibrate distance
12
+ back_to_middle_bridge_distance = 190 # distance from the back of the bridge to the middle where color square is
13
+ manual_commands = { # I could've used a match statement, but IDK, I just felt like using this instead.
15
14
'w' : tello .move_forward ,
16
15
's' : tello .move_back ,
17
16
'd' : tello .move_right ,
18
17
'a' : tello .move_left ,
19
18
't' : tello .takeoff ,
20
19
'l' : tello .land ,
21
20
}
22
- manual_commands_str = "\n " .join ([f"{ letter } : { func .__name__ } " for letter , func in manual_commands .items ()]) # commands in human-readable format
23
- battery_left = tello .get_battery () # how much batter left
21
+ manual_commands_str = "\n " .join (
22
+ [f"{ letter } : { func .__name__ } " for letter , func in manual_commands .items ()]) # commands in human-readable format
23
+ battery_left = tello .get_battery () # how much battery left
24
24
25
- def enter_manual_mode ():
25
+
26
+ def enter_manual_mode () -> None :
26
27
"""
27
28
Enters Manual Mode
28
29
29
30
Commands are:
30
31
- w: moves the drone forward
31
- - s: moves the drone backword
32
+ - s: moves the drone backward
32
33
- d: moves the drone right
33
34
- a: moves the drone left
34
35
- t: takeoff
35
36
- l: lands
36
37
"""
37
38
distance = 50
38
-
39
+
39
40
while True :
40
41
for letter , func in manual_commands .items ():
41
42
if keyboard .is_pressed (letter ):
42
43
# checking for the number of arguments the function takes
43
- if len (signature (func ).parameters ) == 1 :
44
+ if len (signature (func ).parameters ) > 0 :
45
+ # noinspection PyArgumentList
44
46
func (distance )
45
47
else :
46
48
func ()
47
49
elif keyboard .is_pressed ('q' ):
48
50
# getting outta manual mode
49
51
return
50
52
51
- def get_color ():
52
- """ TODO """
53
+
54
+ def get_color () -> None :
55
+ # ToDo
53
56
# tello code to get color from building
54
57
tello .takeoff ()
55
58
tello .move_up (100 ) # needs to check this distance go over the building
@@ -62,35 +65,38 @@ def get_color():
62
65
tello .move_right (back_to_middle_bridge_distance )
63
66
tello .land ()
64
67
65
- def enter_recon_path ():
66
- """ TODO """
68
+
69
+ def enter_recon_path () -> None :
70
+ # ToDo
67
71
# first recon path
68
72
tello .takeoff ()
69
73
tello .move_forward (school_distance )
70
74
# HERE IS WHERE CODE GO FOR PARACHUTE DROP
71
75
tello .move_back (school_distance )
72
76
tello .land ()
73
77
74
- def main ():
78
+
79
+ def main () -> None :
75
80
while True :
76
81
img = tello .get_frame_read ().frame
77
82
img = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
78
83
cv2 .imshow ('frame' , img )
79
-
84
+
80
85
if keyboard .is_pressed ('r' ):
81
86
enter_recon_path ()
82
87
elif keyboard .is_pressed ('c' ):
83
88
get_color ()
84
89
elif keyboard .is_pressed ('m' ):
85
90
enter_manual_mode ()
86
91
92
+
87
93
if __name__ == '__main__' :
94
+ tello .connect ()
95
+ tello .streamon ()
96
+
88
97
Tello .LOGGER .info (f"Battery: { battery_left } %" )
89
98
90
99
try :
91
100
main ()
92
- except KeyboardInterrupt :
93
- tello .land ()
94
- exit (1 )
95
101
finally :
96
102
tello .land ()
0 commit comments