Hello Guest it is April 25, 2024, 05:42:21 AM

Author Topic: mcX360 Plugin for Lua  (Read 45457 times)

0 Members and 3 Guests are viewing this topic.

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #10 on: November 28, 2016, 09:01:54 AM »
When running the Log Facillity i noticed the script hammers Velocity Stop so i fixed that...

This will likely be "it" for a while. I have some Machine issues to fix... :D

Code: [Select]
local inst = mc.mcGetInstance()
local X360_PNL = mcLuaPanelParent

---- CONFIG
    local DeadZone = 25 --Based on controller output value (-99 => 99)
    local MaxJogSpeed = 25 --Percentage of axix max speed

    local RTHY_MapToMashineAxis = mc.AXIS2 -- Z-AXIS
    local RTHX_MapToMashineAxis = mc.AXIS3 -- A-AXIS
    local LTHY_MapToMashineAxis = mc.AXIS1 -- Y-AXIS
    local LTHX_MapToMashineAxis = mc.AXIS0 -- X-AXIS
    
    local isPressed_BTN = {false,false,false,false} -- Buttons A,B,X,Y

-- FUNCTIONS
    function GetX360(xinput)
        local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
        return mc.mcRegGetValueString(hreg)
    end

    function EnableMashine(finst,pressed)
        if pressed then
            --I dont want to clear E-Stop on BTN_E-Stop_UP so instead i use X360´s MashineEnable for it...
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0);
            wx.wxMilliSleep(100)
            mc.mcCntlEnable(finst, true)
        else
            --mc.mcCntlSetLastError(finst, "X360_Enabled_Machine")
        end
        return
    end
    function CycleStart(finst,pressed)
        if pressed then
            mc.mcCntlCycleStart(finst)
        else
        end
        return
    end
    function EStop(finst,pressed)
        if pressed then
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 1);
        else
            -- Moved to EnableMashine
            --mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0);
        end
        return
    end
    
    function HandleButtonPress(finst,btn,btnNo,func,msg)
        if btn == "1" and isPressed_BTN[btnNo] == false then
            func(finst,true)
            mc.mcCntlSetLastError(finst, msg)
            isPressed_BTN[btnNo] = true
        end
        if btn == "0" and isPressed_BTN[btnNo] == true then
            func(finst,false)
            isPressed_BTN[btnNo] = false
        end
        return
    end

    function HandleThumbInput(finst,th,axis, isSecured,DZ, MaxJS)
        if (tonumber(th) >= (DZ*-1)) and (tonumber(th) <= DZ) then
            mc.mcCntlSetLastError(finst, "JogVelocity: "..mc.mcJogGetVelocity(finst, axis))
            if mc.mcJogGetVelocity(finst, axis) == 0 then
            else
                mc.mcJogSetRate(finst, axis, 0)
                mc.mcJogVelocityStop(finst, axis);
            end
        else
            if isSecured then
                if tonumber(th) > tonumber(DZ) then
                    mc.mcJogSetRate(finst, axis, (((tonumber(th)-DZ)/(100-DZ))*MaxJS))
                    mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_POS)
                elseif tonumber(th) < (tonumber(DZ)*-1) then
                    mc.mcJogSetRate(finst, axis, ((((tonumber(th)+DZ)/(100-DZ))*MaxJS)*-1))
                    mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_NEG)
                end
            end
        end
        return
    end

X360_timer = wx.wxTimer(X360_PNL)

    X360_PNL:Connect(wx.wxEVT_TIMER,   function (event)

-- SECURITY MEASURE -- Require Both triggerbuttons to be pressed...
    local isSecured = (GetX360("Btn_RS") == "1" ) and (GetX360("Btn_LS") == "1" )

-- HANDLE E-STOP ON BTN_B
    HandleButtonPress(inst,GetX360("Btn_B"),2,EStop,"X360_E-STOP")
-- HANDLE ALL OTHER BUTTONS
    if isSecured then
        -- MASHINE ENABLE ON BTN_X
        HandleButtonPress(inst,GetX360("Btn_X"),3,EnableMashine,"X360_Enabled_Machine")
        -- CYCLE START ON BTN_A
        HandleButtonPress(inst,GetX360("Btn_A"),1,CycleStart,"X360_CycleStart")
    end

-- HANDLE THUMBSTICKS
    HandleThumbInput(inst,GetX360("RTH_Y_Val"),RTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("RTH_X_Val"),RTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_Y_Val"),LTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_X_Val"),LTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    
    end)

    X360_timer:Start(100)
