From 9a1614a5a34bc2b508a5168bcfc472529afc9581 Mon Sep 17 00:00:00 2001 From: Zhiying Li <zhiyingli@g.ucla.edu> Date: Mon, 18 Oct 2021 20:32:46 -0700 Subject: [PATCH] upgrade the distance and send it all together --- .../PyTorch_with_ESPCAM/feed-to-ESP32-Tx.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Code/Ball_Detection/PyTorch_with_ESPCAM/feed-to-ESP32-Tx.py b/Code/Ball_Detection/PyTorch_with_ESPCAM/feed-to-ESP32-Tx.py index bbcfeb2..164ee67 100644 --- a/Code/Ball_Detection/PyTorch_with_ESPCAM/feed-to-ESP32-Tx.py +++ b/Code/Ball_Detection/PyTorch_with_ESPCAM/feed-to-ESP32-Tx.py @@ -9,6 +9,8 @@ serial_port.open() gbx = 0 gby = 0 +dist = 0 +gbc = 0 ### Declare Varables and Constants device = 'cuda' @@ -26,9 +28,10 @@ waitTime = 0.1 while True: ## Testing (using Live Streaming) - gbx, gby = live_feed.detectLive(model) - + gbx, gby, dist = live_feed.detectLive(model) + intDist = int(dist) # cm if gbx != -1 and gby != -1: + """ value = 'gbx' + str(gbx) + '\n' print( value , end = '') serial_port.write(value.encode()) @@ -38,6 +41,27 @@ while True: print( value) serial_port.write(value.encode()) time.sleep(waitTime) + """ + if gbx < 100: + strgbx = '0' + str(gbx) + else: + strgbx = str(gbx) + if gby < 100: + strgby = '0' + str(gby) + else: + strgby = str(gby) + if intDist < 100: + strdist = '0' + str(intDist) + else: + strdist = str(intDist) + + + value = 'gbc' + strgbx + strgby + strdist + '\n' + # value = 'gbc' + str(dist) + '\n' + print(value) + serial_port.write(value.encode()) + time.sleep(waitTime) + else: value = 'gbx-1\n' serial_port.write(value.encode()) -- GitLab