Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Gcode scrolling / stepping / skipping #1397

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 49 additions & 28 deletions printrun/printcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def _sender(self):
def _checksum(self, command):
return reduce(lambda x, y: x ^ y, map(ord, command))

def startprint(self, gcode, startindex = 0):
def startprint(self, gcode, startindex = 0, really_start=True):
"""Start a print.

The `mainqueue` is populated and then commands are gradually sent to
Expand Down Expand Up @@ -575,10 +575,14 @@ def startprint(self, gcode, startindex = 0):
self._send("M110 N-1")

resuming = (startindex != 0)
self.print_thread = threading.Thread(target = self._print,
name = 'print thread',
kwargs = {"resuming": resuming})
self.print_thread.start()

if really_start:
self.print_thread = threading.Thread(target = self._print,
name = 'print thread',
kwargs = {"resuming": resuming})
self.print_thread.start()
else:
self.pause()
return True

def cancelprint(self):
Expand All @@ -600,6 +604,21 @@ def runSmallScript(self, filename):
except:
pass

def current_line(self, context=5):
if self.mainqueue and self.mainqueue.has_index(self.queueindex):
lines = []
index = self.queueindex - context
while index < self.queueindex + context:
(layer, line) = self.mainqueue.idxs(index)
gline = self.mainqueue.all_layers[layer][line]

prefix = "> " if index == self.queueindex else " "
suffix = " <" if index == self.queueindex else ""

lines.append((index, layer, prefix + gline.raw + suffix))
index = index + 1
return lines

def pause(self):
"""Pauses an ongoing print.

Expand All @@ -616,12 +635,13 @@ def pause(self):
self.paused = True
self.printing = False

# ';@pause' in the gcode file calls pause from the print thread
if not threading.current_thread() is self.print_thread:
try:
self.print_thread.join()
except:
self.logError(traceback.format_exc())
if self.print_thread:
# ';@pause' in the gcode file calls pause from the print thread
if not threading.current_thread() is self.print_thread:
try:
self.print_thread.join()
except:
self.logError(traceback.format_exc())

self.print_thread = None

Expand All @@ -634,7 +654,7 @@ def pause(self):
self.pauseRelative = self.analyzer.relative
self.pauseRelativeE = self.analyzer.relative_e

def resume(self):
def resume(self, restore=True):
"""Resumes a paused print.

`printcore` will first attempt to set the position and conditions it
Expand All @@ -649,22 +669,23 @@ def resume(self):
"""
if not self.paused: return False
# restores the status
self.send_now("G90") # go to absolute coordinates

xyFeed = '' if self.xy_feedrate is None else ' F' + str(self.xy_feedrate)
zFeed = '' if self.z_feedrate is None else ' F' + str(self.z_feedrate)

self.send_now("G1 X%s Y%s%s" % (self.pauseX, self.pauseY, xyFeed))
self.send_now("G1 Z" + str(self.pauseZ) + zFeed)
self.send_now("G92 E" + str(self.pauseE))

# go back to relative if needed
if self.pauseRelative:
self.send_now("G91")
if self.pauseRelativeE:
self.send_now('M83')
# reset old feed rate
self.send_now("G1 F" + str(self.pauseF))
if restore:
self.send_now("G90") # go to absolute coordinates

xyFeed = '' if self.xy_feedrate is None else ' F' + str(self.xy_feedrate)
zFeed = '' if self.z_feedrate is None else ' F' + str(self.z_feedrate)

self.send_now("G1 X%s Y%s%s" % (self.pauseX, self.pauseY, xyFeed))
self.send_now("G1 Z" + str(self.pauseZ) + zFeed)
self.send_now("G92 E" + str(self.pauseE))

# go back to relative if needed
if self.pauseRelative:
self.send_now("G91")
if self.pauseRelativeE:
self.send_now('M83')
# reset old feed rate
self.send_now("G1 F" + str(self.pauseF))

self.paused = False
self.printing = True
Expand Down
36 changes: 29 additions & 7 deletions printrun/pronsole.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of the Printrun suite.
# file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +38,7 @@
get_home_pos, parse_build_dimensions, parse_temperature_report, \
setup_logging
install_locale('pronterface')
from .settings import Settings, BuildDimensionsSetting
from .settings import Settings, BuildDimensionsSetting, BooleanSetting
from .power import powerset_print_start, powerset_print_stop
from printrun import gcoder
from .rpc import ProntRPC
Expand Down Expand Up @@ -180,6 +180,7 @@ def __init__(self):
self.processing_args = False
self.settings = Settings(self)
self.settings._add(BuildDimensionsSetting("build_dimensions", "200x200x100+0+0+0+0+0+0", _("Build Dimensions:"), _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ"), "Printer"), self.update_build_dimensions)
self.settings._add(BooleanSetting("stepping_mode", False, "GCode Stepping Mode: When true, will go into paused mode when starting and disable restore on resume"))
self.settings._port_list = self.scanserial
self.update_build_dimensions(None, self.settings.build_dimensions)
self.update_tcp_streaming_mode(None, self.settings.tcp_streaming_mode)
Expand Down Expand Up @@ -589,8 +590,8 @@ def set(self, var, str):
def do_set(self, argl):
args = argl.split(None, 1)
if len(args) < 1:
for k in [kk for kk in dir(self.settings) if not kk.startswith("_")]:
self.log("%s = %s" % (k, str(getattr(self.settings, k))))
for k in self.settings._all_settings():
self.log("%s = %s" % (k.name, k.value))
return
if len(args) < 2:
# Try getting the default value of the setting to check whether it
Expand Down Expand Up @@ -932,6 +933,17 @@ def statuschecker(self):
# File loading handling
# --------------------------------------------------------------

def do_line(self, l=''):
lines = self.p.current_line()
if lines:
for line in lines:
self.log("%04d: %s" % (line[0], line[2]))

def do_skip(self, l):
skip = int(l)
self.p.queueindex = self.p.queueindex + skip


def do_load(self, filename):
self._do_load(filename)

Expand Down Expand Up @@ -1094,7 +1106,16 @@ def do_print(self, l):
self.log(_("Printing %s") % self.filename)
self.log(_("You can monitor the print with the monitor command."))
self.sdprinting = False
self.p.startprint(self.fgcode)
really = not (l and l == 'pause') and not self.settings.stepping_mode
self.p.startprint(self.fgcode, really_start=really)
if not really:
self.paused = True

def do_next(self, l):
if self.paused:
self.p.printing = True
self.p._sendnext()
self.p.printing = False

def do_pause(self, l):
if self.sdprinting:
Expand All @@ -1121,7 +1142,8 @@ def do_resume(self, l):
self.p.send_now("M24")
return
else:
self.p.resume()
do_restore = (not l or l != 'direct') and not self.settings.stepping_mode
self.p.resume(do_restore)

def help_resume(self):
self.log(_("Resumes a paused print."))
Expand Down Expand Up @@ -1509,7 +1531,7 @@ def do_monitor(self, l):
elif self.sdprinting:
preface = _("SD print progress: ")
progress = self.percentdone
prev_msg = preface + "%.1f%%" % progress
prev_msg = preface + "%3.1f%% - %d" % (progress, self.p.queueindex)
if self.silent is False:
sys.stdout.write("\r" + prev_msg.ljust(prev_msg_len))
sys.stdout.flush()
Expand Down
1 change: 1 addition & 0 deletions pronsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@
logging.error(_("Caught an exception, exiting:")
+ "\n" + traceback.format_exc())
interp.p.disconnect()
import pdb; pdb.post_mortem()