« Last Edit: November 28, 2016, 09:04:00 AM by Bx3mE »

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #11 on: November 29, 2016, 03:06:37 AM »
Quote
When running the Log Facillity i noticed the script hammers Velocity Stop so i fixed that...

It takes a lot more code but makes a lot of sense to reframe from too many "else" statements, i tend to use "elseif" and give it something to check against, another thing I need to mention is it is an error to quit without stopping the timer, in your screen unload script you need to be placing a timer:Stop() command for the panel

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #12 on: November 29, 2016, 09:11:50 AM »
Thanks for that!!

I will make a comment about it in the script and fix it for my panel.

Regarding the "else":s i had it using elseif:s first but there was an error i was hunting down so i removed all elseif:s - I never got arount to fix that.

Maybe if i get some time tonight...

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #13 on: November 29, 2016, 02:23:47 PM »
Here is the updated script...

Code: [Select]
local inst = mc.mcGetInstance()
local X360_PNL = mcLuaPanelParent

---- CONFIG

        -- ======================================================================
        -- = Dont forget to add X360_timer:Stop() to your screen unload script  =
        -- ======================================================================

    local DeadZone = 25 --Based on controller output value (-99 => 99)
    local MaxJogSpeed = 25 --Percentage of axix max speed

    local RTHY_MapToMashineAxis = mc.AXIS2 -- Z-AXIS
    local RTHX_MapToMashineAxis = mc.AXIS3 -- A-AXIS
    local LTHY_MapToMashineAxis = mc.AXIS1 -- Y-AXIS
    local LTHX_MapToMashineAxis = mc.AXIS0 -- X-AXIS
   
    local isPressed_BTN = {false,false,false,false} -- Buttons A,B,X,Y

-- FUNCTIONS
    function GetX360(xinput)
        local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
        return mc.mcRegGetValueString(hreg)
    end

    function EnableMashine(finst,pressed)
        if pressed then
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0) --I dont want to clear E-Stop on BTN_E-Stop_UP so instead i use X360´s MashineEnable for it... (see E-Stop function)
            wx.wxMilliSleep(100) -- You cannot enable unless E-Stop is cleared so we must wait for mcSignalSetState to complete
            mc.mcCntlEnable(finst, true)
        end
        return
    end
    function CycleStart(finst,pressed)
        if pressed then
            mc.mcCntlCycleStart(finst)
        end
        return
    end
    function EStop(finst,pressed)
        if pressed then
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 1)
        --else
            -- Uncomment this if you want E-Stop cleared on button release
            --mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0)
        end
        return
    end
   
    function HandleButtonPress(finst,btn,btnNo,func,msg)
        if btn == "1" and isPressed_BTN[btnNo] == false then
            func(finst,true)
            mc.mcCntlSetLastError(finst, msg)
            isPressed_BTN[btnNo] = true
        elseif btn == "0" and isPressed_BTN[btnNo] == true then
            func(finst,false)
            isPressed_BTN[btnNo] = false
        end
        return
    end

    function HandleThumbInput(finst,th,axis, isSecured,DZ, MaxJS)
        if (tonumber(th) >= (DZ*-1)) and (tonumber(th) <= DZ) then
            if mc.mcJogGetVelocity(finst, axis) ~= 0 then
                mc.mcJogSetRate(finst, axis, 0)
                mc.mcJogVelocityStop(finst, axis);
            end
        elseif isSecured then
            if tonumber(th) > tonumber(DZ) then
                mc.mcJogSetRate(finst, axis, (((tonumber(th)-DZ)/(100-DZ))*MaxJS))
                mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_POS)
            elseif tonumber(th) < (tonumber(DZ)*-1) then
                mc.mcJogSetRate(finst, axis, ((((tonumber(th)+DZ)/(100-DZ))*MaxJS)*-1))
                mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_NEG)
            end
        end
        return
    end

X360_timer = wx.wxTimer(X360_PNL)

    X360_PNL:Connect(wx.wxEVT_TIMER,   function (event)

-- SECURITY MEASURE -- Require Both triggerbuttons to be pressed...
    local isSecured = (GetX360("Btn_RS") == "1" ) and (GetX360("Btn_LS") == "1" )

-- HANDLE E-STOP ON BTN_B
    HandleButtonPress(inst,GetX360("Btn_B"),2,EStop,"X360_E-STOP")
-- HANDLE ALL OTHER BUTTONS (Only X and A are configured)
    if isSecured then
        -- MASHINE ENABLE ON BTN_X
        HandleButtonPress(inst,GetX360("Btn_X"),3,EnableMashine,"X360_Enabled_Machine")
        -- CYCLE START ON BTN_A
        HandleButtonPress(inst,GetX360("Btn_A"),1,CycleStart,"X360_CycleStart")
    end

-- HANDLE THUMBSTICKS
    HandleThumbInput(inst,GetX360("RTH_Y_Val"),RTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("RTH_X_Val"),RTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_Y_Val"),LTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_X_Val"),LTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
   
    end)

    X360_timer:Start(100)

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #14 on: December 04, 2016, 04:22:44 PM »
Updated the script with some nice expo to the thumb input. Now you can almost singlestep the steppermotors while having the same max speed  ;D ;D ;D

Over all I am getting happy with the script. That said i dont like the large Deadzone. I think DazTheGas could fix that in the plugin but on the other hand i think the current values are resonable given the large impresicion of the controller so for the X360 it is the best you can get... If the plugin would support multiple controllers i think this should be configurable but for the X360 it would be just plain dangerous.

Here is the updated script with some expo :P
Code: [Select]
local inst = mc.mcGetInstance()
local X360_PNL = mcLuaPanelParent

---- CONFIG

        -- ======================================================================
        -- = Dont forget to add X360_timer:Stop() to your screen unload script  =
        -- ======================================================================

    local DeadZone = 25 --Based on controller output value (-99 => 99)
    local MaxJogSpeed = 50 --Percentage of axix max speed

    local RTHY_MapToMashineAxis = mc.AXIS2 -- Z-AXIS
    local RTHX_MapToMashineAxis = mc.AXIS3 -- A-AXIS
    local LTHY_MapToMashineAxis = mc.AXIS1 -- Y-AXIS
    local LTHX_MapToMashineAxis = mc.AXIS0 -- X-AXIS
   
    local isPressed_BTN = {false,false,false,false} -- Buttons A,B,X,Y

-- FUNCTIONS
    function GetX360(xinput)
        local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
        return mc.mcRegGetValueString(hreg)
    end

    function EnableMashine(finst,pressed)
        if pressed then
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0) --I dont want to clear E-Stop on BTN_E-Stop_UP so instead i use X360´s MashineEnable for it... (see E-Stop function)
            wx.wxMilliSleep(100) -- You cannot enable unless E-Stop is cleared so we must wait for mcSignalSetState to complete
            mc.mcCntlEnable(finst, true)
        end
        return
    end
    function CycleStart(finst,pressed)
        if pressed then
            mc.mcCntlCycleStart(finst)
        end
        return
    end
    function EStop(finst,pressed)
        if pressed then
            mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 1)
        --else
            -- Uncomment this if you want E-Stop cleared on button release
            --mc.mcSignalSetState (mc.mcSignalGetHandle (finst, mc.ISIG_EMERGENCY), 0)
        end
        return
    end
   
    function HandleButtonPress(finst,btn,btnNo,func,msg)
        if btn == "1" and isPressed_BTN[btnNo] == false then
            func(finst,true)
            mc.mcCntlSetLastError(finst, msg)
            isPressed_BTN[btnNo] = true
        elseif btn == "0" and isPressed_BTN[btnNo] == true then
            func(finst,false)
            isPressed_BTN[btnNo] = false
        end
        return
    end

    function HandleThumbInput(finst,th,axis, isSecured,DZ, MaxJS)
        if (tonumber(th) >= (DZ*-1)) and (tonumber(th) <= DZ) then
            if mc.mcJogGetVelocity(finst, axis) ~= 0 then
                mc.mcJogSetRate(finst, axis, 0)
                mc.mcJogVelocityStop(finst, axis);
            end
        elseif isSecured then
            if tonumber(th) > tonumber(DZ) then
                mc.mcJogSetRate(finst, axis, ((((tonumber(th)-DZ)*(tonumber(th)-DZ))/((100-DZ)*(100-DZ)))*MaxJS))
                mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_POS)
            elseif tonumber(th) < (tonumber(DZ)*-1) then
                mc.mcJogSetRate(finst, axis, ((((tonumber(th)+DZ)*(tonumber(th)+DZ))/((100-DZ)*(100-DZ)))*MaxJS))
                mc.mcJogVelocityStart(finst, axis, mc.MC_JOG_NEG)
            end
        end
        return
    end

