diff --git a/control_motor.py b/control_motor.py index fe4a336..2d07aef 100644 --- a/control_motor.py +++ b/control_motor.py @@ -68,4 +68,10 @@ def goToBin(bin): if verbose: print('[ INFO ] Grbl message: ',grbl_out) break print("[ INFO ] Waiting for " + str(delay) + " seconds.") - time.sleep(delay) \ No newline at end of file + 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') \ No newline at end of file diff --git a/detect.py b/detect.py index 302dc58..3c3f1bc 100644 --- a/detect.py +++ b/detect.py @@ -176,7 +176,7 @@ def detect(calibration_width, img_file, show, quick): """ pixelsPerMetric = 25 orig = image.copy() - objtype = "Unknown" + objtype = "Object" objname = "" # loop over the contours individually for c in cnts: @@ -224,7 +224,7 @@ def detect(calibration_width, img_file, show, quick): else: circular = True cv2.circle(orig, (int(x), int(y)), int(radius), (255, 0, 0), 2) - objtype = "Unknown" + objtype = "Object" itemw = larger(dimA, dimB) itemwr = itemw itemwr *= 8 @@ -306,7 +306,7 @@ def detect(calibration_width, img_file, show, quick): # 0.65, (255, 255, 255), 2) if objtype != "Penny": objtype = magicSort(c) - if objtype == "Unknown": + if objtype == "Object": objtype = magicSort(c) output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh) 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 #magicNumber1 = 0 #magicNumber2 = 0 - name = "Unknown" + name = "Object" for i in range(0,7): if humoments[i] == 0: humoments[i] = 0.1; diff --git a/pi_client.py b/pi_client.py index c066103..d2565a8 100644 --- a/pi_client.py +++ b/pi_client.py @@ -15,12 +15,17 @@ while True: data = s.recv(1024) #control_pixel.ledOn() if not data: break - print("[ INFO ] Item name: "+ str(data)[2:len(str(data))-1]) - selectedBin = sort.sort(str(data)[2:len(str(data))-1]) - control_pixel.ledOff() - control_motor.goToBin(selectedBin) - control_pixel.ledOn() - s.sendall(b'Continue') + 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]) + selectedBin = sort.sort(str(data)[2:len(str(data))-1]) + control_pixel.ledOff() + control_motor.goToBin(selectedBin) + control_pixel.ledOn() + s.sendall(b'Continue') except socket.error: print("[ EXIT ] Socket connection error.") break diff --git a/run_detect.py b/run_detect.py index c851f64..f1f5b4d 100644 --- a/run_detect.py +++ b/run_detect.py @@ -88,6 +88,7 @@ else : x = 0 if len(items) > 0: #items.remove("Penny") + sendString("Pause ") itema = items[0] valid = True for item in items: @@ -97,11 +98,11 @@ else : break if valid: if currentItem == itema: - samples += 1 + samples += 2 else: currentItem = itema samples = 0 - if samples == 5: + if samples >= 10: samples = 0 capture.release() sendString(currentItem) @@ -118,7 +119,11 @@ else : except socket.error: print("[ EXIT ] Socket connection error.") break - + else: + if samples > 0: + samples -= 1 + if samples == 0: + sendString("Intake") if cv2.waitKey(1)&0xFF == ord('q'): print("[ EXIT ] Shutting down.") s.shutdown(1)