Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions detect_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def process(frame):
Args:
frame: Frame de vídeo a ser processado para detecção de QR codes.
Returns:
frame: Frame processado após a detecção e execução dos comandos.
[frame, x, y, x+w, y+h, len(decoded_objects), qr_text]
'''
decoded_objects = decode(frame)
global x, y, w, h, data, qr_text
Expand All @@ -28,4 +28,4 @@ def process(frame):
#print(data)
return [frame, x, y, x+w, y+h, len(decoded_objects), qr_text]

#cv2.namedWindow('QR Code', cv2.WINDOW_AUTOSIZE)
#cv2.namedWindow('QR Code', cv2.WINDOW_AUTOSIZE)
3 changes: 1 addition & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
#print(data)
#cap.release()
tello.end_tello()
cv2.destroyAllWindows()

cv2.destroyAllWindows()
28 changes: 26 additions & 2 deletions tello_control.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from tracking_base import tracking
from detect_qr import process
import time
Expand All @@ -8,6 +9,22 @@
start_time = time.time() # Inicializa o tempo
searching = False

logging.basicConfig(
filename="codes/log.txt",
level=logging.INFO,
format="%(asctime)s - %(message)s",
datefmt="%d-%m-%Y %H:%M:%S"
)

def log_command(command, response=None):
'''
Registra um comando enviado e a resposta recebida no log.
Args:
command (str): Comando enviado ao drone.
response (str, opcional): Resposta recebida do drone.
'''
logging.info(f"{command}, {response}")

def timer():
'''
Função que verifica se o timer de 5 segundos expirou.
Expand All @@ -32,7 +49,8 @@ def search(tello, frame):
'''
response = tello.send_cmd('ccw 20') # Rotaciona 20 graus
time.sleep(0.01) # testar se resposta é exibida
print(f"Rotação enviada: {response}")
print(f"Rotação: {response}")
log_command('ccw 20', response)
return frame

def moves(tello, frame):
Expand All @@ -58,22 +76,28 @@ def moves(tello, frame):
frame = search(tello, frame)
elif old_move == 'follow': # necessário para que o drone não continue a se movimentar sem detecção de follow
tello.send_rc_control(0, 0, 0, 0)
log_command('rc 0 0 0 0')

if text == 'follow':
frame = tracking(tello, frame)
log_command('follow') # ver como vai ficar isso

if detections == 1 and text == 'land':
while float(tello.get_state_field('h')) >= 13:
tello.send_rc_control(0, 0, -70, 0)
tello.send_cmd(str(text))
log_command(text)

elif detections == 1 and text == 'takeoff' and old_move != 'takeoff':
response = tello.send_cmd_return(text)
print(f"{text}' '{response}")
log_command(text, response)

elif detections == 1 and text in pace_moves:
response = tello.send_cmd_return(f"{text}{pace}")
print(f"{text}{pace}' '{response}")
log_command(f"{text}{pace}", response)

old_move = text
return frame
print(f"Old move: {old_move}")
return frame
10 changes: 3 additions & 7 deletions tracking_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
Kd = 0.2

width_detect = 0
area_land = 0
text = ''
response = ''
old_move = ''

def tracking(tello, frame):
'''
Processa o frame para detectar QR codes e executa comandos no drone Tello com base no texto detectado.
Expand All @@ -31,7 +30,7 @@ def tracking(tello, frame):
Returns:
frame: Frame processado após a detecção e execução dos comandos.
'''
global prevErrorX, prevErrorY, CenterX, CenterY, Kp, Kd, text, width_detect, area_land
global prevErrorX, prevErrorY, CenterX, CenterY, Kp, Kd, text, width_detect
_, x1, y1, x2, y2, detections, text = process(frame)
speedFB = 0
cxDetect = (x2 + x1) // 2
Expand Down Expand Up @@ -80,7 +79,4 @@ def tracking(tello, frame):
#o erro atual vira o erro anterior
prevErrorX = errorX
prevErrorY = errorY
return frame



return frame