Interpreter ignoring axis move commands ina M6 remap 2.8.0-pre1

02 Sep 2020 16:48 #180446 by neller
Hi, I am trying to create an automatic tool changer and have the same problems. In python, I control valves and check sensors, then run the g-code, then check the sensors again, and run the g-code again, but it doesn't work in that sequence. For some reason, all the g-code command is executed directly at the end. How did you get around this problem? I am attaching my config. This is an urgent need, please help.

Warning: Spoiler!

Please Log in or Create an account to join the conversation.

02 Sep 2020 17:01 #180448 by andypugh
Can you put the code in
code tags

The reason I ask is because it is impossible to follow Python code without the indenting, and the spoiler tags seem to have lost that
The following user(s) said Thank You: neller

Please Log in or Create an account to join the conversation.

02 Sep 2020 17:14 #180450 by neller
from interpreter import INTERP_OK
from emccanon import MESSAGE
import hal, linuxcnc, emccanon, time

linuxcncStat = linuxcnc.stat();
linuxcncCmd = linuxcnc.command()

fork_offset_y = 20

tool1_x = 10
tool1_y = 100

tool2_x = 20
tool2_y = 100

tool3_x = 30
tool3_y = 100

tool4_x = 40
tool4_y = 100

tool5_x = 50
tool5_y = 100

fork_z = 0
fork_y = 110

safety_z = 10

def func1(self,current_tool):
    if current_tool == 1:
        self.execute("G0 X%f Y%f" % (tool1_x,tool1_y-fork_offset_y))
    elif current_tool == 2:
        self.execute("G0 X%f Y%f" % (tool2_x,tool2_y-fork_offset_y))
    elif current_tool == 3:
        self.execute("G0 X%f Y%f" % (tool3_x,tool3_y-fork_offset_y))
    elif current_tool == 4:
        self.execute("G0 X%f Y%f" % (tool4_x,tool4_y-fork_offset_y))
    elif current_tool == 5:
        self.execute("G0 X%f Y%f" % (tool5_x,tool5_y-fork_offset_y))

def func2(self):
    self.execute("G0 Z%f" % (fork_z))

def func3(self):
    self.execute("G0 Y%f" % (fork_y))

def func4(self):
    self.execute("G0 Z%f" % (safety_z))

def func5(self,new_tool):

    new_tool_y=0 #Local

    if new_tool == 1:
        self.execute("G0 X%f Y%f" % (tool1_x,tool1_y))
    elif new_tool == 2:
        self.execute("G0 X%f Y%f" % (tool1_x,tool2_y))
    elif new_tool == 3:
        self.execute("G0 X%f Y%f" % (tool1_x,tool3_y))
    elif new_tool == 4:
        self.execute("G0 X%f Y%f" % (tool1_x,tool4_y))
    elif new_tool == 5:
        self.execute("G0 X%f Y%f" % (tool1_x,tool5_y))

    return new_tool_y

def func6(self,new_tool_y):
     self.execute("G0 Y%f" % (new_tool_y-fork_offset_y))    

def change_prolog_m6(self, **words):




    print("This is m6 prolog")

    hal.set_p(store,"TRUE") #Open Store
    time.sleep(2) #Delay

    if hal.get_value(store_sensor):
        print("store sensor activated")
        #Go to current tool store position

        #Z to down (fork)

        #Go to fork
        hal.set_p(patron,"TRUE") #Open patron
        time.sleep(2) #Delay

        if hal.get_value(patron_sensor):
            print("patron sensor activated")

            #Z to up (safety position)
            #Go to new tool

            new_tool_y = func5(self,new_tool)

            #Z to down (fork)

            hal.set_p(patron,"FALSE") #Close patron
            time.sleep(2) #Delay 

            if hal.get_value(patron_sensor)!=True:
                print("patron sensor activated")

                #Z to up (safety position)
                print("#Error 03: patron sensor not activated")
            print("#Error 02: patron sensor not activated")
        print("#Error 01: store sensor not activated")

Please Log in or Create an account to join the conversation.

02 Sep 2020 17:37 #180451 by andypugh
I only see a few sleep commands, and no wait-for-sensor loops.

I don't think that this is likely to be the problem, but it is an area where an improvement is possible.

It's more clunky in some ways, and less so in others, but controlling the sequence via a G-code routine can work well. G-code has built-in wait-on-input functions which include timeout handling.

There is an example of a G-code tool-change here:

One reason this is potentially useful is that the interpreter does not try to queue moves through a wait-on-input G-code.

It looks like your tool change is all in the prolog code. I am wondering if that is the problem. prolog code is intended to run before the main toolchange sequence and typically just sorts out what need to be done.

Carousel postioning is typically done as part of a remapped T command, and then the change itself as the main M6 remap.

Please Log in or Create an account to join the conversation.

Time to create page: 0.067 seconds
Powered by Kunena Forum