diff --git a/Code/Control/Laptop_Code/ESP32_AT/imageTread_AT.py b/Code/Control/Laptop_Code/ESP32_AT/imageTread_AT.py index eed809adfb09d390019253eae7fae8b31eff144a..b64646b2197b538ded8e126b760f5be12429df1b 100644 --- a/Code/Control/Laptop_Code/ESP32_AT/imageTread_AT.py +++ b/Code/Control/Laptop_Code/ESP32_AT/imageTread_AT.py @@ -13,7 +13,7 @@ def nothing(x): detector = Detector() -def get_AT_6DOF_info(url): +def get_AT_6DOF_info(url, detectFlag = True): tid,tx,ty,tz= 0,100000,100000,0 rx = [0.0,0.0,0.0] ry = [0.0, 0.0, 0.0] @@ -29,6 +29,12 @@ def get_AT_6DOF_info(url): gray_image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) h, w, _ = frame.shape + + if not detectFlag: + resized_frame = cv2.resize(frame,(400,300)) + cv2.imshow("Image", resized_frame) + return -1,0,0,0,0,0,0 + # put a dot in center of the frame cv2.circle(frame, (w // 2, h // 2), 7, (255, 0, 0), -1) # set camera parameters diff --git a/Code/Control/Laptop_Code/ESP32_slave/ESP32_slave.ino b/Code/Control/Laptop_Code/ESP32_slave/ESP32_slave.ino index f79c97c83061e6cf1f75ad7859c7af98c83b4f03..c5fb4689be0aac7d717923b4024996cee924b6e6 100644 --- a/Code/Control/Laptop_Code/ESP32_slave/ESP32_slave.ino +++ b/Code/Control/Laptop_Code/ESP32_slave/ESP32_slave.ino @@ -11,14 +11,21 @@ // REPLACE WITH THE MAC Address of your receiver (MASTER) // Slave: 40:F5:20:44:B6:4C // MAC Address of the receiver (MASTER) -uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; // #1 +//uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; // #1 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xBD, 0xF8}; // #2 //uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x8A, 0x98}; // #3 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xC0, 0xD8}; // #5 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xDE, 0xE0}; // #6 //uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xD3, 0x3C}; // #7 -// uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x9B, 0x04, 0x98}; // #8 +uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x9B, 0x04, 0x98}; // #8 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xBE, 0x84}; // #9 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB9, 0x5C}; // #10 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xC1, 0xD8}; // #11 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0xC8}; // #12 +//uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0xA1, 0x14}; // #13 +//uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x49, 0x4F, 0xC8}; // #14 + String success; // Define variables to store incoming readings diff --git a/Code/Control/Laptop_Code/ball_detection/ball_detection.py b/Code/Control/Laptop_Code/ball_detection/ball_detection.py index 3a012883947f54a5341b1ec735289bb5b7f60854..0aa001451821df168dac58cd9157a771f5399667 100644 --- a/Code/Control/Laptop_Code/ball_detection/ball_detection.py +++ b/Code/Control/Laptop_Code/ball_detection/ball_detection.py @@ -33,7 +33,7 @@ def modifyCore(): cAddLineNums = [254, 256, 257, 258, 259] # REPLACABLE LINE FOR DIFFERENT LOCAL COMPUTER DEVICES - coreFile = 'C:\\Users\\uclal\\.conda\\envs\\foray3\\Lib\\site-packages\\detecto\\core.py' + coreFile = 'C:\\Users\\aaronjs\\.conda\\envs\\FORAYenv\\Lib\\site-packages\\detecto\\core.py' cModLineVals = [" def __init__(self, classes=None, device=None, pretrained=True, modelname=\'fasterrcnn_resnet50_fpn\'):\n", " # Load a model pre-trained on COCO - User-Modified", @@ -81,7 +81,7 @@ def returnModel(device, labelSet, modelLoc, modelFile): return model #### Live Detection -def detectLive(url , model, minDetectionScore = 0.90, showSight = True): +def detectLive(url , model, minDetectionScore = 0.90, showSight = True, detectFlag = True): ''' Descrption: ball detection ML Functions @@ -104,6 +104,13 @@ def detectLive(url , model, minDetectionScore = 0.90, showSight = True): imgnp = np.array(bytearray(img_resp.read()), dtype = np.uint8) frame = cv2.imdecode(imgnp, -1) + if not detectFlag: + if showSight: + resized_frame = cv2.resize(frame,(400,300)) + cv2.imshow('Ball Detection', resized_frame) + key = cv2.waitKey(1) & 0xFF + return gbx, gby, dist + labels, boxes, scores = model.predict(frame) for i in range(boxes.shape[0]): box = boxes[i] diff --git a/Code/Control/Laptop_Code/basic_comm_test/ESP32_master/ESP32_master.ino b/Code/Control/Laptop_Code/basic_comm_test/ESP32_master/ESP32_master.ino index 446b2506f8497ee6d91e1e8a121d0b4f0ffc28cb..08e49e50ef46d1c4dab909f083f9c3bb6ec0012f 100644 --- a/Code/Control/Laptop_Code/basic_comm_test/ESP32_master/ESP32_master.ino +++ b/Code/Control/Laptop_Code/basic_comm_test/ESP32_master/ESP32_master.ino @@ -10,8 +10,14 @@ //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xC0, 0xD8}; // #5 //uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xDE, 0xE0}; // #6 -uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xD3, 0x3C}; // #7 +//uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xD3, 0x3C}; // #7 //uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x9B, 0x04, 0x98}; // #8 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xBE, 0x84}; // #9 +uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB9, 0x5C}; // #10 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xC1, 0xD8}; // #11 +//uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0xC8}; // #12 +//uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0xA1, 0x14}; // #13 +//uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x49, 0x4F, 0xC8}; // #14 // ==================================== global data ================================================= String success; // Define variables to store BME280 readings to be sent diff --git a/Code/Control/Laptop_Code/main_joystick_1_6.py b/Code/Control/Laptop_Code/main_joystick_1_6.py index 1141e5d9e935219e13a5359bbdcb2141643f9025..d66e831d3288a7688ead8fd7a2c7df41c8c06877 100644 --- a/Code/Control/Laptop_Code/main_joystick_1_6.py +++ b/Code/Control/Laptop_Code/main_joystick_1_6.py @@ -9,7 +9,7 @@ from ESP32_AT.imageTread_AT import get_AT_6DOF_info global mc_print,ml_on,esp_cam_on,feather_data_on url_gb = 'http://10.0.0.7/cam-hi.jpg' -url_AT = 'http://10.0.0.1/cam-hi.jpg' +url_AT = 'http://10.0.0.30/cam-hi.jpg' mc_print = 1 # manual control print flag ml_on = 1 @@ -60,6 +60,8 @@ def manual_horizontal(): return abs(pwm3),abs(pwm4),dir3,dir4 def manual_control(): + gbx, gby, gb_dist = ball_detection.detectLive(url_gb, model, minDetectionScore, showSight=True, detectFlag = False) + tid, tx, ty, tz, rx, ry, rz = get_AT_6DOF_info(url_AT, detectFlag = False) pwm1,pwm2,dir1,dir2 = manual_vertical() pwm3,pwm4,dir3,dir4 = manual_horizontal() if mc_print == 1: @@ -195,6 +197,8 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di return Ctl_com def manual_in_auto(Ctl_com, serial_port, flag): + gbx, gby, gb_dist = ball_detection.detectLive(url_gb, model, minDetectionScore, showSight=True, detectFlag = False) + tid, tx, ty, tz, rx, ry, rz = get_AT_6DOF_info(url_AT, detectFlag = False) done = 1 if joystick.get_button(axes_win.get('button_LB')): flag = 12 @@ -235,7 +239,7 @@ def serial_port_in_v1(serial_port): # DEBUG Verbose print("initiating one round of serial in ...") - for i in range(8): + for i in range(7): line = serial_port.readline() val = int(line.decode()) @@ -253,9 +257,10 @@ def serial_port_in_v1(serial_port): rz = val elif i == 6: LIDAR_dist1 = val - elif i == 7: - LIDAR_dist2 = val + # elif i == 7: + # LIDAR_dist2 = val + LIDAR_dist2 = 0 line = serial_port.readline() debugM = line.decode() @@ -519,7 +524,7 @@ if __name__ == '__main__': # =========== SET UP ============ # Defining Variables for ESP 32 Serial I/O - PORT = "COM9" # for Alienware + PORT = "COM11" # for Alienware serial_port = serial.Serial(PORT, 115200) serial_port.close() serial_port.open() diff --git a/Code/Control/Laptop_Code/main_joystick_8_10.py b/Code/Control/Laptop_Code/main_joystick_8_10.py index ef7207db497499d428a2c165096e1196c84333d8..05ee803c30fc56fdc4717dee48b50b2e7764a8d1 100644 --- a/Code/Control/Laptop_Code/main_joystick_8_10.py +++ b/Code/Control/Laptop_Code/main_joystick_8_10.py @@ -9,7 +9,7 @@ from ESP32_AT.imageTread_AT import get_AT_6DOF_info global mc_print,ml_on,esp_cam_on,feather_data_on url_gb = 'http://10.0.0.7/cam-hi.jpg' -url_AT = 'http://10.0.0.1/cam-hi.jpg' +url_AT = 'http://10.0.0.5/cam-hi.jpg' mc_print = 1 # manual control print flag ml_on = 1 @@ -176,13 +176,17 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di print("gbx,gby:{},{}".format(gbx, gby)) line = serial_port.readline() + print("line") if feather_data_on == 1: + print("feather_data_on == 1") if line == b'SERIAL_IN_START\r\n': + print("line == b'SERIAL_IN_START\r\n'") tx, ty, tz, rx, ry, rz, LIDAR_dist1, LIDAR_dist2, debugM = serial_port_in_v1(serial_port) # only getting the Lidar data back time.sleep(waitTime) # in second if esp_cam_on == 1: + print("esp_cam_on == 1") # ids,txs,tys,tzs,rxs,rys,rzs = get_AT_6DOF_info_list(url_AT) tid, tx, ty, tz, rx, ry, rz = get_AT_6DOF_info(url_AT) # LIDAR_dist1 = 0 @@ -519,7 +523,7 @@ if __name__ == '__main__': # =========== SET UP ============ # Defining Variables for ESP 32 Serial I/O - PORT = "COM16" # for Alienware + PORT = "COM3" # for Alienware serial_port = serial.Serial(PORT, 115200) serial_port.close() serial_port.open()