Referring to the attached txt file, I had to insert a yield 
INTERP_EXECUTE_FINISH just before my "EPILOG". I have to set global variables 
for the machine to remember what tool is active, and what tool is in the 
spindle AFTER the "yield INTERP_EXECUTE_FINISH". (The machine is a router and 
has multiple drills and spindles, one of which is able to pick tools from 
pockets, while the rest are just lowered by pneumatic cylinders when active)


Doing otherwise caused readahead to set such variables before the actual 
toolchange takes place, hence when I stop the machine during program runs, the 
global variables always reflect the "next tool in the program" and not what is 
actually active.


Inserting "yield INTERP_EXECUTE_FINISH" kinda solved the readahead issue, but 
then in the following conditions:


- I open part1.nc in axis and run it without problem
- I open part2.nc in axis
- I run part2.nc
- I manually stop part2.nc midway
- part1.nc is loaded back automatically. Titlebar shows part1.nc. Axis Preview 
still shows part2.nc. Pressing RUN from axis actually runs part1.nc!!
- Manually pressing CTRL-R or reload icon reloads part2.nc



Kind Regards,

Terence




________________________________
From: Terence Delia <[email protected]>
Sent: Thursday, November 2, 2017 10:40 PM
To: Enhanced Machine Controller (EMC)
Subject: Re: [Emc-users] Issues with reloading from Oword

It has to do with yield INTERP_EXECUTE_FINISH and code following it in the M6 
function. The remap has been done purely in python, I will attach the code 
tomorrow from my shop. Thanks!


________________________________
From: andy pugh <[email protected]>
Sent: Thursday, November 2, 2017 9:11 PM
To: Enhanced Machine Controller (EMC)
Subject: Re: [Emc-users] Issues with reloading from Oword

On 2 November 2017 at 08:03, Terence Delia <[email protected]> wrote:

> Following bizarre behavior related to a remapped M6 (the machine would 
> automatically load the last gcode file without me knowing),

Can we start there. I have not heard of this problem before, and I
would imagine that we would have done.

Can you describe steps to reproduce it?


--
atp
"A motorcycle is a bicycle with a pandemonium attachment and is
designed for the especial use of mechanical geniuses, daredevils and
lunatics."
— George Fitch, Atlanta Constitution Newspaper, 1916

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users
from interpreter import *
from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, 
CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT,CHANGE_TOOL,STRAIGHT_FEED,STRAIGHT_TRAVERSE
import ConfigParser
import linuxcnc
c = linuxcnc.command()
s = linuxcnc.stat()

throw_exceptions = 1

configParser = ConfigParser.RawConfigParser()   

_sticky_params = dict()
_current_tool = 0
_tool_in_hsd = 0

def m6(self):
    if self.task==0:
       yield INTERP_OK

    result = m6_prolog(self)

    if result == 1:
        print("m6 prolog ready")
        yield INTERP_EXECUTE_FINISH
    elif result == 2:
        print("M6: no change required")
        yield INTERP_OK
    else:
        print("M6: prolog error")
        yield INTERP_ERROR

    if m6_epilog(self) == 1:
        print("m6 epilog ready")
        yield INTERP_OK
    else:
        print("M6: epilog error")
        yield INTERP_ERROR

