Hello Guest it is April 16, 2024, 02:01:20 AM

Author Topic: Lua Gcode calls and screenLoadScript sigLib communication help...  (Read 6820 times)

0 Members and 1 Guest are viewing this topic.

Hi folks,

I'm Josh...new around here. I've read a lot on this forum, built a machine, immediately jumped from Mach3 to Mach4 and have been working Lua a bit. Currently, I have a signal library built in the screen load script to watch for ISIG_INPUT0 events that will stop the axis from moving (Gcode cycles and jogging) from the basic if statement in the signal script. This works. Because G31 is not supported by my hardware yet I am trying to find a work around with programming the AutoToolSet button. The issue I am having is that the signal library is not recognizing the mc.mcCntlGcode...calls to stop the axis from moving when I code in Lua the button scripts. I think that screen scripts are different than mCode scripts from an interpreter standpoint that load into a different stack/buffer?.?.?... Anywho, any recommendations on how to say the signal library can recognize a call to mc.mcCntlGcodeExecute(inst, "G01 X...Y...Z..F.../n") and recognize an input signal mapped to mc.ISIG_INPUT0  in the signal library to stop the axis? Also, for kicks, if I call mc.mcCntLoadlGcode or string or file, how do I get that to execute? mc.mcCntlEnabled(inst, 1), mc.mcCntrlCycleStat(inst) doesn't execute the string (I've also tried incorporating input/output handle/get/set state function calls in the algorithm). I think I am missing something easy here...I am just asking for some direction and I can take Mach4 for a ride :o) I pretty much memorized the calls get/set/do from the down and dirty Lua pdf, scripting manual, pound variable list, signals list, the Spaced Out Lua reference (that was awesome!), Mach4 API, Lua Calls, etc. (yep, there is a reason why I am divorced :o) I can't remember "her" birthday but sure as ********* can remember programming function calls! Hope to hear from y'all and promise to share any code that may be relevant to new users coming from Mach3. After all, Mach 4 Hobby users are the beta testers for NFS. Great business strategy btw...crowd source beta testing...at a little cost. But, I've learned so much that it's okay with me and am glad to become apart of the community. Now...if I can cut my first part before I am 100 yrs. old...reliability, repeatability, and accuracy; it is computer numerical control for a reason, lol. Yes, I've learned Gcode sequences too, but the beauty of Mach4 is combining Lua and Gcode to execute a block. The potential capabilities are pretty darn good. I just need a strip map to let screen calls and mCode macro calls communicate with global function / reference tables and the signal script. My two cent...ok, may three cents...

-josh
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #1 on: May 27, 2015, 03:44:21 AM »
mc.mcCntlCycleStart(inst)...not mc.mcCntrlCycleStat(inst), I know how some can be picky but woodfordReserve knows forgiveness!
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #2 on: May 27, 2015, 09:26:52 PM »
Got a theory (well, another avenue of approach)...stay tuned.
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #3 on: May 28, 2015, 04:00:05 AM »
--yep figured it out using conditional repeat/until structure as a timer based on a false signal condition, break when true

--only destroyed both my digital probe and tool setter in the process. The cost of having fun.

--this way I can start a jogging / probing routine without G31, now onto the easy stuff. the more I realize the more I think Lua was used just to create a series of function calls and variables that are just mapped Gcode blocks inside those functions and the variables are are mapped to #var, the power of G65/G66. Ok, I'm just talking to myself now.


function workingAutoToolSet ()

local mInst = 0
local rc = 0
local inst = mc.mcGetInstance (mInst)
local gCode = ""

local hSig = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT0)


mc.mcCntlEnable (inst, 1)
mc.mcJogSetRate (inst, 2, 10)
mc.mcJogVelocityStart (inst, 2, -3)


repeat mc.mcCntlSetLastError (inst, "Approaching tool setter")
    until mc.mcSignalGetState (hSig) == 1; mc.mcJogVelocityStop (inst, 2)

end

--[[
gCode = "G0 G28 Z0.0\nG1 G53 Z-4.0 F5.0\n"
mc.mcCntlMdiExecute (inst, gCode)

end
if mc.mcInEditor () == 1 then workingAutoToolSet() end
--]]

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #4 on: May 28, 2015, 04:50:14 AM »
you can use fanuc macro b as well most of them work like this one I have tried it worked fine, disclaimer use at own risk

G49 (Cancel TLO)

G58 (Switch to work offset G58)

G0 X0 Y0 (move the tool over the toolsetter)

G31 Z-10 F150 (probe tool down till it touches the toolsetter)

G10 L1 P1 Z#2002 (set the tool length offset value to the G58 Z position where the probe tripped)

G0 Z5 (move up to safe distance)

G54 (reapply old work offset coordinate system)

G43 H1 (apply new TLO for tool 1)

if I have time I might try your one
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #5 on: May 28, 2015, 05:39:39 AM »
thanx for sharing! I've seen you post that earlier. My motion device doesn't support G31 probing commands yet.....hence trying to find a work around. I liked your reference in the bug report pointing to another thread about mcCntlGcodeExecute vs. mcCntlGcodeExecuteWait vs. mcCntlMdiExecute. It help shed some light on the applicability of when to use each function call depending on the circumstance.
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #6 on: May 28, 2015, 05:52:28 AM »
before you try it....that is just the start of an auto tool zero function. The code written only tells the Z axis to start jogging at a specific rate in a specific direction until it comes in contact with the tool setter, table, or top of material. The stop jogging command is triggered by my input signal through a conditional ~loop.

this is just one step in the process. one block sorta say. I can execute Gcode and move around in a button script. what I cannot do is execute Gcode and have my probe trigger a mc.FileHoldAcquire, or feedhold and any kind of stop movement command. I can only achieve this by using jogging commands and using time with a conditional loop to stop movement because I do not have the capability to utilize G31.
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #7 on: May 28, 2015, 06:07:39 AM »
workingAutoToolSet() => work in progress!!!! arghhh.....bad way to name a function, how do you edit your own posts? I don't want to confuse anyone.
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #8 on: May 28, 2015, 06:09:21 AM »
better yet, how do you delete your own posts? I talk to much on here...

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua Gcode calls and screenLoadScript sigLib communication help...
« Reply #9 on: May 28, 2015, 06:23:01 AM »
all post are time limited I think its 30 mins after you post you have said its not finished so that's enough have you seen the M4 scripting manual its in here  http://www.machsupport.com/help-learning/product-manuals/

there is a tool height probe thing in it, I have not tested it my self, what hard wear are you using