Skip to content

Commit

Permalink
compile is pushing directly into the queue, to avoid waiting when sta…
Browse files Browse the repository at this point in the history
…rting a run
  • Loading branch information
vlachoudis committed Apr 12, 2016
1 parent c06dcfb commit 539de05
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 83 deletions.
51 changes: 33 additions & 18 deletions CNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -3765,11 +3765,22 @@ def optimize(self, items):
#----------------------------------------------------------------------
# Use probe information to modify the g-code to autolevel
#----------------------------------------------------------------------
def compile(self):
def compile(self, queue):
#lines = [self.cnc.startup]
paths = []

def add(line, path):
if line is not None:
if isinstance(line,str) or isinstance(line,unicode):
queue.put(line+"\n")
else:
queue.put(line)
paths.append(path)

autolevel = not self.probe.isEmpty()
lines = [self.cnc.startup]
paths = [None]
self.initPath()
for line in CNC.compile(self.cnc.startup.splitlines()):
add(line, None)

for i,block in enumerate(self.blocks):
if not block.enable: continue
Expand All @@ -3781,11 +3792,11 @@ def compile(self):
cmds = CNC.breakLine(cmds)
else:
# either CodeType or tuple, list[] append at it as is
lines.append(cmds)
#lines.append(cmds)
if isinstance(cmds,types.CodeType) or isinstance(cmds,int):
paths.append(None)
add(cmds, None)
else:
paths.append((i,j))
add(cmds, (i,j))
continue

skip = False
Expand All @@ -3797,8 +3808,9 @@ def compile(self):
if not xyz:
# while auto-levelling, do not ignore non-movement
# commands, just append the line as-is
lines.append(line)
paths.append(None)
#lines.append(line)
#paths.append(None)
add(line, None)
else:
extra = ""
for c in cmds:
Expand All @@ -3807,15 +3819,15 @@ def compile(self):
x1,y1,z1 = xyz[0]
for x2,y2,z2 in xyz[1:]:
for x,y,z in self.probe.splitLine(x1,y1,z1,x2,y2,z2):
lines.append(" G1%s%s%s%s"%\
add(" G1%s%s%s%s"%\
(self.fmt("X",x/self.cnc.unit),
self.fmt("Y",y/self.cnc.unit),
self.fmt("Z",z/self.cnc.unit),
extra))
paths.append((i,j))
extra),
(i,j))
extra = ""
x1,y1,z1 = x2,y2,z2
lines[-1] = lines[-1].strip()
#lines[-1] = lines[-1].strip()
self.cnc.motionEnd()
continue
else:
Expand All @@ -3834,9 +3846,11 @@ def compile(self):
expand = CNC.compile(self.cnc.toolChange())
self.cnc.motionEnd()

if expand:
lines.extend(expand)
paths.extend([None]*len(expand))
if expand is not None:
#lines.extend(expand)
#paths.extend([None]*len(expand))
for line in expand:
add(line, None)
expand = None
continue
elif skip:
Expand All @@ -3855,10 +3869,11 @@ def compile(self):
if cmd is not None:
newcmd.append(cmd)

lines.append("".join(newcmd))
paths.append((i,j))
#lines.append("".join(newcmd))
#paths.append((i,j))
add("".join(newcmd), (i,j))

return lines,paths
return paths

#if __name__=="__main__":
# orient = Orient()
Expand Down
42 changes: 20 additions & 22 deletions Sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,33 +446,31 @@ def open(self, device, baudrate):
self.thread.start()
return True

# #----------------------------------------------------------------------
# def close(self):
# if self.serial is None: return
# try:
# self.stopRun()
# except:
# pass
# self._runLines = 0
# self.thread = None
# time.sleep(1)
# self.serial.close()
# self.serial = None
# CNC.vars["state"] = NOT_CONNECTED
# CNC.vars["color"] = STATECOLOR[CNC.vars["state"]]
# try:
# self.state.config(text=CNC.vars["state"],
# background=CNC.vars["color"])
# except TclError:
# pass
#----------------------------------------------------------------------
# Close serial port
#----------------------------------------------------------------------
def close(self):
if self.serial is None: return
try:
self.stopRun()
except:
pass
self._runLines = 0
self.thread = None
time.sleep(1)
self.serial.close()
self.serial = None
CNC.vars["state"] = NOT_CONNECTED
CNC.vars["color"] = STATECOLOR[CNC.vars["state"]]
try:
self.dro.updateState()
except TclError:
pass

