Hope this can help some of you learning to work with Lua. Several issues are addressed for the beginners like me.
This is a single probe move in Y to identify the coordinates at a probe strike and store the coordinates in a file I created and in the registry.
The probing in G31 or G31.1 etc automatically loads the #variables with the x,y,and z coordinates of the probe strike,
I have tried to document the file for descriptions of what is happening.
----------------------
--CHECK diameter of a grinding WHEEL
--I have a grinding wheel in the chuck of a Z axis spindle motor. It is moving toward a switch.
-- The switch is wired as a second probe in my setup
-- so I am using G31.1 It you are only using a single probe then use G31
--This program is to help learn how to probe as well as some basics of using Lua in Mach4
--I am just learning as well and I hope this can help other Mach4 users
----------------------
local inst = mc.mcGetInstance();
wx.wxMessageBox("Ready for zeroing all axes?")
--xero all axes
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 Y0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 X0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 Z0.0")
--this path business is TRICKY notice the double \\ and the ..
--the path that the Lua code sees will be c:\Mach4Hobby\GcodeFiles\KFCProbeWheel.csv
--notice the formatting the probing routine will automatically load the probe file
-- with coordinates of the probe eg.: -.4657,-.8949,9.000
local path = wx.wxGetCwd() .. "\\GcodeFiles\\KFCProbeWheel.csv"--this file is where I store the probed coordinates of the grinding wheel
mc.mcCntlProbeFileOpen(inst, path, "%.4AXIS_X,%.4AXIS_Y,%.4AXIS_Z", true);
---------Set up for 31.1 only Using probe #2
local ProbeCode=31.1
------------- Check Probe -------------
--This is the function from the probing module Called CheckProbe that I just copied, renamed and put in my screen load script
-- it is not really mandatory to use this but it checks to see which probe and if the probe is working properly
-- to find the source look at the mcProbing.lua file in the Modules directory. Look for the function called Probing.CheckProbe
local rc = KFCCheckProbe(1, ProbeCode); if not rc then; do return end; end
--move to set position near limit switch to check diameter
rc=mc.mcCntlGcodeExecuteWait(inst,"G90 G01 X-.3652 Z-.6170 Y-.25 F30.0")
mm.ReturnCode(rc)
rc = KFCCheckProbe(1, ProbeCode); if not rc then; do return end; end
-- probe 31.1 for probe1 (limit switch which is the SECOND probe in my system)
-- Mach4 - IMPORTANT TO REALIZE THAT Mach4 USES "probe" for the first probe. If you have a second probe it will be "probe1")
-- G31 or G31.0 if you have a single probe. G31.1 for the second probe called probe1, G31.2 for a third probe called probe2)
rc=mc.mcCntlGcodeExecuteWait(inst,"G31.1 Y-.525 F10.0")
mm.ReturnCode(rc)
rc = KFCCheckProbe(0, ProbeCode); if not rc then; do return end; end
--the probing routine places the machine coordinates in these #variables 5071 for x, 5072 for y, 5073 for z
local ProbedMeasXAbs1 = mc.mcCntlGetPoundVar(inst, 5071)
local ProbedMeasYAbs1 = mc.mcCntlGetPoundVar(inst, 5072)
local ProbedMeasZAbs1 = mc.mcCntlGetPoundVar(inst, 5073)
--position near the switch and aligned with the switch so it can probe
mc.mcCntlGcodeExecuteWait(inst,"G91G01 Y.05 F10.0")
mc.mcCntlGcodeExecuteWait(inst,"G90")
mc.mcCntlSetLastError(inst,string.format("%1.4f:%1.4f:%1.4f",ProbedMeasXAbs1,ProbedMeasYAbs1,ProbedMeasZAbs1))
--I am putting the coordinates into the registry file
-- write to ireg0 in register
WriteRegister("Probe2XWheel",ProbedMeasXAbs1)
WriteRegister("Probe2YWheel",ProbedMeasYAbs1)
WriteRegister("Probe2ZWheel",ProbedMeasZAbs1)
--move all axes to zero
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 Y0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 X0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G00 Z0.0")
--close the probe file
mc.mcCntlProbeFileClose(inst)