def m6_prolog(self):
    global _current_tool
    global _tool_in_hsd

    print("Current tool: %d, HSD: %d, Selected: %s" % (_current_tool, 
_tool_in_hsd, self.selected_tool))

            
    if self.selected_pocket < 0:
        self.set_errormsg("M6: no tool prepared")
        return 0
    if self.cutter_comp_side:
        self.set_errormsg("Cannot change tools with cutter radius compensation 
on")
        return 0

#        self.params["tool_in_spindle"] = self.current_tool
    self.params["selected_tool"] = self.selected_tool
    self.params["current_pocket"] = self.current_pocket # this is probably 
nonsense
    self.params["selected_pocket"] = self.selected_pocket

    if _current_tool == self.selected_tool and not self.selected_tool == 0:
        print("exiting prolog, nothing to do; current: %d, HSD: %d, selected: 
%s" % (_current_tool, _tool_in_hsd, self.selected_tool)) #td
        return 2

#    if self.params[2000] == -1 and _current_tool >= 2000 and _current_tool <= 
2999:
#        if not m6atc(self, _tool_in_hsd, 0) == 1: return 0
    



    self.selected_pocket =  int(self.params["selected_pocket"])

##CLEAR X from tool changer pockets ## does not work due to readahead    
#    s.poll()
#    position_x = s.position[0]
#    print("Position X: %f" % position_x)
#    if position_x < -150:
#        self.execute("G53 G0 X-150")
    
    CHANGE_TOOL(self.selected_pocket)
    if self.selected_tool >= 2000 and self.selected_tool <= 2999:
        if self.params[2000] >= 2000:
            _tool_in_hsd = self.params[2000]
            self.params[2000] = 0
        if m6atc(self, _tool_in_hsd, self.selected_tool) == 1: return 1
        else: return 0
   
    return 1

def m6_epilog(self):

    global _current_tool
    global _tool_in_hsd

    self.current_pocket = self.selected_pocket
    self.current_tool = self.selected_tool
    _current_tool = self.current_tool
    if self.selected_tool >= 2000 and self.selected_tool <= 2999:
        if self.selected_tool == 2999: _tool_in_hsd = 0
        else: _tool_in_hsd = self.selected_tool
    self.selected_pocket = -1
    self.selected_tool = -1
    # cause a sync()
    self.toolchange_flag = True
    self.set_tool_parameters()
    print("2 current: %d, HSD: %d, selected: %s" % (_current_tool, 
_tool_in_hsd, self.selected_tool)) #td
    return 1


def m6atc(self, unload_tool, load_tool):

    unload={}
    load={}
    station={}
    x_clear=150
    
    if load_tool == 2999: load_tool = 0

    configParser.read(r"./constantstd.ini")

    for i in range(4):
#        print(i)
#        print(configParser.get("ATC", "ST%s" % i))
        station[int(configParser.get("ATC", "ST%s" % i))] = i

    if unload_tool == load_tool:
#        MESSAGE("m6atc nothing to do")
        return 1

    if not unload_tool in station:
        self.set_errormsg("Unload Tool station not found")
        return 0
    if not load_tool in station and load_tool >0:
        self.set_errormsg("Load Tool station not found")
        return 0

    self.execute("M05") #just in case

    if unload_tool > 0:
        unload["x"] = float(configParser.get("ATC", "X%s" % 
station[unload_tool]))
        unload["y"] = float(configParser.get("ATC", "Y%s" % 
station[unload_tool]))
        unload["z"] = float(configParser.get("ATC", "Z%s" % 
station[unload_tool]))
#        self.execute("M0")
        self.execute("G53 G0 X%f Y%f Z0" % (unload["x"]+x_clear,unload["y"]))
        self.execute("G53 G0 X%f Y%f Z0" % (unload["x"],unload["y"]))
        self.execute("G53 G0 Z%f" % (unload["z"]))
        self.execute("M64 P0")
        self.execute("G4 P0.5")
#        MESSAGE("UNLOADING1 %d" % unload_tool)
        self.execute("G53 G0 Z0")
        self.execute("G53 G0 X%f Y%f Z0" % (unload["x"]+x_clear,unload["y"]))


    if load_tool > 0:
        load["x"] = float(configParser.get("ATC", "X%s" % station[load_tool]))
        load["y"] = float(configParser.get("ATC", "Y%s" % station[load_tool]))
        load["z"] = float(configParser.get("ATC", "Z%s" % station[load_tool]))
#        self.execute("M0")
        self.execute("G53 G0 X%f Y%f Z0" % (load["x"]+x_clear,load["y"]))
        self.execute("G53 G0 X%f Y%f Z0" % (load["x"],load["y"]))
        self.execute("M64 P0")
        self.execute("G53 G0 Z%f" % (load["z"]))
        self.execute("M65 P0")
        self.execute("G4 P0.5")
#        MESSAGE("LOADING %d" % load_tool)
        self.execute("G53 G0 Z0")
        self.execute("G53 G0 X%f Y%f Z0" % (load["x"]+x_clear,load["y"]))
    
    if load_tool==0:
        self.execute("M65 P0")
        self.execute("G4 P0.5")
#        MESSAGE("not LOADING")
    
    return 1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to