Hi,
you don't want to use the Touch Off module because the buttons aren't big enough? All the hard work has been done but for the lack of a mouse or track ball
you'd ditch it?

Anyway:
local mInst = 0; --Sets current controller instance to 0, if running multiple controller instances, this will need to change
local rc = 0; --Clear rc
local hSig = 0; --Clear hSig
You don't need to reset these, they are created anew each time it runs and they are garbage collected once they go out of scope. Redundant. Lua uses a stack for local
variables not a fixed memory location.
--SETUP OF VARIABLES
local probe = mc.ISIG_PROBE; --Set input here, mc.<INPUT_NAME>; input needs to be mapped in Mach4
local strikePlateThickness = 0.060; --What is the thickness of the strikeplate, or how much do you want to offset 0?
Why bother, you're just getting cute, there is nothing wrong with mc.ISIG_PROBE There might be a case for a strike plate thickness variable. I'm not going to bother,
I want to get this code down short and sweet, if you want to come back later and pretty it up OK but in the first instance get it to go!
function checkProbe ()
hSig, rc = mc.mcSignalGetHandle(inst, probe); --Load hReg with probe state
state = mc.mcSignalGetState(hSig); --Get Signal State
if (state == 1) then --if hReg true ('if probe is activated then')
return true
else
return false
end
end --checkProbe()
Do you really need a separate function to do this...it means a new local stack and context switch overhead and you use it only twice in the whole script.
I can write it in one line so why bother complicating this thing?
return false
This is I suspect will result in a syntax error, 'false' may have meaning in C or C++ but in Lua 0 means false any other number like 1 means true.
local CurrFeedRate = mc.mcCntlGetPoundVar(inst, 2134); --Gets current Feed Rate, #var 2134
local CurrFeedMode = mc.mcCntlGetPoundVar(inst, 4001); --Gets current G0/G1 state, #var 4001
local CurrPositionMode = mc.mcCntlGetPoundVar(inst, 4003); --Gets current G90/G91 state, #var 4003
local zProbeStrikePos = 0; --clear variable
Whats the point of these, you are collecting and storing this info but nowhere later in the script is it being used. Meanwhile you risk syntax/logic errors and for no
gain. Redundant.
local zProbeStrikePos = 0; --clear variable
As per above, this variable is created anew in a stack, no need to clear it.
local zAxisCurrentPos = mc.mcAxisGetPos(inst, 2); --Get Current Z position, sometimes the probe will continue past strike point.
local zAxisDifference = (zProbeStrikePos – ZaxisCurrentPos); --Gets overshoot, returns positive
local zAxisNewOffset = strikePlateThickness – zAxisDifference; --Subracts overshoot from known thickness of strikeplat
I use a solid probe when making circuit boards. If there was any significant overrun at the probe event I would know and yet there is not. Do you have any
evidence that allowing for overrun is actually required? I'm not going to bother because I know from personal experience that its not required. Save the extra
coding and the syntax/logic errors that could creep in and upset what should be simple code.
I have some code written and am testing it out. I can't test it on my machine so it may be a bit ragged. Will post when complete.
Craig