Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Overloaded on May 06, 2014, 08:36:45 PM

Title: Lua Lua Lua Louieeeeeee
Post by: Overloaded on May 06, 2014, 08:36:45 PM
 Looking at various btn script examples, like this one:

    local inst = mc.mcGetInstance()
    mc.mcCntlMdiExecute(inst, 'G00 X0 Y0 Z0 A0')

How would you write it to do multiple lines of GCode with one finishing before the next one starts ? [[   ]]    /n   \n    ::)

One of several embarrassingly futile attempts: ::)
    local inst = mc.mcGetInstance()
    mc.mcCntlMdiExecute(inst, 'G00 Z2')
    mc.mcCntlMdiExecute(inst, 'G00 X0 Y0')

Hey, I'm just tinkering here, don't go out of your way now, this is not important.   :)
But, being you've already read it ............. ;D

Thanks again,
Russ
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Brian Barker on May 06, 2014, 11:19:55 PM

Here is a snip of a tool changer so you can see how I formatted the strings
Code: [Select]
--Drop off the current tool
        local code = "G0 G53 Z0.0\n"
        code = code .. string.format("G0 G53 X%.4f Y%.4f\n", m_changePos[CurrentTool].x + m_X_Pullout, m_changePos[CurrentTool].y + m_Y_Pullout)
        code = code .. string.format("G0 G53 Z%.4f\n", m_ZtoolHeight)
        code = code .. string.format("G0 G53 X%.4f Y%.4f\n", m_changePos[CurrentTool].x, m_changePos[CurrentTool].y)
        mc.mcCntlGcodeExecute(inst, tostring(code))

        --Release tool
        mc.mcSignalSetState(unclamp, true);--Unclamp
        wx.wxSleep(.75)

        --Move to new tool
        code = string.format("G0 G53 Z%.4f\n", m_ZtoolHeight + m_PullupDist)
        code = code .. string.format("G0 G53 X%.4f Y%.4f", m_changePos[NewTool].x, m_changePos[NewTool].y)
        code = code .. string.format("G0 G53 Z%.4f", m_ZtoolHeight)
        mc.mcCntlGcodeExecute(inst, tostring(code))

        --Clamp tool
        mc.mcSignalSetState(unclamp, false);--Unclamp
        wx.wxSleep(.75)
        mc.mcToolSetCurrent(inst, NewTool)

        code = string.format("G0 G53 X%.4f Y%.4f", m_changePos[NewTool].x + m_X_Pullout, m_changePos[NewTool].y + m_Y_Pullout)
        code = code .. string.format("G0 G53 Z0.0")
        mc.mcCntlGcodeExecute(inst, tostring(code))


I am going to wait for the sun and look for dust...
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Overloaded on May 06, 2014, 11:57:36 PM
Thanks for your time Brian  :)
I'll glean what I can out of that example. (almost looks like you found one of them scrolls too  ;D )

Supposed to be cloudy here tomorrow, so the dust shouldn't distract me.  ;D

See ya bud, thanks,
Russ
 :)
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Overloaded on May 07, 2014, 09:28:47 AM
With Brian's example, (and several references to the Rosetta Stone  ;D ), I came up with this:

--Go to Part Zero via Safe Z
    local inst = mc.mcGetInstance()
    local code = "G0 G53 Z0.0\n"
          code = code .. string.format("G0 X0 Y0\n")
          code = code .. string.format("G0 Z0.5\n")
          code = code .. string.format("G1 Z0 F10\n")
          mc.mcCntlGcodeExecute(inst, tostring(code))

It works as expected. I was pleasantly surprised.  :)

Added a button for a Safe Z type G28 also using the same format, a treat.  :)

Thanks Brian, Steve !
Russ
 :)
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Chaoticone on May 07, 2014, 10:53:53 AM
 :)
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Brian Barker on May 07, 2014, 11:23:07 AM
And so it is, One more example is the dead machine scrolls ... I will put them in a cave so no one can find them!
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Overloaded on May 07, 2014, 01:09:17 PM
 ;D

Thanks again,
  :)
Title: Re: Lua Lua Lua Louieeeeeee
Post by: BR549 on May 07, 2014, 01:48:39 PM
QUESTION, is mach4 using LUA or wxLUA or BOTH ??

(;-) TP
Title: Re: Lua Lua Lua Louieeeeeee
Post by: smurph on May 07, 2014, 06:53:20 PM
wxLua. 

The hard part to get under one's hat is that there are two wxLua environments.  One in the GUI and one in the mcLua plugin.  The mcLua plugin is the one that runs all of the macros.  Putting the macro scripting in a plugin makes it possible for other script languages to be added later.  But I HIGHLY doubt that the GUI will ever run anything other than LUA.  So anyway, be aware that there are two separate scripting environments.  Both have access to the mc.* API.  But only the GUI has access to the scr.*  screen API.
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Ya-Nvr-No on May 07, 2014, 07:00:43 PM
Is that why you can not change a button label from a m3 script?
Title: Re: Lua Lua Lua Louieeeeeee
Post by: smurph on May 07, 2014, 07:08:45 PM
Yep, that is why.  It is possible.  But you have to get crafty.  Both script environments have access to the Mach Registers.  So a register can be used to "communicate" between the two environments.  So in the M3 script, you set a register to something like "1" and in the PLC screen script, you watch that register.  If the register is "1" change the button label to one thing.  It is it "0", change the label to something else, etc...

Steve
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Ya-Nvr-No on May 07, 2014, 07:13:48 PM
Might be easier to do it in the PLC Script and just look for a ledCW on or off
Title: Re: Lua Lua Lua Louieeeeeee
Post by: smurph on May 07, 2014, 07:16:45 PM
Yes.  There is that!

Title: Re: Lua Lua Lua Louieeeeeee
Post by: Ya-Nvr-No on May 07, 2014, 10:12:51 PM
This code worked for me in the PLC Script to change the button labels.

I am interested in the ability to get and set values to the registers.
looked at it, but just caused Lua and Mach4 to crash several times just trying to get a value.

Code: [Select]
local SpinCW = scr.GetProperty('ledSpindleCW','Value','Value',0);
local SpinCCW = scr.GetProperty('ledSpindleCCW','Value','Value',0);

if (SpinCW == "1") then
    scr.SetProperty('btnSpindleCW', 'Label', 'SpindleCW OFF');
else
    scr.SetProperty('btnSpindleCW', 'Label', 'SpindleCW ON');
end
if (SpinCCW == "1") then
    scr.SetProperty('btnSpindleCCW', 'Label', 'SpindleCCW OFF');
else
    scr.SetProperty('btnSpindleCCW', 'Label', 'SpindleCCW ON');
end
Title: Re: Lua Lua Lua Louieeeeeee
Post by: Overloaded on May 08, 2014, 12:10:33 AM
Crafty indeed !
The nifty possibilities continue, thanks for posting that Craig.

Russ
 :)