-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDroneMovements.py
82 lines (57 loc) · 1.62 KB
/
DroneMovements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import threading
from djitellopy import tello
import cv2
from time import sleep
imgSaved = None
def getBattery():
f = open("Battery.txt", "w")
f.write(str(me.get_battery()))
f.close()
f = open("Battery.txt", "r")
lines = f.readlines()
print(lines)
f.close()
me = tello.Tello()
me.connect()
getBattery()
def land():
me.land()
def takeoff():
me.takeoff()
def control_drone(action='l', LR=0, FB=0, UD=0, Yaw=0, SLP=2):
if action == 'l':
me.send_rc_control(LR // SLP, FB // SLP, UD // SLP, Yaw // SLP)
sleep(SLP + 1)
elif action == 'c':
me.rotate_clockwise(LR)
sleep(1)
elif action == 'f':
me.flip_back()
sleep(SLP)
elif action == 'lo':
sleep(4)
global imgSaved
imgSaved = me.get_frame_read().frame # individual image
saved = cv2.imwrite("savedImage.jpg", imgSaved)
else:
return
def safeLand():
control_drone('l', 0, 0, 0, 0)
land()
def imageCapture():
while True:
img = me.get_frame_read().frame # individual image
cv2.imshow("Image", img)
cv2.waitKey(1) # delay shutdown
path = [('l', 0, 0, 20, 0), ('c', 43), ('l', 0, 40, 0, 0), ('lo',), ('l', 0, -40, 0, 0), ('l', 0, 0, -20, 0)]
path2 = [('lo',)]
square_path = [('l', 0, 0, 50, 0), ('c', -90), ('l', 0, 50, 0, 0), ('c', 90), ('l', 0, 50, 0, 0), ('c', 90),
('l', 0, 50, 0, 0), ('c', 90), ('l', 0, 50, 0, 0), ('f',), ('l', 0, 0, -50, 0)]
me.streamon()
x = threading.Thread(target=imageCapture, args=())
x.start()
takeoff()
for action in path:
control_drone(*action)
safeLand()
x.join()