X360_timer = wx.wxTimer(X360_PNL)

    X360_PNL:Connect(wx.wxEVT_TIMER,   function (event)

-- SECURITY MEASURE -- Require Both triggerbuttons to be pressed...
    local isSecured = (GetX360("Btn_RS") == "1" ) and (GetX360("Btn_LS") == "1" )

-- HANDLE E-STOP ON BTN_B
    HandleButtonPress(inst,GetX360("Btn_B"),2,EStop,"X360_E-STOP")
-- HANDLE ALL OTHER BUTTONS (Only X and A are configured)
    if isSecured then
        -- MASHINE ENABLE ON BTN_X
        HandleButtonPress(inst,GetX360("Btn_X"),3,EnableMashine,"X360_Enabled_Machine")
        -- CYCLE START ON BTN_A
        HandleButtonPress(inst,GetX360("Btn_A"),1,CycleStart,"X360_CycleStart")
    end

-- HANDLE THUMBSTICKS
    HandleThumbInput(inst,GetX360("RTH_Y_Val"),RTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("RTH_X_Val"),RTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_Y_Val"),LTHY_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
    HandleThumbInput(inst,GetX360("LTH_X_Val"),LTHX_MapToMashineAxis,isSecured, DeadZone, MaxJogSpeed)
   
    end)

    X360_timer:Start(100)

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #15 on: December 04, 2016, 06:04:53 PM »
The return code from the controller (32670) is divided by 330 to give 99, I based this on velocity etc being set by percentage which I believe is the best approach, totally agree with NOT having 2 controllers ;-)

So just a few pointers to help you on your quest, I have downloaded and tested your script but unfortunately it kills any other form of jogging in mach4 - IE jog buttons and even the shuttle. You could do with setting some more  'if' statements.

You dont have to run everything in 1 timer, windows is an event driven os so use what is required.

There are many ways of retrieving a registry try

return mc.mcRegGetValueLong(hreg) instead of converting strings with tostring

Heres a few snippets from my script.


Code: [Select]
local mInst = 0

-- Enable
Xenabled = 0
JogRate = 0
Enable_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
Enable_Timer = wx.wxTimer(Enable_Panel)
-- Velocity
Vel_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
Vel_Timer = wx.wxTimer(Vel_Panel)
-- DPad
DPad_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
DPad_Timer = wx.wxTimer(DPad_Panel)

As you can see its possible to run many timers, these are a few and the only timer that is running const is the enable timer which is looking/waiting for the left trigger, on the left trigger value being over 150 it starts all the other timers and on release stops them.

