]> wolfpit.net Git - hardware/fuck_tomatoes/.git/blame - Printer.py
Tested package and detection lifecycles
[hardware/fuck_tomatoes/.git] / Printer.py
CommitLineData
673c0f35 1import serial, time
dcd7df75 2from settings import frameSettings
673c0f35 3from utils import MatrixConversion, Geometry, Gcode, PrinterUtils
e99251ce 4
5class Printer():
3aae658b 6 def __init__(self, PrinterCOM, bedSize):
97af21ad 7 self.COM = PrinterCOM
5d2f6093 8 self.max_X, self.max_Y = bedSize
e99251ce 9 self.position = (0,0)
16703c8e 10 self.sendSerial = False
dcd7df75
MR
11 self.settings = frameSettings.frameSettings()
12 self.coeffs = MatrixConversion.find_coeffs(self.settings.image_frame.corners, self.settings.laser_frame.corners)
673c0f35 13 try: self.printerSerial = serial.Serial(PrinterCOM, 115200, timeout = 25)
3aae658b 14 except: print("Connection Failure")
e99251ce 15
97af21ad 16
5d2f6093 17 def writePoint(self, xy):
e99251ce 18 x,y = xy
5e014f1f 19 x = self.max_X - x
e99251ce 20 self.position = xy
dcd7df75 21 command = 'G0 F5000 X%d Y%d\n'%(x, y) + 'G4 P1000\n' + 'G0 F5000 X0 Y0\n'
e99251ce 22
97af21ad
MR
23 if self.printerSerial is not None and Geometry.pointWithinBounds(xy, (self.max_X, self.max_Y)):
24 self.printerSerial.write(command.encode())
5e014f1f 25 return 1
e99251ce 26 else:
5e014f1f 27 return 0
e99251ce 28
5d2f6093 29 def writePackage(self, package):
97af21ad 30 if self.printerSerial is not None:
97af21ad 31 self.printerSerial.write(package.encode())
e99251ce 32
5d2f6093
MR
33 def adjustXY(self, xy):
34 printer_points = [(self.max_X,self.max_Y), (0,self.max_Y), (0,0), (self.max_X,0)]
35 self.coeffs = MatrixConversion.find_coeffs(self.settings.laser_frame.corners, printer_points)
36 return MatrixConversion.warped_xy((xy), self.coeffs)
37
38 def write(self, xy):
39 self.writePoint(self.adjustXY(xy))
40
438aeb6d
MR
41 #Cannot send packages with over 3 locations at once,
42 #it overflows the printer's serial buffer because it's a peice of dog shit
5d2f6093 43 def sendPackage(self, points):
c350c4fa 44 package = Gcode.buildGcodePackage(list(map(self.adjustXY, points)), (self.max_X, self.max_Y))
5d2f6093
MR
45 self.writePackage(package)
46
97af21ad 47 def packageIsExecuting(self):
3aae658b 48 #Query the printer for position
c350c4fa 49 #self.printerSerial.reset_input_buffer()
673c0f35
MR
50 self.printerSerial.write('M114'.encode())
51 printerData = ''
52 while self.printerSerial.in_waiting > 0:
53 printerData += str(self.printerSerial.readline())
673c0f35 54 if 'Count' in printerData:
c350c4fa
MR
55 headPosition = PrinterUtils.parsePrinterXY(printerData)
56 return not PrinterUtils.isHomed(headPosition)
673c0f35 57 return True
c350c4fa 58
5d2f6093 59 def raiseZ(self):
97af21ad 60 self.printerSerial.write('G0 F5000 Z50\n'.encode())
5d2f6093 61
5e014f1f 62 def callibrate(self):
97af21ad 63 self.printerSerial.write('G28\n'.encode())
5e014f1f
MR
64
65 def home(self):
97af21ad 66 self.printerSerial.write('G0 F5000 X0 Y0\n'.encode())
5e014f1f 67
e99251ce 68 def read(self):
97af21ad 69 print(self.printerSerial.readline())