diff --git a/__pycache__/control_motor.cpython-37.pyc b/__pycache__/control_motor.cpython-37.pyc new file mode 100644 index 0000000..6f3de70 Binary files /dev/null and b/__pycache__/control_motor.cpython-37.pyc differ diff --git a/__pycache__/control_pixel.cpython-37.pyc b/__pycache__/control_pixel.cpython-37.pyc new file mode 100644 index 0000000..4852398 Binary files /dev/null and b/__pycache__/control_pixel.cpython-37.pyc differ diff --git a/__pycache__/sort.cpython-37.pyc b/__pycache__/sort.cpython-37.pyc new file mode 100644 index 0000000..183eabf Binary files /dev/null and b/__pycache__/sort.cpython-37.pyc differ diff --git a/bins.txt b/bins.txt index a28ecf4..2c68f89 100644 Binary files a/bins.txt and b/bins.txt differ diff --git a/camera.service b/camera.service new file mode 100644 index 0000000..387dd3b --- /dev/null +++ b/camera.service @@ -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 diff --git a/client.service b/client.service new file mode 100644 index 0000000..d0b3af8 --- /dev/null +++ b/client.service @@ -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 diff --git a/control_motor.py b/control_motor.py index 2d07aef..fd06d4b 100644 --- a/control_motor.py +++ b/control_motor.py @@ -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') \ No newline at end of file + 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 diff --git a/control_pixel.py b/control_pixel.py index 0f5b038..626df41 100644 --- a/control_pixel.py +++ b/control_pixel.py @@ -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)) \ No newline at end of file + pixels.fill((2,2,2)) diff --git a/pi_client.py b/pi_client.py old mode 100644 new mode 100755 index d2565a8..fb384fd --- a/pi_client.py +++ b/pi_client.py @@ -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() \ No newline at end of file +s.close() diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..24357fc --- /dev/null +++ b/run.sh @@ -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