G codes for Auto Z touch plate commands?

Hi folks,
I want to do touch offs right away after a manual tool change. I use Avid’s Auto Z plate and I have it situated directly underneath my tool change position. I’d love to be able to write the code right into the tool paths so once I “Resume Toolpath” it touches off without me having to use the interface. Does anyone do this or know how?
Thanks!

Calling the touchplate routine is easy, you can find the code in the screen button that launches it. However, you need to get to the next level down to call the “Z only touch” that is called from the window, and they don’t publish the source code for the module so thats invisible to the user. Maybe AVID would tell you that functiona name if you contact their support.

Otherwise, its pretty easy to write a Z probing routine, just uses G31 moves. You can build that into your tool change macro.

Here is a good video to get you started on that: https://www.youtube.com/watch?v=AthCnSaqV08&t=370s
It shows all the basics of making a safe probing routine in Mach4 with the ESS.

There is also plenty of probing examples in the modules directory in the mcTouchOff.lua and mcProbing.lua modules that come with Mach4.

1 Like

Hi!

You will need the probing routine that has been pointed out to you in that YouTube video, but you’ll also need additional logic in the macro to set the proper height of your workpiece. The probe routine will return a height of the probe which is useful but not alone. After you make a tool change, you will also need to restart the spindle and adjust the work coordinate Z height. Here’s the macro that I wrote and works with any probe type As long as it’s configured in your system to be a G 31 probe.

If you have any further questions after reviewing my code, I’d be more than happy to explain it to you over the phone. In the meantime, you can email me at paul@mageau.com.

Paul
——————————————
function m6()

--------------------------------Auto Tool Change specific----------------------------------------------------------------------------------
local xProbeCenter = 1.12              		--Machine Coordinate of the tool setter on X axis
local yProbeCenter = 0.87			   		--Machine Coordinate of the tool setter on Y axis
local zSafeHeight = -0.5			   		--Machine Coordinate of the Safe Z height that won''t trip the limit switch
local XToolchangePosition = xProbeCenter	--Machine Coordinate of where you want to change your tool on X axis
local YToolchangePosition = yProbeCenter	--Machine Coordinate of where you want to change your tool on Y axis
local ColletAtProbeZCoordinate = -7.2010    --Machine Coordinate of the distance from machine home Z must travel for the collet without a tool to hit the tool setter
local ProbeOperationDistance = -7.2010      --Machine Coordinate of how far Z will move while looking for a probe hit. 
------------------------------------Tool information----------------------------------------------------------------------------------------
local DefaultToolLength = 4                                 -- Must be at least as long or longer then your longest tool This is what's used if your tool table is not filled in.
local ExtraProbeDistance = 0                                -- This is your margin of error the smaller this number the larger the pucker factor.
local ProbePrepSpeed = 40                                   -- This is how fast Z travels before it slows down to probe. The larger this number, the larger the pucker factor.
local ProbeSpeed = 3                                        -- This is how fast Z will probe at. Keep this number small for accuracy.
local SpindleDwell = 3000                                   -- this is the amount of time to wait in microseconds for the spindle to stop or start spinning. Example is 10 seconds
local ProbeDwell = 1000                                     -- pause before final probe at slow speed for accuracy
local selectedTool = 100                                     -- init 
local currentTool = 101                                      -- init 

---------------------------------------------------------------------------------------------------------------------------	

local inst = mc.mcGetInstance();
local int answer =999;

mc.mcCntlSetLastError(inst, "M6 Tool Change: Saving Current Machine State !")
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)

mc.mcCntlSetLastError(inst, "Current Tool "..tostring(currentTool).." Selelected Tool "..tostring(selectedTool))

local xstart = mc.mcAxisGetPos(inst,0) 	-- X work coordinate 
local ystart = mc.mcAxisGetPos(inst,1)	-- Y work coordinate 
local zstart = mc.mcAxisGetPos(inst,2)	-- Z work coordinate 
mc.mcCntlSetLastError(inst, "Current Location X:"..tonumber(xstart).." Y:"..tonumber(ystart).." Z:"..tonumber(zstart))
mc.mcCntlSetLastError(inst, "Current Location X:"..tonumber(xstart).." Y:"..tonumber(ystart).." Z:"..tonumber(zstart))

--get the current mode so we can return to it when macro ends
local posMode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) 

if selectedTool == currentTool then

