Hello Guest it is March 28, 2024, 04:22:25 AM

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

0 Members and 1 Guest are viewing this topic.

Offline mhd

*
  •  11 11
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #80 on: September 25, 2018, 04:22:55 PM »
Your GetXin function is incorrect

your code
Code: [Select]
function GetXin(Xinput)
   local hreg = mc.mcRegGetHandle(mInst , string.format("mcX360_LUA/%s") , Xinput)
   return mc.mcRegGetHandle(hreg) -- This line is wrong
end

code should be
Code: [Select]
function GetXin(xinput)
local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
return mc.mcRegGetValue(hreg) -- or return mc.mcRegGetValueLong(hreg)
end

DazTheGas



Dear Sir


I change it and still, I can not get the feed in the stateusList



------- Declaer local---------------
local mInst = mc.mcGetInstance()
local Xenable= 0

-------------- Ps3 Init Panel------------

Ps3_Penal = wx.wxPanel( wx.NULL , wx.wxID_ANY , wx.wxDefaultPosition , wx.wxDefaultSize)
Ps3_Timer = wx.wxTimer (Ps3_Penal)
Ps3_Timer : Start(100)

----------- Fauntion----------------

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

------------Event Timers-------------
Ps3_Penal : Connect (wx.wxEVT_TIMER , function(event)
      
      if GetXin("LTR_Val") > 150 and Xenable == 0 then
         Xenable = 1
         mc.mcCntlSetLastError(mInst , "Ps3 Running")
         
      elseif GetXin ("LTR_Val") < 50 and Xenable == 1 then
         Xenable =0
         mc.mcCntlSetLastError(mInst , "Ps3 Stopped")
         
      end   
      
      
   end   )

Offline mhd

*
  •  11 11
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #81 on: September 26, 2018, 10:07:43 AM »
Your GetXin function is incorrect

your code
Code: [Select]
function GetXin(Xinput)
   local hreg = mc.mcRegGetHandle(mInst , string.format("mcX360_LUA/%s") , Xinput)
   return mc.mcRegGetHandle(hreg) -- This line is wrong
end

code should be
Code: [Select]
function GetXin(xinput)
local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
return mc.mcRegGetValue(hreg) -- or return mc.mcRegGetValueLong(hreg)
end

DazTheGas



Dear Sir


I change it and still, I can not get the feed in the stateusList



------- Declaer local---------------
local mInst = mc.mcGetInstance()
local Xenable= 0

-------------- Ps3 Init Panel------------

Ps3_Penal = wx.wxPanel( wx.NULL , wx.wxID_ANY , wx.wxDefaultPosition , wx.wxDefaultSize)
Ps3_Timer = wx.wxTimer (Ps3_Penal)
Ps3_Timer : Start(100)

----------- Fauntion----------------

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

------------Event Timers-------------
Ps3_Penal : Connect (wx.wxEVT_TIMER , function(event)
      
      if GetXin("LTR_Val") > 150 and Xenable == 0 then
         Xenable = 1
         mc.mcCntlSetLastError(mInst , "Ps3 Running")
         
      elseif GetXin ("LTR_Val") < 50 and Xenable == 1 then
         Xenable =0
         mc.mcCntlSetLastError(mInst , "Ps3 Stopped")
         
      end   
      
      
   end   )




Sir, I copy this code for your previous and I insert what you explained from the video on it. It works know but I don't understand why?



local inst = mc.mcGetInstance()
local Xenable=0

