Contact me: hankecnc@gmail.com

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970

推推 grbl 3年前 (2023-01-30) 203次浏览
打开
1个任务完成
mydani 打开了这个问题 2020 年 10 月 28 日 · 7条评论
打开
1个任务完成

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估#970

mydani 打开了这个问题 2020 年 10 月 28 日 · 7条评论

注释

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970

以下是我重现该问题所遵循的步骤:

  1. 打开Linuxcnc,确保工具表中的工具如下: Tool 1 Pocket 5, Tool 2 Pocket 10
  2. 通过 M6 将工具更改为工具 1,然后是工具 2
  3. 使用 “change_prolog” 方法打印出 self.current_tool, self.selected_tool, self.current_pocket, self.selected_pocket 的值

这是我期望发生的事情:

“工具”值反映了工具编号。在工具表中
,“口袋”值反映了正确的口袋号。刀具表中的刀具

例如
self.current_tool = 1
self.selected_tool = 2
self.current_pocket = 5
self.selected_pocket = 10

这是发生了什么:

self.current_tool = 1
self.selected_tool = 2
self.current_pocket = 1
self.selected_pocket = 2

似乎口袋值是工具表的索引而不是口袋号。

在此之前它工作正常:

  • 我让它在 2.8 发布之前的分支中工作,但从未在主流上工作(2.7 和 2.8 都没有)。
  • 如果使用方法“self.find_tool_pocket(self.xxx_tool)”,则使用正确的口袋值。这在 sim 中有效,但不幸的是在加载 UI 时在真机上停止。

有关我的硬件和软件的信息:

  • 我正在使用这个 Linux 发行版:Debian Wheezy
    • 来自 linuxcnc.org 的二进制版本(包括 buildbot.linuxcnc.org)
  • 我正在使用这个用户界面:gmoccapy
  • 台面 5i25 + 7i77
Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970 mydani 更改了标题 Tool Pocket 在 2.8 stdglue 中未正确评估 Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 2020 年 10 月 28 日
Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970 rene-dev 自行分配了这个 2020 年 10 月 28 日
Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
作者
迈达尼 评论了 2020 年 10 月 29 日  

所以这就是我为我修复它的方式——注意,我不使用标准的 M6 例程,因此需要添加更多的东西。(同样棘手的是要找出对所有 INTERP_… 使用“yield”而不是“return”,因为 INTERP_EXECUTE_FINISH 会抛出 python 错误(INTERP_EXECUTE_FINISH 需要正确的 python 生成器)。)