Code: [Select]
Enable_Panel:Connect(wx.wxEVT_TIMER, function (event)
if GetXin("LTR_Val") > 150 and Xenabled == 0 then
JogRate = mc.mcJogGetRate(mInst, mc.X_AXIS)
EStop_Timer:Start(50)
DPad_Timer:Start(100)
Vel_Timer:Start(100)
LTH_Timer:Start(100)
RTH_Timer:Start(100)
BTN_Timer:Start(100)
Xenabled = 1
elseif GetXin("LTR_Val") < 50 and Xenabled == 1 then
DPad_Timer:Stop()
Vel_Timer:Stop()
EStop_Timer:Stop()
LTH_Timer:Stop
RTH_Timer:Stop()
BTN_Timer:Stop()
Xenabled = 0
mc.mcJogSetRate(mInst, mc.X_AXIS, JogRate)
mc.mcJogSetRate(mInst, mc.Y_AXIS, JogRate)
mc.mcJogSetRate(mInst, mc.Z_AXIS, JogRate)
end
end)
   
As you can see after releasing the left trigger my jograte is returned to what it was before and throughout the script is lots and lots of if and more if`s with the main goal of keeping overheads towards the gui at a minimum when the controller is not in use.

Must be time for a choccy biccy now ;-)

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #16 on: December 07, 2016, 05:41:10 AM »
Thanks! Im finding this beeing a great way to learn LUA Script and your input is valuable and step by step inspiring me to improve my code and skills. Thanks!

I dont know why i did not think of timers as event timers... in my mind X360_Timer was just a mystical "dont bother now" thingy which i totally overlooked. But i have been thinking of a way to lighten the load the script creates. For me it is not really nessesary since i only use X360 to navigate my machine but for sake of order it should be done.

How is all other jogging killed? Is it me setting zero velocity for safety reasons on all axes (First if statment in HandleThumbInput) when not enabled? That can definitely be improved. ......Just thought about that code for a second and looks like I've been tired when writing that - it´s just wrong... :P
I will get back to my script this weekend (or maybe earlier.. ;P)

LunchTime :P

Daniel

What are your thoughts on the following:
having probing on the D-Pad (BTN_Back for Z and A)
Spindle speed and feedrate on Y+DPad

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #17 on: December 10, 2016, 11:33:25 AM »
Ok so part 1 of the usage is now uploaded and can be found here http://www.machsupport.com/forum/index.php/topic,33792.0.html

Attached is the latest version of driver.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #18 on: December 12, 2016, 05:59:23 PM »
What changed in the plugin? Release notes? :P

Im just finishing up my script, now everything is done except probing (waiting for andy @ warp9)
I have spindle speed on DPad now im setting it using the screen...  Is that the right way or is there another way to do it?
My code is cut and paste from the screen SRO "+" button:

Code: [Select]
function SpindleSpeedInc(finst, pressed)
    if pressed then
        local val = scr.GetProperty('slideSRO', 'Value');
        val = tonumber(val) + 5;
        local maxval = scr.GetProperty('slideSRO', 'Max Value')
        if (tonumber(val) >= tonumber(maxval)) then
         val = maxval;
        end
        scr.SetProperty('slideSRO', 'Value', tostring(val));
    end
end
Re: mcX360 Plugin for Lua
« Reply #19 on: December 18, 2016, 11:28:23 PM »
I need help on a lathe project.  ???  Please see the code below.  After the E-Stop button, I'm trying to toggle between ABS and INC jogging.  Then, I'm trying to change the jog increment.  I'm totally stuck and would appreciate any help I can get.

On the bright side,  I did figure out how to use JogInc=mc.mcJogGetInc(mInst,0) in the dpad buttons. :-\

Code: [Select]
----------------------------------------------------------------------------
--  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 AIState = false
local CJIState = false
local XPState = false
local XNState = false
local YPState = false
local YNState = false
local ZPState = false
local ZNState = false

-- X360 Init Panel
X360_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
X360_Timer = wx.wxTimer(X360_Panel)
X360_Timer:Start(100)
-- EStop
EStop_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
EStop_Timer = wx.wxTimer(EStop_Panel)
-- DPad
DPad_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize)
DPad_Timer = wx.wxTimer(DPad_Panel)

-----------------Functions

function GetXin(xinput)
    local hreg = mc.mcRegGetHandle(mInst, string.format("mcX360_LUA/%s", xinput))
    return mc.mcRegGetValueLong(hreg)
end

-----------------Event Timers

X360_Panel:Connect(wx.wxEVT_TIMER, function (event)
if GetXin("LTR_Val") > 150 and Xenabled == false then
        EStop_Timer:Start(50)
        DPad_Timer:Start(100)
Xenabled = true
        mc.mcCntlSetLastError(mInst,"X_360 Running")
elseif GetXin("LTR_Val") < 50 and Xenabled == true then
        EStop_Timer:Stop()
        DPad_Timer:Stop()
Xenabled = false
        mc.mcCntlSetLastError(mInst,"X_360 Stopped")
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)

DPad_Panel:Connect(wx.wxEVT_TIMER, function (event)
-- ABS/INC
if GetXin("Btn_X") == 1 and AIState == false then
--How do I active the btnToggleJogMode ?
        mc.mcCntlSetLastError(mInst,"B_Button_Pressed")
        ButtonJogModeToggle()
        AIState = true
end
if GetXin("Btn_X") == 0 and AIState == true then
AIState = false
end
-- Cycle_Jog_Inc
if GetXin("Btn_START") == 1 and CJIState == false then
--How do I active the btnCycleJogInc ?
        mc.mcCntlSetLastError(mInst,"START_Button_Pressed")
        ButtonJogModeToggle()
        CJIState = true
end
if GetXin("Btn_START") == 0 and CJIState == true then
CJIState = false
end
-- -- Y++
-- if GetXin("DPad_UP") == 1 and GetXin("Btn_LS") == 0 and YPState == false then
-- mc.mcJogIncStart(mInst, mc.Y_AXIS, JogInc)
-- YPState = true
-- end
-- if GetXin("DPad_UP") == 0 and GetXin("Btn_LS") == 0 and YPState == true then
-- mc.mcJogIncStop(mInst, mc.Y_AXIS,.1)
-- YPState = false
-- end
-- -- Y--
-- if GetXin("DPad_DOWN") == 1 and GetXin("Btn_LS") == 0 and YNState == false then
-- mc.mcJogIncStart(mInst, mc.Y_AXIS, -1 * JogInc)
-- YNState = true
-- end
-- if GetXin("DPad_DOWN") == 0 and GetXin("Btn_LS") == 0 and YNState == true then
-- mc.mcJogIncStop(mInst, mc.Y_AXIS,.1)
-- YNState = false
-- end
-- X++
if GetXin("DPad_DOWN") == 1 and XPState == false then
JogInc=mc.mcJogGetInc(mInst,0)
        mc.mcJogIncStart(mInst, mc.X_AXIS, JogInc)
XPState = true
end
if GetXin("DPad_DOWN") == 0 and XPState == true then
mc.mcJogIncStop(mInst, mc.X_AXIS,.0001)
XPState = false
end
-- X--
if GetXin("DPad_UP") == 1 and XNState == false then
JogInc=mc.mcJogGetInc(mInst,0)
        mc.mcJogIncStart(mInst, mc.X_AXIS, -1 * JogInc)
XNState = true
end
if GetXin("DPad_UP") == 0 and XNState == true then
mc.mcJogIncStop(mInst, mc.X_AXIS,.0001)
XNState = false
end
    -- Z++
if GetXin("DPad_RIGHT") == 1 and ZPState == false then
JogInc=mc.mcJogGetInc(mInst,2)
        mc.mcJogIncStart(mInst, mc.Z_AXIS, JogInc)
ZPState = true
end
if GetXin("DPad_RIGHT") == 0 and ZPState == true then
mc.mcJogIncStop(mInst, mc.Z_AXIS,.0001)
ZPState = false
end
-- Z--
if GetXin("DPad_LEFT") == 1 and ZNState == false then
JogInc=mc.mcJogGetInc(mInst,2)
        mc.mcJogIncStart(mInst, mc.Z_AXIS, -1 * JogInc)
ZNState = true
end
if GetXin("DPad_LEFT") == 0 and ZNState == true then
mc.mcJogIncStop(mInst, mc.Z_AXIS,.0001)
ZNState = false
end
end)

Thanks!