Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: thespindoctor on March 29, 2017, 09:57:48 PM
-
Trying to learn Lua. Simple try by cutting and pasting does not work. I took the script from the Single Surface Y button on the probing screen which works fine when copied to another button. Then I would like to move x and run the single surface y again. So the last lines are below
prb.SingleSurfY(ypos, work)
Local rc=mc.mcCntlGcodeExecuteWait(Inst,"G0 X-5.0")
mm.ReturnCode(rc)
prb.SingleSurfY(ypos, work)
It probes twice very nicely but skips the G0 move. Why?
Thanks
-
I put the code in the load script for the function but that did not help.
Here is the clicked script for the button
--Single Surface Measure Y button
--PRIVATE
--from Y probe button
inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;"
--Master module
package.loaded.MasterModule = nil
mm = require "mcMasterModule"
--Probing module
package.loaded.Probing = nil
local prb = require "mcProbing"
local ypos = scr.GetProperty("droSurfYPos", "Value")
--local work = scr.GetProperty("ledSetWork", "Value") removed by kfc below line added to stop fixture setup
local work = nil
prb.SingleSurfY(ypos, work)
rc = mc.mcCntlGCodeExecuteWait(inst, "G0 X-5.0") --This is the standard function call for executing gcode. it waits for motor feedback before continuing in the file.
mm.ReturnCode(rc)
prb.SingleSurfY(ypos, work)
Now it probes one time then gets to the gcode line and says an error occurred with a nil value
Not sure how to make progress here.
-
I would throw these lines in right before the first
prb.SingleSurfY(ypos, work)
to check to make sure that these values were valid:
if prb==nil then
wx.wxMessageBox("prb is nil")
if inst==nil then
wx.wxMessageBox("inst is nil")
-
Rhtuttle,
The error is saying that mcCntlGCodeExecuteWait is nil The prb.SingleSurfy line is working great.
I am not able to figure out how to program Gcode moves from Lua. I was doing it easily in basic with Mach3. Lua is so much more difficult.
It would be great for someone to come up with a tutorial for 'Lua for Mach4'.
Thanks!
-
Your mcCntlGCodeExecuteWait uses inst as a parameter, check to make sure that it is not nil at that point.
-
once you have verified that your current inst is valid then you are probably running up against the same issues I did:
http://www.machsupport.com/forum/index.php/topic,34451.0.html
You are correct that there are few good examples of mach and Lua. Four functions in particular do not act as one would intuitively expect:
mcGCodeExecute
mcGCodeExecuteWait
mcScriptExecute
mcMdiExecute
No description as to when and where each can/cannot be successfully used.
-
Still getting the error that the call for mc.mcCntlGCodeExecuteWait which is nil
The Inst is not nil Very confusing.
Not understanding all the issues with your post Re: Mach4/Lua script do's and Dont's
Do I have to define the function for mc.mcCntlGCodeExecuteWait as I did in the screen load script? Below is the script I copied from an example
function GCodeExecute(GCodeString)
local rc = mc.mcCntlGCodeExecuteWait(inst, GCodeString) --This is the standard function call for executing gcode. it waits for motor feedback before continuing in the file.
if rc ~= mc.MERROR_NOERROR then return "GCode failed", false end
end
I have a long way to go to...
-
It is working great now. Just took the code
local rc = mc.mcCntlGcodeExecuteWait(inst, "G0 X-4.0")
mm.ReturnCode(rc)
Now I have control over Gcode in Lua. Got probing with stepover repeating using a do loop. Now to learn file I/O
Feeling better...