Make it actually sort stuff and everything!

video
Cole Deck 5 years ago
parent 4f59cc07d5
commit 830a8e7727

Binary file not shown.

Before

Width:  |  Height:  |  Size: 809 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 824 KiB

Binary file not shown.

@ -7,11 +7,11 @@ ser = serial.Serial('/dev/ttyUSB0', 115200)
gpio.setmode(gpio.BCM) gpio.setmode(gpio.BCM)
gpio.setup(13, gpio.OUT) gpio.setup(13, gpio.OUT)
pwm = gpio.PWM(13, 100) pwm = gpio.PWM(13, 100)
pwm.start(5) pwm.start(13)
verbose = True verbose = True
print("Initializing Grbl...") print("Initializing Grbl...")
ser.write("\r\n\r\n") ser.write(b'\r\n\r\n')
time.sleep(2) time.sleep(2)
ser.write(b'$RST=#\n') ser.write(b'$RST=#\n')
time.sleep(1) time.sleep(1)
@ -21,37 +21,42 @@ def goToBin(bin):
adjustedBin = math.floor(bin / 2) adjustedBin = math.floor(bin / 2)
distance = adjustedBin * 18 distance = adjustedBin * 18
delay = 0.5 + 0.93 * adjustedBin delay = 0.5 + 0.93 * adjustedBin
command = 'G0 -X' command = 'G0 X-'
command += distance command += str(distance)
command += '\n' command += '\n'
ser.write(b'$X\n')
time.sleep(1)
print(command)
ser.write(command.encode('utf-8')) ser.write(command.encode('utf-8'))
# s.write("$C\n") # s.write("$C\n")
while True: while True:
grbl_out = s.readline().strip() # Wait for grbl response with carriage return grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
if grbl_out.find('error') >= 0 : print(grbl_out.find('error'))
print "REC:",grbl_out if int(grbl_out.find('error')) >= 0 :
print " Grbl reported error!" print("REC:",grbl_out)
print(" Grbl reported error!")
quit() quit()
elif grbl_out.find('ok') >= 0 : elif int(grbl_out.find('ok')) >= 0 :
if verbose: print 'REC:',grbl_out if verbose: print('REC:',grbl_out)
break break
# time.sleep(delay) time.sleep(delay)
if bin % 2 == 0: # tilt to right if bin % 2 == 0: # tilt to left
pwm.ChangeDutyCycle(0) pwm.ChangeDutyCycle(5)
time.sleep(1) time.sleep(1)
pwm.ChangeDutyCycle(20) pwm.ChangeDutyCycle(14)
else: else:
pwm.ChangeDutyCycle(40) pwm.ChangeDutyCycle(25)
time.sleep(1)
pwm.ChangeDutyCycle(13)
time.sleep(1) time.sleep(1)
pwm.ChangeDutyCycle(20)
ser.write(b'G0 X0\n') ser.write(b'G0 X0\n')
while True: while True:
grbl_out = s.readline().strip() # Wait for grbl response with carriage return grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
if grbl_out.find('error') >= 0 : if int(grbl_out.find('error')) >= 0 :
print "REC:",grbl_out print("REC:",grbl_out)
print " Grbl reported error!" print(" Grbl reported error!")
quit() quit()
elif grbl_out.find('ok') >= 0 : elif int(grbl_out.find('ok')) >= 0 :
if verbose: print 'REC:',grbl_out if verbose: print('REC:',grbl_out)
break break
#time.sleep(delay) time.sleep(delay)

@ -89,7 +89,7 @@ def detect(calibration_width, img_file, show, quick):
image = cv2.imread(img_file) image = cv2.imread(img_file)
#image = img_file.copy() #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) #image = cv2.resize(image, (1000, int(image.shape[0]/image.shape[1] * 1000)), interpolation=cv2.INTER_NEAREST)
if show and not quick: if show and not quick:

@ -3,18 +3,20 @@ import sort
import control_motor import control_motor
import control_pixel 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 port = 9001 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port)) s.connect((host, port))
s.sendall(b'Connected to server!') s.sendall(b'Connected to server!')
control_pixel.ledOn() control_pixel.ledOn()
while True: while True:
control_pixel.ledOn()
try: try:
data = s.recv(1024) data = s.recv(1024)
#control_pixel.ledOn()
if not data: break if not data: break
print("Found "+data) print("Found "+str(data))
selectedBin = sort.sort(data) selectedBin = sort.sort(str(data)[2:len(str(data))-1])
control_pixel.ledOff() control_pixel.ledOff()
control_motor.goToBin(selectedBin) control_motor.goToBin(selectedBin)
control_pixel.ledOn() control_pixel.ledOn()

@ -1,6 +1,6 @@
import time import time
import pixel_control import control_pixel
pixel_control.ledOn() control_pixel.ledOn()
time.sleep(10) time.sleep(10)
pixel_control.ledOff() control_pixel.ledOff()
pixel_control.ledOff() control_pixel.ledOff()

@ -80,11 +80,11 @@ else :
#print('frame') #print('frame')
if x > 1: if x > 1:
ret,frame = capture.retrieve() 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) items,output = detect.detect(calibration_width, frame, True, True)
cv2.imshow('Item Sorter', output) cv2.imshow('Item Sorter', output)
x = 0 x = 0
if "Penny" in items: if "Penny" in items and len(items) > 1:
items.remove("Penny") items.remove("Penny")
itema = items[0] itema = items[0]
valid = True valid = True
@ -101,14 +101,17 @@ else :
samples = 0 samples = 0
if samples == 5: if samples == 5:
samples = 0 samples = 0
capture.release()
sendString(currentItem) sendString(currentItem)
waitForPi = True waitForPi = True
while waitForPi is True: while waitForPi is True:
try: try:
data = conn.recv(1024) data = conn.recv(1024)
if not data: break if not data: break
if data == "Continue": print(str(data))
if str(data) == "b'Continue'":
waitForPi = False 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: except socket.error:
print("Error Occured.") print("Error Occured.")
break break

Loading…
Cancel
Save