Skip to content

Commit

Permalink
Interpretation of the state of the machine
Browse files Browse the repository at this point in the history
  • Loading branch information
vlachoudis committed Sep 4, 2015
1 parent e9e5a9a commit 827b038
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
17 changes: 15 additions & 2 deletions ControlPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

try:
from Tkinter import *
import tkMessageBox
except ImportError:
from tkinter import *
import tkinter.messagebox as tkMessageBox

import math

Expand All @@ -22,6 +24,7 @@
import tkExtra
import Unicode
import CNCRibbon
from Sender import ERROR_CODES

_LOWSTEP = 0.0001
_HIGHSTEP = 1000.0
Expand Down Expand Up @@ -208,11 +211,14 @@ def __init__(self, master, app):
col = 0
Label(self,text="Status:").grid(row=row,column=col,sticky=E)
col += 1
self.state = Label(self,
self.state = Button(self,
text=Sender.NOT_CONNECTED,
font=DROFrame.dro_status,
background=Sender.STATECOLOR[Sender.NOT_CONNECTED])
command=self.showState,
background=Sender.STATECOLOR[Sender.NOT_CONNECTED],
activebackground="LightYellow")
self.state.grid(row=row,column=col, columnspan=3, sticky=EW)
tkExtra.Balloon.set(self.state, "Show current state of the machine")

row += 1
col = 0
Expand Down Expand Up @@ -375,6 +381,13 @@ def _wcsSet(self, x, y, z):
data="Set workspace %s to X%s Y%s Z%s"%(WCS[p],str(x),str(y),str(z)))
self.event_generate("<<CanvasFocus>>")

#----------------------------------------------------------------------
def showState(self):
state = CNC.vars["state"]
tkMessageBox.showinfo("State: %s"%(state),
ERROR_CODES.get(state,"No info available.\n.Please contact the author."),
parent=self)

#===============================================================================
# ControlFrame
#===============================================================================
Expand Down
52 changes: 37 additions & 15 deletions Sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,39 @@

STATECOLORDEF = "LightYellow"