`
import os
import sys
import emccanon 
from interpreter import *
from gscreen import preferences
throw_exceptions = 1

debug = True
if debug:
    pydevdir = '/home/daniel/Dokumente/aptana/Aptana_Studio_3/plugins/org.python.pydev_3.0.0.1484937626/pysrc'

    # the 'emctask' module is present only in the milltask instance, otherwise both the UI and
    # milltask would try to connect to the debug server.

    if os.path.isdir( pydevdir ) and  'emctask' in sys.builtin_module_names:
        sys.path.append( pydevdir )
        sys.path.insert( 0, pydevdir )
        try:
            import pydevd
            emccanon.MESSAGE( "pydevd imported, connecting to Eclipse debug server..." )
            pydevd.settrace()
        except:
            emccanon.MESSAGE( "no pydevd module found" )
            pass

# REMAP=M6  modalgroup=6 prolog=change_prolog ngc=change epilog=change_epilog
# exposed parameters:
#    #<tool_in_spindle>
#    #<selected_tool>
#    #<current_pocket>
#    #<selected_pocket>

def change_prolog(self, **words):
    try:
        # this is relevant only when using iocontrol-v2.
        if self.params[5600] > 0.0:
            if self.params[5601] < 0.0:
                self.set_errormsg("Toolchanger hard fault %d" % (int(self.params[5601])))
                yield INTERP_ERROR
            print "change_prolog: Toolchanger soft fault %d" % int(self.params[5601])

        if self.selected_pocket < 0:
            self.set_errormsg("M6: no tool prepared")
            yield INTERP_ERROR

        if self.cutter_comp_side:
            self.set_errormsg("Cannot change tools with cutter radius compensation on")
            yield INTERP_ERROR

        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool

        if self.current_tool>=0:
            (status, pocket) = self.find_tool_pocket(self.current_tool)
            if status != INTERP_OK:
                self.set_errormsg("T \"%d\": pocket not found" % (self.current_tool))
                yield status
        else:
            pocket = -1 # this is a T0 - tool unload

        self.params["current_pocket"] = pocket

        if self.selected_tool>=0:
            (status, pocket) = self.find_tool_pocket(self.selected_tool)
            if status != INTERP_OK:
                self.set_errormsg("T%d: pocket not found" % (self.selected_tool))
                yield status
        else:
            pocket = -1 # this is a T0 - tool unload

        self.params["selected_pocket"] = pocket

        yield INTERP_OK

    except Exception, e:
        self.set_errormsg("M6/change_prolog: %s" % (e))
        yield INTERP_ERROR


def change_epilog(self, **words):
    try:
        if not self.value_returned:
            
            r = self.blocks[self.remap_level].executing_remap
            self.set_errormsg("the %s remap procedure %s did not yield a value"
                             % (r.name,r.remap_ngc if r.remap_ngc else r.remap_py))
            yield INTERP_ERROR
        
        if self.blocks[self.remap_level].builtin_used:
            #print "---------- M6 builtin recursion, nothing to do"
            yield INTERP_OK

        # this is relevant only when using iocontrol-v2.
        if self.params[5600] > 0.0:
            if self.params[5601] < 0.0:
                self.set_errormsg("Toolchanger hard fault %d" % (int(self.params[5601])))
                yield INTERP_ERROR
            print "change_epilog: Toolchanger soft fault %d" % int(self.params[5601])

        if self.return_value > 0.0:
                # commit change
                self.selected_pocket =  int(self.params["selected_pocket"])
                emccanon.CHANGE_TOOL(self.selected_tool)
                self.current_pocket = self.selected_pocket
                self.selected_pocket = -1
                self.selected_tool = -1
                # cause a sync()
                self.set_tool_parameters()
                self.toolchange_flag = True
                yield INTERP_EXECUTE_FINISH
        else:
            if self.return_value == -1:
                message = "Searchvel <= 0, not permitted!, Please correct INI Settings."
            elif self.return_value == -2:
                message = "Probevel <= 0, not permitted!, Please correct INI Settings."
            elif self.return_value == -3:
                message = "Probe contact failiure !!"
            else:
                message = "M6 aborted (yield code %.1f)" % (self.yield_value)
            self.set_errormsg(message)
            yield INTERP_ERROR

    except Exception, e:
        self.set_errormsg("M6/change_epilog: %s" % (e))
        yield INTERP_ERROR


_uvw = ("u","v","w","a","b","c")
_xyz = ("x","y","z","a","b","c")
# given a plane, yield  sticky words, incompatible axis words and plane name
# sticky[0] is also the movement axis
_compat = {
    emccanon.CANON_PLANE_XY : (("z","r"),_uvw,"XY"),
    emccanon.CANON_PLANE_YZ : (("x","r"),_uvw,"YZ"),
    emccanon.CANON_PLANE_XZ : (("y","r"),_uvw,"XZ"),
    emccanon.CANON_PLANE_UV : (("w","r"),_xyz,"UV"),
    emccanon.CANON_PLANE_VW : (("u","r"),_xyz,"VW"),
    emccanon.CANON_PLANE_UW : (("v","r"),_xyz,"UW")}           

# extract and pass parameters from current block, merged with extra parameters on a continuation line
# keep tjose parameters across invocations
# export the parameters into the oword procedure
def cycle_prolog(self,**words):
    # self.sticky_params is assumed to have been initialized by the
    # init_stgdlue() method below
    global _compat
    try:    
        # determine whether this is the first or a subsequent call
        c = self.blocks[self.remap_level]
        r = c.executing_remap
        if c.g_modes[1] == r.motion_code:
            # first call - clear the sticky dict
            self.sticky_params[r.name] = dict()

        self.params["motion_code"] = c.g_modes[1]
        
        (sw,incompat,plane_name) =_compat[self.plane]
        for (word,value) in words.items():
            # inject current parameters
            self.params[word] = value
            # record sticky words
            if word in sw:
                if self.debugmask & 0x00080000: print "%s: record sticky %s = %.4f" % (r.name,word,value)
                self.sticky_params[r.name][word] = value
            if word in incompat:
                yield "%s: Cannot put a %s in a canned cycle in the %s plane" % (r.name, word.upper(), plane_name)

        # inject sticky parameters which were not in words:
        for (key,value) in self.sticky_params[r.name].items():
            if not key in words:
                if self.debugmask & 0x00080000: print "%s: inject sticky %s = %.4f" % (r.name,key,value)
                self.params[key] = value

        if not "r" in self.sticky_params[r.name]:
            yield "%s: cycle requires R word" % (r.name)
        else:
            if self.sticky_params[r.name] <= 0.0:
                yield "%s: R word must be > 0 if used (%.4f)" % (r.name, words["r"])

        if "l" in words:
            # checked in interpreter during block parsing
            # if l <= 0 or l not near an int
            self.params["l"] = words["l"]
            
        if "p" in words:
            p = words["p"]
            if p < 0.0:
                yield "%s: P word must be >= 0 if used (%.4f)" % (r.name, p)
            self.params["p"] = p

        if self.feed_rate == 0.0:
            yield "%s: feed rate must be > 0" % (r.name)
        if self.feed_mode == INVERSE_TIME:
            yield "%s: Cannot use inverse time feed with canned cycles" % (r.name)
        if self.cutter_comp_side:
            yield "%s: Cannot use canned cycles with cutter compensation on" % (r.name)
        yield INTERP_OK
    
    except Exception, e:
        raise
        yield "cycle_prolog failed: %s" % (e)

# make sure the next line has the same motion code, unless overriden by a
# new G code
def cycle_epilog(self,**words):
    try:
        c = self.blocks[self.remap_level]
        self.motion_mode = c.executing_remap.motion_code # retain the current motion mode
        yield INTERP_OK
    except Exception, e:
        yield "cycle_epilog failed: %s" % (e)

# this should be called from TOPLEVEL __init__()
def init_stdglue(self):
    self.sticky_params = dict()



`
Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
作者

