Make it actually sort stuff and everything!
This commit is contained in:
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.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)
|
||||
time.sleep(delay)
|
@ -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:
|
||||
|
@ -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()
|
||||
|
8
pixel.py
8
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()
|
||||
control_pixel.ledOff()
|
||||
control_pixel.ledOff()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user