Move imports to after connection, add service files to pi
This commit is contained in:
parent
dbde062909
commit
052ea30f73
BIN
__pycache__/control_motor.cpython-37.pyc
Normal file
BIN
__pycache__/control_motor.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/control_pixel.cpython-37.pyc
Normal file
BIN
__pycache__/control_pixel.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/sort.cpython-37.pyc
Normal file
BIN
__pycache__/sort.cpython-37.pyc
Normal file
Binary file not shown.
13
camera.service
Normal file
13
camera.service
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=UDP Camera Stream
|
||||||
|
After=network.target auditd.service media-writable.mount
|
||||||
|
Requires=media-writable.mount
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/media/writable/run.sh
|
||||||
|
Restart=always
|
||||||
|
Type=idle
|
||||||
|
User=pi
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
15
client.service
Normal file
15
client.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Python Sorting Client
|
||||||
|
After=network.target auditd.service media-writable.mount
|
||||||
|
Requires=media-writable.mount
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/media/writable/item-sort/pi_client.py
|
||||||
|
Restart=always
|
||||||
|
Type=idle
|
||||||
|
User=root
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
RestartSec=5
|
||||||
|
WorkingDirectory=/media/writable/item-sort
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -16,6 +16,8 @@ time.sleep(2)
|
|||||||
ser.write(b'$RST=#\n')
|
ser.write(b'$RST=#\n')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ser.flushInput()
|
ser.flushInput()
|
||||||
|
time.sleep(0.25)
|
||||||
|
ser.write(b'$X\n')
|
||||||
print("[ INFO ] Grbl is ready.")
|
print("[ INFO ] Grbl is ready.")
|
||||||
|
|
||||||
def goToBin(bin):
|
def goToBin(bin):
|
||||||
@ -27,17 +29,17 @@ def goToBin(bin):
|
|||||||
adjustedBin = 0;
|
adjustedBin = 0;
|
||||||
distance = adjustedBin * 18
|
distance = adjustedBin * 18
|
||||||
delay = 0.5 + 0.93 * adjustedBin
|
delay = 0.5 + 0.93 * adjustedBin
|
||||||
command = 'G0 X-'
|
command = '$J=X-'
|
||||||
command += str(distance)
|
command += str(distance)
|
||||||
|
command += ' F2000'
|
||||||
print("[ INFO ] Sending command to Grbl: " + command)
|
print("[ INFO ] Sending command to Grbl: " + command)
|
||||||
command += '\n'
|
command += '\n'
|
||||||
ser.write(b'$X\n')
|
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
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 = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
||||||
#print(grbl_out.find('error'))
|
print(grbl_out)
|
||||||
if int(grbl_out.find('error')) >= 0 :
|
if int(grbl_out.find('error')) >= 0 :
|
||||||
print("[ EXIT ] Grbl reported an error.")
|
print("[ EXIT ] Grbl reported an error.")
|
||||||
quit()
|
quit()
|
||||||
@ -55,10 +57,10 @@ def goToBin(bin):
|
|||||||
print("[ INFO ] Titling motor to right side.")
|
print("[ INFO ] Titling motor to right side.")
|
||||||
pwm.ChangeDutyCycle(25)
|
pwm.ChangeDutyCycle(25)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
pwm.ChangeDutyCycle(13)
|
pwm.ChangeDutyCycle(14)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print("[ INFO ] Sending command to Grbl: G0 X0")
|
print("[ INFO ] Sending command to Grbl: G0 X0")
|
||||||
ser.write(b'G0 X0\n')
|
ser.write(b'$j=X0 F2000\n')
|
||||||
while True:
|
while True:
|
||||||
grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
||||||
if int(grbl_out.find('error')) >= 0 :
|
if int(grbl_out.find('error')) >= 0 :
|
||||||
@ -70,8 +72,30 @@ def goToBin(bin):
|
|||||||
print("[ INFO ] Waiting for " + str(delay) + " seconds.")
|
print("[ INFO ] Waiting for " + str(delay) + " seconds.")
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
def stopInput():
|
def stopInput():
|
||||||
command = str(0x85)
|
command = '!'
|
||||||
command += '\n'
|
command += '\n'
|
||||||
ser.write(command.encode('utf-8'))
|
ser.write(command.encode('utf-8'))
|
||||||
|
print(command)
|
||||||
|
#command2 = str(0x85)
|
||||||
|
#ser.write(command2.encode('utf-8'))
|
||||||
|
#while True:
|
||||||
|
# grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
||||||
|
# if int(grbl_out.find('error')) >= 0 :
|
||||||
|
# print("[ EXIT ] Grbl reported an error.")
|
||||||
|
# quit()
|
||||||
|
# elif int(grbl_out.find('ok')) >= 0 :
|
||||||
|
# if verbose: print('[ INFO ] Grbl message: ',grbl_out)
|
||||||
|
# break
|
||||||
def startInput():
|
def startInput():
|
||||||
ser.write(b'$J=G91 Y-5000 F400\n')
|
ser.write(b'$J=G91 Y-5000 F400\n')
|
||||||
|
print("intake")
|
||||||
|
#x = 0
|
||||||
|
#while True and x < 10:
|
||||||
|
#x += 1
|
||||||
|
#grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
|
||||||
|
#if int(grbl_out.find('error')) >= 0 :
|
||||||
|
# print("[ EXIT ] Grbl reported an error.")
|
||||||
|
# quit()
|
||||||
|
#elif int(grbl_out.find('ok')) >= 0 :
|
||||||
|
# if verbose: print('[ INFO ] Grbl message: ',grbl_out)
|
||||||
|
# break
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
pixels = neopixel.NeoPixel(board.D18, 24)
|
pixels = neopixel.NeoPixel(board.D18, 23)
|
||||||
def ledOff():
|
def ledOff():
|
||||||
pixels.fill((0,0,0))
|
pixels.fill((0,0,0))
|
||||||
def ledOn():
|
def ledOn():
|
||||||
pixels.fill((40,40,40))
|
pixels.fill((2,2,2))
|
||||||
|
12
pi_client.py
Normal file → Executable file
12
pi_client.py
Normal file → Executable file
@ -1,13 +1,13 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
import socket
|
import socket
|
||||||
import sort
|
host = "192.168.1.249" # socket.gethostname()
|
||||||
import control_motor
|
|
||||||
import control_pixel
|
|
||||||
|
|
||||||
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!')
|
||||||
|
import sort
|
||||||
|
import control_motor
|
||||||
|
import control_pixel
|
||||||
control_pixel.ledOn()
|
control_pixel.ledOn()
|
||||||
while True:
|
while True:
|
||||||
control_pixel.ledOn()
|
control_pixel.ledOn()
|
||||||
@ -29,4 +29,4 @@ while True:
|
|||||||
except socket.error:
|
except socket.error:
|
||||||
print("[ EXIT ] Socket connection error.")
|
print("[ EXIT ] Socket connection error.")
|
||||||
break
|
break
|
||||||
s.close()
|
s.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user