From 052ea30f73ce8499932ab8fef030ddbf734d2737 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Mon, 18 May 2020 15:49:04 -0500 Subject: [PATCH] Move imports to after connection, add service files to pi --- __pycache__/control_motor.cpython-37.pyc | Bin 0 -> 2288 bytes __pycache__/control_pixel.cpython-37.pyc | Bin 0 -> 472 bytes __pycache__/sort.cpython-37.pyc | Bin 0 -> 761 bytes bins.txt | Bin 40 -> 113 bytes camera.service | 13 ++++++++ client.service | 15 +++++++++ control_motor.py | 38 ++++++++++++++++++----- control_pixel.py | 4 +-- pi_client.py | 12 +++---- run.sh | 3 ++ 10 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 __pycache__/control_motor.cpython-37.pyc create mode 100644 __pycache__/control_pixel.cpython-37.pyc create mode 100644 __pycache__/sort.cpython-37.pyc create mode 100644 camera.service create mode 100644 client.service mode change 100644 => 100755 pi_client.py create mode 100755 run.sh diff --git a/__pycache__/control_motor.cpython-37.pyc b/__pycache__/control_motor.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f3de7060f63739e372d4392879fc6bf26874454 GIT binary patch literal 2288 zcmah~&2Jk;6yMno+u7KTlQ;>bt=N|mI zXS{0wPpItC%qY)kuE6u8i;wWacZOf&qkIhG1Rv)`jFX(L8?zHVcxJ4&vh!R#oL6f9 z*7`y@FrG4_m%~DjgKV_U-t|^imu`4pc`Nlm1(h&p1@)@8EVsf^sT9*S<=mXxGr`1Z zkeQq78<$^qdklOP9qrdEv4vq~(``)+)R6`+h&?GPe803!aB3-Z2YnGe&O)og-7D5M z4%rksGnCn}+6FgI8(nt5+KgL!w)_AnTYKyr7~IkGsiJXU@-)x1S<#p>4lF)&V7G1P zG7s5@2Jzgb5qpQ*c3(T@vU<+$IQ_d+sZP3$c=CLg(cOOgjbfM^>KYxl3yTgMWwae_ z*>KzGWcf&!9Ww6hIr0~1F6foqAtLqQ2h~T64iG=6y!;EOF=#+`tO0YIJRXOY7J1Bz zM_$98wngWY@00Lx&wRq<60j5cgpp2xPtv*~%cnF)bFUCre*?Hv1Kg`G!yVge@Y5O( z@A(1>}qRzkU>{P7(5h` z(lJn?=Bdcr3hI|UNlDoo25G%D0Dm5av>JOm%`lwyZpE}M!uFjodPFNFNh#PH1360D z->+1E{`bO{-#`8PO3RtKc6oEImGYL}DVNKwa|6BWqRvUxc2uiX>YR+A%)aC$%pIhE z%W0~exsMV@NEykNch~!3b7cc>N_*a%ceh+3q8fpMYOQC=KyQR>k%lSF!XkkeX0M;WpA?_qpTV;_b+dj`xocVjwVh6AybJJE1B4}irP&a#2|v8f|^L2 zI259RWg!#ikwj#Zl&Ehx_@N(KOtB6}yO^TdA83{;XvK)0e;Bv#{5%^z9Z zt<?SykBz#XP0mT#Vq&rmS-7! zHogqYf@bxYVJ<6}Ce|}-44tTLxGcqrSfM>GzO30Fi6@TmMU5`96wnz+@*K|Dro*UF zJ`YOi1qhrS=<Wjw*d*jj33^NKmCLT5LIza!#H@A9J~Hi?O&*EbFc*QAN?UdZlltdn;40;L zNV8M2fFVgC@$j4TGdI_Q((>BM4d3q5Y9ojwl?Okyt|9tJKOGBILw5Ss!s2z`fz)jH z){R>mzO{Dyx;#rdk*+vco&m2fu78i@lke_?&3ISaq@$;ANE`G*7c!sVtY#=arQpUF aK`394M`ji@kM1)2M5Z7&%*?x)k^cY&I~QgE literal 0 HcmV?d00001 diff --git a/__pycache__/control_pixel.cpython-37.pyc b/__pycache__/control_pixel.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..485239839cb5fa586125c671a5b3fbf4d4d19c11 GIT binary patch literal 472 zcmb7Ay-ve05cWBL2B}?nh9E(Ji2)%5%%u{W2TK)I1R z!~ny0p(BhirWzyMi!|v;CuaQt;gabX0g)TZW=hbCH6UyNs5Ob?EDb!+{SH#u#jEnw z*rp4M(%MhqBYwc}bC^{I%RGDWWt%Uo$;#GLM~(AswsdvtoqgPDk5_M9Yz^KO1@F~J z0s%fD{Fk?$g5X-5e5gP+S2qeZVh@}JK5}WFj%iYQ6kWwX6`60>3 z-{{Zq%GAHW#Pd2z0SQa*wV z884iz%JIrqp`6xkTm`py-nTxC87{hSG2@uy;rbjPXh@e$WM>?~zH*zd#crST8Pa`CK4ajSqpsW1Mpe5eEd{#TWfNjvcA(P6tZJ;g2DMPS zW$*)j$V5a1Iuna~I7-EsHP-qw0CQy^Lp7otnvo~TGUQJYopH+H@KlMv6DZ8q6)^+p zr{%)D`boi2lD)rvQm>vbQFw@bQDZ1bQBCAsE{c_0!bDm YV`Ku91JWQ=$c&-c0wN0{3t3Y20G@>yX#fBK literal 40 rcmZo*nJUWw0kKmwde}qrvh(uG^QQE02bUz~rR1lj8S9x&N!0@Y)Q}7C 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