Hello Guest it is April 16, 2024, 02:34:44 PM

Author Topic: Macro - Pause until input triggered  (Read 8405 times)

0 Members and 1 Guest are viewing this topic.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Macro - Pause until input triggered
« Reply #10 on: September 27, 2016, 04:50:31 PM »
The only problem I can see is if your home switch is also the limit this could cause mach4 to disable, just as a thought have you thought of using something like mc.mcCntlGcodeExecuteWait(inst, "G0 Z-1 F50") this will halt the gcode.
I have been looking into the mc.mcSignalWait and all works well when using any of the ISIG_INPUT0 to 63 etc but not working on anything else???

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Macro - Pause until input triggered
« Reply #11 on: September 28, 2016, 09:58:52 AM »
Daz - I mapped the Z home signal to Input_21 and I still can't get mc.mcSignalWait to work? The API says to use the signal handle, are you using the handle?  I haven't tried the others yet.

Current M100:

Code: [Select]
function M100()
   
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    local z_home_sig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT21) -- Get handle for Z axis home switch
    --local z_home_sig_state = mc.mcSignalGetState(z_home_sig) --Get state of  signal

    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then --If input_20_State equals 1, then the signal is active.
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the signal is inactive.
            --wx.wxMessageBox("Setting input_20 high")
            mc.mcSignalSetState(input_20, 1)
            mc.mcSignalWait(inst, z_home_sig, WAIT_MODE_HIGH, 20)
        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end

Re: Macro - Pause until input triggered
« Reply #12 on: September 28, 2016, 10:28:15 AM »
I looked at mc.mcCntlGcodeExecuteWait. I don't know how I could use it because the Z axis is not controlled via G-code.
Re: Macro - Pause until input triggered
« Reply #13 on: September 28, 2016, 10:38:49 AM »
I got mcSignalWait to work.  I was wrong API does not say to use handle.  It worked by putting the signal ID.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #14 on: September 28, 2016, 10:43:48 AM »
Was just looking at that myself.

From the manual......
sigId      A valid signal ID. (NOT a signal handle)

Glad you got it sorted.  :)

How about post the code that worked so others will see what right looks like.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Macro - Pause until input triggered
« Reply #15 on: September 28, 2016, 10:51:52 AM »
Here is the code that works:

Code: [Select]

function M100()
    
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    local z_home_sig = mc.ISIG_INPUT21 -- Get Signal ID for Z axis home switch
    
    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then --If input_20_State equals 1, then the signal is active.
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the signal is inactive.
            --wx.wxMessageBox("Setting input_20 high")
            mc.mcSignalSetState(input_20, 1)
            mc.mcSignalWait(inst, z_home_sig, 1, 0)
        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #16 on: September 28, 2016, 11:02:34 AM »
Nice, thanks!

Does this work as well?

Code: [Select]
function M100()
    
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    
    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then --If input_20_State equals 1, then the signal is active.
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the signal is inactive.
            --wx.wxMessageBox("Setting input_20 high")
            mc.mcSignalSetState(input_20, 1)
   mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 0)
        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end

Also, just wondering what this is.........  mc.mcSignalSetState(input_20, 1)

Shouldn't that be turning on an output to fire the raise solenoid?
« Last Edit: September 28, 2016, 11:05:34 AM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Macro - Pause until input triggered
« Reply #17 on: September 28, 2016, 11:22:56 AM »
Actually I am using input 20 as a "In automatic Cycle" signal. The M100 is interacting with the PLC script to monitor the Z-axis encoder and change direction when necessary.  I am still working on the Z axis reciprocation and automatic grinding cycle part at the moment, but as of now, yes the input 20 is setting the output_1 high in the PLC script which sends the Z axis home.

Yes your sample works also.
« Last Edit: September 28, 2016, 11:24:43 AM by beezerlm »

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Macro - Pause until input triggered
« Reply #18 on: September 28, 2016, 11:51:21 AM »
yay you lot have been busy, glad its working for you now.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #19 on: September 28, 2016, 11:55:11 AM »
Is there a simple way to pause motion until an input is triggered within a macro?  

I would like to ensure my Z axis returns home before the macro ends because after the macro would be an X-Y move. This is a cylinder where I have output 1 activate the "up" direction and output 0 activate the "down" direction.  

Something like this:

1. activate output_1 (up)
2. wait for Z home switch to trigger
3. end macro.

What is the best way to code step 2 (wait for input) in a Macro?

Good, thanks for testing!

This does not do any error checking and the time it waits for the input to go high is indefinite (neither of which are very good ideas) and it does not take your "In automatic Cycle" into account but it should be all that is needed to do what you were looking for originally.

Also note the 2 M100's were changed to m100 so should be saved as m100.mcs. Early on their was some debate about whether or not M codes should be upper or lower case in the scripts themselves. The answer is lower case. It should prevent some possible issues in non Windows OS's.

I would also delete any other M100 files (M100.mcs, M100.mcc, M100.bak) each time you edit the macro and before testing. If not, your changes may not take effect until you do.

Code: [Select]
function m100()
    
    local inst, hSig
    inst = mc.mcGetInstance()
    hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
    
    mc.mcSignalSetState(hSig, 1) --turn on output 1
    mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 0) --Wait indefinitely (0) for input 21 to become active
  
end

if (mc.mcInEditor() == 1) then
    m100()
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!