11
Mach4 General Discussion / Re: Altering M6 but am confused
« on: September 16, 2016, 04:52:51 PM »
Thanks Bob I just subscribed.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
function M6() -- this code is based on a CNC Router table where zero is always the machine top.
local inst = mc.mcGetInstance();
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
--your machine info custom to you
local touchplate = 0 -- this is the height above or below table surface for non flush touchplates.
local longesttool = 6 -- this is the longest bit that you own that you could possibly use
local zclearance = -11.375 -- this is the measurment from your collet to machine top "Zero"
local probeclearance = .25 -- this is safe distance above touchplate where you want probe to start
-- end of your machine info
local undefinedtoolprobe = (zclearance + longesttool +touchplate + probeclearance )
local undefinedprobetravel = (zclearance + longesttool + touchplate)
local probestart = (zclearance + toollen + probeclearance +touchplate)
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location
wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
if toollen ~= 0 then -- if toollen is defined in tool table do this
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
repeat
mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
mc.mcAxisSetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcAxisSetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
end
else
wx.wxMessageBox("Undefined tool proceed with caution")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
repeat
mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
mc.mcAxisSetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcAxisSetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
end
end
end
end
if (mc.mcInEditor() == 1) then
M6()
end
function M6() -- this code is based on a CNC Router table where zero is always the machine top.
local inst = mc.mcGetInstance();
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
--your machine info custom to you
local touchplate = 0 -- this is the height above or below table surface for non flush touchplates.
local longesttool = 6 -- this is the longest bit that you own that you could possibly use
local zclearance = -11.375 -- this is the measurment from your collet to machine top "Zero"
local probeclearance = .25 -- this is safe distance above touchplate where you want probe to start
-- end of your machine info
local undefinedtoolprobe = (zclearance + longesttool +touchplate + probeclearance )
local undefinedprobetravel = (zclearance + longesttool + touchplate)
local probestart = (zclearance + toollen + probeclearance +touchplate)
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location
wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
if toollen ~= 0 then -- if toollen is defined in tool table do this
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
repeat
mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
mc.mcAxissetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcAxisSetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
end
else
wx.wxMessageBox("Undefined tool proceed with caution")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z-"..undefinedprobetravel.." F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
repeat
mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z-"..undefinedprobetravel.." F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
mc.mcAxissetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcAxissetPos(inst, 2, (0 - touchplate))
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
mc.mcToolSetCurrent(inst, selectedtool)
end
end
end
end
if (mc.mcInEditor() == 1) then
M6()
end
This sounds like the there may be an issue in the SmartBOB with *very* short moves during probing. I'll have to try that here. When you run the M6 the 2nd time, is the tool still in contact with the touch plate? Or has it backed off a little bit? A lot?QuoteYour fixture offset may be getting clobbered because of this call:
mc.mcAxisSetPos(inst, 2, toolz)
Bob, I don't believe this to be an issue since I have not finished this portion of the code and have yet to run an instance where this portion is utilized. Saying that, I don't know if there would be any adverse effects to it just being in there.
function M6()
local inst = mc.mcGetInstance();
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
[color=blue] -- local currentheightoffset = mc.mcCntlGetOffset (inst , 2) basis for controlling event that tool offset is active
--local HOState = mc.mcCntlGetPoundVar(inst, 4008)
--if (HOState == 49) then
--mc.mcCntlMdiExecute(inst, "G43")
--else
--mc.mcCntlMdiExecute(inst, "G49")
--end[/color]
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
if toollen ~= 0 then
local probestart = (-11 + toollen)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then
repeat
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
local zoffset = mc.mcAxisGetPos(inst, 2)
mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")
else
local zoffset = mc.mcAxisGetPos(inst, 2)
mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")
end
else
wx.wxMessageBox("No tool length currently defined Lower Z to above touch plate, hit enter to start probe")
[color=red] --need a way to lower Z manually here and have not verified this portion of code--[/color]
mc.mcCntlGcodeExecuteWait(inst," G91 G31 Z-.5 F25")
ProbeState = mc.mcSignalGetState(hsig)
repeat
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
until(ProbeState ~= 0)
mc.mcAxisSetPos(inst, 2, toolz)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--wx.wxMessageBox("Please turn on spindle and click ok to continue") --can be removed if required
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")end
end
mc.mcToolSetCurrent(inst, selectedtool)
end
if (mc.mcInEditor() == 1) then
M6()
end