2
« on: November 19, 2017, 06:31:06 PM »
Hi,
im testing mach4 and at the moment i implement probing functions. My problem is that script is ending unexpected
Probing starts but the script stops running after this step. "probing.enableTrigger(false)" is never called.
I checked the script without coroutine and this works but freezing the ui
Can someone help me?
Thanks,
Steffen
Here is the button code:
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;"
--Probing module
package.loaded.ProbingModule = nil
probing = require("sthProbing")
function demoprobe()
probing.do_probing(-5, 25, 5)
end
co = coroutine.create (demoprobe)
coroutine.resume(co)
sthProbing.lua code
local probing = {}
probing.AXIS_X = "X"
probing.AXIS_Y = "Y"
probing.AXIS_Z = "Z"
function probing.enableTrigger(enable)
local inst = mc.mcGetInstance()
local digitrigger= mc.mcSignalGetHandle(inst, mc.OSIG_DIGTRIGGER)
mc.mcSignalSetState(digitrigger, enable);
end
function probing.isProbeActive()
local inst = mc.mcGetInstance()
local probsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
return mc.mcSignalGetState(probsig) == 1
end
function Code(Gcode)
local inst = mc.mcGetInstance()
rc = mc.mcCntlGcodeExecute(inst, Gcode)
coroutine.yield(rc)
end
function probing.do_probing(maxoffset, speed, safez)
local inst = mc.mcGetInstance()
------ Get current state ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
if probing.isProbeActive() then
mc.mcCntlSetLastError(inst, "ERROR: Probe is already triggered")
return
end
probing.enableTrigger(true)
--mc.mcCntlGcodeExecuteWait(inst, "G01 G91 G21 G31 Z" .. maxoffset .. " F" .. speed)
Code("G01 G91 G21 G31 Z" .. maxoffset .. " F" .. speed)
probing.enableTrigger(false)
local zProbeStrikePos = mc.mcCntlGetPoundVar(inst, 5063)
local zAxisCurrentPos = mc.mcAxisGetPos(inst, 2)
local zGoPos = zProbeStrikePos + safez
mc.mcCntlSetLastError(inst, "Probe: " .. zProbeStrikePos)
mc.mcCntlSetLastError(inst, "Probe2: " .. zAxisCurrentPos)
mc.mcCntlSetLastError(inst, "Go: " .. zGoPos)
mc.mcCntlGcodeExecuteWait(inst, "G0 G91 G21 Z" .. safez)
mc.mcAxisSetPos(inst, 2, 0)
------ Reset state ------
mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
end
return probing