31
Mach4 General Discussion / Re: Error, Y axis commanded over SoftMin after auto tool touch then tool change?
« on: October 23, 2019, 10:35:59 PM »
Wow this is a pain. I cannot figure out why a Y returns to -0.0000 instead of 0.0000. Even if I take my formulas out and just tell it to straight up return to Y0, it still becomes -0.0000 when it is done.
So, after trying a few different things, this is what finally fixes it. It is a workaround, but it is not noticeable in actual operation. If the valY = 0 (the recorded position when the Auto Tool Zero function is initiated), then I have to tell it to return back to basically 0.0001 (using a new variable and equations). Then I have it move back using a variable that is that value -.0001 (which basically makes it zero again).
The fact that I am basing this on valY=0 to even run, proves the variable is also true zero, but the variable or an actual Y0 just won't work directly. It has to go through these extra BS steps to truly get back to 0.0000 instead of the impossible to even exist -0.0000...
This is skipped if the starting position is not Y=0.0000, because any other value works like it should and returns perfectly.
Here is the work around code. I will be interested to see why commanding it to just go back to Y0 directly will not even work.....
So, after trying a few different things, this is what finally fixes it. It is a workaround, but it is not noticeable in actual operation. If the valY = 0 (the recorded position when the Auto Tool Zero function is initiated), then I have to tell it to return back to basically 0.0001 (using a new variable and equations). Then I have it move back using a variable that is that value -.0001 (which basically makes it zero again).
The fact that I am basing this on valY=0 to even run, proves the variable is also true zero, but the variable or an actual Y0 just won't work directly. It has to go through these extra BS steps to truly get back to 0.0000 instead of the impossible to even exist -0.0000...
This is skipped if the starting position is not Y=0.0000, because any other value works like it should and returns perfectly.
Here is the work around code. I will be interested to see why commanding it to just go back to Y0 directly will not even work.....
Code: [Select]
-----Auto Tool Zero button------
function AutoToolZero()
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 ToolRadius = mc.mcToolGetData(inst, mc.MTOOL_MILL_RAD, currenttool) --Get the radius of the current tool
--Get positions before moving to do tool change
local valX, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) --Get the position of the X axis in Machine Position
local valY, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) --Get the position of the Y axis in Machine Position
local valZ, rc = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) --Get the position of the Z axis in Machine Position
rc = mc.mcCntlGcodeExecuteWait(inst, "M05") --Turns off the spindle (includes decel time)
if (ToolRadius < .4500) then --checks to see if the tool is too big for the touch plate
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000") --Move the Z to Home
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X19.5250 Y14.4445") --Move the the X, Y Coords to to the touch pad location
rc = mc.mcCntlSetLastError(inst, 'Now in Tool Measuring Position')
else
local xValDiamCor = (19.5250 - ToolRadius) -- Tool plate center minus tool radius to hit edge of tool
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000") --Move the Z to Home
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(xValDiamCor) .. "Y14.4445") --Move the the X, Y Coords to to the touch pad location minus tool radius
local MyChoice = wx.wxMessageBox("Manually rotate tool so lowest cutting edge is over the center of the touch plate","Click OK to continue once tool area is clear!" , 4)
end
local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
if (MyChoice == 16) then
rc = mc.mcCntlSetLastError(inst, 'Auto Tool Zero was cancelled.')
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000 F15.0") --Retract back to Z home
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
return
elseif (MyChoice == 4) then
rc = mc.mcCntlSetLastError(inst, "Probing in Progress!")
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G31.1 Z-8.125 F20.0") --Quick probe to find touch plate, Z distance min for shortest tool to hit
local touchLoc = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) --Assigns Z Probed position in Machine coords at touch plate
local RetractPoint = touchLoc + .200 --Adds retract distance to touch plate probed point
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z" .. tonumber(RetractPoint) .. "F15.0") --Retracts to prepare for slow approach
local approachDist = RetractPoint - .210 --Subtracts retract distance to touch plate probe, slightly more to make sure probe trips
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G31.1 Z" .. tonumber(approachDist) .. "F5.0") --Probe the new tool at slow speed
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000 F20.0") --Retract back to Z home
---This Code is to fix an issue where returning to Y=0 changes the Y coord to -0.0000 (should not have a -)
if valY == 0 then
local valYfix = valY + .0001
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valYfix)) --Move back to X & Y initial location
local valYfixb = valYfix - .0001
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valYfixb)) --Move back to X & Y initial location
else
---^^This Code is to fix an issue where returning to Y=0 changes the Y coord to -0.0000 (should not have a -)
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
end
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
rc = mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode)) --Return to pre macro mode G90, or G91
local ToolSetterHeight = mc.mcProfileGetDouble(inst , "ProbingSettings", "ToolHeightZ", 0.0000) --Gets the Tool Height Setter Z position from the probing tab settings
local NewOffset = math.abs (probedz - ToolSetterHeight) --Gives the Absolute value of the probed Z minus the Tool Height Setter Z position
rc = mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool, NewOffset)
rc = mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
wx.wxMessageBox("Toolchange Complete.\nTLO Set")
end
end