#----------------------------------------------------------------------
# Send to controller a gcode or command
#----------------------------------------------------------------------
def sendGCode(self, cmd):
# sys.stdout.write(">>> %s"%(cmd))
# import traceback
# traceback.print_stack()
if self.serial and not self.running:
self.queue.put(cmd)

Expand Down
71 changes: 28 additions & 43 deletions bCNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,19 +1948,8 @@ def open(self, device, baudrate):

#-----------------------------------------------------------------------
def close(self):
if self.serial is None: return
Sender.close(self)
try:
self.stopRun()
except:
pass
self._runLines = 0
self.thread = None
time.sleep(1)
self.serial.close()
self.serial = None
try:
CNC.vars["state"] = NOT_CONNECTED
CNC.vars["color"] = STATECOLOR[CNC.vars["state"]]
self.dro.updateState()
except TclError:
pass
Expand Down Expand Up @@ -1991,7 +1980,6 @@ def run(self, lines=None):
parent=self)
return

self.setStatus(_("Preparing to run ..."), True)
self.editor.selectClear()
self.selectionChange()
CNC.vars["errline"] = ""
Expand All @@ -2011,56 +1999,53 @@ def run(self, lines=None):
# parent=self)
# return

lines,paths = self.gcode.compile()
if not lines:
self._paths = self.gcode.compile(self.queue)
if not self._paths:
tkMessageBox.showerror(_("Empty gcode"),
_("Not gcode file was loaded"),
parent=self)
return

# reset colors
for ij in paths:
for ij in self._paths:
if not ij: continue
path = self.gcode[ij[0]].path(ij[1])
if path:
self.canvas.itemconfig(
path,
width=1,
fill=CNCCanvas.ENABLE_COLOR)
else:
lines = CNC.compile(lines)
paths = None

# # the buffer of the machine should be empty?
# self.initRun()
# self.canvas.clearSelection()
# self._gcount = 0 # count executed lines
# self._selectI = 0 # last selection pointer in items
if CNC.developer:
f = open("run.output","w");
f.write(lines.join("\n"))
f.close()
return

self.initRun()
# the buffer of the machine should be empty?
self.canvas.clearSelection()
self._runLines = len(lines) + 1 # plus the wait
self._paths = paths # drawing paths for canvas
# the buffer of the machine should be empty?
self._runLines = len(self._paths) + 1 # plus the wait
else:
n = 1 # including one wait command
for line in CNC.compile(lines):
if line is not None:
if isinstance(line,str) or isinstance(line,unicode):
self.queue.put(line+"\n")
else:
self.queue.put(line)
n += 1
self._runLines = n # set it at the end to be sure that all lines are queued

self.queue.put((WAIT,)) # wait at the end fo become idle

# print "Lines=",self.queue.qsize()
# print "Paths=",len(self._paths)
# print "RunLines=",self._runLines
# fout = open("run.out","w")
# while self.queue.qsize()>0:
# line = self.queue.get()
# print >>fout, line
# fout.close()
# return

self.setStatus(_("Running..."))
self.statusbar.setLimits(0, self._runLines)
self.statusbar.configText(fill="White")
self.statusbar.config(background="DarkGray")

for line in lines:
if line is not None:
if isinstance(line,str) or isinstance(line,unicode):
self.queue.put(line+"\n")
else:
self.queue.put(line)
self.queue.put((WAIT,)) # increase the runLines + 1

#-----------------------------------------------------------------------
# Start the web pendant
#-----------------------------------------------------------------------
Expand Down

0 comments on commit 539de05

Please sign in to comment.