add input code

video
Cole Deck 5 years ago
parent 26119e4056
commit dbde062909

@ -69,3 +69,9 @@ def goToBin(bin):
break break
print("[ INFO ] Waiting for " + str(delay) + " seconds.") print("[ INFO ] Waiting for " + str(delay) + " seconds.")
time.sleep(delay) time.sleep(delay)
def stopInput():
command = str(0x85)
command += '\n'
ser.write(command.encode('utf-8'))
def startInput():
ser.write(b'$J=G91 Y-5000 F400\n')

@ -176,7 +176,7 @@ def detect(calibration_width, img_file, show, quick):
""" """
pixelsPerMetric = 25 pixelsPerMetric = 25
orig = image.copy() orig = image.copy()
objtype = "Unknown" objtype = "Object"
objname = "" objname = ""
# loop over the contours individually # loop over the contours individually
for c in cnts: for c in cnts:
@ -224,7 +224,7 @@ def detect(calibration_width, img_file, show, quick):
else: else:
circular = True circular = True
cv2.circle(orig, (int(x), int(y)), int(radius), (255, 0, 0), 2) cv2.circle(orig, (int(x), int(y)), int(radius), (255, 0, 0), 2)
objtype = "Unknown" objtype = "Object"
itemw = larger(dimA, dimB) itemw = larger(dimA, dimB)
itemwr = itemw itemwr = itemw
itemwr *= 8 itemwr *= 8
@ -306,7 +306,7 @@ def detect(calibration_width, img_file, show, quick):
# 0.65, (255, 255, 255), 2) # 0.65, (255, 255, 255), 2)
if objtype != "Penny": if objtype != "Penny":
objtype = magicSort(c) objtype = magicSort(c)
if objtype == "Unknown": if objtype == "Object":
objtype = magicSort(c) objtype = magicSort(c)
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh) output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
if circular: if circular:
@ -355,7 +355,7 @@ def magicSort(contour):
#humoments[6] = abs(humoments[6]) #it's possible for the last number to change sign if item is mirrored #humoments[6] = abs(humoments[6]) #it's possible for the last number to change sign if item is mirrored
#magicNumber1 = 0 #magicNumber1 = 0
#magicNumber2 = 0 #magicNumber2 = 0
name = "Unknown" name = "Object"
for i in range(0,7): for i in range(0,7):
if humoments[i] == 0: if humoments[i] == 0:
humoments[i] = 0.1; humoments[i] = 0.1;

@ -15,6 +15,11 @@ while True:
data = s.recv(1024) data = s.recv(1024)
#control_pixel.ledOn() #control_pixel.ledOn()
if not data: break if not data: break
if str(data)[2:8] == "Pause ":
control_motor.stopInput()
elif str(data)[2:8] == "Intake":
control_motor.startInput()
elif str(data)[2:8] == "Object":
print("[ INFO ] Item name: "+ str(data)[2:len(str(data))-1]) print("[ INFO ] Item name: "+ str(data)[2:len(str(data))-1])
selectedBin = sort.sort(str(data)[2:len(str(data))-1]) selectedBin = sort.sort(str(data)[2:len(str(data))-1])
control_pixel.ledOff() control_pixel.ledOff()

@ -88,6 +88,7 @@ else :
x = 0 x = 0
if len(items) > 0: if len(items) > 0:
#items.remove("Penny") #items.remove("Penny")
sendString("Pause ")
itema = items[0] itema = items[0]
valid = True valid = True
for item in items: for item in items:
@ -97,11 +98,11 @@ else :
break break
if valid: if valid:
if currentItem == itema: if currentItem == itema:
samples += 1 samples += 2
else: else:
currentItem = itema currentItem = itema
samples = 0 samples = 0
if samples == 5: if samples >= 10:
samples = 0 samples = 0
capture.release() capture.release()
sendString(currentItem) sendString(currentItem)
@ -118,7 +119,11 @@ else :
except socket.error: except socket.error:
print("[ EXIT ] Socket connection error.") print("[ EXIT ] Socket connection error.")
break break
else:
if samples > 0:
samples -= 1
if samples == 0:
sendString("Intake")
if cv2.waitKey(1)&0xFF == ord('q'): if cv2.waitKey(1)&0xFF == ord('q'):
print("[ EXIT ] Shutting down.") print("[ EXIT ] Shutting down.")
s.shutdown(1) s.shutdown(1)

Loading…
Cancel
Save