|
|
@ -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)
|
|
|
|
time.sleep(1)
|
|
|
|
pwm.ChangeDutyCycle(20)
|
|
|
|
pwm.ChangeDutyCycle(13)
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
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)
|