def readline(self): try: if (self.baudrateError): if (self._baudrate != self.baudrate): gpx.write("M105") return '' try: return self.outgoing.get_nowait() except Queue.Empty: pass if gpx.listing_files(): return gpx.readnext() while True: timeout = 2 if gpx.waiting else self.timeout try: return self.outgoing.get(timeout=timeout) except Queue.Empty: self._append(gpx.readnext()) except gpx.CancelBuild: self._bot_reports_build_cancelled() return '// echo: build cancelled'
def progress(self, percent): try: # loop sending for a while if the queue isn't full or if the bot # isn't listening for i in range(0, 10): try: gpx.write("M73 P%d" % percent) break except gpx.BufferOverflow: time.sleep(0.1) except gpx.Timeout: time.sleep(0.1) except gpx.CancelBuild: self._bot_reports_build_cancelled()
def home(): setup_gcode = """ T0; set primary extruder M73 P0; enable show build progress M104 S42 T0; set nozzle heater to first layer temperature G21; set units to mm -- maybe unnecessary G162 X Y F6000; home XY axes maximum G161 Z F9000; home Z axis minimum G92 Z0; set Z to 0 M132 X Y Z A B; Recall stored home offsets -- unknown G90; set positioning to absolute -- default G1 X-95 Y-73 Z30 F14000; move to waiting position (front left corner of print bed) ;G130 X0 Y0 A0 B0; set stepper motor vref to lower value while heating ;M6 T0; wait for bed and extruder to heat up ;G130 X127 Y127 A127 B127; set stepper motor vref to defaults ;M108 T0 R3; set extruder speed ;G92 E0; set E to 0 M320; acceleration enabled for all commands that follow -- default? no change without ;G1 Z0.2 F6000.000; move to first layer height ;G1 X100 Y-73 F14000.000; move to front right corner of bed ;G1 X-90 Y-73 ;E24 F2000.000; extrude a line of filament across the front edge of the bed ;G4 P2000; wait for ooze to slow ;G1 Z0 F6000.000; lower nozzle height to 0 ;G1 X-95; wipe nozzle ;G1 Z0.2 F6000.000; set nozzle to first layer height ;G1 F12000; ensure fast travel to first print move ;G92 E0; set E to 0 again ;M73 P0; reset build progress to 0 """ for line in setup_gcode.splitlines(): result = gpx.write(line) print line, ":", result
def progress(self, percent): # we don't want the progress event to pre-empt the build start or # override the build end notification and the M73 causes a build start # if we aren't already running one if gpx.build_started(): try: # loop sending for a while if the queue isn't full or if the bot # isn't listening for i in range(0, 10): try: gpx.write("M73 P%d" % percent) break except gpx.BufferOverflow: time.sleep(0.01) except gpx.Timeout: time.sleep(0.1) except gpx.CancelBuild: self._bot_reports_build_cancelled()
def write(self, data): try: data = data.strip() if self.baudrate != self._baudrate: try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put("") return # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) if match is not None: lineno = int(match.group(1)) if lineno == 1 and not "M112" in data: self._bot_cancelled = False currentJob = self._printer.get_current_job() if ( currentJob is not None and "file" in currentJob.keys() and "name" in currentJob["file"] and currentJob["file"]["name"] is not None ): build_name = os.path.splitext(os.path.basename(currentJob["file"]["name"]))[0] gpx.write("(@build %s)" % build_name) gpx.write("M136 (%s)" % build_name) else: gpx.write("M136") # try to talk to the bot try: if match is None: reprapSave = gpx.reprap_flavor(True) # loop sending until the queue isn't full retries = 0 while True: try: self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: time.sleep(0.1) except gpx.Timeout: time.sleep(1) retries += 1 if retries >= 5: raise finally: if match is None: gpx.reprap_flavor(reprapSave) except gpx.CancelBuild: self._bot_reports_build_cancelled()
def write(self, data): data = data.strip() # strip checksum if "*" in data: data = data[:data.rfind("*")] if (self.baudrate != self._baudrate): try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put('') pass return # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) if match is not None: lineno = int(match.group(1)) if lineno == 1: currentJob = self._printer.get_current_job() if currentJob is not None and "file" in currentJob.keys() and "name" in currentJob["file"]: gpx.write("M136 %s" % os.path.basename(currentJob["file"]["name"])) else: gpx.write("M136") # try to talk to the bot while True: try: if match is None: reprapSave = gpx.reprap_flavor(True) self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: self._append("buffer overflow") time.sleep(1) pass finally: if match is None: gpx.reprap_flavor(reprapSave)
def write(self, data): try: rval = len(data) data = data.strip() if (self.baudrate != self._baudrate): try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put('') return 0 # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) # try to talk to the bot try: if match is None: reprapSave = gpx.reprap_flavor(True) # loop sending until the queue isn't full timeout_retries = 0 bo_retries = 0 while True: try: self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: bo_retries += 1 try: if gpx.build_paused(): if bo_retries == 1: self._append( "// echo: print paused at bot") time.sleep(1) # 1 sec except IOError: pass time.sleep(0.1) # 100 ms except gpx.Timeout: time.sleep(1) timeout_retries += 1 if (timeout_retries >= 5): raise finally: if match is None: gpx.reprap_flavor(reprapSave) except gpx.CancelBuild: self._bot_reports_build_cancelled() return rval
def write(self, data): try: data = data.strip() if (self.baudrate != self._baudrate): try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put('') return # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) if match is not None: lineno = int(match.group(1)) if lineno == 1 and not "M112" in data: self._bot_cancelled = False currentJob = self._printer.get_current_job() if currentJob is not None and "file" in currentJob.keys( ) and "name" in currentJob["file"] and currentJob["file"][ "name"] is not None: build_name = os.path.splitext( os.path.basename(currentJob["file"]["name"]))[0] gpx.write("(@build %s)" % build_name) gpx.write("M136 (%s)" % build_name) else: gpx.write("M136") # try to talk to the bot try: if match is None: reprapSave = gpx.reprap_flavor(True) # loop sending until the queue isn't full retries = 0 while True: try: self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: time.sleep(0.1) except gpx.Timeout: time.sleep(1) retries += 1 if (retries >= 5): raise finally: if match is None: gpx.reprap_flavor(reprapSave) except gpx.CancelBuild: self._bot_reports_build_cancelled()
def readline(self): try: while (self.baudrateError): if (self._baudrate != self.baudrate): gpx.write("M105") return '' try: s = self.outgoing.get_nowait() self._logger.debug("readline: %s" % s) return s except Queue.Empty: pass s = gpx.readnext() timeout = self.timeout append_later = None if gpx.waiting(): append_later = s timeout = 2 else: self._append(s) while True: try: s = self.outgoing.get(timeout=timeout) if append_later is not None: self._append(s) s = append_later self._logger.debug("readline: %s" % s) return s except Queue.Empty: self._logger.debug("timeout") if append_later is None: return '' self._append(append_later) append_later = None except gpx.CancelBuild: self._bot_reports_build_cancelled() return '// echo: build cancelled'
def readline(self): try: while self.baudrateError: if self._baudrate != self.baudrate: gpx.write("M105") return "" try: s = self.outgoing.get_nowait() self._logger.debug("readline: %s" % s) return s except Queue.Empty: pass s = gpx.readnext() timeout = self.timeout append_later = None if gpx.waiting(): append_later = s timeout = 2 else: self._append(s) while True: try: s = self.outgoing.get(timeout=timeout) if append_later is not None: self._append(s) s = append_later self._logger.debug("readline: %s" % s) return s except Queue.Empty: self._logger.debug("timeout") if append_later is None: return "" self._append(append_later) append_later = None except gpx.CancelBuild: self._bot_reports_build_cancelled() return "// echo: build cancelled"
def readline(self): try: if (self.baudrateError): if (self._baudrate != self.baudrate): gpx.write("M105") return '' try: return self.outgoing.get_nowait() except Queue.Empty: pass if gpx.listing_files(): return gpx.readnext() timeout = 2 if gpx.waiting else self.timeout try: return self.outgoing.get(timeout=timeout) except Queue.Empty: return gpx.readnext() except gpx.CancelBuild: self._bot_reports_build_cancelled() return '// echo: build cancelled'
def write(self, data): try: rval = len(data) data = data.strip() if (self.baudrate != self._baudrate): try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put('') return 0 # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) if match is not None: lineno = int(match.group(1)) if lineno == 1 and not "M112" in data: self._bot_cancelled = False currentJob = self._printer.get_current_job() try: build_name = currentJob["file"]["name"] build_name = os.path.splitext(os.path.basename(build_name))[0] except KeyError: build_name = "OctoPrint" gpx.write('(@build "%s")' % build_name) gpx.write("M136 (%s)" % build_name) # try to talk to the bot try: if match is None: reprapSave = gpx.reprap_flavor(True) # loop sending until the queue isn't full timeout_retries = 0 bo_retries = 0 while True: try: self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: bo_retries += 1 try: if gpx.build_paused(): if bo_retries == 1: self._append("// echo: print paused at bot") time.sleep(1) # 1 sec except IOError: pass time.sleep(0.1) # 100 ms except gpx.Timeout: time.sleep(1) timeout_retries += 1 if (timeout_retries >= 5): raise finally: if match is None: gpx.reprap_flavor(reprapSave) except gpx.CancelBuild: self._bot_reports_build_cancelled() return rval
dB = pos[axis]-cornerB[axis] if fabs(dA) < fabs(dist): dist = dA closest = axis if fabs(dB) < fabs(dist): dist = dB closest = axis outside = outside - 1 if closest > -1 and outside == 0: force[closest] = -stiffness*dist; print_pos = [(a) * 200 for a in avg_pos] print_pos = (print_pos[0]) * 2, (-print_pos[2] + 30) * 2, -print_pos[1] if not gpx.waiting(): gcode = 'G1 X{:3.3f} Y{:3.3f} Z{:3.3f} F9999999'.format(*print_pos) print gcode gpx.write(gcode) import time time.sleep(0.03) force = [0, 0, 0] force_fv.x = force[0] force_fv.y = force[1] force_fv.z = force[2] fdd.setForces(force_fv)
import gpx gpx.connect("/dev/ttyACM0", 0, "/home/pi/gpx.ini") gpx.write("M72 P1") gpx.disconnect()
def write(self, data): try: rval = len(data) data = data.strip() if (self.baudrate != self._baudrate): try: self._baudrate = self.baudrate self._logger.info("new baudrate = %d" % self.baudrate) gpx.set_baudrate(self.baudrate) self.baudrateError = False except ValueError: self.baudrateError = True self.outgoing.put('') return 0 # look for a line number # line number means OctoPrint is streaming gcode at us (gpx.ini flavor) # no line number means OctoPrint is generating the gcode (reprap flavor) match = self._regex_linenumber.match(data) if match is not None: lineno = int(match.group(1)) if lineno == 1 and not "M112" in data: self._bot_cancelled = False currentJob = self._printer.get_current_job() try: build_name = currentJob["file"]["name"] build_name = os.path.splitext( os.path.basename(build_name))[0] except KeyError: build_name = "OctoPrint" gpx.write('(@build "%s")' % build_name) gpx.write("M136 (%s)" % build_name) # try to talk to the bot try: if match is None: reprapSave = gpx.reprap_flavor(True) # loop sending until the queue isn't full timeout_retries = 0 bo_retries = 0 while True: try: self._append(gpx.write("%s" % data)) break except gpx.BufferOverflow: bo_retries += 1 try: if gpx.build_paused(): if bo_retries == 1: self._append( "// echo: print paused at bot") time.sleep(1) # 1 sec except IOError: pass time.sleep(0.1) # 100 ms except gpx.Timeout: time.sleep(1) timeout_retries += 1 if (timeout_retries >= 5): raise finally: if match is None: gpx.reprap_flavor(reprapSave) except gpx.CancelBuild: self._bot_reports_build_cancelled() return rval
import gpx gpx.connect("/dev/ttyACM0", 0, "/home/pi/gpx.ini") print gpx.write("M105") print gpx.write("M114") print gpx.write("G91") gpx.disconnect()