Move imports to after connection, add service files to pi

video
Cole Deck 5 years ago
parent dbde062909
commit 052ea30f73

Binary file not shown.

Binary file not shown.

@ -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

@ -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))

@ -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()

@ -0,0 +1,3 @@
#!/bin/bash
cd /media/writable/MIPI_Camera/RPI
./video2stdout | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=10 pt=96 ! udpsink host=192.168.1.249 port=9000
Loading…
Cancel
Save