评论
合作者
|
听起来很合理……如果你愿意做一个 PR,我们可以合并这个 |
贡献者
贡献者
|
这些是我自己的笔记,解释了我想如何改进代码。 #----------------------------------------------------------------------
# TODO: This function can be removed in favor of other function calls.
# However, many plugins rely on it and they need to be recoded first.
# Also, glinev and garcv use it; they should also be removed.
# Note that we basically have six dupe (nine total) functions that do
# the same thing, I would prefer the functions that are more explicit
# and don't rely on the zip function.
# Used by plugins: e.g. CNC.gcode(1, [("f",CNC.vars["cutfeed"])])
@staticmethod
def gcode(g, pairs): # XXX: Issue #1313
s = "g%d"%(g)
for c,v in pairs:
s += " %c%g"%(c, round(v,CNC.digits))
return s
#----------------------------------------------------------------------
@staticmethod
def _gcode(g, **args):
s = "g%d"%(g)
for n,v in args.items():
s += ' ' + CNC.fmt(n,v)
return s
#----------------------------------------------------------------------
@staticmethod
def _goto(g, x=None, y=None, z=None, **args):
s = "g%d"%(g)
if x is not None: s += ' '+CNC.fmt('x',x)
if y is not None: s += ' '+CNC.fmt('y',y)
if z is not None: s += ' '+CNC.fmt('z',z)
for n,v in args.items():
s += ' ' + CNC.fmt(n,v)
return s
#----------------------------------------------------------------------
@staticmethod
def grapid(x=None, y=None, z=None, **args):
return CNC._goto(0,x,y,z,**args)
#----------------------------------------------------------------------
@staticmethod
def gline(x=None, y=None, z=None, **args):
return CNC._goto(1,x,y,z,**args)
#----------------------------------------------------------------------
# TODO: This function should be removed in favor of 'gline' above.
# Only box, midi2cnc and pyrograph plugins use it atm,
# but they need to be recoded first.
@staticmethod
def glinev(g, v, feed=None):
pairs = zip("xyz",v) if OLD else list(zip("xyz",v)) # XXX: Issue #1363
if feed is not None:
pairs.append(("f",feed))
return CNC.gcode(g, pairs)
#----------------------------------------------------------------------
# TODO: This function should be removed in favor of 'garc' below.
# Only the box plugin uses it atm, but needs to be recoded first.
@staticmethod
def garcv(g, v, ijk):
if OLD:
return CNC.gcode(g, zip("xyz",v) + zip("ij",ijk[:2])) # XXX: Issue #1363
else:
return CNC.gcode(g, list(zip("xyz",v)) + list(zip("ij",ijk[:2])))
#----------------------------------------------------------------------
@staticmethod
def garc(g, x=None, y=None, z=None, i=None, j=None, k=None, **args):
s = "g%d"%(g)
if x is not None: s += ' '+CNC.fmt('x',x)
if y is not None: s += ' '+CNC.fmt('y',y)
if z is not None: s += ' '+CNC.fmt('z',z)
if i is not None: s += ' '+CNC.fmt('i',i)
if j is not None: s += ' '+CNC.fmt('j',j)
if k is not None: s += ' '+CNC.fmt('k',k)
for n,v in args.items():
s += ' ' + CNC.fmt(n,v)
return s
请注意,新添加的 6 轴也使用显式 #----------------------------------------------------------------------
@staticmethod
def _gotoABC(g, x=None, y=None, z=None, a=None, b=None, c=None, **args):
s = "g%d"%(g)
if x is not None: s += ' '+CNC.fmt('x',x)
if y is not None: s += ' '+CNC.fmt('y',y)
if z is not None: s += ' '+CNC.fmt('z',z)
if a is not None: s += ' '+CNC.fmt('a',a)
if b is not None: s += ' '+CNC.fmt('b',b)
if c is not None: s += ' '+CNC.fmt('c',c)
for n,v in args.items():
s += ' ' + CNC.fmt(n,v)
return s
#----------------------------------------------------------------------
@staticmethod
def grapidABC(x=None, y=None, z=None, a=None, b=None, c=None, **args):
return CNC._gotoABC(0,x,y,z,a,b,c,**args)
#----------------------------------------------------------------------
@staticmethod
def glineABC(x=None, y=None, z=None, a=None, b=None, c=None, **args):
return CNC._gotoABC(1,x,y,z,a,b,c,**args)
实际上,它们可以合并为三个函数,使代码更简单,更易于维护。每个 然后,只需 for g,x,y,z,r in zip(gP, xP,yP,zP, rP):
if RotAxis == "A" :
if g==0:
block.append(CNC.grapidABC(x,y,z,r,CNC.vars["wb"],CNC.vars["wc"]))
#sys.stdout.write("%s,%s,%s,%s,%s"%(g,x,y,z,r))
else:
block.append(CNC.glineABC(x,y,z,r,CNC.vars["wb"],CNC.vars["wc"]))
#sys.stdout.write("%s,%s,%s,%s,%s"%(g,x,y,z,r))
elif RotAxis == "B" :
if g==0:
block.append(CNC.grapidABC(x,y,z,CNC.vars["wa"],r,CNC.vars["wc"]))
else:
block.append(CNC.glineABC(x,y,z,CNC.vars["wa"],r,CNC.vars["wc"]))
elif RotAxis == "C" :
if g==0:
block.append(CNC.grapidABC(x,y,z,CNC.vars["wa"],CNC.vars["wb"],r))
else:
block.append(CNC.glineABC(x,y,z,CNC.vars["wa"],CNC.vars["wb"],r))
在其他人开始为此编码之前,现在可能更容易做到这一点。 @tsmarks您如何看待上述提议? |
贡献者
|
这对我来说很好。我试图在开始时避免组合函数,以降低工作 XYZ 代码的风险。到目前为止,我对这些添加没有任何问题,所以我觉得将代码集成到 XYZ 函数中可能是安全的。过去几周我一直在使用第 4 轴代码,但没有完成任何 3 轴工作。如果没有人有问题,我认为这很好。蒂姆
|
贡献者
|
@tsmarks感谢您的反馈。
同样在这里,总是好的测试,然后再继续。 我有几个问题要问你。有什么特别的原因不在 ("CutBoth", "True,False", "True", _("Cut in Both Directions")),
("LiftPass", "True,False", "False", _("Lift before rotate")),
到: ("CutBoth", "bool", True, _("Cut in Both Directions")),
("LiftPass", "bool", False, _("Lift before rotate")),
它只会将其更改为 a 好吧,我说过我有几个问题,但我会等一下,把一些东西放在一起,向您展示我认为在使用、数据库等方面会有所帮助的东西 |
贡献者
|
我不太确定为什么要使用该代码。但你是 100% 正确的。布尔会好得多。我想,我从一个不同的计划开始,转移到 True/False 并且从未更新过它。对我马虎。
|


CNC.py类CNC中的这个函数
与self.gcode 同名
我已将函数gcode重命名为gcode_string ,它更能描述它的作用并避免歧义和潜在错误。