diff --git a/Item Sorter_screenshot_08.01.2020-1.png b/Item Sorter_screenshot_08.01.2020-1.png deleted file mode 100644 index 431e1bd..0000000 Binary files a/Item Sorter_screenshot_08.01.2020-1.png and /dev/null differ diff --git a/Item Sorter_screenshot_08.01.2020-2.png b/Item Sorter_screenshot_08.01.2020-2.png deleted file mode 100644 index d09ae23..0000000 Binary files a/Item Sorter_screenshot_08.01.2020-2.png and /dev/null differ diff --git a/Item Sorter_screenshot_08.01.2020-3.png b/Item Sorter_screenshot_08.01.2020-3.png deleted file mode 100644 index 2de5c06..0000000 Binary files a/Item Sorter_screenshot_08.01.2020-3.png and /dev/null differ diff --git a/__pycache__/detect.cpython-38.pyc b/__pycache__/detect.cpython-38.pyc index 8fc7e01..efaa408 100644 Binary files a/__pycache__/detect.cpython-38.pyc and b/__pycache__/detect.cpython-38.pyc differ diff --git a/control_motor.py b/control_motor.py index 9a6794f..9205a08 100644 --- a/control_motor.py +++ b/control_motor.py @@ -7,11 +7,11 @@ ser = serial.Serial('/dev/ttyUSB0', 115200) gpio.setmode(gpio.BCM) gpio.setup(13, gpio.OUT) pwm = gpio.PWM(13, 100) -pwm.start(5) +pwm.start(13) verbose = True print("Initializing Grbl...") -ser.write("\r\n\r\n") +ser.write(b'\r\n\r\n') time.sleep(2) ser.write(b'$RST=#\n') time.sleep(1) @@ -21,37 +21,42 @@ def goToBin(bin): adjustedBin = math.floor(bin / 2) distance = adjustedBin * 18 delay = 0.5 + 0.93 * adjustedBin - command = 'G0 -X' - command += distance + command = 'G0 X-' + command += str(distance) command += '\n' + ser.write(b'$X\n') + time.sleep(1) + print(command) ser.write(command.encode('utf-8')) # s.write("$C\n") while True: - grbl_out = s.readline().strip() # Wait for grbl response with carriage return - if grbl_out.find('error') >= 0 : - print "REC:",grbl_out - print " Grbl reported error!" + grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return + print(grbl_out.find('error')) + if int(grbl_out.find('error')) >= 0 : + print("REC:",grbl_out) + print(" Grbl reported error!") quit() - elif grbl_out.find('ok') >= 0 : - if verbose: print 'REC:',grbl_out + elif int(grbl_out.find('ok')) >= 0 : + if verbose: print('REC:',grbl_out) break - # time.sleep(delay) - if bin % 2 == 0: # tilt to right - pwm.ChangeDutyCycle(0) + time.sleep(delay) + if bin % 2 == 0: # tilt to left + pwm.ChangeDutyCycle(5) time.sleep(1) - pwm.ChangeDutyCycle(20) + pwm.ChangeDutyCycle(14) else: - pwm.ChangeDutyCycle(40) + pwm.ChangeDutyCycle(25) time.sleep(1) - pwm.ChangeDutyCycle(20) + pwm.ChangeDutyCycle(13) + time.sleep(1) ser.write(b'G0 X0\n') while True: - grbl_out = s.readline().strip() # Wait for grbl response with carriage return - if grbl_out.find('error') >= 0 : - print "REC:",grbl_out - print " Grbl reported error!" + grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return + if int(grbl_out.find('error')) >= 0 : + print("REC:",grbl_out) + print(" Grbl reported error!") quit() - elif grbl_out.find('ok') >= 0 : - if verbose: print 'REC:',grbl_out + elif int(grbl_out.find('ok')) >= 0 : + if verbose: print('REC:',grbl_out) break - #time.sleep(delay) \ No newline at end of file + time.sleep(delay) \ No newline at end of file diff --git a/detect.py b/detect.py index 0d17544..2594e36 100644 --- a/detect.py +++ b/detect.py @@ -89,7 +89,7 @@ def detect(calibration_width, img_file, show, quick): image = cv2.imread(img_file) #image = img_file.copy() - image = cv2.resize(image, (floor(image.shape[1]*0.5), floor(image.shape[0]*0.5))) + image = cv2.resize(image, (math.floor(image.shape[1]*0.5), math.floor(image.shape[0]*0.5))) #image = cv2.resize(image, (1000, int(image.shape[0]/image.shape[1] * 1000)), interpolation=cv2.INTER_NEAREST) if show and not quick: diff --git a/pi_client.py b/pi_client.py index 9619e76..9100649 100644 --- a/pi_client.py +++ b/pi_client.py @@ -3,18 +3,20 @@ import sort import control_motor import control_pixel -host = 192.168.1.3 # socket.gethostname() +host = "192.168.1.248" # socket.gethostname() port = 9001 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.sendall(b'Connected to server!') control_pixel.ledOn() while True: + control_pixel.ledOn() try: data = s.recv(1024) + #control_pixel.ledOn() if not data: break - print("Found "+data) - selectedBin = sort.sort(data) + print("Found "+str(data)) + selectedBin = sort.sort(str(data)[2:len(str(data))-1]) control_pixel.ledOff() control_motor.goToBin(selectedBin) control_pixel.ledOn() diff --git a/pixel.py b/pixel.py index 520aec7..97c9d1d 100644 --- a/pixel.py +++ b/pixel.py @@ -1,6 +1,6 @@ import time -import pixel_control -pixel_control.ledOn() +import control_pixel +control_pixel.ledOn() time.sleep(10) -pixel_control.ledOff() -pixel_control.ledOff() \ No newline at end of file +control_pixel.ledOff() +control_pixel.ledOff() diff --git a/run_detect.py b/run_detect.py index 4e70dd8..a1e451d 100644 --- a/run_detect.py +++ b/run_detect.py @@ -80,11 +80,11 @@ else : #print('frame') if x > 1: ret,frame = capture.retrieve() - frame = frame[130:1000, 450:1475] + frame = frame[130:1120, 275:1350] items,output = detect.detect(calibration_width, frame, True, True) cv2.imshow('Item Sorter', output) x = 0 - if "Penny" in items: + if "Penny" in items and len(items) > 1: items.remove("Penny") itema = items[0] valid = True @@ -101,14 +101,17 @@ else : samples = 0 if samples == 5: samples = 0 + capture.release() sendString(currentItem) waitForPi = True while waitForPi is True: try: data = conn.recv(1024) if not data: break - if data == "Continue": + print(str(data)) + if str(data) == "b'Continue'": waitForPi = False + capture = cv2.VideoCapture('udpsrc port=9000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false', cv2.CAP_GSTREAMER) except socket.error: print("Error Occured.") break