Hello Guest it is April 18, 2024, 08:47:08 AM

Author Topic: Mach 4 Auto Probe and Tool offset  (Read 645 times)

0 Members and 1 Guest are viewing this topic.

Mach 4 Auto Probe and Tool offset
« on: September 20, 2022, 06:53:11 PM »
Hi,

I am looking for some help if any one can. I have taken the sample code from mach 4 basic videos, and adapted it to my situation.  Everything seems fine. When I zero to the bed, and then run the macro to set the offsets based on tool 1 it works perfect. My issue happens when I want to rezero tool 1 to the surface of my material, it is not adjusting the height. Am I missing somthing? I am not a coder, and only have very basic knowledge.

Here is the code that I am using.

function m20()
   
local inst = mc.mcGetInstance()

----------------------------------------------------------------------------------
--change lines here to either auto rapid, or manually jog to a tool change position
----------------------------------------------------------------------------------
--Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
--local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
---------------------------------------------------------------------------------
--Auto Lines.  Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
--Edit to include the machine coordinate values of that tool change position.

--AUTO LINES
mc.mcCntlGcodeExecuteWait(inst, "G53 G0 Z0\nG53 G0 X25 Y25")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
local currenttool = mc.mcToolGetCurrent(inst)
local masterToolLength = 0;

local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
        mc.mcCntlSetLastError(inst, "Probing in Progress!")
        mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F5.")--probe the new tool
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
        mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
  mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z0 ")--Retract
 
local NewOffset = probedz

if(currenttool ~= 1) then
    NewOffset = probedz - masterToolLength
end

  mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool, NewOffset)
  mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
wx.wxMessageBox("Toolchange Complete.\nTLO Set")

end
Re: Mach 4 Auto Probe and Tool offset
« Reply #1 on: December 21, 2023, 11:44:43 AM »
I think you misunderstand how TLO's as a whole actually work.

The tool length if using a Tool Setter is a function of how long the tool is and not where the material is. The macro you posted merely defines the actual tool length based on a known master tool which would be the value from the spindle gage line if you have a CAT(SK) or BT spindle type or the distance from the tool probe trigger to the end of the ER collet located in the spindle. Typically the value of the tool length will be a positive value when using a ATLM or Automatic Tool Length Measurement device. That value is the actual length of the tool, not how the far the tool is from your part or material.

In order for the machine to properly take the tool length into account when setting your work coordinate for Z you must have G43 active for the tool in the spindle. You can do so by writing this in MDI and executing the code. This assumes you have Tool 1 in the spindle. G43 activates Tool Length Offset modal code. H1 is the tool length offset you want to attach to the current tool in the spindle. If I have Tool 1 in the spindle but desire to use Length Offset 2 pull from the tool length table from tool slot 2 then I can simply use G43 H2 even though tool 1 is the current tool. This is very dangerous and very confusing so I highly recommend not doing that. If you use tool 1 use tool offset H1. KISS - Keep It Simple Stupid Method

G43 H1

With that active and you have already set the tool length via your tool setter, when you set the Z work coordinate anywhere the tool length will be accounted for.

G49 will cancel the tool offset H1 from above.

Please note that using G43 Hx is solid and standard practice even if you have a manual tool change machine with an ER collet and no setter. Even if the tool offset in the table = 0. Most every CAM post processor of any consequence will always output the G43 no matter what. The caveat is that if you are setting you work coordinates it is done outside the CAM and is a function of the user and responsibility of the user to do this correctly.

ATLM functions the same in Mach4 as any other CNC controller Fanuc, Siemens, Heidenhain, PlanetCNC.... The difference is where the parameters for the macro reside and the way the macro code works. Functionally they are all the same. G43 is a standard code across them all.

Just always remeber that a G43 is modal. It is active until canceled. Even through program change as long as the control has not been restarted. Most CAM's will insert "Safe Code" at the top of the program that will include a G49 call to cancel any and all tool offsets. Therefore, you must have a G43 caled in your program after that to instantiate the tool offset for the tool you want to use.

Safe Code Example

G80 G20 G49 G90

G80 - Cancel any canned cycle calls

G20 or G21 - Inch or Metric Mode

G49 - Cancel Tool Offsets

G90 - Absolute Positioning Mode

To start a tool run I can then...

M6 T1 (Change to tool 1)
G90 G00 G54 X(whatever) Y(whatever)  (Go to my G54 location)
G90 G43 H1 Z 1. (Move Z to 1" above the Z G54 value taking the tool length into account)
M3 S(whatever)
~ The cutting code I wan to perform
G90 G00 Z1. (Return Z to a safe retract height)
M5
M9
G49

Next tool run....

M6 T2
G90 G00 G54 X(whatever) Y(whatever)  (Go to my G54 location)
(Use Tool Offset 2 for Tool 2)
G90 G43 H2 Z 1. (Move Z to 1" above the Z G54 value taking the tool length into account)
M3 S(whatever)
~ The cutting code I want to perform
G90 G00 Z1. (Return Z to a safe retract height)
M5
M9
G49

Hope that helps.