Move imports to after connection, add service files to pi

video
Cole Deck 4 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')
time.sleep(1)
ser.flushInput()
time.sleep(0.25)
ser.write(b'$X\n')
print("[ INFO ] Grbl is ready.")
def goToBin(bin):
@ -27,17 +29,17 @@ def goToBin(bin):
adjustedBin = 0;
distance = adjustedBin * 18
delay = 0.5 + 0.93 * adjustedBin
command = 'G0 X-'
command = '$J=X-'
command += str(distance)
command += ' F2000'
print("[ INFO ] Sending command to Grbl: " + command)
command += '\n'
ser.write(b'$X\n')
time.sleep(0.25)
ser.write(command.encode('utf-8'))
# s.write("$C\n")
while True:
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 :
print("[ EXIT ] Grbl reported an error.")
quit()
@ -55,10 +57,10 @@ def goToBin(bin):
print("[ INFO ] Titling motor to right side.")
pwm.ChangeDutyCycle(25)
time.sleep(1)
pwm.ChangeDutyCycle(13)
pwm.ChangeDutyCycle(14)
time.sleep(1)
print("[ INFO ] Sending command to Grbl: G0 X0")
ser.write(b'G0 X0\n')
ser.write(b'$j=X0 F2000\n')
while True:
grbl_out = str(ser.readline().strip()) # Wait for grbl response with carriage return
if int(grbl_out.find('error')) >= 0 :
@ -70,8 +72,30 @@ def goToBin(bin):
print("[ INFO ] Waiting for " + str(delay) + " seconds.")
time.sleep(delay)
def stopInput():
command = str(0x85)
command = '!'
command += '\n'
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():
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 neopixel
pixels = neopixel.NeoPixel(board.D18, 24)
pixels = neopixel.NeoPixel(board.D18, 23)
def ledOff():
pixels.fill((0,0,0))
def ledOn():
pixels.fill((40,40,40))
pixels.fill((2,2,2))

@ -1,13 +1,13 @@
#!/usr/bin/python3
import socket
import sort
import control_motor
import control_pixel
host = "192.168.1.248" # socket.gethostname()
host = "192.168.1.249" # 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!')
import sort
import control_motor
import control_pixel
control_pixel.ledOn()
while True:
control_pixel.ledOn()
@ -29,4 +29,4 @@ while True:
except socket.error:
print("[ EXIT ] Socket connection error.")
break
s.close()
s.close()

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