之前也报告过 Pocket 行为,#400
“错误”返回而不是之前报告的 yield 使用,#217

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
合作者

@rene-dev我以为这是固定的?

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
合作者

@andypugh情况很复杂。python 模块只是公开了 c 代码的内容,而 c 代码在内部使用索引,就像他说的:

如果使用方法“self.find_tool_pocket(self.xxx_tool)”,则使用正确的口袋值。这在 sim 中有效,但不幸的是在加载 UI 时在真机上停止。

所以你确实需要调用这个函数来获取真实的数字,就像 C 代码一样。为什么它只适用于 sim 我会调查。

它更多的是文档问题,或者默认 stdglue 的问题。
真的应该有一种方法可以在没有 python 的情况下使用 remap,因为它只会让一切变得复杂。

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
作者

顺便提一句。在这里,我在 2.8 版本上做了一个分支,它提供了口袋而不是工具表索引。
然而,这是一个更大的变化……

大师...mydani:2.8_pocketfix_on_release

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
作者

@rene-dev
为什么它只适用于 sim 我会调查

现在不再是这种情况了,这是更新 stdglue 的问题(yield 而不是 return,错误的转换等)。
使用上面的示例代码,它在我的物理机器上运行良好。

Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970
作者

从今天的调试更新:
<_current_tool>、<_selected_tool>、<_current_pocket>、<_selected_pocket> 直接在更改宏中工作,而无需在 stdglue 中使用额外的魔法。这使得对查找函数的调用变得不必要。

这适用于所有 >0 且型腔值 >0 的工具。_current_tool 是主轴中的实际刀具,_selected_tool 是新刀具,_current_pocket 是换刀器中当前刀具需要放回的刀套,_selected_pocket 是新刀具需要取出的刀套。

特殊情况是:

  • tool 0 (no tool) => selected_pocket 不一致但无关紧要
  • 带口袋号的工具 EQ 0 => _selected_pocket 将为这些 -1(而不是 0)
  • 带口袋号的工具 LT 0 => _selected_pocket 将与刀具表中一样,当前在主轴中时 _current_pocket 将为 0

免费注册 在 GitHub 上加入此对话。已有帐户? 登录评论
标签
还没有
项目

还没有

发展

没有分支机构或拉取请求

3人参加
Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970Tool Pocket 在 2.8 stdglue、非随机 tc 中未正确评估 #970

喜欢 (0)