Hello Guest it is April 25, 2024, 08:17:30 AM

Author Topic: Why doesn't this work? (FEED HOLD state)  (Read 1519 times)

0 Members and 1 Guest are viewing this topic.

Why doesn't this work? (FEED HOLD state)
« on: July 02, 2021, 01:38:35 PM »
Code: [Select]
function InputFeedHold()

-- Momentary pushbutton, so we get TWO signals with each button press:
        -- an "ON" and an "OFF"
        -- So check state and ignore the "OFF"

local hHoldButton
local HoldButtonState
hHoldButton, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)      -- signal 2
HoldButtonState, rc = mc.mcSignalGetState(hHoldButton)

if (HoldButtonState == 1) then

mc.mcCntlSetLastError(inst, "Control Panel Feed Hold PRESS")

-- If we are running a program, pause
-- If we are already paused, stop
local Running
local Paused
Running, rc = mc.mcCntlIsInCycle(inst)
Paused, rc = mc.mcCntlFeedHoldState(inst)

if (Running) then -- We are running, so do something
if (Paused) then -- We are paused, so stop
CycleStop()
mc.mcCntlSetLastError(inst, "Control Panel CYCLE STOP")
else -- Pause
rc = mc.mcCntlFeedHold(inst)            -- Should this maybe be FeedHold()?
mc.mcCntlSetLastError(inst, "Control Panel FEED HOLD")
end
else
-- Spurious button press
mc.mcCntlSetLastError(inst, "Not running or paused - IGNORE ME")
end
else
mc.mcCntlSetLastError(inst, "Control Panel Feed Hold RELEASE")
end
end

The idea here is that push FEED HOLD once (a physical button) should activate FEED HOLD, and pushing FEED HOLD a second time (while already paused) should CYCLE STOP.

The code above triggers CYCLE STOP

The test for Running works, the test for Paused does not.

What have i missed?

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Why doesn't this work? (FEED HOLD state)
« Reply #1 on: July 02, 2021, 02:46:43 PM »
I could be wrong but i think you need to put a value for Running and Paused.

You have;
if (Paused) then

I think you need;
if (Paused=1) then

Re: Why doesn't this work? (FEED HOLD state)
« Reply #2 on: July 02, 2021, 03:07:37 PM »
Just want to watch this thread.  I tried to do this when Mach4 was just a tiny baby and I didn't know anything about LUA  HAHA
Chad Byrd
Re: Why doesn't this work? (FEED HOLD state)
« Reply #3 on: July 02, 2021, 03:50:23 PM »
OK, you are right - it seems that LUA doesn't follow the same idioms that some other languages do. It needs an explicit equality check.

But not done yet - it seems that Running, rc = mc.mcCntlIsInCycle(inst) may not be the right test.That appears to test if a *file* is running, not that the machine is active (so it doesn't work for MDI programs).

Code: [Select]
--------------------------------------------------------------
-- Control Panel Feed Hold
-- One push for Feed Hold, two pushes for Cycle Stop
---------------------------------------------------------------

function InputFeedHold()

-- Momentary pushbutton, so we get TWO signals with each button press:
        -- an "ON" and an "OFF"
        -- So check state and ignore the "OFF"

local hHoldButton
local HoldButtonState
hHoldButton, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)      -- signal 2
HoldButtonState, rc = mc.mcSignalGetState(hHoldButton)

if (HoldButtonState == 1) then

mc.mcCntlSetLastError(inst, "Control Panel Feed Hold PRESS")

-- If we are running a program, pause
-- If we are already paused, stop
local Running
local Paused
Running, rc = mc.mcCntlIsInCycle(inst)
Paused, rc = mc.mcCntlFeedHoldState(inst)

if (Paused == 1) then -- We are paused, so stop
CycleStop()
-- rc = mc.mcCntlFeedHold(inst) -- TODO This is wrong, but I want hold not stop right now
mc.mcCntlSetLastError(inst, "Control Panel CYCLE STOP")
elseif (Running == 1) then -- We are running, so do something

rc = mc.mcCntlFeedHold(inst)            -- Should this maybe be FeedHold()?
mc.mcCntlSetLastError(inst, "Control Panel FEED HOLD")
else
-- Spurious button press
mc.mcCntlSetLastError(inst, "Not running or paused - IGNORE ME")
end
else
mc.mcCntlSetLastError(inst, "Control Panel Feed Hold RELEASE")
end

end


This will CycleStop if the machine is in feed hold (via the GUI) but doen't respond to a button press feed hold; it follows the IGNORE ME path.

CONFIRMED - works perfectly if I load a gcode from *file*, but MDI fails.

There doesn't seem to be an API call that returns true if an MDI file is running?
« Last Edit: July 02, 2021, 04:01:28 PM by RecceDG »

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Why doesn't this work? (FEED HOLD state)
« Reply #4 on: July 02, 2021, 05:45:35 PM »
Can you get the state with mc.mcCntlGetState(inst) and check you're not in an idle state (mc.MC_STATE_IDLE)? Or in newer version of Mach4 there's an output signal mc.OSIG_MACHINE_IDLE.
Re: Why doesn't this work? (FEED HOLD state)
« Reply #5 on: July 02, 2021, 08:09:09 PM »
Is there a doc somewhere that lists the possible machine states and their aliases?

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Why doesn't this work? (FEED HOLD state)
« Reply #6 on: July 02, 2021, 10:35:17 PM »
I don't think it's in the docs, but this post has the possible return values from mc.mcCntlGetState(inst)

https://www.machsupport.com/forum/index.php?topic=41409.msg271498#msg271498
Re: Why doesn't this work? (FEED HOLD state)
« Reply #7 on: July 02, 2021, 10:40:27 PM »
FRUN is “run from file” and MRUN is “run from MDI”?

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Why doesn't this work? (FEED HOLD state)
« Reply #8 on: July 02, 2021, 10:44:35 PM »
Yes
Re: Why doesn't this work? (FEED HOLD state)
« Reply #9 on: July 03, 2021, 12:10:21 AM »
Hi,
there is another listing for the return values and quite a few other ENUMS etc:

https://www.machsupport.com/forum/index.php?topic=40051.0

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'