Skip to content

Commit

Permalink
Loading and setting the values from grbl
Browse files Browse the repository at this point in the history
  • Loading branch information
vlachoudis committed Nov 2, 2016
1 parent edd221b commit 9fb71fb
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
7 changes: 5 additions & 2 deletions CNCCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,9 +1750,12 @@ def drawPaths(self):
if time.time() - startTime > DRAW_TIME:
raise AlarmException()
n = 1000
#cmd = self.cnc.parseLine(line)
try:
cmd = CNC.breakLine(self.gcode.evaluate(CNC.compileLine(line)))
cmd = self.gcode.evaluate(CNC.compileLine(line))
if isinstance(cmd,tuple):
cmd = None
else:
cmd = CNC.breakLine(cmd)
except AlarmException:
raise
except:
Expand Down
19 changes: 15 additions & 4 deletions Sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
TLOPAT = re.compile(r"^\[(...):([+\-]?\d*\.\d*)\]$")
DOLLARPAT = re.compile(r"^\[G\d* .*\]$")
FEEDPAT = re.compile(r"^(.*)[fF](\d+\.?\d+)(.*)$")

SPLITPAT = re.compile(r"[:,]")
VARPAT = re.compile(r"^\$(\d+)=(\d*\.?\d*) *\(?.*")

CONNECTED = "Connected"
NOT_CONNECTED = "Not connected"
Expand Down Expand Up @@ -830,7 +830,7 @@ def stopRun(self, event=None):
def serialIO(self):
cline = [] # length of pipeline commands
sline = [] # pipeline commands
wait = False # wait for commands to complete
wait = False # wait for commands to complete (status change to Idle)
tosend = None # next string to send
status = False # waiting for status <...> report
tr = tg = time.time() # last time a ? or $G was send to grbl
Expand Down Expand Up @@ -903,7 +903,7 @@ def serialIO(self):
#print "+++",repr(tosend)
if isinstance(tosend, tuple):
#print "gcount tuple=",self._gcount
# wait to empty the grbl buffer
# wait to empty the grbl buffer and status is Idle
if tosend[0] == WAIT:
# Don't count WAIT until we are idle!
wait = True
Expand Down Expand Up @@ -1022,6 +1022,11 @@ def serialIO(self):
CNC.vars["wcoy"] = float(word[2])
CNC.vars["wcoz"] = float(word[3])

# Machine is Idle buffer is empty stop waiting and go on
if wait and not cline and fields[0]=="Idle":
wait = False
self._gcount += 1

else:
status = False
pat = STATUSPAT.match(line)
Expand Down Expand Up @@ -1124,7 +1129,7 @@ def serialIO(self):
self._stop = True
self.runEnded()

elif line[:4]=="Grbl": # and self.running:
elif line[:4]=="Grbl" or line[:13]=="CarbideMotion": # and self.running:
tg = time.time()
self.log.put((Sender.MSG_RECEIVE, line))
self._stop = True
Expand All @@ -1148,6 +1153,12 @@ def serialIO(self):
# a valid gcode event occurs
self._alarm = False

elif line[0] == "$":
self.log.put((Sender.MSG_RECEIVE, line))
pat = VARPAT.match(line)
if pat:
CNC.vars["grbl_%s"%(pat.group(1))] = pat.group(2)

else:
self.log.put((Sender.MSG_RECEIVE, line))

Expand Down
96 changes: 91 additions & 5 deletions ToolsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
from operator import attrgetter

import os
import time
import glob
import Utils
import Ribbon
import tkExtra
import Unicode
import CNCRibbon

from CNC import CNC

_EXE_FONT = ("Helvetica",12,"bold")

#===============================================================================
Expand Down Expand Up @@ -106,6 +109,10 @@ def update(self):
def event_generate(self, msg, **kwargs):
self.master.listbox.event_generate(msg, **kwargs)

# ----------------------------------------------------------------------
def beforeChange(self, app):
pass

# ----------------------------------------------------------------------
def populate(self):
self.master.listbox.delete(0,END)
Expand Down Expand Up @@ -484,7 +491,7 @@ def execute(self, app):
#==============================================================================
# CNC machine configuration
#==============================================================================
class CNC(_Base):
class Config(_Base):
def __init__(self, master):
_Base.__init__(self, master)
self.name = "CNC"
Expand Down Expand Up @@ -514,8 +521,8 @@ def __init__(self, master):
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
self.master.inches = self["units"]
self.master.digits = int(self["round"])
self.master.inches = self["units"]
self.master.digits = int(self["round"])
self.master.cnc().decimal = self.master.digits
self.master.cnc().startup = self["startup"]
self.master.gcode.header = self["header"]
Expand Down Expand Up @@ -757,6 +764,84 @@ def execute(self,app):
app.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z)
app.setStatus(_("Create tabs on blocks"))

