Thanks Daz - I'll use that strategy.
I noticed that the machine can be left in a state where the axis continues to jog even though the safety triggers are released. This may be due to the strategy I used and may not be an issue for other people. I included some code after the timer stop commands to prevent any possible movement after the safety triggers are released, just to be safe.
Once again, thanks for your help with this. I'm not a LUA expert, but I feel like I've learned a lot.
----------------------------------------------------------------------------
-- X_360 Lua by DazTheGas - Last Updated 07/12/16 SDK 3233
----------------------------------------------------------------------------
-----------------Declares
local mInst = mc.mcGetInstance()
local Xenabled = false
local ESState = false
local JogInc = .001
local CState = false
local FHState = false
local RSState = false
local AIState = false
local XPState = false
local TXPState = false
local XNState = false
local TXNState = false
local YPState = false
local TYPState = false
local YNState = false
local TYNState = false
local ZPState = false
local TZPState = false
local ZNState = false
local TZNState = false
local islok = false
local DZ = 25 --Dead Zone Based on controller output value (-99 => 99)
local JIState = false
local JDState = false
local Jog_Rate = 0
-- X360 Init Panel
X360_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
X360_Timer = wx.wxTimer(X360_Panel)
-- EStop
EStop_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
EStop_Timer = wx.wxTimer(EStop_Panel)
-- Buttons
Btns_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
Btns_Timer = wx.wxTimer(Btns_Panel)
-----------------Functions
--Read XBox Controller Values
function GetXin(xinput)
local hreg = mc.mcRegGetHandle(mInst, string.format("mcX360_LUA/%s", xinput))
return mc.mcRegGetValueLong(hreg)
end
-- X Pos
function jog_XP(xpisinc,xpmove)
if xpisinc == false then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_JOGXP), xpmove)
end
if xpisinc == true then
if xpmove == 1 then
JogInc=mc.mcJogGetInc(mInst,0) / 2. -- Diameter Mode for Lathe
mc.mcJogIncStart(mInst, mc.X_AXIS, JogInc)
else
mc.mcJogIncStop(mInst, mc.X_AXIS,.0001)
end
end
end
-- X Neg
function jog_XN(xnisinc,xnmove)
if xnisinc == false then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_JOGXN), xnmove)
end
if xnisinc == true then
if xnmove == 1 then
JogInc=mc.mcJogGetInc(mInst,0) / 2. -- Diameter Mode for Lathe
mc.mcJogIncStart(mInst, mc.X_AXIS, JogInc * -1.)
else
mc.mcJogIncStop(mInst, mc.X_AXIS,.0001)
end
end
end
-- Z Pos
function jog_ZP(zpisinc,zpmove)
if zpisinc == false then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_JOGZP), zpmove)
end
if zpisinc == true then
if zpmove == 1 then
JogInc=mc.mcJogGetInc(mInst,2)
mc.mcJogIncStart(mInst, mc.Z_AXIS, JogInc)
else
mc.mcJogIncStop(mInst, mc.Z_AXIS,.0001)
end
end
end
-- Z Neg
function jog_ZN(znisinc,znmove)
if znisinc == false then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_JOGZN), znmove)
end
if znisinc == true then
if znmove == 1 then
JogInc=mc.mcJogGetInc(mInst,2)
mc.mcJogIncStart(mInst, mc.Z_AXIS, -1 * JogInc)
else
mc.mcJogIncStop(mInst, mc.Z_AXIS,.0001)
end
end
end
-----------------Event Timers
X360_Timer:Start(100)
X360_Panel:Connect(wx.wxEVT_TIMER, function (event)
if GetXin("LTR_Val") + GetXin("RTR_Val") > 400 and Xenabled == false then
EStop_Timer:Start(50)
Btns_Timer:Start(50) -- was 100
Xenabled = true
mc.mcCntlSetLastError(mInst,"Pendant Enabeled")
elseif GetXin("LTR_Val") + GetXin("RTR_Val") < 100 and Xenabled == true then
EStop_Timer:Stop()
Btns_Timer:Stop()
Xenabled = false
-- Stop all jogging if safety triggers are released
jog_XP(isinc,0)
jog_XN(isinc,0)
jog_ZP(isinc,0)
jog_ZN(isinc,0)
--
mc.mcCntlSetLastError(mInst,"Pendant Disabled")
end
end)
EStop_Panel:Connect(wx.wxEVT_TIMER, function (event)
if GetXin("Btn_B") == 1 and ESState == false then
local EStop = mc.mcSignalGetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY))
if (EStop == 1) then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY), 0)
else
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY), 1)
end
ESState = true
end
if GetXin("Btn_B") == 0 and ESState == true then
ESState = false
end
end)
Btns_Panel:Connect(wx.wxEVT_TIMER, function (event)
-- Cont or Inc Jog Mode
if GetXin("Btn_X") == 1 and AIState == false then
if isinc == false then
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.OSIG_JOG_CONT), 0)
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.OSIG_JOG_INC), 1)
isinc = true
else
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.OSIG_JOG_INC), 0)
mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.OSIG_JOG_CONT), 1)
isinc = false
end
AIState = true
end
if GetXin("Btn_X") == 0 and AIState == true then
AIState = false
end
-- Cycle_Start
if GetXin("Btn_A") == 1 and CState == false then
--CycleStart()
--mc.mcCntlCycleStart (mInst)
local rc;
local tab, rc = scr.GetProperty("MainTabs", "Current Tab")
local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
--local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab")
--wx.wxMessageBox("tab == " .. tostring(tab) )
--See if we have to do an MDI command
if ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1)) then --or (tonumber(tab) == 2 and tonumber(tabG_Mditwo) == 1 )) then
local state = mc.mcCntlGetState(mInst);
if (state == mc.MC_STATE_MRUN_MACROH) then
mc.mcCntlCycleStart(mInst);
mc.mcCntlSetLastError(mInst, "Do Cycle Start");
else
if (tonumber(tab) == 0) then
scr.ExecMdi('mdi1');
mc.mcCntlSetLastError(mInst, "Do MDI 1");
end
end
else
--Do CycleStart
mc.mcCntlSetLastError(mInst, "Do Cycle Start");
mc.mcCntlCycleStart(mInst);
--wx.wxMessageBox("Do Cycle Start")
end
--mc.mcCntlSetLastError(mInst,"A_Button_Pressed")
CState = true
end
if GetXin("Btn_A") == 0 and CState == true then
CState = false
end
-- Feed_Hold
if GetXin("Btn_Y") == 1 and FHState == false then
mc.mcCntlFeedHold(mInst)
mc.mcCntlSetLastError(mInst,"Feed Hold")
FHState = true
end
if GetXin("Btn_Y") == 0 and FHState == true then
FHState = false
end
-- Jog_Increase
if GetXin("Btn_START") == 1 then
Jog_Rate = Jog_Rate + 2
if Jog_Rate > 100 then
Jog_Rate = 100
end
mc.mcJogSetRate(mInst,mc.AXIS0,Jog_Rate)
mc.mcJogSetRate(mInst,mc.AXIS2,Jog_Rate)
--mc.mcCntlSetLastError(mInst,"Jog Rate Increase")
end
-- Jog_Decrease
if GetXin("Btn_BACK") == 1 then
Jog_Rate = Jog_Rate - 2
if Jog_Rate < 1 then
Jog_Rate = 1
end
mc.mcJogSetRate(mInst,mc.AXIS0,Jog_Rate)
mc.mcJogSetRate(mInst,mc.AXIS2,Jog_Rate)
--mc.mcCntlSetLastError(mInst,"Jog Rate Decrease")
end
-- Jog_Increment
if GetXin("Btn_RS") == 1 and RSState == false then
--mc.mcCntlSetLastError(mInst,"Jog Increment Changed")
local CurInc = mc.mcProfileGetInt(mInst,"Preferences","JogIncSet",0) --make a new setting in profile to hold our current inc number
local SetInc = mc.mcProfileGetDouble(mInst,"Preferences","JogInc"..CurInc,0.00) -- fetch our inc value from the profile JogInc + 2 say = [Preferences][JogInc2]
CurInc = CurInc + 1 -- increment our CurInc by 1
if CurInc > 10 then CurInc = 1 end -- if our CurInc is greater than 10 then go back to 1
mc.mcJogSetInc(mInst, mc.X_AXIS, SetInc) -- set inc for axis
mc.mcJogSetInc(mInst, mc.Y_AXIS, SetInc) -- set inc for axis
mc.mcJogSetInc(mInst, mc.Z_AXIS, SetInc) -- set inc for axis
mc.mcProfileWriteInt(mInst,"Preferences","JogIncSet",CurInc) --set our profile to new CurInc
RSState = true
end
if GetXin("Btn_RS") == 0 and RSState == true then
RSState = false
end
-- X++ DPAD
if GetXin("DPad_DOWN") == 1 and XPState == false and islok == false then
jog_XP(isinc,1)
XPState = true
islok = true
end
if GetXin("DPad_DOWN") == 0 and XPState == true then
jog_XP(isinc,0)
XPState = false
islok = false
end
-- X++ THUMB STICKS
if GetXin("LTH_Y_Val") <= (DZ*-1.) and TXPState == false and islok == false then
jog_XP(isinc,1)
TXPState = true
islok = true
end
if GetXin("LTH_Y_Val") > (DZ*-1.) and TXPState == true then
jog_XP(isinc,0)
TXPState = false
islok = false
end
-- X-- DPAD
if GetXin("DPad_UP") == 1 and XNState == false and islok == false then
jog_XN(isinc,1)
XNState = true
islok = true
end
if GetXin("DPad_UP") == 0 and XNState == true then
jog_XN(isinc,0)
XNState = false
islok = false
end
-- X-- THUMB STICKS
if GetXin("LTH_Y_Val") >= (DZ*1.) and TXNState == false and islok == false then
jog_XN(isinc,1)
TXNState = true
islok = true
end
if GetXin("LTH_Y_Val") < (DZ*1.) and TXNState == true then
jog_XN(isinc,0)
TXNState = false
islok = false
end
-- Z++ DPAD
if GetXin("DPad_RIGHT") == 1 and ZPState == false and islok == false then
jog_ZP(isinc,1)
ZPState = true
islok = true
end
if GetXin("DPad_RIGHT") == 0 and ZPState == true then
jog_ZP(isinc,0)
ZPState = false
islok = false
end
-- Z++ THUMB STICKS
if GetXin("RTH_X_Val") >= (DZ*1.) and TZPState == false and islok == false then
jog_ZP(isinc,1)
TZPState = true
islok = true
end
if GetXin("RTH_X_Val") < (DZ*1.) and TZPState == true then
jog_ZP(isinc,0)
TZPState = false
islok = false
end
-- Z-- DPAD
if GetXin("DPad_LEFT") == 1 and ZNState == false and islok == false then
jog_ZN(isinc,1)
ZNState = true
islok = true
end
if GetXin("DPad_LEFT") == 0 and ZNState == true then
jog_ZN(isinc,0)
ZNState = false
islok = false
end
-- Z-- THUMB STICKS
if GetXin("RTH_X_Val") <= (DZ*-1.) and TZNState == false and islok == false then
jog_ZN(isinc,1)
TZNState = true
islok = true
end
if GetXin("RTH_X_Val") > (DZ*-1.) and TZNState == true then
jog_ZN(isinc,0)
TZNState = false
islok = false
end
end)