So I have built a custom control panel for my Mach4/EthernetSmoothStepper lathe. It has:
1. Pushbuttons for Cycle Start, Feed Hold, and Manual Spindle (for tailstock drilling etc where the spindle needs to run but no machine motions take place)
2. An E-Stop mushroom
3. A Jog Handle, consisting of an MPG, an X/Z selector Switch, and a 4-position rotary switch for OFF/0.1/0.01/0.001
4. A Program Run LED
5. A Feed Hold LED
6. A Manual Jog Active LED
I'm now at the point where I can wire it into the controller and set up scripting.
Here are the functions if should do:
1. If Cycle Start is pressed, it should react the same as if the on-screen button has been clicked. The on-screen button should light the Program Run LED while a program is running, and turn it off when the program stops.
2. If Feed Hold is pressed when a program is running, it should react the same as if the on-screen button has been clicked. The on-screen button should light the Feed Hold LED and turn off the Program Run while a program is paused, and reverse the LEDs when the program is resumed.
3. If Manual Spindle Start is pressed, the script should check to see if a non-zero value is set in Program RPM. If yes, turn on the spindle. If no, set Program RPM to 1200 and turn on the spindle. If the spindle is already running, turn it off.
4. If EStop is activated, stop the machine.
5. If the rotary Jog Resolution switch is set to 0.1, 0.01, or 0.001, set the MPG resolution to the appropriate value, activate the axis selected by the X/Z selector switch, and turn on the Jog Handle LED. If no resolution is selected, set the MPG resolution to 0, deselect all jog axis, and turn off the Jog LED.
My initial kick at the cat is below. It is missing some functions, identified as "FIXME". Comments and suggestions welcome.
--------------------------------------
-- FNR Control Console Code --
--------------------------------------
SigLib = {
[mc.ISIG_INPUT10] = function (state) -- Cycle Start
RunFNR()
end,
[mc.ISIG_INPUT11] = function (state) -- Feed Hold
RunFNR()
end,
[mc.ISIG_INPUT12] = function (state) -- Manual Spindle Start
RunFNR()
end,
[mc.ISIG_INPUT13] = function (state) -- EStop
RunFNR()
end,
[mc.ISIG_INPUT14] = function (state) -- Jog On, 0.001
RunFNR()
end,
[mc.ISIG_INPUT15] = function (state) -- Jog On, 0.01
RunFNR()
end,
[mc.ISIG_INPUT16] = function (state) -- Jog On, 0.1
RunFNR()
end
}
---------------------------------------------------------------
-- FNR Control Console function.
---------------------------------------------------------------
function RunFNR()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10) -- Is mapped to Port X Pin X *Cycle Start
local FNRCycleStart, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11) -- Is mapped to Port X Pin X *Feed Hold
local FNRFeedHold, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12) -- Is mapped to Port X Pin X *Spindle Start
local FNRSpindleStart, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13) -- Is mapped to Port X Pin X *EStop
local FNREStop, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14) -- Is mapped to Port X Pin X *.001 Select
local FNRStep001, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15) -- Is mapped to Port X Pin X *.010 Select
local FNRStep010, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16) -- Is mapped to Port X Pin X *.100 Select
local FNRStep100, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17) -- Is mapped to Port X Pin X *X Axis Jog Select
local FNRXJog, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18) -- Is mapped to Port X Pin X *Z Axis Jog Select
local FNRZJog, rc = mc.mcSignalGetState(hSig)
local FNRJogLED, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)-- Is mapped to Port X Pin X *Jog Active LED
local FNRRunLED, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT11)-- Is mapped to Port X Pin X *Program Run LED
local FNRPauseLED, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12)-- Is mapped to Port X Pin X *Pause LED
-- Set active axis based on X/Z switch
if FNRXJog == 1 then
mc.mcMpgSetAxis(inst, 0, 0) --X Axis
mc.mcCntlSetLastError(inst, "X Jog Selected")
elseif FNRZJog == 1 then
mc.mcMpgSetAxis(inst, 0, 1) --Z Axis
mc.mcCntlSetLastError(inst, "Z Jog Selected")
else
-- Can't get here, so there's a fault
mc.mcMpgSetAxis(inst, 0, -1) --No Axis
mc.mcCntlSetLastError(inst, "No Jog Axis Selected - IMPOSSIBLE - EStop triggered!")
mc.mcSignalSetState(FNRJogLED, 0)
mc.mcCntlEStop(inst)
end
-- Set step resolution and activate jog based on rotary selector switch
if FNRStep001 == 1 then
mc.mcMpgSetInc(inst, 0, .001)
mc.mcCntlSetLastError(inst, "MPG JOG ON - Thousandths")
mc.mcSignalSetState(FNRJogLED, 1)
elseif FNRStep010 == 1 then
mc.mcMpgSetInc(inst, 0, .010)
mc.mcCntlSetLastError(inst, "MPG JOG ON - Hundredths")
mc.mcSignalSetState(FNRJogLED, 1)
elseif FNRStep100 == 1 then
mc.mcMpgSetInc(inst, 0, .100)
mc.mcCntlSetLastError(inst, "MPG JOG ON - Tenths")
mc.mcSignalSetState(FNRJogLED, 1)
else -- None of the jog enable switches are closed, so ensure jog is off
mc.mcMpgSetInc(inst, 0, 0) -- Set jog increment to 0 to shut it off. FIXME: is this valid?
mc.mcMpgSetAxis(inst, 0, -1) -- Set jog axis to -1 to shut off jogging.
mc.mcCntlSetLastError(inst, "MPG JOG OFF")
mc.mcSignalSetState(FNRJogLED, 0)
end
-- EStop
if FNREStop == 1 then
mc.mcCntlEStop(inst)
end
-- Cycle Start
if FNRCycleStart == 1 then
mc.mcCntlSetLastError(inst, "Console Cycle Start")
mc.mcSignalSetState(FNRRunLED, 1)
-- FIXME: Need command to run "Cycle Start"
-- FIXME: LED control should go in main cycle start command so it works with screen controls too
end
-- Feed Hold
if FNRCycleStart == 1 then
mc.mcCntlSetLastError(inst, "Console Feed Hold")
mc.mcSignalSetState(FNRRunLED, 0)
mc.mcSignalSetState(FNRPauseLED, 1)
-- FIXME: Need command to run "Feed Hold"
-- FIXME: LED control should go in main cycle start / feed hold command so it works with screen controls too
end
-- Manual Spindle
if FNRSpindleStart == 1 then
-- Check current spindle setting, if 0, set to 1200, otherwise leave alone
-- Check if spindle running, if no, then start. If yes, then stop
-- FIXME: need code to do this
end
end