diff --git a/detect_qr.py b/detect_qr.py index 410fe41..3605673 100644 --- a/detect_qr.py +++ b/detect_qr.py @@ -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 @@ -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) \ No newline at end of file diff --git a/main.py b/main.py index 2d8658b..00af129 100644 --- a/main.py +++ b/main.py @@ -19,5 +19,4 @@ #print(data) #cap.release() tello.end_tello() -cv2.destroyAllWindows() - +cv2.destroyAllWindows() \ No newline at end of file diff --git a/tello_control.py b/tello_control.py index 3f282d0..33e019f 100644 --- a/tello_control.py +++ b/tello_control.py @@ -1,3 +1,4 @@ +import logging from tracking_base import tracking from detect_qr import process import time @@ -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. @@ -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): @@ -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 \ No newline at end of file diff --git a/tracking_base.py b/tracking_base.py index 5a2f392..6d2a27b 100644 --- a/tracking_base.py +++ b/tracking_base.py @@ -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. @@ -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 @@ -80,7 +79,4 @@ def tracking(tello, frame): #o erro atual vira o erro anterior prevErrorX = errorX prevErrorY = errorY - return frame - - - + return frame \ No newline at end of file