From 4454b17e18817e4da1967f9d08f1d0878964da87 Mon Sep 17 00:00:00 2001 From: Zhiying Li <zhiyingli@g.ucla.edu> Date: Mon, 8 Nov 2021 12:09:29 -0800 Subject: [PATCH] test and manul_in_auto function and fixed other bugs in test function --- Code/Control/Laptop_Code/main_keyboard.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Code/Control/Laptop_Code/main_keyboard.py b/Code/Control/Laptop_Code/main_keyboard.py index 373ec09..aeb9e42 100644 --- a/Code/Control/Laptop_Code/main_keyboard.py +++ b/Code/Control/Laptop_Code/main_keyboard.py @@ -6,7 +6,7 @@ import timeit import pygame from constants import * from ESP32_AT.imageTread_AT import get_AT_6DOF_info - +import cv2 global ml,esp_cam_on,openmv_on AT_detected_time = time.time() @@ -648,7 +648,7 @@ def test_function(): tid, tx, ty, tz, rx, ry, rz = get_AT_6DOF_info(url_AT) gbx, gby, gb_dist = ball_detection.detectLive(url_gb, model, minDetectionScore, showSight = True) - + print("testing new function") print("-----------------------") print("tid:{}".format(tid)) @@ -665,7 +665,18 @@ def test_function1(): print("tx,ty,tz:{},{},{}".format(tx,ty,tz)) print("rx,ry,rz:{},{},{}".format(rx,ry,rz)) +def manual_in_auto(Ctl_com,serial_port,flag): + if get_key('m'): + flag = 12 + while (flag == 12): + manual_control(Ctl_com,serial_port) + flag = manual_return2auto('r',flag) + return flag +def manual_return2auto(key_press,flag_r): + if get_key(key_press): + flag_r = 1 + return flag_r # ===== Main Function ===== if __name__ == '__main__': @@ -723,6 +734,8 @@ if __name__ == '__main__': print('auto_control') auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist1, LIDAR_dist2, debugM,count_h) flag, print_count = keyboard_stop(flag,print_count) + flag = manual_in_auto(Ctl_com,serial_port,flag) + elif get_key('s'): pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4 = stop_all() serial_port_out(serial_port, pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4) @@ -747,6 +760,8 @@ if __name__ == '__main__': test_function() flag, print_count = keyboard_stop(flag, print_count) + cv2.destroyAllWindows() + elif get_key('k'): break -- GitLab