– answer = wx.wxMessageBox(“Tool Numbers Match, Skip Tool Change ?”, “Confirm”,wxYES_NO);
answer = wx.wxMessageBox(“Tool Numbers Match, Skip Tool Change ?”, “Manual Tool Change”, wx.wxYES_NO );
if (answer == wx.wxYES) then
mc.mcCntlSetLastError(inst, “ToolChange Activated But Not Required, Tool Numbers Match”);
return;
end
end

mc.mcCntlSetLastError(inst, "M6 Tool Change Executing !")

-- give the spindle some time to spind down if it was on
mc.mcCntlSetLastError(inst, "Dwell for "..tonumber(SpindleDwell/1000).." seconds to give the spindle time to spin down")
mc.mcCntlGcodeExecuteWait(inst, "M5 G4 P"..SpindleDwell)


--Move the Z axis up out of the way using machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G1 Z"..tonumber(zSafeHeight).." F100");
--Move spindle over probe to change tool
mc.mcCntlGcodeExecuteWait(inst, "G1 G53 X"..tonumber(xProbeCenter).." Y"..tonumber(yProbeCenter).."F100");


-- PROBE the Current Tool -----
mc.mcCntlSetLastError(inst, "M6 Tool Change: Probing Current Tool")

-- 1st approach is fast
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G31 Z"..tonumber(ColletAtProbeZCoordinate).." F"..ProbePrepSpeed)
-- back of by 0.2" slowly, g91 =relative move
mc.mcCntlGcodeExecuteWait(inst, "G91 G1 Z0.2 F"..ProbeSpeed)
-- 2nd probe approach must slower, reestabish absolute positioning(G90) 
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G31 Z"..tonumber(ColletAtProbeZCoordinate).." F"..ProbeSpeed)  
--get probed z pos for current tool 
local toolz = mc.mcAxisGetPos(inst,2) --work coordinate of Z height
-- Back to a safe Z height in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G1 Z"..tonumber(zSafeHeight).." F100");

-- CHANGE to new tool
--This will pause the tool change here and wait for a press of cycle start to continue
wx.wxMessageBox("Please change to tool number "..tostring(selectedTool).."\n and click ok to continue, then click CYCLE START")
mc.mcCntlToolChangeManual(inst,true)

--PROBE the New Tool
mc.mcCntlSetLastError(inst, "M6 Tool Change: Probing New Tool")
-- 1st approach is fast
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G31 Z"..tonumber(ColletAtProbeZCoordinate).." F"..ProbePrepSpeed)
-- back of by 0.2" slowly, g91 =relative move
mc.mcCntlGcodeExecuteWait(inst, "G91 G1 Z0.2 F"..ProbeSpeed)
-- 2nd probe approach must slower, reestabish absolute positioning(G90) 
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G31 Z"..tonumber(ColletAtProbeZCoordinate).." F"..ProbeSpeed)  
--get probed z pos for current tool 
--regardless of what the new z heoght of the new tool is, simply set the work position Z to the z pos of the original tool
--this step compensates for the new tool length whether larger or smaller!
mc.mcAxisSetPos(inst, 2 ,toolz) -- set Z WORK coordinate

-- Back to a safe Z height in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G1 Z"..tonumber(zSafeHeight).." F100");

-- set current tool to new tool number
mc.mcCntlSetLastError(inst, "M6 Tool Change: Setting current tool to tool# : "..tostring(selectedTool))
mc.mcToolSetCurrent(inst, selectedTool)

mc.mcCntlGcodeExecuteWait(inst, "M3 G4 P"..SpindleDwell)

--return back to the original XY WORK coordinate location, Z location will come from the code after the M6 in the toolpath gcode.
mc.mcCntlSetLastError(inst, "M6 Tool Change: Returning to original position")

– mc.mcCntlGcodeExecuteWait(inst,“G90 G1 X”…xstart…" Y"…ystart…“F100”)
– mc.mcCntlGcodeExecuteWait(inst,“G90 G1 Z”…zstart…“F50”)

--return to pre macro mode G90, or G91
mc.mcCntlGcodeExecute(inst, string.format('G ' .. posMode))

mc.mcCntlSetLastError(inst, "Tool Change Finished")

end

if (mc.mcInEditor() == 1) then
m6()
end

Hi all… I just wanted to reach back and thank you for sharing your input here. I got side tracked on a job and was pulled away for a bit.

Right now im very close to just buying the Rapid Change system Jim Neeb was testing. Tired of manual changes. The last run i did was 88 sheets with 3 tool changes per sheet :sweat_smile: