Added printer XY position sampling
authorMichael Reeves <michaelreeves808@gmail.com>
Fri, 22 Feb 2019 03:10:09 +0000 (19:10 -0800)
committerMichael Reeves <michaelreeves808@gmail.com>
Fri, 22 Feb 2019 03:10:09 +0000 (19:10 -0800)
FuckTomato.py
Printer.py
Tests.py
__pycache__/Printer.cpython-37.pyc
utils/PrinterUtils.py [new file with mode: 0644]
utils/__pycache__/Gcode.cpython-37.pyc
utils/__pycache__/Geometry.cpython-37.pyc

index 635776babd38323ef519b6743ef7fee520868d02..4a44ce2d1569a07cd5459fa6886268ce19a4f784 100644 (file)
@@ -13,8 +13,8 @@ while(True):
        cv2.imshow('image', frame)
 
        # ...Detection and package send... #
-
        #After g-code package send, check for XY reset and update printer execution status
+       
        if not printer.packageIsExecuting():
                #Run image evaluation and printer position check
                pass
index 2f50b7e2056ce3e8ac29ab05c69175a3bdc3a8a0..ad68151d591ff9c4602df04d61c6df388187282a 100644 (file)
@@ -1,6 +1,6 @@
-import serial
+import serial, time
 from settings import frameSettings
-from utils import MatrixConversion, Geometry, Gcode
+from utils import MatrixConversion, Geometry, Gcode, PrinterUtils
 
 class Printer():
        def __init__(self, PrinterCOM, bedSize):
@@ -9,7 +9,7 @@ class Printer():
                self.position = (0,0)
                self.settings = frameSettings.frameSettings()
                self.coeffs = MatrixConversion.find_coeffs(self.settings.image_frame.corners, self.settings.laser_frame.corners) 
-               try: self.printerSerial = serial.Serial(PrinterCOM, 115200, timeout = 1)
+               try: self.printerSerial = serial.Serial(PrinterCOM, 115200, timeout = 25)
                except: print("Connection Failure")
 
        
@@ -43,8 +43,17 @@ class Printer():
 
        def packageIsExecuting(self):
                #Query the printer for position
-               pass
+               self.printerSerial.reset_input_buffer()
+               self.printerSerial.write('M114'.encode())
+               printerData = ''
+               while self.printerSerial.in_waiting > 0:
+                       printerData += str(self.printerSerial.readline())
 
+               if 'Count' in printerData:
+                       x, y = PrinterUtils.parsePrinterXY(printerData)
+                       if x == 0 and y == 0: return False
+               return True
+               
        def raiseZ(self):
                self.printerSerial.write('G0 F5000 Z50\n'.encode())
        
index 7a07d2e580a6b1928fed0de95a87bbbdece64f55..8e670e47e8c5daf93a7467bcebd16da2334015b6 100644 (file)
--- a/Tests.py
+++ b/Tests.py
@@ -1,4 +1,4 @@
-import Printer
+import Printer, time
 
 testPoints = [
 (176, 204),
@@ -10,5 +10,12 @@ testPoints = [
 (246, 189)
 ]
 
-p = Printer.Printer('', '', (200,200))
-print(p.sendPackage(testPoints))
\ No newline at end of file
+p = Printer.Printer('COM4', (200,200))
+time.sleep(8)
+p.writePoint((75, 75))
+while 1:
+    res = p.packageIsExecuting()
+    if 'Count' in res:
+        xy = res.split('Count')[1].split('Z')[0].strip().replace('Y:', '').split(' ')[1:]
+        x, y = (xy[0], xy[1])
+        print(str(x) + '  ' + str(y))
\ No newline at end of file
index b157db5de3b26e18ae39265352305d292229340e..ba14e9b19275b72b58f4241c581f4e622d78c62e 100644 (file)
Binary files a/__pycache__/Printer.cpython-37.pyc and b/__pycache__/Printer.cpython-37.pyc differ
diff --git a/utils/PrinterUtils.py b/utils/PrinterUtils.py
new file mode 100644 (file)
index 0000000..a0a3c0d
--- /dev/null
@@ -0,0 +1,5 @@
+
+def parsePrinterXY(printerData):
+    xy = printerData.split('Count')[1].split('Z')[0].strip().replace('Y:', '').split(' ')[1:]
+    return (xy[0], xy[1])
+        
\ No newline at end of file
index b3572d6c2c4e264496af45db7560945816b1436c..31b7b8e73a250f398277c858944cc0076b930a54 100644 (file)
Binary files a/utils/__pycache__/Gcode.cpython-37.pyc and b/utils/__pycache__/Gcode.cpython-37.pyc differ
index 2777f61a4776a43682029e9f622eb9cb134b30d7..8a99f324c264b47093e0c588f3039dfa6229bfac 100644 (file)
Binary files a/utils/__pycache__/Geometry.cpython-37.pyc and b/utils/__pycache__/Geometry.cpython-37.pyc differ