---------------------------------------------------------------
-- Monitor the switches on the Pendant.
-- We break the three different mechanical switches into three separate function calls, since each function has a separate job.
-- We don't need to assign the MPG wheel since Mach handles that for us.
---------------------------------------------------------------
SigLib = {
[mc.ISIG_INPUT10] = function (state) --If you are not using INPUT10 for the Axis Selection X, change the INPUT#!!!!
PendantAxisChange() --This is called if there is a change with the Pendant's Axis Selection Switch Posion X
end,
[mc.ISIG_INPUT11] = function (state) --If you are not using INPUT11 for the Axis Selection Y, change the INPUT#!!!!
PendantAxisChange() --This is called if there is a change with the Pendant's Axis Selection Switch Posion Y
end,
[mc.ISIG_INPUT12] = function (state) --If you are not using INPUT12 for the Axis Selection Z, change the INPUT#!!!!
PendantAxisChange() --This is called if there is a change with the Pendant's Axis Selection Switch Posion Z
end,
-------------
[mc.ISIG_INPUT13] = function (state) --If you are not using INPUT6 for theX1 Selection, change the INPUT#!!!!
PendantSpeedChange() --This is called if there is a change with the Pendant's Rate Selection Switch X1
end,
[mc.ISIG_INPUT14] = function (state) --If you are not using INPUT7 for the X10 Selection, change the INPUT#!!!!
PendantSpeedChange() --This is called if there is a change with the Pendant's Rate Selection Switch X10
end,
[mc.ISIG_INPUT15] = function (state) --If you are not using INPUT8 for the X100 Selection, change the INPUT#!!!!
PendantSpeedChange() --This is called if there is a change with the Pendant's Rate Selection Switch X100
end,
-------------
[mc.ISIG_INPUT16] = function (state) --If you are not using INPUT9 for the Pendant EStop Switch, change the INPUT#!!!!
PendantEStopChange() --This is called if there is a change with the Pendant's EStop Switch
end,
-------------
--These next three are not part of the Pendant code, but show you a few more options for inputs
[mc.ISIG_INPUT17] = function (state) --Performs a Cycle Start
InputCycleStart()
end,
[mc.ISIG_INPUT18] = function (state) --Performs a Cycle Stop
InputCycleStop()
end,
[mc.ISIG_INPUT19] = function (state) --Performs a reset
InputReset()
end
}
---------------------------------------------------------------
-- The Input Signal for a Cycle Start Occurred. This is not needed for the rest of the pendant example
---------------------------------------------------------------
function InputCycleStart() --This will do a cycle start because of a button push
CycleStart()
mc.mcCntlSetLastError(inst, "Input Cycle Start")
end
---------------------------------------------------------------
-- The Input Signal for a Cycle Stop Occurred. This is not needed for the rest of the pendant example
---------------------------------------------------------------
function InputCycleStop() --This will do a cycle stop because of a button push
CycleStop()
mc.mcCntlSetLastError(inst, "Input Cycle Stop")
end
---------------------------------------------------------------
-- The Input Signal for a Reset Occurred. This is not needed for the rest of the pendant example
---------------------------------------------------------------
function InputReset() --This will do a Reset because of a button push
mc.mcCntlReset(inst)
mc.mcSpindleSetDirection(inst, 0)
mc.mcCntlSetLastError(inst, "Input Reset")
end
--In Mach's Config tab for MPGs, if you don't have the ESS's encoder for the pendant assigned to MPG#7, change the 7 to the number you are using:
local MachMpgNumberForPendant = 1
local PendantStepSize = 0.001 --This is in your Mach4's units, mm or Inches, whichever one you have it set to
local PendantDistanceX1 = PendantStepSize * 1 --Multiply by one
local PendantDistanceX10 = PendantStepSize * 10 --Multiply by ten
local PendantDistanceX100 = PendantStepSize * 100 --Multiply by one hundred
--These shouldn't need to be modified, but they reduce the amount of apparently random numbers in the code:
local UnmapMPG = -1 --Use this one for when Axis selector switch is set to OFF
local AxisNumber_X = 0 -- Linear axis X (one of six coordinated motion axes)
local AxisNumber_Y = 1 -- Linear axis Y (one of six coordinated motion axes)
local AxisNumber_Z = 2 -- Linear axis Z (one of six coordinated motion axes)
--Coordinated motion means all six coordinated axes get to the destination point at the same time.
--Not coordinated with motion means that axis can be doing whatever, whenever. Like a conveyor belt that is always running.
---------------------------------------------------------------
-- The Pendant's EStop switch changed...
-- This will process the Pendant's EStop Switch
-- THIS ESTOP SHOULD BE CONSIDERED A COURTESY SIGNAL, since it based on softare
-- You should still have a EStop that is pure hardwre that can disconnect power.
--If you start Mach with the button pressed in, it will not work when you need to press it!
---------------------------------------------------------------
function PendantEStopChange()
local hPendantEStop
local PendantEStop
hPendantEStop, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9) --If you are not using INPUT9 for the Pendant EStop Switch, change the INPUT#!!!!
PendantEStop, rc = mc.mcSignalGetState(hPendantEStop)
if (PendantEStop == 1) then
mc.mcCntlEStop(inst) --Activate the EStop signal in Mach
mc.mcCntlSetLastError(inst, "Pendant EStop Activated") --Show a message in the Screen Set
else
mc.mcCntlSetLastError(inst, "Pendant EStop Cleared") --Show a message in the Screen Set
end
end
---------------------------------------------------------------
-- The Pendant's Speed switch changed... Reconfigure appropriate settings in Mach4
--This will process the Pendant's Rate/Speed Selection Switch
---------------------------------------------------------------
function PendantSpeedChange()
--Variable prep first for handles
local hX1
local hX10
local hX100
--Variable prep for signal values
local Step1
local Step10
local Step100
hX1, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13) --If you are not using INPUT6 for theX1 Selection, change the INPUT#!!!!
Step1, rc = mc.mcSignalGetState(hX1)
hX10, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14) --If you are not using INPUT7 for the X10 Selection, change the INPUT#!!!! -- X10 Port 3 Pin 4
Step10, rc = mc.mcSignalGetState(hX10)
hX100, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15) --If you are not using INPUT8 for the X100 Selection, change the INPUT#!!!!
Step100, rc = mc.mcSignalGetState(hX100)
local msg
if (Step1 == 1) then
mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX1 )
msg = "Jog Distance X1 = " .. PendantDistanceX1
mc.mcCntlSetLastError(inst, msg) --Show a message in the Screen Set
elseif (Step10 == 1) then
mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX10)
msg = "Jog Distance X10 = " .. PendantDistanceX10
mc.mcCntlSetLastError(inst, msg) --Show a message in the Screen Set
elseif (Step100 == 1) then
mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX100)
msg = "Jog Distance X100 = " .. PendantDistanceX100
mc.mcCntlSetLastError(inst, msg) --Show a message in the Screen Set
end
end
---------------------------------------------------------------
-- The Pendant's Axis switch changed... Reconfigure appropriate settings in Mach4 and turn the Pendant LED ON/OFF
--This will process the Pendant's Axis Selection Switch
---------------------------------------------------------------
function PendantAxisChange()
--Variable prep first for handles
local hAxis_X --Position X on Pendant Switch
local hAxis_Y --Position Y on Pendant Switch
local hAxis_Z --Position Z on Pendant Switch
--Variable prep for signal values, MAKE SURE YOU MATCH THE ONES IN HERE WITH THE ONES JUST ABOVE
local SelectAxis_X
local SelectAxis_Y
local SelectAxis_Z
hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10) --If you are not using INPUT0 for the Axis Selection Switch X, change the INPUT#!!!!
SelectAxis_X, rc = mc.mcSignalGetState(hAxis_X)
hAxis_Y, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11) --If you are not using INPUT1 for the Axis Selection Switch Y, change the INPUT#!!!!
SelectAxis_Y, rc = mc.mcSignalGetState(hAxis_Y)
hAxis_Z, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12) --If you are not using INPUT2 for the Axis Selection Switch Z, change the INPUT#!!!!
SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)
--This is the Pendant's LED, and it will be ON when an axis is active on the Pendant's switch
local hLedForActivePendantAxis
hLedForActivePendantAxis, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)-- Pendant LED Port 3 Pin 1
--Now actual axis Selection Switch processing code
if (SelectAxis_X == 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_X) --Map the MPG to control the X Axis
mc.mcCntlSetLastError(inst, "X Axis Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_Y== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Y) --Map the MPG to control the Y Axis
mc.mcCntlSetLastError(inst, "Y Axis Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_Z== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Z) --Map the MPG to control the Z Axis
mc.mcCntlSetLastError(inst, "Z Axis Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
else
--None of the Axis Switch inputs are active, so unmap the MPG from all axes (by assigning an invalid axis -1)
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, UnmapMPG ) --Unmap the MPG, so it won't control any axes
mc.mcCntlSetLastError(inst, "NO Pendant Axis Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 0) --Turn the Pendant's LED OFF to show no axis is active
end
end
--We will now call the three functions we made
--This is so the functions will be initalized to the current pendant values
--When the Screen is loaded by Mach4
PendantEStopChange()
PendantSpeedChange()
PendantAxisChange()