diff --git a/bCNC/ControlPage.py b/bCNC/ControlPage.py index 08bdce593..957c80047 100644 --- a/bCNC/ControlPage.py +++ b/bCNC/ControlPage.py @@ -13,6 +13,7 @@ W, E, EW, + NS, NSEW, CENTER, X, @@ -31,6 +32,7 @@ BooleanVar, Button, Checkbutton, + DoubleVar, Entry, Frame, Label, @@ -505,7 +507,7 @@ def updateState(self): def updateCoords(self): try: focus = self.focus_get() - except Exception: + except KeyError: focus = None if focus is not self.xwork: self.xwork.delete(0, END) @@ -563,7 +565,7 @@ def setX(self, event=None): try: value = round(eval(self.xwork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(value, None, None, None, None, None) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -573,7 +575,7 @@ def setY(self, event=None): try: value = round(eval(self.ywork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(None, value, None, None, None, None) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -583,7 +585,7 @@ def setZ(self, event=None): try: value = round(eval(self.zwork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(None, None, value, None, None, None) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -798,7 +800,7 @@ def __init__(self, master, app): def updateCoords(self): try: focus = self.focus_get() - except Exception: + except KeyError: focus = None if focus is not self.awork: self.awork.delete(0, END) @@ -864,7 +866,7 @@ def setA(self, event=None): try: value = round(eval(self.awork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(None, None, None, value, None, None) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -874,7 +876,7 @@ def setB(self, event=None): try: value = round(eval(self.bwork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(None, None, None, None, value, None) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -884,7 +886,7 @@ def setC(self, event=None): try: value = round(eval(self.cwork.get(), None, CNC.vars), 3) self.app.mcontrol._wcsSet(None, None, None, None, None, value) - except Exception: + except ValueError: pass # ---------------------------------------------------------------------- @@ -910,15 +912,43 @@ def __init__(self, master, app): CNCRibbon.PageExLabelFrame.__init__( self, master, "Control", _("Control"), app) + try: + self.zsteplist = [float(x) for x in Utils.config.get("Control", "zsteplist").split()] + except ValueError: + self.zsteplist = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0, 50.0, 100.0] + + try: + self.steplist = [float(x) for x in Utils.config.get("Control", "steplist").split()] + except ValueError: + self.steplist = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0, 50.0, 100.0, 500.0] + + try: + step = float(Utils.config.get("Control", "step")) + except ValueError: + step = float(self.steplist[int(len(self.steplist)/2-1)]) + + try: + zstep = Utils.config.get("Control", "zstep") + except ValueError: + zstep = float(self.zsteplist[int(len(self.zsteplist)/2-1)]) + + try: + jogRate = float(Utils.config.get("Control", "jograte")) + except Exception: + JogRate = min(CNC.feedmax_x, CNC.feedmax_y, CNC.feedmax_z) + frame = Frame(self()) frame.pack(side=TOP, fill=X) row, col = 0, 0 Label(frame, text=_("Z")).grid(row=row, column=col) - col += 3 + col += 4 Label(frame, text=_("Y")).grid(row=row, column=col) + col += 3 + Label(frame, text=_("Jog Rate")).grid(row=row, column=col, columnspan=2) + # --- row += 1 col = 0 @@ -938,7 +968,26 @@ def __init__(self, master, app): tkExtra.Balloon.set(b, _("Move +Z")) self.addWidget(b) - col += 2 + col += 1 + self.zScaleValue = DoubleVar() + self.zScale = Scale(frame, + variable=self.zScaleValue, + resolution=0.001, + from_=math.log10(float(self.zsteplist[0])), + to=math.log10(float(self.zsteplist[-1])), + orient="vertical", + showvalue=0, + command=self.setZValue) + self.zScale.grid(row=row, column=col, rowspan=3, sticky=NS) + if zstep == _NOZSTEP: + self.zScaleValue.set(math.log10(float(step))) + else: + self.zScaleValue.set(math.log10(float(zstep))) + tkExtra.Balloon.set(self.zScale, _("Z jog stepsize")) + self.addWidget(self.zScale) + col += 1 + + col += 1 b = Button( frame, text=Unicode.UPPER_LEFT_TRIANGLE, @@ -976,7 +1025,22 @@ def __init__(self, master, app): tkExtra.Balloon.set(b, _("Move +X +Y")) self.addWidget(b) - col += 2 + col += 1 + self.xyScaleValue = DoubleVar() + self.xyScale = Scale(frame, + variable=self.xyScaleValue, + resolution=0.001, + from_=math.log10(float(self.steplist[0])), + to=math.log10(float(self.steplist[-1])), + orient="vertical", + showvalue=0, + command=self.setXYValue) + self.xyScale.grid(row=row, column=col, rowspan=3, sticky=NS) + self.xyScale.set(math.log10(step)) + tkExtra.Balloon.set(self.xyScale, _("XY jog stepsize")) + self.addWidget(self.xyScale) + + col += 1 b = Button( frame, text="\u00D710", command=self.mulStep, width=3, padx=1, pady=1 @@ -985,6 +1049,23 @@ def __init__(self, master, app): tkExtra.Balloon.set(b, _("Multiply step by 10")) self.addWidget(b) + def xceptReturn(event): + frame.focus() + + self.jogValue = DoubleVar() + self.jogValue.set(float(jogRate)) + self.checkJogValue = self.register(self.checkJogentry) + self.jograte = Entry(frame, + justify=RIGHT, + textvariable=self.jogValue, + validate='key', + validatecommand=(self.checkJogValue, '%P'), + width=4) + self.jograte.grid(row=row, column=col, columnspan=2, sticky=EW + N) + self.jograte.bind('',xceptReturn) + self.jograte.bind('',xceptReturn) + self.addWidget(self.jograte) + col += 1 b = Button(frame, text=_("+"), command=self.incStep, width=3, padx=1, pady=1) @@ -994,10 +1075,9 @@ def __init__(self, master, app): # --- row += 1 - - col = 1 + col = 2 Label(frame, text=_("X"), - width=3, anchor=E).grid(row=row, column=col, sticky=E) + width=1, anchor=E).grid(row=row, column=col, sticky=E) col += 1 b = Button( @@ -1045,51 +1125,46 @@ def __init__(self, master, app): self.addWidget(b) # -- - col += 1 - Label(frame, "", width=2).grid(row=row, column=col) - - col += 1 + col += 2 self.step = tkExtra.Combobox( - frame, width=6, background=tkExtra.GLOBAL_CONTROL_BACKGROUND + frame, width=6, background=tkExtra.GLOBAL_CONTROL_BACKGROUND, + command=self.setSliders ) self.step.grid(row=row, column=col, columnspan=2, sticky=EW) self.step.set(Utils.config.get("Control", "step")) - self.step.fill( - map(float, Utils.config.get("Control", "steplist").split())) + self.step.fill(self.steplist) tkExtra.Balloon.set(self.step, _("Step for every move operation")) self.addWidget(self.step) - - # -- Separate zstep -- - try: - zstep = Utils.config.get("Control", "zstep") - self.zstep = tkExtra.Combobox( - frame, width=4, background=tkExtra.GLOBAL_CONTROL_BACKGROUND - ) - self.zstep.grid(row=row, column=0, columnspan=1, sticky=EW) - self.zstep.set(zstep) - zsl = [_NOZSTEP] - zsl.extend( - map(float, Utils.config.get("Control", "zsteplist").split())) - self.zstep.fill(zsl) - tkExtra.Balloon.set(self.zstep, _("Step for Z move operation")) - self.addWidget(self.zstep) - except Exception: - self.zstep = self.step + self.step.bind('<>', self.setSliders) + + # -- Separate zstep combobox -- + self.zstep = tkExtra.Combobox( + frame, width=4, background=tkExtra.GLOBAL_CONTROL_BACKGROUND, + command=self.setSliders + ) + self.zstep.grid(row=row, column=0, columnspan=1, sticky=EW) + zsl = [_NOZSTEP] + zsl.extend(self.zsteplist) + self.zstep.fill(zsl) + self.zstep.set(zstep) + tkExtra.Balloon.set(self.zstep, _("Step for Z move operation")) + self.addWidget(self.zstep) + self.zstep.bind('<>', self.setSliders) # Default steppings try: self.step1 = Utils.getFloat("Control", "step1") - except Exception: + except ValueError: self.step1 = 0.1 try: self.step2 = Utils.getFloat("Control", "step2") - except Exception: + except ValueError: self.step2 = 1 try: self.step3 = Utils.getFloat("Control", "step3") - except Exception: + except ValueError: self.step3 = 10 # --- @@ -1108,7 +1183,7 @@ def __init__(self, master, app): tkExtra.Balloon.set(b, _("Move -Z")) self.addWidget(b) - col += 2 + col += 3 b = Button( frame, text=Unicode.LOWER_LEFT_TRIANGLE, @@ -1167,9 +1242,15 @@ def __init__(self, master, app): # ---------------------------------------------------------------------- def saveConfig(self): + Utils.setFloat("Control", "jograte", self.jogValue.get()) Utils.setFloat("Control", "step", self.step.get()) - if self.zstep is not self.step: - Utils.setFloat("Control", "zstep", self.zstep.get()) + zstep = self.zstep.get() + if zstep == _NOZSTEP: + Utils.setStr("Control", "zstep", zstep) + else: + Utils.setFloat("Control", "zstep", zstep) + Utils.setFloat("Control", "steplist", self.steplist) + Utils.setFloat("Control", "zsteplist", self.zsteplist) # ---------------------------------------------------------------------- # Jogging @@ -1187,52 +1268,56 @@ def getStep(self, axis="x"): def moveXup(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X{self.step.get()}") + self.app.mcontrol.jog(f"X{self.step.get()}", self.jogValue.get()) def moveXdown(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X-{self.step.get()}") + self.app.mcontrol.jog(f"X-{self.step.get()}", self.jogValue.get()) def moveYup(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"Y{self.step.get()}") + self.app.mcontrol.jog(f"Y{self.step.get()}", self.jogValue.get()) def moveYdown(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"Y-{self.step.get()}") + self.app.mcontrol.jog(f"Y-{self.step.get()}", self.jogValue.get()) def moveXdownYup(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X-{self.step.get()}Y{self.step.get()}") + self.app.mcontrol.jog(f"X-{self.step.get()}Y{self.step.get()}", + self.jogValue.get()) def moveXupYup(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X{self.step.get()}Y{self.step.get()}") + self.app.mcontrol.jog(f"X{self.step.get()}Y{self.step.get()}", + self.jogValue.get()) def moveXdownYdown(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X-{self.step.get()}Y-{self.step.get()}") + self.app.mcontrol.jog(f"X-{self.step.get()}Y-{self.step.get()}", + self.jogValue.get()) def moveXupYdown(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"X{self.step.get()}Y-{self.step.get()}") + self.app.mcontrol.jog(f"X{self.step.get()}Y-{self.step.get()}", + self.jogValue.get()) def moveZup(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"Z{self.getStep('z')}") + self.app.mcontrol.jog(f"Z{self.getStep('z')}", self.jogValue.get()) def moveZdown(self, event=None): if event is not None and not self.acceptKey(): return - self.app.mcontrol.jog(f"Z-{self.getStep('z')}") + self.app.mcontrol.jog(f"Z-{self.getStep('z')}", self.jogValue.get()) def go2origin(self, event=None): self.sendGCode("G90") @@ -1243,13 +1328,57 @@ def go2origin(self, event=None): # ---------------------------------------------------------------------- def setStep(self, s, zs=None): self.step.set(f"{s:.4g}") - if self.zstep is self.step or zs is None: + self.xyScaleValue.set(math.log10(s)) + if zs is None or zs is _NOZSTEP: + self.zScaleValue.set(math.log10(s)) self.event_generate("<>", data=_("Step: {:g}").format(s)) else: self.zstep.set(f"{zs:.4g}") + self.zScaleValue.set(math.log10(zs)) self.event_generate( "<>", data=_("Step: {:g} Zstep: {:g} ").format(s, zs)) + def checkJogentry(self, inStr): + try: + if float(inStr) <= 0.0: return False + except ValueError: + return False + return True + + #---------------------------------------------------------------------- + # Slider methods + #---------------------------------------------------------------------- + # + def setSliders(self): + xyvalue = self.step.get() + self.xyScaleValue.set(math.log10(float(xyvalue))) + # the following is enclosed in a try/except since it maybe called + # before the zstep combobox has been created + try: + zvalue = self.zstep.get() + if zvalue == _NOZSTEP: + self.zScaleValue.set(math.log10(float(xyvalue))) + else: + self.zScaleValue.set(math.log10(float(zvalue))) + except Exception: + pass + + def setZValue(self, slider): + find_f = 10.0**float(slider) + tval = self.zsteplist[min(range(len(self.zsteplist)), + key=lambda i: abs(self.zsteplist[i] - find_f))] + sval = str(tval) + self.zstep.set(sval) + self.zScaleValue.set(math.log10(tval)) + + def setXYValue(self, slider): + find_f = 10.0**float(slider) + tval = self.steplist[min(range(len(self.steplist)), + key=lambda i: abs(self.steplist[i] - find_f))] + sval = str(tval) + self.step.set(sval) + self.xyScaleValue.set(math.log10(tval)) + # ---------------------------------------------------------------------- @staticmethod def _stepPower(step): @@ -1257,7 +1386,7 @@ def _stepPower(step): step = float(step) if step <= 0.0: step = 1.0 - except Exception: + except ValueError: step = 1.0 power = math.pow(10.0, math.floor(math.log10(step))) return round(step / power) * power, power @@ -1372,8 +1501,6 @@ def setStep3(self, event=None): # ============================================================================= # abc ControlFrame # ============================================================================= - - class abcControlFrame(CNCRibbon.PageExLabelFrame): def __init__(self, master, app): CNCRibbon.PageExLabelFrame.__init__( @@ -1541,23 +1668,23 @@ def __init__(self, master, app): self.astep.fill(asl) tkExtra.Balloon.set(self.astep, _("Step for A move operation")) self.addWidget(self.astep) - except Exception: + except ValueError: self.astep = self.step # Default steppings try: self.step1 = Utils.getFloat("abcControl", "step1") - except Exception: + except ValueError: self.step1 = 0.1 try: self.step2 = Utils.getFloat("abcControl", "step2") - except Exception: + except ValueError: self.step2 = 1 try: self.step3 = Utils.getFloat("abcControl", "step3") - except Exception: + except ValueError: self.step3 = 10 # --- @@ -1727,7 +1854,7 @@ def _stepPower(step): step = float(step) if step <= 0.0: step = 1.0 - except Exception: + except ValueError: step = 1.0 power = math.pow(10.0, math.floor(math.log10(step))) return round(step / power) * power, power @@ -1843,8 +1970,6 @@ def setStep3(self, event=None): # ============================================================================= # StateFrame # ============================================================================= - - class StateFrame(CNCRibbon.PageExLabelFrame): def __init__(self, master, app): global wcsvar @@ -2347,5 +2472,7 @@ def register(self): self._register( (ConnectionGroup, UserGroup, RunGroup), - (DROFrame, abcDROFrame, ControlFrame, abcControlFrame, StateFrame), + (DROFrame, abcDROFrame, + ControlFrame, abcControlFrame, + StateFrame) ) diff --git a/bCNC/bCNC.ini b/bCNC/bCNC.ini index cfbf77030..10a525f96 100644 --- a/bCNC/bCNC.ini +++ b/bCNC/bCNC.ini @@ -40,6 +40,7 @@ step1 = 0.1 step2 = 1 step3 = 10 swap = 0 +jograte = 600 steplist = 0.001 0.005 0.01 0.05 0.1 0.5 1 5 10 50 100 500 zsteplist = 0.001 0.005 0.01 0.05 0.1 0.5 1 5 10 25 diff --git a/bCNC/controllers/GRBL1.py b/bCNC/controllers/GRBL1.py index 76b063259..6fef2c7b8 100644 --- a/bCNC/controllers/GRBL1.py +++ b/bCNC/controllers/GRBL1.py @@ -32,9 +32,8 @@ def __init__(self, master): self.has_override = True self.master = master - def jog(self, direction): - self.master.sendGCode(f"$J=G91 {direction} F100000") - # XXX is F100000 correct? + def jog(self, direction, feed): + self.master.sendGCode(f"$J=G91 {direction} F{float(feed)}") def overrideSet(self): CNC.vars["_OvChanged"] = False # Temporary