# From https://github.com/grbl/grbl/wiki/Interfacing-with-Grbl
ERROR_CODES = {
23 : "A G or M command value in the block is not an integer. For example, G4 can't be G4.13. Some G-code commands are floating point (G92.1), but these are ignored.",
24 : "Two G-code commands that both require the use of the XYZ axis words were detected in the block.",
25 : "A G-code word was repeated in the block.",
26 : "A G-code command implicitly or explicitly requires XYZ axis words in the block, but none were detected.",
27 : "The G-code protocol mandates N line numbers to be within the range of 1-99,999. We think that's a bit silly and arbitrary. So, we increased the max number to 9,999,999. This error occurs when you send a number more than this.",
28 : "A G-code command was sent, but is missing some important P or L value words in the line. Without them, the command can't be executed. Check your G-code.",
29 : "Grbl supports six work coordinate systems G54-G59. This error happens when trying to use or configure an unsupported work coordinate system, such as G59.1, G59.2, and G59.3.",
30 : "The G53 G-code command requires either a G0 seek or G1 feed motion mode to be active. A different motion was active.",
31 : "There are unused axis words in the block and G80 motion mode cancel is active.",
32 : "A G2 or G3 arc was commanded but there are no XYZ axis words in the selected plane to trace the arc.",
33 : "The motion command has an invalid target. G2, G3, and G38.2 generates this error. For both probing and arcs traced with the radius definition, the current position cannot be the same as the target. This also errors when the arc is mathematically impossible to trace, where the current position, the target position, and the radius of the arc doesn't define a valid arc.",
34 : "A G2 or G3 arc, traced with the radius definition, had a mathematical error when computing the arc geometry. Try either breaking up the arc into semi-circles or quadrants, or redefine them with the arc offset definition.",
35 : "A G2 or G3 arc, traced with the offset definition, is missing the IJK offset word in the selected plane to trace the arc.",
36 : "There are unused, leftover G-code words that aren't used by any command in the block.",
37 : "The G43.1 dynamic tool length offset command cannot apply an offset to an axis other than its configured axis. The Grbl default axis is the Z-axis.",
NOT_CONNECTED : "Grbl is not connected. Please specify the correct port and click Open.",
"ok" : "All is good! Everything in the last line was understood by Grbl and was successfully processed and executed.",
"error:Expected command letter" : "G-code is composed of G-code \"words\", which consists of a letter followed by a number value. This error occurs when the letter prefix of a G-code word is missing in the G-code block (aka line).",
"error:Bad number format" : "The number value suffix of a G-code word is missing in the G-code block, or when configuring a $Nx=line or $x=val Grbl setting and the x is not a number value.",
"error:Invalid statement" : "The issued Grbl $ system command is not recognized or is invalid.",
"error:Value < 0" : "The value of a $x=val Grbl setting, F feed rate, N line number, P word, T tool number, or S spindle speed is negative.",
"error:Setting disabled" : "Homing is disabled when issuing a $H command.",
"error:Value < 3 usec" : "Step pulse time length cannot be less than 3 microseconds (for technical reasons).",
"error:EEPROM read fail. Using defaults" : "If Grbl can't read data contained in the EEPROM, this error is returned. Grbl will also clear and restore the effected data back to defaults.",
"error:Not idle" : "Certain Grbl $ commands are blocked depending Grbl's current state, or what its doing. In general, Grbl blocks any command that fetches from or writes to the EEPROM since the AVR microcontroller will shutdown all of the interrupts for a few clock cycles when this happens. There is no work around, other than blocking it. This ensures both the serial and step generator interrupts are working smoothly throughout operation.",
"error:Alarm lock" : "Grbl enters an ALARM state when Grbl doesn't know where it is and will then block all G-code commands from being executed. This error occurs if G-code commands are sent while in the alarm state. Grbl has two alarm scenarios: When homing is enabled, Grbl automatically goes into an alarm state to remind the user to home before doing anything; When something has went critically wrong, usually when Grbl can't guarantee positioning. This typically happens when something causes Grbl to force an immediate stop while its moving from a hard limit being triggered or a user commands an ill-timed reset.",
"error:Homing not enabled" : "Soft limits cannot be enabled if homing is not enabled, because Grbl has no idea where it is when you startup your machine unless you perform a homing cycle.",
"error:Line overflow" : "Grbl has to do everything it does within 2KB of RAM. Not much at all. So, we had to make some decisions on what's important. Grbl limits the number of characters in each line to less than 80 characters (70 in v0.8, 50 in v0.7 or earlier), excluding spaces or comments. The G-code standard mandates 256 characters, but Grbl simply doesn't have the RAM to spare. However, we don't think there will be any problems with this with all of the expected G-code commands sent to Grbl. This error almost always occurs when a user or CAM-generated G-code program sends position values that are in double precision (i.e. -2.003928578394852), which is not realistic or physically possible. Users and GUIs need to send Grbl floating point values in single precision (i.e. -2.003929) to avoid this error.",
"error:Modal group violation" : "The G-code parser has detected two G-code commands that belong to the same modal group in the block/line. Modal groups are sets of G-code commands that mutually exclusive. For example, you can't issue both a G0 rapids and G2 arc in the same line, since they both need to use the XYZ target position values in the line. LinuxCNC.org has some great documentation on modal groups.",
"error:Unsupported command" : "The G-code parser doesn't recognize or support one of the G-code commands in the line. Check your G-code program for any unsupported commands and either remove them or update them to be compatible with Grbl.",
"error:Undefined feed rate" : "There is no feed rate programmed, and a G-code command that requires one is in the block/line. The G-code standard mandates F feed rates to be undefined upon a reset or when switching from inverse time mode to units mode. Older Grbl versions had a default feed rate setting, which was illegal and was removed in Grbl v0.9.",
"error:Invalid gcode ID:23" : "A G or M command value in the block is not an integer. For example, G4 can't be G4.13. Some G-code commands are floating point (G92.1), but these are ignored.",
"error:Invalid gcode ID:24" : "Two G-code commands that both require the use of the XYZ axis words were detected in the block.",
"error:Invalid gcode ID:25" : "A G-code word was repeated in the block.",
"error:Invalid gcode ID:26" : "A G-code command implicitly or explicitly requires XYZ axis words in the block, but none were detected.",
"error:Invalid gcode ID:27" : "The G-code protocol mandates N line numbers to be within the range of 1-99,999. We think that's a bit silly and arbitrary. So, we increased the max number to 9,999,999. This error occurs when you send a number more than this.",
"error:Invalid gcode ID:28" : "A G-code command was sent, but is missing some important P or L value words in the line. Without them, the command can't be executed. Check your G-code.",
"error:Invalid gcode ID:29" : "Grbl supports six work coordinate systems G54-G59. This error happens when trying to use or configure an unsupported work coordinate system, such as G59.1, G59.2, and G59.3.",
"error:Invalid gcode ID:30" : "The G53 G-code command requires either a G0 seek or G1 feed motion mode to be active. A different motion was active.",
"error:Invalid gcode ID:31" : "There are unused axis words in the block and G80 motion mode cancel is active.",
"error:Invalid gcode ID:32" : "A G2 or G3 arc was commanded but there are no XYZ axis words in the selected plane to trace the arc.",
"error:Invalid gcode ID:33" : "The motion command has an invalid target. G2, G3, and G38.2 generates this error. For both probing and arcs traced with the radius definition, the current position cannot be the same as the target. This also errors when the arc is mathematically impossible to trace, where the current position, the target position, and the radius of the arc doesn't define a valid arc.",
"error:Invalid gcode ID:34" : "A G2 or G3 arc, traced with the radius definition, had a mathematical error when computing the arc geometry. Try either breaking up the arc into semi-circles or quadrants, or redefine them with the arc offset definition.",
"error:Invalid gcode ID:35" : "A G2 or G3 arc, traced with the offset definition, is missing the IJK offset word in the selected plane to trace the arc.",
"error:Invalid gcode ID:36" : "There are unused, leftover G-code words that aren't used by any command in the block.",
"error:Invalid gcode ID:37" : "The G43.1 dynamic tool length offset command cannot apply an offset to an axis other than its configured axis. The Grbl default axis is the Z-axis.",
}