#==============================================================================
# Controller setup
#==============================================================================
class Controller(_Base):
def __init__(self, master):
_Base.__init__(self, master)
self.name = "Controller"
self.variables = [
("grbl_0", "int", 10, _("$0 Step pulse time [us]")),
("grbl_1", "int", 25, _("$1 Step idle delay [ms]")),
("grbl_2", "int", 0, _("$2 Step pulse invert [mask]")),
("grbl_3", "int", 0, _("$3 Step direction invert [mask]")),
("grbl_4", "bool", 0, _("$4 Invert step enable pin")),
("grbl_5", "bool", 0, _("$5 Invert limit pins")),
("grbl_6", "bool", 0, _("$6 Invert probe pin")),
("grbl_10", "int", 1, _("$10 Status report options [mask]")),
("grbl_11", "float", 0.010, _("$11 Junction deviation [mm]")),
("grbl_12", "float", 0.002, _("$12 Arc tolerance [mm]")),
("grbl_13", "bool", 0, _("$13 Report in inches")),
("grbl_20", "bool", 0, _("$20 Soft limits enable")),
("grbl_21", "bool", 0, _("$21 Hard limits enable")),
("grbl_22", "bool", 0, _("$22 Homing cycle enable")),
("grbl_23", "int", 0, _("$23 Homing direction invert [mask]")),
("grbl_24", "float", 25., _("$24 Homing locate feed rate [mm/min]")),
("grbl_25", "float", 500., _("$25 Homing search seek rate [mm/min]")),
("grbl_26", "int", 250, _("$26 Homing switch debounce delay, ms")),
("grbl_27", "float", 1., _("$27 Homing switch pull-off distance [mm]")),
("grbl_30", "float", 1000., _("$30 Maximum spindle speed [RPM]")),
("grbl_31", "float", 0., _("$31 Minimum spindle speed [RPM]")),
("grbl_32", "bool", 0, _("$32 Laser-mode enable")),
("grbl_100", "float", 250., _("$100 X-axis steps per mm")),
("grbl_101", "float", 250., _("$101 Y-axis steps per mm")),
("grbl_102", "float", 250., _("$102 Z-axis steps per mm")),
("grbl_110", "float", 500., _("$110 X-axis maximum rate [mm/min]")),
("grbl_111", "float", 500., _("$111 Y-axis maximum rate [mm/min]")),
("grbl_112", "float", 500., _("$112 Z-axis maximum rate [mm/min]")),
("grbl_120", "float", 10., _("$120 X-axis acceleration [mm/sec^2]")),
("grbl_121", "float", 10., _("$121 Y-axis acceleration [mm/sec^2]")),
("grbl_122", "float", 10., _("$122 Z-axis acceleration [mm/sec^2]")),
("grbl_130", "float", 200., _("$130 X-axis maximum travel [mm]")),
("grbl_131", "float", 200., _("$131 Y-axis maximum travel [mm]")),
("grbl_132", "float", 200., _("$132 Z-axis maximum travel [mm]"))]
self.buttons.append("exe")

# ----------------------------------------------------------------------
def execute(self, app):
lines = []
for n,t,d,c in self.variables:
v = self[n]
try:
if t=="float":
if v == float(CNC.vars[n]): continue
else:
if v == int(CNC.vars[n]): continue
except:
continue
lines.append("$%s=%s"%(n[5:],str(v)))
lines.append("%wait")
lines.append("$$")
app.run(lines=lines)

# ----------------------------------------------------------------------
def beforeChange(self, app):
app.sendGCode("$$")
time.sleep(1)

# ----------------------------------------------------------------------
def populate(self):
for n, t, d, l in self.variables:
try:
if t=="float":
self.values[n] = float(CNC.vars[n])
else:
self.values[n] = int(CNC.vars[n])
except KeyError:
pass
_Base.populate(self)

#==============================================================================
# Tools container class
#==============================================================================
Expand All @@ -772,7 +857,7 @@ def __init__(self, gcode):
self.listbox = None

# CNC should be first to load the inches
for cls in [ CNC, Font, Color, Cut, Drill, EndMill, Events,
for cls in [ Config, Font, Color, Controller, Cut, Drill, EndMill, Events,
Material, Pocket, Profile, Shortcut, Stock,
Tabs]:
tool = cls(self)
Expand Down Expand Up @@ -1316,7 +1401,7 @@ def __init__(self, master, app):
self.tools.addButton("exe",b)

self.toolList = tkExtra.MultiListbox(self,
((_("Name"), 16, None),
((_("Name"), 24, None),
(_("Value"), 24, None)),
header = False,
stretch = "last",
Expand All @@ -1340,6 +1425,7 @@ def __init__(self, master, app):
#----------------------------------------------------------------------
def change(self, a=None, b=None, c=None):
tool = self.tools.getActive()
tool.beforeChange(self.app)
tool.populate()
tool.update()
self.tools.activateButtons(tool)
Expand Down

0 comments on commit 9fb71fb

Please sign in to comment.