Hello Guest it is January 22, 2020, 11:56:24 PM

Author Topic: Anybody have a working M6 ATC Macro for Mach 4 ?  (Read 1204 times)

0 Members and 1 Guest are viewing this topic.

Anybody have a working M6 ATC Macro for Mach 4 ?
« on: July 01, 2018, 02:25:42 PM »
Looking for anything that actually works. Please post your Macro below with a brief description of execution. .

Thanks!

Offline Chaoticone

*
  • *
  •  5,634 5,634
  • Precision Chaos
    • View Profile
Re: Anybody have a working M6 ATC Macro for Mach 4 ?
« Reply #1 on: July 01, 2018, 04:55:08 PM »
Here are 2 m6s I have done. Neither of these are for ATC though. Both are for manual/manumatic. Descriptions are in the comments in the code.

This one is the current default m6 that comes with Mach4. It was recently updated. It is meant for those doing manual tool changes. It does not stop the spindle, coolant, update any offsets, etc. It just stops running the Gcode. Gcode is resumed with a press of cycle start.

Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)

if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --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.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
end
end

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

The code below is very similar to the default above. Only instead of just pausing the Gcode it allows you to jog to a probing position and once over the probe, click cycle start. This will begin a probing move. If that probe move is successful it will update the tools height in the tool table. It is very important to have the default move after the probing in the Gcode....... or you could add this default move to the m6 itself but it is not in it as is.
Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local maxDown = -4.0000 --Max distance Z will go down in the touch routine
local rate = 30 --Feed rate the Z will go down in the touch routine
local safeZ = 0 --Machine coordinates the Z will rapid to after touch move

if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0") --Uncomment this line if you would like to move the Z axis to machine coords 0
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") --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.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlSetLastError(inst, "Performing touch routine")
mc.mcCntlGcodeExecuteWait(inst, string.format("G31 Z%0.4f F%0.4f\nG0 G53 Z%0.4f", tostring(maxDown), tostring(rate), tostring(safeZ))) --Probe move
mc.mcCntlSetLastError(inst, "Touch move complete")
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
local didStrike, rc = mc.mcCntlProbeGetStrikeStatus(inst)
if (didStrike == 1) then
--#5063 = User position #5073 = Machine position
value, rc = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
--value, rc = mc.mcCntlGetPoundVar(inst, 5063) --Same as line above but line above uses the Mach constant instead of the #var
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value) --Set the tool height to what was determined by probe move
mc.mcCntlGcodeExecute(inst, string.format("G43 H" .. tostring(selectedTool)))
mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value))
else
mc.mcCntlSetLastError(inst, "The touch move did not touch so we did not set a tool offset.") --Message that shows after Cycle Start
end
end
end

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

« Last Edit: July 01, 2018, 05:27:15 PM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Anybody have a working M6 ATC Macro for Mach 4 ?
« Reply #2 on: November 26, 2019, 05:24:15 PM »
My probe is about .33" thick, how can i accommodate this offset within the M6 macro?
Any & all help is appreciated!
The code below is very similar to the default above. Only instead of just pausing the Gcode it allows you to jog to a probing position and once over the probe, click cycle start. This will begin a probing move. If that probe move is successful it will update the tools height in the tool table. It is very important to have the default move after the probing in the Gcode....... or you could add this default move to the m6 itself but it is not in it as is.
Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local maxDown = -4.0000 --Max distance Z will go down in the touch routine
local rate = 30 --Feed rate the Z will go down in the touch routine
local safeZ = 0 --Machine coordinates the Z will rapid to after touch move

if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0") --Uncomment this line if you would like to move the Z axis to machine coords 0
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") --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.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlSetLastError(inst, "Performing touch routine")
mc.mcCntlGcodeExecuteWait(inst, string.format("G31 Z%0.4f F%0.4f\nG0 G53 Z%0.4f", tostring(maxDown), tostring(rate), tostring(safeZ))) --Probe move
mc.mcCntlSetLastError(inst, "Touch move complete")
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
local didStrike, rc = mc.mcCntlProbeGetStrikeStatus(inst)
if (didStrike == 1) then
--#5063 = User position #5073 = Machine position
value, rc = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
--value, rc = mc.mcCntlGetPoundVar(inst, 5063) --Same as line above but line above uses the Mach constant instead of the #var
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value) --Set the tool height to what was determined by probe move
mc.mcCntlGcodeExecute(inst, string.format("G43 H" .. tostring(selectedTool)))
mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value))
else
mc.mcCntlSetLastError(inst, "The touch move did not touch so we did not set a tool offset.") --Message that shows after Cycle Start
end
end
end

if (mc.mcInEditor() == 1) then
m6()
end
Re: Anybody have a working M6 ATC Macro for Mach 4 ?
« Reply #3 on: November 29, 2019, 02:14:22 AM »
one thing very important to add/think about when you create yours M6
if you press stop ,or machine stop by itself ,you must handle this event in yours M6 before each output activate
because stop in mach 4 its only movement stop,all other still run ,that mean even its will stop ,its will drop the tool ,and wait until signal to lock the tool
also you must break the function when stop ,other its can run in loop and stack yours mach

Offline Chaoticone

*
  • *
  •  5,634 5,634
  • Precision Chaos
    • View Profile
Re: Anybody have a working M6 ATC Macro for Mach 4 ?
« Reply #4 on: November 29, 2019, 09:50:06 AM »
Just add your probe height.

value, rc = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
value = (value + .33)

You can add it in by hard coding in your script as above. You could also get the probe height value from a DRO on your screen or a register. Lots of ways to do it.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!