-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject-keyboardControlImageCapture.py
More file actions
executable file
·99 lines (71 loc) · 1.91 KB
/
Project-keyboardControlImageCapture.py
File metadata and controls
executable file
·99 lines (71 loc) · 1.91 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 26 20:19:37 2021
@author: andre-itv
"""
import keyPressModule as kp
from djitellopy import tello
import time
import cv2
# Inicia o módulo de capturar o teclado com pygame
kp.init()
# Cria o objeto tello paracontrolar o drone
me = tello.Tello()
# Conecta com o drone e checa nível de bateria
me.connect()
print(f'Battery: {me.get_battery()}')
# Cria a variável para salvar as imagens
global img
# Inicia o steam da câmera
me.streamon()
# Função para realizar os comandos de voo
def getKeyboardInput():
# lr: left - rigth
# fb: forward - backward
# ud: up - down
# yv: yaw velocity
lr, fb, ud, yv = 0, 0, 0, 0
speed = 50
# Captura dos movimentos
if kp.getKey('LEFT'):
lr = -speed
elif kp.getKey('RIGHT'):
lr = speed
if kp.getKey('UP'):
fb = speed
elif kp.getKey('DOWN'):
fb = -speed
if kp.getKey('w'):
ud = speed
elif kp.getKey('s'):
ud = -speed
if kp.getKey('a'):
yv = -speed
elif kp.getKey('d'):
yv = speed
# Captura das teclas de takeoff e land
if kp.getKey('e'):
me.takeoff()
if kp.getKey('q'):
me.land()
# Captura da tecla de salvar foto
if kp.getKey('z'):
cv2.imwrite(f'Resources/Images/{time.time()}.jpg', img)
time.sleep(0.3)
return [lr, fb, ud, yv]
while True:
# Captura as teclas
vals = getKeyboardInput()
# Envia comandos de voo parao drone
me.send_rc_control(vals[0], vals[1], vals[2], vals[3])
# Captra o frame
img = me.get_frame_read().frame
#img = cv2.resize(img, (360, 240))
cv2.imshow('image from Drone', img)
c = cv2.waitKey(1)
if c == 27:
me.land()
time.sleep(2)
break
cv2.destroyAllWindows()