Contact me: hankecnc@gmail.com

CNC.py 中的潜在问题 #1313

推推 grbl 3年前 (2023-02-02) 225次浏览
打开
onekk 打开了这个问题 2019 年 12 月 6 日 · 6条评论
打开

CNC.py 中的潜在问题#1313

onekk 打开了这个问题 2019 年 12 月 6 日 · 6条评论

评论

CNC.py 中的潜在问题 #1313
贡献者

CNC.py类CNC中的这个函数

    @staticmethod
    def gcode(g, pairs):
        s = "G{0}".format(g)
        for c, v in pairs:
            s += " {0}{1:0.{2}f}".format(c, round(v, OCV.digits), OCV.digits)
        return s

self.gcode 同名

        self.retractz = True  # G98/G99     retract to Z or R
        self.gcode = None
        self.plane = XY

我已将函数gcode重命名为gcode_string ,它更能描述它的作用并避免歧义和潜在错误。

CNC.py 中的潜在问题 #1313 哈维 补充说 需要帮助/欢迎 PR 研究和代码清理 需要更多思考的长期想法标签 2020 年 4 月 9 日
CNC.py 中的潜在问题 #1313
合作者

听起来很合理……如果你愿意做一个 PR,我们可以合并这个

CNC.py 中的潜在问题 #1313
贡献者

@Harvie 不合理,除非你想重新编码所有依赖的插件CNC.gcode()
@onekk 这实际上什至不是问题,它是staticmethod插件为了方便而使用的。

如果你愿意,你可以在其中放置一个print声明,老实说,除了插件之外,它不会被任何东西触及。self.gcode在这种情况下不是一回事。

CNC.py 中的潜在问题 #1313
贡献者
GitHubCaps 评论了 2020 年 5 月 17 日  

这些是我自己的笔记,解释了我想如何改进代码。

	#----------------------------------------------------------------------
	# 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 轴也使用显式for循环而不是使用zip函数(spiral.py使用 a zip,但应该不是问题)。

	#----------------------------------------------------------------------
	@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)

实际上,它们可以合并为三个函数,使代码更简单,更易于维护。每个*ABC功能都可以替换现有的并省略*ABC(保留原始名称),因为它们本质上是同一件事。

然后,只需spiral.py要将函数重命名即可。

		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您如何看待上述提议?

CNC.py 中的潜在问题 #1313
贡献者
标记 评论了 2020 年 5 月 17 日 通过电子邮件
CNC.py 中的潜在问题 #1313
贡献者
GitHubCaps 评论了 2020 年 5 月 17 日  

@tsmarks感谢您的反馈。

我试图在开始时避免组合函数,以降低工作 XYZ 代码的风险。

同样在这里,总是好的测试,然后再继续。

我有几个问题要问你。有什么特别的原因不在bool这里使用,或者你可以改变吗?

			("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 tickbox,而不是 a combobox。在我看来它会更好,因为代码不会检查它是否是None(以防用户没有选择任何一个选项)。

好吧,我说过我有几个问题,但我会等一下,把一些东西放在一起,向您展示我认为在使用、数据库等方面会有所帮助的东西StockMaterial希望Endmill我们有自己的论坛来进行这些讨论改进!

CNC.py 中的潜在问题 #1313
贡献者
标记 评论了 2020 年 5 月 18 日 通过电子邮件

免费注册 在 GitHub 上加入此对话。已有帐户? 登录评论
标签
需要帮助/欢迎 PR研究和代码清理需要更多思考的长期想法
项目

还没有

发展

没有分支机构或拉取请求

4人参加
CNC.py 中的潜在问题 #1313CNC.py 中的潜在问题 #1313CNC.py 中的潜在问题 #1313CNC.py 中的潜在问题 #1313

喜欢 (0)