#==============================================================================
Expand Down Expand Up @@ -727,6 +744,11 @@ def serialIO(self):
if isinstance(tosend, unicode):
tosend = tosend.encode("ascii","replace")

# FIXME should be smarter and apply the feed override
# also on cards with out feed (the first time only)
# I should track the feed rate for every card
# and when it is changed apply a F### command
# even if it is not there
if CNC.vars["override"] != 100:
pat = FEEDPAT.match(tosend)
if pat is not None:
Expand Down
9 changes: 7 additions & 2 deletions ToolsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, master):
self.listdb = {} # lists database
self.current = None # currently editing index
self.n = 0
self.buttons = None
self.buttons = []

# ----------------------------------------------------------------------
def __setitem__(self, name, value):
Expand Down Expand Up @@ -431,6 +431,12 @@ def __init__(self, master):
class Shortcut(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Shortcut", "str")
self.buttons.append("exe")

#----------------------------------------------------------------------
def execute(self, app):
print "Loading shortcuts"
app.loadShortcuts()

#==============================================================================
# CNC machine configuration
Expand Down Expand Up @@ -731,7 +737,6 @@ def addButton(self, name, button):
def activateButtons(self, tool):
for btn in self.buttons.values():
btn.config(state=DISABLED)
if tool.buttons is None: return
for name in tool.buttons:
self.buttons[name].config(state=NORMAL)

Expand Down
7 changes: 4 additions & 3 deletions bCNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,8 @@ def loadShortcuts(self):
for name, value in Utils.config.items("Shortcut"):
# Convert to uppercase
key = name.title()
if not value:
self.unbind("<%s>"%(key))
else:
self.unbind("<%s>"%(key)) # unbind any possible old value
if value:
self.bind("<%s>"%(key), lambda e,s=self,c=value : s.execute(c))

#-----------------------------------------------------------------------
Expand Down Expand Up @@ -1519,6 +1518,8 @@ def _monitorSerial(self):
# Update position if needed
if self._posUpdate:
state = CNC.vars["state"]
#print state
#print Sender.ERROR_CODES[state]
try:
CNC.vars["color"] = STATECOLOR[state]
except KeyError:
Expand Down

0 comments on commit 827b038

Please sign in to comment.