9
« on: March 08, 2024, 07:52:01 PM »
I got some assistance over at Warp 9 and have some fixes:
Manual Spindle Button
function InputManualSpindle()
-- Momentary pushbutton, so we get TWO signals with each button press:
-- an "ON" and an "OFF"
-- So check state and ignore the "OFF"
local hSpindleButton
local SpindleButtonState
hSpindleButton, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3) -- signal 3
SpindleButtonState, rc = mc.mcSignalGetState(hSpindleButton)
if (SpindleButtonState == 1) then
mc.mcCntlSetLastError(inst, "Control Panel Manual Spindle PRESS")
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON) -- This turns on the spindle
local hsig2 = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEFWD) -- This turns on the UI button on screen
local spindstate, rc = mc.mcSignalGetState(hsig)
if (spindstate == 0) then -- If spindle is off, turn it on
mc.mcSignalSetState(hsig, 1)
mc.mcSignalSetState(hsig2, 1)
mc.mcCntlSetLastError(inst, "Control Panel Manual Spindle ON")
else -- Otherwise, turn it off
mc.mcSignalSetState(hsig, 0)
mc.mcSignalSetState(hsig2, 0)
mc.mcCntlSetLastError(inst, "Control Panel Manual Spindle OFF")
end
else
mc.mcCntlSetLastError(inst, "Control Panel Manual Spindle RELEASE")
end
end
Jog Axis Select Switch:
function PendantAxisChange()
-- handles
local hAxis_X
local hAxis_Z
local SelectAxis_X
local SelectAxis_Z
local PanelMachMPGNumber = 7 -- setting this here because of suspicions that the "constant" we were using is getting garbage collected by Lua 5.3
-- March 8 2024
-- All of a sudden, following an update, MACH is picking up on the split second when it appears that both lines are HIGH
-- Adding noise reduction to the ESS config had not effect, so I suspect that the switch really does have both lines HIGH
-- as the switch moves across the contacts.
-- LUA does nt appear to have a native DELAY function and I'm not sure about OS dependancies so a simple delay isn't (yet) an option
-- so we need another solution
-- The status of the JOG ON light can be used as a flag. Is this yucky, or brilliant?
local hJogLight
hJogLight, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
local JogState, rc = mc.mcSignalGetState(hJogLight)
local AxisState
AxisState, rc = mc.mcMpgGetAxis(inst, PanelMachMPGNumber)
hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)
SelectAxis_X, rc = mc.mcSignalGetState(hAxis_X)
hAxis_Z, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)
SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)
-- mc.mcCntlSetLastError(inst, "Entered PendantAxisChange()") -- Hoe many times is this thing getting called per switch? The answer is TWO.
if (AxisState == AxisNumber_X) then
-- We started at X, so we must want Z
if (JogState == 1) then -- Make sure jog is active
if (SelectAxis_Z== 1) then
mc.mcMpgSetAxis(inst, PanelMachMPGNumber, AxisNumber_Z) -- Map the MPG to control the Z Axis
mc.mcCntlSetLastError(inst, "Panel Jog Axis Z Selected") -- Show a message in the Screen Set
else
-- Should this fail like this?
-- This traps the second call
-- mc.mcCntlSetLastError(inst, "I think we want Z but the Z line isn't HIGH - ABEND")
end
else
mc.mcCntlSetLastError(inst, "Changed axis select to Z while jog disabled - IGNORED")
end
elseif (AxisState == AxisNumber_Z) then
-- We started at Z, so we must want X
if (JogState == 1) then -- Make sure jog is active
if (SelectAxis_X == 1) then
mc.mcMpgSetAxis(inst, PanelMachMPGNumber, AxisNumber_X) -- Map the MPG to control the X Axis
mc.mcCntlSetLastError(inst, "Panel Jog Axis X Selected") -- Show a message in the Screen Set
else
-- Should this fail like this?
-- mc.mcCntlSetLastError(inst, "I think we want X but the X line isn't HIGH - ABEND")
-- This traps the second call
end
else
-- This never seems to execute
mc.mcCntlSetLastError(inst, "Changed axis select to X while jog disabled - IGNORED")
end
else
-- We somehow have a wrong axis?
-- Actually this triggers when we change the axis switch with jogging disabled
mc.mcCntlSetLastError(inst, "Jog Axis Switch does not recognize previously enabled axis - ABEND")
end
-- Disabled while we try the new regime because of debounce
--if (AxisState ~= -1) then -- Temporarily (?) hardcoded to see if our constant was getting garbage collected in Lua 5.3
--
-- hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)
-- SelectAxis_X, rc = mc.mcSignalGetState(hAxis_X)
--
-- hAxis_Z, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)
-- SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)
--
-- -- Now actual axis Selection Switch processing code
-- if ((SelectAxis_X == 1) and (SelectAxis_Z== 1)) then
-- This is a problem - the switch is shorted or something
-- mc.mcMpgSetAxis(inst, PanelMachMPGNumber, -1 ) -- Unmap the MPG, so it won't control any axes
-- mc.mcCntlSetLastError(inst, "ABEND - Both control panel axis select lines are HIGH") -- Show a message in the Screen Set
--
-- elseif (SelectAxis_X == 1) then
-- mc.mcMpgSetAxis(inst, PanelMachMPGNumber, AxisNumber_X) -- Map the MPG to control the X Axis
-- mc.mcCntlSetLastError(inst, "Pendant Axis X Selected") -- Show a message in the Screen Set
--
-- elseif (SelectAxis_Z== 1) then
-- mc.mcMpgSetAxis(inst, PanelMachMPGNumber, AxisNumber_Z) -- Map the MPG to control the Z Axis
-- mc.mcCntlSetLastError(inst, "Pendant Axis Z Selected") -- Show a message in the Screen Set
--
-- else
-- -- This is a problem, because the axis select switch is one or the other
-- -- We have no high pin - so shut off jogging
-- mc.mcMpgSetAxis(inst, PanelMachMPGNumber, -1 ) -- Unmap the MPG, so it won't control any axes
-- mc.mcCntlSetLastError(inst, "ABEND -Both control panel axis select lines are LOW") -- Show a message in the Screen Set
-- end
-- else
-- mc.mcCntlSetLastError(inst, "Changed axis select while jog disabled - IGNORED")
-- end
end