local X360_PNL = mcLuaPanelParent;


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


   X360_timer = wx.wxTimer(X360_PNL)
    X360_timer:Start(100)

    X360_PNL:Connect(wx.wxEVT_TIMER,   function (event)
   
    if GetXin("LTR_Val") > "150" and Xenable==0 then
      Xenable=1
    mc.mcCntlSetLastError(inst,"PS3 Running")
    end
   
    if GetXin("LTR_Val") < "1"  and Xenable==1 then
      Xenable=0
    mc.mcCntlSetLastError(inst,"PS3 Stopped")
    end
 
    end)

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #82 on: September 26, 2018, 12:30:13 PM »
Glad you have it working, the problem I have is I can only test with an xbox controller as I dont have PS3 controller and I know it works. So as long as theres no typo`s then all should be good.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline mhd

*
  •  11 11
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #83 on: September 26, 2018, 01:53:36 PM »
Dear Sir ,

I think the problem was in the (( if GetXin("LTR_Val") > "150" )) the number should be in " ". I'm not that expert in coding but the fixed my problem.

Can I ask you for a favour. if you can do video in PMC it will be helpful for those who have a basic in code.

Best regard
shrooqi

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #84 on: September 27, 2018, 04:55:03 PM »
I know absolutely nothing about the PMC/Ladder logic, ive always preferred to code what i need. Take a look at this example from an earlier post.

http://www.machsupport.com/forum/index.php/topic,33121.msg236608.html#msg236608

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #85 on: December 23, 2018, 05:59:25 PM »
Hey Daz, thank you for your work ! Just a quick question, does the controller script work for slaved axes aswell ?

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #86 on: December 24, 2018, 06:40:10 PM »
Hey Daz, thank you for your work ! Just a quick question, does the controller script work for slaved axes aswell ?

Yes it does, you are moving an axis not individual motors so if you have a Y axis that consists of say motors 1 and 4 then both of these will move if you command the Y axis to move.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #87 on: April 24, 2020, 08:50:36 PM »
Daz and others, you are amazing and my head is spinning.  I have enough on my plate and am not the biggest fan of reinventing the wheel so I would like to know what it would take to get or buy a copy of the script to allow me to use a xbox 360 controller with Mach4?
I would much rather spend my time using my CNC rather than coding in MACH4
Curt
Re: mcX360 Plugin for Lua
« Reply #88 on: May 10, 2020, 09:56:28 PM »
TomL21
Are you or anyone reading this thread willing to help me with getting Mach4 set up to use a X360 controller?
Curt
Has anyone tried this in the PMC? I played with it for an hour or two this morning. Found a couple little bugs that I forwarded off to the Artsoft gang, but all in all works pretty good. And easy to implement.

If you haven't used the pmc yet just drop these two files in the mach4>pmc folder. Then in the screen editor on the screen properties one of the options is pmc objects. Check the one you want to use and that is it.

I did this with the following functions:
Left joystick X and Y axis jog
DPad X and Y axis jog
Right joystick Z axis jog
Hold left button to enable continuous jogging (must be held down to jog any axis)
Hold right button to enable incremental jogging (must be held down to jog any axis)
Start cycles the jog increment
B is disable
Y is enable
A is cycle start
X is feed hold
Back is cycle stop

One of the bugs was I couldn't enter negative values. So I had to hack the .lua file to get a dead zone on the sticks. You'll see in the ladder of the pmc file the stick values are compared to 0, in the lua file i changed these zeroes to 30 and -30.
Re: mcX360 Plugin for Lua
« Reply #89 on: May 30, 2020, 04:54:37 PM »
TomL21
Are you or anyone reading this thread willing to help me with getting Mach4 set up to use a X360 controller?
Curt

I recently downloaded Mach4 and wanted to use my Xbox controller with it.  A big thanks to DazTheGas on his videos and code snippets.  My wife was able to put together Daz's code with a couple of tweaks to get it working the way I wanted.

I've noticed a lot of people asking for the same thing I was looking for:  the LUA code already typed up and ready to dump into Mach4.  So my wife and I put together a zip file (attached) with some pre-configured code and quick guides.  The guides will give you an idea of how to put the code into Mach4, and will show you which buttons are configured for the Xbox controller depending on which of the scripts you decide to install. 

So keep watching Daz since he's really an expert on the whole Mach4/Lua code topic, but hopefully, someone else will find the pre-configured code helpful - especially if you aren't a coder.