1
Mach4 General Discussion / M6 and auto tool measure script.
« on: February 03, 2020, 03:14:48 PM »
Hi all!
I'm struggeling with my tool measurement. I've developed my own probe and tested that everything works.
I've also made a fully functional M6 tool change macro. Btw, my mill is a Emco VMC-100, with 10 tools.
And now I would like to make a tool measure macro that I can call in the MDI and it will run through all my tools before I start.
I've called it M10. But there seems to be a problem. My first tool, tool 1, is always shorter, or the other tools are longer....
what's wrong here??
(some of the comments in norwegian...(not important)
I'm struggeling with my tool measurement. I've developed my own probe and tested that everything works.
I've also made a fully functional M6 tool change macro. Btw, my mill is a Emco VMC-100, with 10 tools.
And now I would like to make a tool measure macro that I can call in the MDI and it will run through all my tools before I start.
I've called it M10. But there seems to be a problem. My first tool, tool 1, is always shorter, or the other tools are longer....
what's wrong here??
(some of the comments in norwegian...(not important)
Code: [Select]
function m6()
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local toolPos = {0,36,72,108,144,180,216,252,288,324}
-----------------------------NYTT HERFRA----------------------------
mc.mcCntlGcodeExecuteWait(inst, "M5")
mc.mcCntlGcodeExecuteWait(inst, "G04 1")
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst,"No need for tool change, go on!")
return
else
-----------Get current state-----------------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
---------------------------------------------
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X0.0 Y0.0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z87.0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G54 G40 G0 A"..toolPos[selectedTool].."")
mc.mcCntlGcodeExecuteWait(inst, "G43 H"..selectedTool.."")
local sigh1 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1) --Steppermotor i posisjon
local sigState1 = mc.mcSignalGetState(sigh1)
if (sigState1 == 1) then
mc.mcCntlSetLastError(inst,"Toolchange is finished, going down")
mc.mcCntlSetLastError(inst, "ToolNo. "..currentTool.." changed to ToolNo. "..selectedTool.." with position "..toolPos[selectedTool].."")
else
mc.mcCntlEStop(inst)
wx.wxMessageBox("Is the tool wheel in the correct position?")
return
end
end
mc.mcCntlGcodeExecuteWait(inst, "G04 1")
--local sigh0 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0)
--local sigState0 = mc.mcSignalGetState(sigh0)
--if (sigState0 == 1) then
-- mc.mcCntlSetLastError("Tool 1 is in position")
--mc.mcAxisSetMachinePos(inst, 3, 0)
--end
mc.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G01 F200 Z87.0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G01 F1200 Z0.0") --Går tilbake til Z0.0
local sigh2 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)
local sigState2 = mc.mcSignalGetState(sigh2)
if (sigState2 == 1) then
mc.mcCntlSetLastError(inst,"Tool is in position, Spindle can start")
------ Reset state ------
mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
-------------------------
else
mc.mcCntlEStop(inst)
wx.wxMessageBox("The toolhead is not on position")
end
mc.mcCntlGcodeExecuteWait(inst, "G40")
end
if (mc.mcInEditor() == 1) then
m6()
end
Code: [Select]
function m10()
local inst = mc.mcGetInstance()
--wx.wxMessageBox("Have you Referenced all axis?")
for i =1,10,1 do
mc.mcCntlGcodeExecuteWait(inst, "M6 t"..i.."")
mc.mcCntlGcodeExecuteWait(inst, " g53 G40 G90 G0 Z0.0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 x-8 y-32")
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 F300 Z-100")
mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z2")
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 F25 Z-3")
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
local NewOffset = probedz
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, i, NewOffset)
mc.mcCntlGcodeExecuteWait(inst, "G53 G90 g0 Z0")
end
mc.mcCntlGcodeExecuteWait(inst, "M6 t1")
end
if (mc.mcInEditor() == 1) then
m10()
end