Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: lesspaul on May 30, 2018, 06:47:00 PM
-
After sitting on a license for several years I'm finally going to give Mach4 the old college try, but I'm pretty wedded to the simple and multi-tool zero functions in Gerry's 2010 screenset, as well as his X/Y zero to laser crosshairs feature.
I'm well aware that in cases such as this, Lua is my friend, and I'm no stranger to coding. However, there is never a point to reinventing the wheel so I thought I'd ask if anyone already has scripting similar in function. If not, time to knock the dust off my ol' friend UltraEdit.
(DaTheGas -- I've already seen your excellent youtube videos on modifying M6!)
Thanks!
-- Paul
-
Hi,
whats wrong with the probing module?
Craig
-
I've been diverted as life often does.
What I want to do is this:
Initial tool zero:
Probe to zero offset by the thickness of a plate on top of the material. - Probing module does this.
then proceed to a fixed plate on side of work area and note offset between material zero and this plate. - Probing module does not do this as far as I can tell.
M6 for subsequent tools:
Change tool. Tool probes to fixed plate. Offset from fixed plate to material determined above applied to set tool zero. -- this would be a custom M6
I've gathered a few existing scripts and it won't be a big deal to write the scripts and modify the screenset.
I've already done a quick and dirty "Zero to laser crosshairs" which is here for anyone interested. Create or edit a button to launch this script with offsetX and offsetY adjusted to your machine:
local inst = mc.mcGetInstance();
local offsetX = -4.7335 -- X axis distance from laser crosshairs to spindle center
local offsetY = -0.0137 -- Y axis distance from laser crosshairs to spindle center
-- wx.wxMessageBox("Zeroing to \nX: "..offsetX.."\nY: "..offsetY)
mc.mcAxisSetPos(inst,0,offsetX)
mc.mcAxisSetPos(inst,1,offsetY)
mc.mcCntlSetLastError(inst, "Workpiece X/Y zeros set to laser crosshair")
-
Hi,
have you had a look at the Offsets Tab? It might be possible to snafu various bits of code attached to the buttons.
Craig
-
Hi,
yes...the Set Tool button to the right of the screen has code attached, reasonably simple code at that. You could copy it, add a GcodeExecuteWait() type move to
your fixed plate then use the tool offset code .
Craig
-
I've worked a bit more and have a working initial tool Zero routine (below).
My approach will (hopefully) be as follows:
Initial tool zero:
Set Z-zero to top of material
Set fixed_plate_offset = NOT_SET
M6:
If "(fixed_plate_offset = NOT_SET)
Probe to fixed plate with current tool
Record offset
set "fixed_plate_offset" to SET"
Change tool
Probe fixed plate and apply offset to tool zero.
Here is my messy but working initial tool zero (using coroutine for screen updating) which is assigned to a screen button.
probeMove = coroutine.create(function()
local inst = mc.mcGetInstance()
local TouchPlate = 0.622 -- Thickness of touchplate above material
local SlowProbeRate = 0.7 -- IPM
local FastProbeRate = 5.0 -- IPM
local JogRate = 60
local Pos
wx.wxMessageBox("1) Check that touch plate is connected.\n2) Position the tool\'s tip above and within 2\" of the plate.\n Press ENTER.")
-- Fast probe Z zero
mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-2.0 F".. FastProbeRate)
coroutine.yield()
-- Retract slightly
mc.mcCntlGcodeExecute(inst,"G91 Z0.05 F".. JogRate)
coroutine.yield()
-- Slow probe Z zero
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)
coroutine.yield()
-- Get touch position (G53) and jog to it in case of overshoot
Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) -- Get Touch Position (work coordinates)
mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
coroutine.yield()
-- Set DRO to height of touchplate and retract to a safe height
mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate)
mc.mcCntlGcodeExecute(inst,"G91 Z1.0 F".. JogRate)
coroutine.yield()
mc.mcCntlSetLastError(inst, "Z Zero set")
mc.mcCntlReset(0)
end)
-
The final piece is in place: the m6 macro.
I've more-or-less duplicated the functionality of my favorite Screenset 2010 features via two button scripts and an M6. Hopefully I've commented them enough to make the journey a bit easier for someone in the future. Other than assigning the scripts to two buttons and editing m6.mcs, the only other setup is using the Regfile plugin to create an Instance Register named "Tool_Offset" with an initial value over 90. (an arbitrary flag value as the Register is dual use -- as a flag (unset) and a value (set).)
There is a lot of room for adding elegance and error checking, but those are both for another day. In the words of Red Green, "This is only temporary. Unless it works."
The M6 has some DazTheGas code, some ArtSoft code, and a bunch of ugly by your's truly.
function m6()
local inst = mc.mcGetInstance();
local offset = mc.mcRegGetHandle(inst,"iRegs0/Tool_Offset")
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local FixedPlateX = 16.212 -- machine coordinate of fixed plate
local FixedPlateY = 0.153 -- machine coordinate of fixed plate
local initialX = mc.mcAxisGetPos(inst,0)
local initialY = mc.mcAxisGetPos(inst,1)
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool")
else
mc.mcCntlSetLastError(inst, "ToolChange Activated ...")
mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0 X".. FixedPlateX .. " Y".. FixedPlateY); -- Position for tool change and probing
if mc.mcRegGetValue(offset) >= 99 then
wx.wxMessageBox("Initial tool. Press enter to probe for offset")
mc.mcRegSetValue(offset, probePlate()) -- Store offset
mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0") -- move up for toolchange
end
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to zero") --Message at beginning of tool change
mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
mc.mcAxisSetPos(inst, mc.Z_AXIS, probePlate()) -- Set new tool to fixed plate offset value
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") -- goto machine Z Zero
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X".. initialX.." Y".. initialY .. "F40") -- return to starting positions
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
mc.mcRegSetValue()
end
end
if (mc.mcInEditor() == 1) then
m6()
end
function probePlate()
local inst = mc.mcGetInstance()
local SlowProbeRate = 0.7 -- IPM
local FastProbeRate = 5.0 -- IPM
local JogRate = 60
local Pos
-- Fast probe Z zero
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z-2.5") -- Pre-position
mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-3.0 F".. FastProbeRate)
-- Retract slightly
mc.mcCntlSetLastError(inst, "Retract . . .")
mc.mcCntlGcodeExecute(inst,"G91 Z0.05 F".. JogRate)
-- Slow probe Z zero
mc.mcCntlSetLastError(inst, "Slow Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)
-- Get touch position and jog to it in case of overshoot
Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) -- Get Touch Position (work coordinates)
mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
return Pos
end
The initial tool zero button routine communicates through a register to let M6 know an offset needs to be measured.
probeMove = coroutine.create(function()
local inst = mc.mcGetInstance()
hreg = mc.mcRegGetHandle(inst, "iRegs0/Tool_Offset")
local TouchPlate = 0.622 -- Thickness of touchplate above material
local SlowProbeRate = 0.7 -- IPM
local FastProbeRate = 5.0 -- IPM
local JogRate = 60
local Pos
wx.wxMessageBox("1) Check that touch plate is connected.\n2) Position the tool\'s tip above and within 2\" of the plate.\n Press ENTER.")
-- Fast probe Z zero
mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-2.0 F".. FastProbeRate)
coroutine.yield()
-- Retract slightly
mc.mcCntlGcodeExecute(inst,"G91 Z0.05 F".. JogRate)
coroutine.yield()
-- Slow probe Z zero
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)
coroutine.yield()
-- Get touch position (G53) and jog to it in case of overshoot
Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) -- Get Touch Position (work coordinates)
mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
coroutine.yield()
-- Set DRO to height of touchplate and retract to a safe height
mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate)
mc.mcCntlGcodeExecute(inst,"G91 Z1.0 F".. JogRate)
coroutine.yield()
mc.mcCntlSetLastError(inst, "Z Zero set")
mc.mcRegSetValue(hreg,99.9)
mc.mcCntlReset(0)
end)
And lastly a very simple button code to set X/Y zero to my laser crosshairs:
local inst = mc.mcGetInstance();
local offsetX = -4.7335 -- X axis distance from laser crosshairs to spindle center
local offsetY = -0.0137 -- Y axis distance from laser crosshairs to spindle center
mc.mcAxisSetPos(inst,0,offsetX)
mc.mcAxisSetPos(inst,1,offsetY)
mc.mcCntlSetLastError(inst, "Workpiece X/Y zeros set to laser crosshair")