def homefilter(self): self.connection.calibrate = [] code = [ "G92 E0", "G1 E 0 F2000", "M119", "G1 E 1 F2000", "M119", "G1 E 2 F2000", "M119", "G1 E 3 F2000", "M119", "G1 E 4 F2000", "M119", "G1 E 5 F2000", "M119", "G1 E 6 F2000", "M119", "G1 E 7 F2000", "M119", "G1 E 8 F2000", "M119", "G1 E 9 F2000", "M119", "G1 E 10 F2000", "M119", "G1 E 11 F2000", "M119", "G1 E 12 F2000", "M119", "G1 E 13 F2000", "M119", "G1 E 14 F2000", "M119", "G1 E 15 F2000", "M119", "G1 E 16 F2000", "M119", "G1 E 17 F2000", "M119", "G1 E 18 F2000", "M119", "G1 E 19 F2000", "M119", "G1 E 20 F2000", "M119", "G1 E 21 F2000", "M119", "G1 E 22 F2000", "M119", "G1 E 23 F2000", "M119", "G1 E 24 F2000", "M119", "G1 E 25 F2000", "M119", "G1 E 26 F2000", "M119", "G1 E 27 F2000", "M119", "G1 E 28 F2000", "M119", "G1 E 29 F2000", "M119", "G1 E 30 F2000", "M119", "G1 E 31 F2000", "M119", "G1 E 32 F2000", "M119", "G1 E 33 F2000", "M119", "G1 E 34 F2000", "M119", "G1 E 35 F2000", "M119", "G1 E 36 F2000", "M119", "G1 E 37 F2000", "M119", "G1 E 38 F2000", "M119", "G1 E 39 F2000", "M119", "G1 E 40 F2000", "M119", "G1 E 41 F2000", "M119", "G1 E 42 F2000", "M119", "G1 E 43 F2000", "M119", "G1 E 44 F2000", "M119", "G1 E 45 F2000", "M119", "G1 E 46 F2000", "M119", "G1 E 47 F2000", "M119", "G1 E 48 F2000", "M119", "G1 E 49 F2000", "M119", "G1 E 50 F2000", "M119", "G1 E 51 F2000", "M119", "G1 E 52 F2000", "M119", "G1 E 53 F2000", "M119", "G1 E 54 F2000", "M119", "G1 E 55 F2000", "M119", "G1 E 56 F2000", "M119", "G1 E 57 F2000", "M119", "G1 E 58 F2000", "M119", "G1 E 59 F2000", "M119", "G1 E 60 F2000", "M119", "G1 E 61 F2000", "M119", "G1 E 62 F2000", "M119", "G1 E 63 F2000", "M119", "G1 E 64 F2000", "M119", "G1 E 65 F2000", "M119", "G1 E 66 F2000", "M119", "G1 E 67 F2000", "M119", "G1 E 68 F2000", "M119", "G1 E 69 F2000", "M119", "G1 E 70 F2000", "M119", "G1 E 71 F2000", "M119", "G1 E 72 F2000", "M119", "G1 E 73 F2000", "M119", "G1 E 74 F2000", "M119", "G1 E 75 F2000", "M119", "G1 E 76 F2000", "M119", "G1 E 77 F2000", "M119", "G1 E 78 F2000", "M119", "G1 E 79 F2000", "M119", "G1 E 80 F2000", "M119", "G1 E 81 F2000", "M119", "G1 E 82 F2000", "M119", "G1 E 83 F2000", "M119", "G1 E 84 F2000", "M119", "G1 E 85 F2000", "M119", "G1 E 86 F2000", "M119", "G1 E 87 F2000", "M119", "G1 E 88 F2000", "M119", "G1 E 89 F2000", "M119", "G1 E 90 F2000", "M119", "G1 E 91 F2000", "M119", "G1 E 92 F2000", "M119", "G1 E 93 F2000", "M119", "G1 E 94 F2000", "M119", "G1 E 95 F2000", "M119", "G1 E 96 F2000", "M119", "G1 E 97 F2000", "M119", "G1 E 98 F2000", "M119", "G1 E 99 F2000", "M119", "G1 E 100 F2000", "M119", "G1 E 101 F2000", "M119", "G1 E 102 F2000", "M119", "G1 E 103 F2000", "M119", "G1 E 104 F2000", "M119", "G1 E 105 F2000", "M119", "G1 E 106 F2000", "M119", "G1 E 107 F2000", "M119", "G1 E 108 F2000", "M119", "G1 E 109 F2000", "M119", "G1 E 110 F2000", "M119", "G1 E 111 F2000", "M119", "G1 E 112 F2000", "M119", "G1 E 113 F2000", "M119", "G1 E 114 F2000", "M119", "G1 E 115 F2000", "M119", "G1 E 116 F2000", "M119", "G1 E 117 F2000", "M119", "G1 E 118 F2000", "M119", "G1 E 119 F2000", "M119", "G1 E 120 F2000", "M119", "G1 E 121 F2000", "M119", "G1 E 122 F2000", "M119", "G1 E 123 F2000", "M119", "G1 E 124 F2000", "M119", "G1 E 125 F2000", "M119", "G1 E 126 F2000", "M119", "G1 E 127 F2000", "M119", "G1 E 128 F2000", "M119", "G1 E 129 F2000", "M119", "G1 E 130 F2000", "M119", "G1 E 131 F2000", "M119", "G1 E 132 F2000", "M119", "G1 E 133 F2000", "M119", "G1 E 134 F2000", "M119", "G1 E 135 F2000", "M119", "G1 E 136 F2000", "M119", "G1 E 137 F2000", "M119", "G1 E 138 F2000", "M119", "G1 E 139 F2000", "M119", "G1 E 140 F2000", "M119", "G1 E 141 F2000", "M119", "G1 E 142 F2000", "M119", "G1 E 143 F2000", "M119", "G1 E 144 F2000", "M119", "G1 E 145 F2000", "M119", "G1 E 146 F2000", "M119", "G1 E 147 F2000", "M119", "G1 E 148 F2000", "M119", "G1 E 149 F2000", "M119", "G1 E 150 F2000", "M119", "G1 E 151 F2000", "M119", "G1 E 152 F2000", "M119", "G1 E 153 F2000", "M119", "G1 E 154 F2000", "M119", "G1 E 155 F2000", "M119", "G1 E 156 F2000", "M119", "G1 E 157 F2000", "M119", "G1 E 158 F2000", "M119", "G1 E 159 F2000", "M119", "G1 E 160 F2000", "M119", "G1 E 161 F2000", "M119", "G1 E 162 F2000", "M119", "G1 E 163 F2000", "M119", "G1 E 164 F2000", "M119", "G1 E 165 F2000", "M119", "G1 E 166 F2000", "M119", "G1 E 167 F2000", "M119", "G1 E 168 F2000", "M119", "G1 E 169 F2000", "M119", "G1 E 170 F2000", "M119", "G1 E 171 F2000", "M119", "G1 E 172 F2000", "M119", "G1 E 173 F2000", "M119", "G1 E 174 F2000", "M119", "G1 E 175 F2000", "M119", "G1 E 176 F2000", "M119", "G1 E 177 F2000", "M119", "G1 E 178 F2000", "M119", "G1 E 179 F2000", "M119", "G1 E 180 F2000", "M119", "G1 E 181 F2000", "M119", "G1 E 182 F2000", "M119", "G1 E 183 F2000", "M119", "G1 E 184 F2000", "M119", "G1 E 185 F2000", "M119", "G1 E 186 F2000", "M119", "G1 E 187 F2000", "M119", "G1 E 188 F2000", "M119", "G1 E 189 F2000", "M119", "G1 E 190 F2000", "M119", "G1 E 191 F2000", "M119", "G1 E 192 F2000", "M119", "G1 E 193 F2000", "M119", "G1 E 194 F2000", "M119", "G1 E 195 F2000", "M119", "G1 E 196 F2000", "M119", "G1 E 197 F2000", "M119", "G1 E 198 F2000", "M119", "G1 E 199 F2000", "M119"] code = gcoder.GCode(code) self.connection.startprint(code) while self.connection.printing: time.sleep(0.1) homepoint = 0 for i in range(len(self.connection.calibrate)): #print self.connection.calibrate[i][-10:-1] if self.connection.calibrate[i][-10:-1] == "TRIGGERED": homepoint = i break print "Homepoint = ", homepoint #self.connection.send_now("G1 E" + str(homepoint) + "F4000") #while self.connection.printing: # time.sleep(0.1) #self.connection.send_now("G92 E0") c = "G1 E" + str(homepoint) + "F4000" code = [ c, "G92 E173"] #E0 before code = gcoder.GCode(code) self.connection.startprint(code) while self.connection.printing: time.sleep(0.1) print 'here' self.connection.calibrate = []
def testBead(self): """docstring for testBead""" path = [] path.append(self.move(self.beadTesterLocation[0],self.beadTesterLocation[1],self.beadplateSafeHeight, s = 9000)) path.append(self.move(self.beadTesterLocation[0],self.beadTesterLocation[1],self.beadTesterLocation[2], s = 9000)) path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: time.sleep(0.1) self.dropBead() time.sleep(0.5) code = ["M119"] code = gcoder.GCode(code) p.connection.startprint(code) while p.connection.printing: time.sleep(0.1) self.pickBead() print p.connection.contact path = [] path.append(self.move(self.beadTesterLocation[0],self.beadTesterLocation[1],self.beadplateSafeHeight, s = 9000)) path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: time.sleep(0.1) state = p.connection.contact
def move(self, x, y, z=167.0, s=15000.0): """Move to X,Y,Z at speed S""" #locationString = "G1 X" + str(x) + " Y" + str(y) + " Z" + str(z) + " F" + str(s) path = gcoder.GCode(["G1 X" + str(x) + " Y" + str(y) + " Z" + str(z) + " F" + str(s)]) self.connection.startprint(path) while self.connection.printing: time.sleep(0.1)
def dropBead(self): """docstring for pickBead""" code = ["M107"] code = gcoder.GCode(code) p.connection.startprint(code) while p.connection.printing: time.sleep(0.1)
def moveToSafeHeight(self): """Move to X,Y,Z at speed S""" path = ["G1 Z" + str(self.safeHeight) + " F" + str(5000.0)] path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: pass#time.sleep(1)
def runGCode(self, code): gcode = code gcode.append("M114") gcode = gcoder.GCode(code) self.connection.startprint(gcode) while self.connection.printing: time.sleep(0.1)
def startPrint(self, jobfile): self.p = printcore.printcore() self.p.tempcb = self._tempCallback self.p.errorcb = self._errorCallback self.p.loud = False try: self.printing = True self.connect() connectCount = 0 while not self.isConnected(): connectCount += 1 time.sleep(1) if connectCount == 5: self.log.debug("Trying to reset port") self.p.printer.baudrate = 9600 self.p.printer.baudrate = self.config['baud'] if connectCount == 20: raise Exception("Could not connect to bot") self.log.debug("Waiting for driver to connect.") self.gcoder = gcoder.GCode(jobfile.localFile) self.p.startprint(self.gcoder) self.printThread = Thread(target=self.printThreadEntry).start() except Exception: self.disconnect() raise
def home(self): """Moves the picker to the home position""" code = ["G28"] code = gcoder.GCode(code) p.connection.startprint(code) while p.connection.printing: time.sleep(1)
def emission(self, wavelength = "485"): code = gcoder.GCode(["G1 E" + self.filters[wavelength] + " F4000", "M114"]) self.connection.startprint(code) while self.connection.printing: time.sleep(0.1) print 'here'
def pickBead(self): """docstring for pickBead""" code = ["M106 S255"] code = gcoder.GCode(code) self.connection.startprint(code) while self.connection.printing: time.sleep(0.1) time.sleep(1)
def __init__(self, port=None, baud=None, dtr=None): """Initializes a printcore instance. Pass the port and baud rate to connect immediately""" self.baud = None self.dtr = None self.port = None self.analyzer = gcoder.GCode() # Serial instance connected to the printer, should be None when # disconnected self.printer = None # clear to send, enabled after responses # FIXME: should probably be changed to a sliding window approach self.clear = 0 self.commands_in_advance = 0 self.MAX_COMMANDS_IN_ADVANCE = 20 # The printer has responded to the initial command and is active self.online = False # is a print currently running, true if printing, false if paused self.printing = False self.mainqueue = None self.priqueue = Queue(0) self.queueindex = 0 self.lineno = 0 self.resendfrom = -1 self.paused = False self.sentlines = {} self.log = deque(maxlen=10000) self.sent = [] self.writefailures = 0 self.tempcb = None # impl (wholeline) self.recvcb = None # impl (wholeline) self.sendcb = None # impl (wholeline) self.preprintsendcb = None # impl (wholeline) self.printsendcb = None # impl (wholeline) self.layerchangecb = None # impl (wholeline) self.errorcb = None # impl (wholeline) self.startcb = None # impl () self.endcb = None # impl () self.onlinecb = None # impl () self.loud = True # emit sent and received lines to terminal self.tcp_streaming_mode = False self.greetings = ['start', 'Grbl '] self.wait = 0 # default wait period for send(), send_now() self.read_thread = None self.stop_read_thread = False self.send_thread = None self.stop_send_thread = False self.print_thread = None self.event_handler = PRINTCORE_HANDLER for handler in self.event_handler: try: handler.on_init() except: logging.error(traceback.format_exc()) if port is not None and baud is not None: self.connect(port, baud) self.xy_feedrate = None self.z_feedrate = None
def start(self, frame): self.gcoder = gcoder.GCode([]) self.glframe = frame self.init_glmodel() self.init_glhead() self.stop_threads = False self.read_thread = threading.Thread(target=self.reader) self.read_thread.start() self.process_thread = threading.Thread(target=self.processor) self.process_thread.start()
def pickColony(self, colonyCoordinate): """docstring for pickColony""" self.moveToSafeHeight() self.move(colonyCoordinate[0],colonyCoordinate[1]) self.move(colonyCoordinate[0],colonyCoordinate[1],z=100.0) #moves to save hight above plate code = ["G30"] code = gcoder.GCode(code) self.connection.startprint(code) self.connection.contact = False self.moveToSafeHeight()
def export_combined(self, name): models = self.models.values() last_real_position = None # Sort models by Z max to print smaller objects first models.sort(key=lambda x: x.dims[-1]) alllayers = [] for (model_i, model) in enumerate(models): alllayers += [(layer.z, model_i, layer_i) for (layer_i, layer) in enumerate(model.gcode.all_layers) if layer] alllayers.sort() laste = [0] * len(models) lasttool = [0] * len(models) lastrelative = [False] * len(models) with open(name, "w") as f: analyzer = gcoder.GCode(None, get_home_pos(self.build_dimensions)) analyzer.write = types.MethodType( lambda self, line: gcoder_write(self, f, line), analyzer) for (layer_z, model_i, layer_i) in alllayers: model = models[model_i] layer = model.gcode.all_layers[layer_i] r = model.rot # no rotation support for now if r != 0 and layer_i == 0: print _("Warning: no rotation support for now, " "object won't be correctly rotated") o = model.offsets co = model.centeroffset offset_pos = last_real_position if last_real_position is not None else ( 0, 0, 0) analyzer.write("; %f %f %f\n" % offset_pos) trans = (-(o[0] + co[0]), -(o[1] + co[1]), -(o[2] + co[2])) trans_wpos = (offset_pos[0] + trans[0], offset_pos[1] + trans[1], offset_pos[2] + trans[2]) analyzer.write("; GCodePlater: Model %d Layer %d at Z = %s\n" % (model_i, layer_i, layer_z)) if lastrelative[model_i]: analyzer.write("G91\n") else: analyzer.write("G90\n") if analyzer.current_tool != lasttool[model_i]: analyzer.write("T%d\n" % lasttool[model_i]) analyzer.write("G92 X%.5f Y%.5f Z%.5f\n" % trans_wpos) analyzer.write("G92 E%.5f\n" % laste[model_i]) for l in layer: if l.command != "G28" and (l.command != "G92" or extrusion_only(l)): analyzer.write(l.raw + "\n") # Find the current real position & E last_real_position = analyzer.current_pos laste[model_i] = analyzer.current_e lastrelative[model_i] = analyzer.relative lasttool[model_i] = analyzer.current_tool print _("Exported merged G-Codes to %s") % name
def export_combined(self, name): models = list(self.models.values()) last_real_position = None # Sort models by Z max to print smaller objects first models.sort(key = lambda x: x.dims[-1]) alllayers = [] for (model_i, model) in enumerate(models): def add_offset(layer): return layer.z + model.offsets[2] if layer.z is not None else layer.z alllayers += [(add_offset(layer), model_i, layer_i) for (layer_i, layer) in enumerate(model.gcode.all_layers) if add_offset(layer) is not None] alllayers.sort() laste = [0] * len(models) lasttool = [0] * len(models) lastrelative = [False] * len(models) with open(name, "w") as f: analyzer = gcoder.GCode(None, get_home_pos(self.build_dimensions)) analyzer.write = types.MethodType(lambda self, line: gcoder_write(self, f, line), analyzer) for (layer_z, model_i, layer_i) in alllayers: model = models[model_i] layer = model.gcode.all_layers[layer_i] r = math.radians(model.rot) o = model.offsets co = model.centeroffset offset_pos = last_real_position if last_real_position is not None else (0, 0, 0) analyzer.write("; %f %f %f\n" % offset_pos) trans = (- (o[0] + co[0]), - (o[1] + co[1]), - (o[2] + co[2])) trans_wpos = (offset_pos[0] + trans[0], offset_pos[1] + trans[1], offset_pos[2] + trans[2]) analyzer.write("; GCodePlater: Model %d Layer %d at Z = %s\n" % (model_i, layer_i, layer_z)) if lastrelative[model_i]: analyzer.write("G91\n") else: analyzer.write("G90\n") if analyzer.current_tool != lasttool[model_i]: analyzer.write("T%d\n" % lasttool[model_i]) analyzer.write("G92 X%.5f Y%.5f Z%.5f\n" % trans_wpos) analyzer.write("G92 E%.5f\n" % laste[model_i]) for l in layer: if l.command != "G28" and (l.command != "G92" or extrusion_only(l)): if r == 0: analyzer.write(l.raw + "\n") else: analyzer.write(rewrite_gline(co, l, math.cos(r), math.sin(r)) + "\n") # Find the current real position & E last_real_position = analyzer.current_pos laste[model_i] = analyzer.current_e lastrelative[model_i] = analyzer.relative lasttool[model_i] = analyzer.current_tool logging.info(_("Exported merged G-Codes to %s") % name)
def pickNextBead(self): """docstring for pickNextBead""" path = [] position = self.nextBead() self.moveToSafeHeight() path.append(self.move(x=self.beadplateLocations[position][0],y=self.beadplateLocations[position][1])) path.append(self.move(x=self.beadplateLocations[position][0],y=self.beadplateLocations[position][1],z = self.beadplateSafeHeight)) path.append(self.move(x=self.beadplateLocations[position][0],y=self.beadplateLocations[position][1],z = self.beadHeight, s = 500)) path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: time.sleep(0.1) self.pickBead() path = [] path.append(self.move(x=self.beadplateLocations[position][0],y=self.beadplateLocations[position][1],z = self.beadplateSafeHeight)) path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: time.sleep(0.1) print "Result:" self.testBead() print "p.connection.contact:" print p.connection.contact path = [] path.append(self.move(x=self.beadplateLocations[position][0],y=self.beadplateLocations[position][1],z = self.beadplateSafeHeight, s = 9000)) path = gcoder.GCode(path) p.connection.startprint(path) while p.connection.printing: time.sleep(0.1) self.dropBead() time.sleep(0.5)
def clear(self): self.lastpos = [0, 0, 0, 0, 0, 0, 0] self.hilightpos = self.lastpos[:] self.gcoder = gcoder.GCode([], get_home_pos(self.build_dimensions)) self.lines = {} self.pens = {} self.arcs = {} self.arcpens = {} self.layers = [] self.clearhilights() self.layerindex = 0 self.showall = 0 self.dirty = 1 wx.CallAfter(self.Refresh)
def __init__(self, port=None, baud=None): """Initializes a printcore instance. Pass the port and baud rate to connect immediately""" self.baud = None self.port = None self.analyzer = gcoder.GCode() self.printer = None # Serial instance connected to the printer, # should be None when disconnected self.clear = 0 # clear to send, enabled after responses self.online = False # The printer has responded to the initial command # and is active self.printing = False # is a print currently running, true if printing # , false if paused self.mainqueue = None self.priqueue = Queue(0) self.queueindex = 0 self.lineno = 0 self.resendfrom = -1 self.paused = False self.sentlines = {} self.log = deque(maxlen=10000) self.sent = [] self.writefailures = 0 self.tempcb = None # impl (wholeline) self.recvcb = None # impl (wholeline) self.sendcb = None # impl (wholeline) self.preprintsendcb = None # impl (wholeline) self.printsendcb = None # impl (wholeline) self.layerchangecb = None # impl (wholeline) self.errorcb = None # impl (wholeline) self.startcb = None # impl () self.endcb = None # impl () self.onlinecb = None # impl () self.loud = False # emit sent and received lines to terminal self.greetings = ['start', 'Grbl '] self.wait = 0 # default wait period for send(), send_now() self.read_thread = None self.stop_read_thread = False self.send_thread = None self.stop_send_thread = False self.print_thread = None if port is not None and baud is not None: self.connect(port, baud) self.xy_feedrate = None self.z_feedrate = None self.pronterface = None self.contact = False self.calibrate = []
def load_file(self, filename): gcode = gcoder.GCode(open(filename)) model = actors.GcodeModel() model.load_data(gcode) obj = gcview.GCObject(model) obj.gcode = gcode obj.dims = [ gcode.xmin, gcode.xmax, gcode.ymin, gcode.ymax, gcode.zmin, gcode.zmax ] obj.centeroffset = [ -(obj.dims[1] + obj.dims[0]) / 2, -(obj.dims[3] + obj.dims[2]) / 2, 0 ] self.add_model(filename, obj) wx.CallAfter(self.Refresh)
def __init__(self, f=None, size=(600, 600), build_dimensions=[200, 200, 100, 0, 0, 0], grid=(10, 50), extrusion_width=0.5, bgcolor="#000000"): super(GvizWindow, self).__init__( None, title=_("Gcode view, shift to move view, mousewheel to set layer"), size=size) panel, vbox = self.create_base_ui() self.p = Gviz(panel, size=size, build_dimensions=build_dimensions, grid=grid, extrusion_width=extrusion_width, bgcolor=bgcolor, realparent=self) self.toolbar.AddSeparator() #self.toolbar.AddSimpleTool(6, wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Insert Code at start of this layer"), '') self.toolbar.Realize() vbox.Add(self.p, 1, wx.EXPAND) self.SetMinSize(self.ClientToWindowSize(vbox.GetMinSize())) self.Bind(wx.EVT_TOOL, lambda x: self.p.zoom(-1, -1, 1.2), id=1) self.Bind(wx.EVT_TOOL, lambda x: self.p.zoom(-1, -1, 1 / 1.2), id=2) self.Bind(wx.EVT_TOOL, lambda x: self.p.layerup(), id=3) self.Bind(wx.EVT_TOOL, lambda x: self.p.layerdown(), id=4) self.Bind(wx.EVT_TOOL, self.resetview, id=5) #self.Bind(wx.EVT_TOOL, lambda x:self.p.inject(), id = 6) self.initpos = None self.p.Bind(wx.EVT_KEY_DOWN, self.key) self.Bind(wx.EVT_KEY_DOWN, self.key) self.p.Bind(wx.EVT_MOUSEWHEEL, self.zoom) self.Bind(wx.EVT_MOUSEWHEEL, self.zoom) self.p.Bind(wx.EVT_MOUSE_EVENTS, self.mouse) self.Bind(wx.EVT_MOUSE_EVENTS, self.mouse) if f: gcode = gcoder.GCode(f, get_home_pos(self.p.build_dimensions)) self.p.addfile(gcode)
def calibrate(self): self.moveToSafeHeight() locations = [[-85.0, 36.0],[-60.0,66.0],[-60.0,11.0],[-29.0,21.0],[-29.0,51.0]] for point in locations: self.pickNextBead() self.moveToSafeHeight() self.move(x=point[0],y=point[1]) self.move(x=point[0],y=point[1], z=100.0) code = ["G30"] code = gcoder.GCode(code) self.connection.startprint(code) self.connection.send_now("G91") self.connection.send_now("G1 Z3") while self.connection.printing: time.sleep(0.1) self.connection.send_now("G90") self.dropBead()
def testBead(self): """docstring for testBead""" self.move(self.beadTesterLocation[0], self.beadTesterLocation[1], self.beadplateSafeHeight) self.move(self.beadTesterLocation[0], self.beadTesterLocation[1], self.beadTesterLocation[2]) self.dropBead() time.sleep(0.5) code = ["M119"] code = gcoder.GCode(code) p.connection.startprint(code) while p.connection.printing: time.sleep(0.1) self.pickBead() self.move(self.beadTesterLocation[0], self.beadTesterLocation[1], self.beadplateSafeHeight)
def __init__(self, f, size = (600, 600), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5): wx.Frame.__init__(self, None, title = "Gcode view, shift to move view, mousewheel to set layer", size = size) self.CreateStatusBar(1); self.SetStatusText("Layer number and Z position show here when you scroll"); self.p = gviz(self, size = size, build_dimensions = build_dimensions, grid = grid, extrusion_width = extrusion_width) vbox = wx.BoxSizer(wx.VERTICAL) toolbar = wx.ToolBar(self, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER) toolbar.AddSimpleTool(1, wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom In [+]', '') toolbar.AddSimpleTool(2, wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom Out [-]', '') toolbar.AddSeparator() toolbar.AddSimpleTool(3, wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Up a Layer [U]', '') toolbar.AddSimpleTool(4, wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Down a Layer [D]', '') toolbar.AddSimpleTool(5, wx.EmptyBitmap(16, 16), 'Reset view', '') toolbar.AddSeparator() #toolbar.AddSimpleTool(6, wx.Image('./images/inject.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Insert Code at start of this layer', '') toolbar.Realize() vbox.Add(toolbar, 0, border = 5) vbox.Add(self.p, 1, wx.EXPAND) self.SetSizer(vbox) self.SetMinSize(self.ClientToWindowSize(vbox.GetMinSize())) self.Bind(wx.EVT_TOOL, lambda x:self.p.zoom(-1, -1, 1.2), id = 1) self.Bind(wx.EVT_TOOL, lambda x:self.p.zoom(-1, -1, 1/1.2), id = 2) self.Bind(wx.EVT_TOOL, lambda x:self.p.layerup(), id = 3) self.Bind(wx.EVT_TOOL, lambda x:self.p.layerdown(), id = 4) self.Bind(wx.EVT_TOOL, self.resetview, id = 5) #self.Bind(wx.EVT_TOOL, lambda x:self.p.inject(), id = 6) self.initpos = [0, 0] self.p.Bind(wx.EVT_KEY_DOWN, self.key) self.Bind(wx.EVT_KEY_DOWN, self.key) self.p.Bind(wx.EVT_MOUSEWHEEL, self.zoom) self.Bind(wx.EVT_MOUSEWHEEL, self.zoom) self.p.Bind(wx.EVT_MOUSE_EVENTS, self.mouse) self.Bind(wx.EVT_MOUSE_EVENTS, self.mouse) if f: gcode = gcoder.GCode(f) self.p.addfile(gcode)
def load_file(self, filename): gcode = gcoder.GCode(open(filename, "rU"), get_home_pos(self.build_dimensions)) model = actors.GcodeModel() if gcode.filament_length > 0: model.display_travels = False generator = model.load_data(gcode) generator_output = next(generator) while generator_output is not None: generator_output = next(generator) obj = gcview.GCObject(model) obj.offsets = [self.build_dimensions[3], self.build_dimensions[4], 0] obj.gcode = gcode obj.dims = [gcode.xmin, gcode.xmax, gcode.ymin, gcode.ymax, gcode.zmin, gcode.zmax] obj.centeroffset = [-(obj.dims[1] + obj.dims[0]) / 2, -(obj.dims[3] + obj.dims[2]) / 2, 0] self.add_model(filename, obj) wx.CallAfter(self.Refresh)
def lightOn(self, color = "white", t = 0.1): """docstring for pickColony""" on = gcoder.GCode(["M42 P" + self.LEDs[color] + " S255"]) #M42 P16 S255 self.connection.startprint(on) time.sleep(0.2)
def __init__(self, port=None, baud=None, dtr=None): """Initializes a printcore instance. Pass the port and baud rate to connect immediately""" self.baud = None self.dtr = None self.port = None self.analyzer = gcoder.GCode() # Serial instance connected to the printer, should be None when # disconnected self.printer = None # clear to send, enabled after responses # FIXME: should probably be changed to a sliding window approach self.clear = 0 # The printer has responded to the initial command and is active self.online = False # is a print currently running, true if printing, false if paused self.printing = False self.mainqueue = None self.priqueue = Queue(0) self.queueindex = 0 self.lineno = 0 self.resendfrom = -1 self.paused = False self.sentlines = {} self.log = deque(maxlen=10000) self.sent = [] self.writefailures = 0 self.tempcb = None # impl (wholeline) self.recvcb = None # impl (wholeline) self.sendcb = None # impl (wholeline) self.preprintsendcb = None # impl (wholeline) self.printsendcb = None # impl (wholeline) self.layerchangecb = None # impl (wholeline) self.errorcb = None # impl (wholeline) self.startcb = None # impl () self.endcb = None # impl () self.onlinecb = None # impl () self.loud = False # emit sent and received lines to terminal self.tcp_streaming_mode = False self.greetings = ['start', 'Grbl '] self.wait = 0 # default wait period for send(), send_now() self.read_thread = None self.stop_read_thread = False self.send_thread = None self.stop_send_thread = False self.print_thread = None self.readline_buf = [] self.selector = None self.event_handler = PRINTCORE_HANDLER # Not all platforms need to do this parity workaround, and some drivers # don't support it. Limit it to platforms that actually require it # here to avoid doing redundant work elsewhere and potentially breaking # things. self.needs_parity_workaround = platform.system( ) == "linux" and os.path.exists("/etc/debian") for handler in self.event_handler: try: handler.on_init() except: logging.error(traceback.format_exc()) if port is not None and baud is not None: self.connect(port, baud) self.xy_feedrate = None self.z_feedrate = None
def lightOff(self, color = "white"): """docstring for pickColony""" off = gcoder.GCode(["M42 P" + self.LEDs[color] + " S0"]) #M42 P16 S255 self.connection.startprint(off) time.sleep(0.1)
loud = True elif o in ('-s', '--statusreport'): statusreport = True if len(args) > 1: port = args[-2] filename = args[-1] print "Printing: %s on %s with baudrate %d" % (filename, port, baud) else: print "Usage: python [-h|-b|-v|-s] printcore.py /dev/tty[USB|ACM]x filename.gcode" sys.exit(2) p = printcore("tty.usbserial-AM0227LU", baud) p.loud = True time.sleep(2) gcode = [i.strip() for i in open(filename)] gcode = gcoder.GCode(gcode) p.startprint(gcode) try: if statusreport: p.loud = False sys.stdout.write("Progress: 00.0%\r") sys.stdout.flush() while p.printing: time.sleep(1) if statusreport: sys.stdout.write("Progress: %02.1f%%\r" % (100 * float(p.queueindex) / len(p.mainqueue),)) sys.stdout.flush() p.disconnect()
import os import logging logging.basicConfig(level=logging.INFO) import wx sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) from printrun.gcview import GcodeViewFrame from printrun import gcoder app = wx.App(redirect = False) build_dimensions = [200, 200, 100, -100, -100, 0] build_dimensions = [200, 200, 100, 0, 0, 0] frame = GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (800, 800), build_dimensions = build_dimensions) gcode = gcoder.GCode(open(sys.argv[1])) print "Gcode loaded" frame.addfile(gcode) first_move = None for i in range(len(gcode.lines)): if gcode.lines[i].is_move: first_move = gcode.lines[i] break last_move = None for i in range(len(gcode.lines) - 1, -1, -1): if gcode.lines[i].is_move: last_move = gcode.lines[i] break nsteps = 20 steptime = 50