Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: jorgenbli on July 18, 2018, 06:16:25 PM
-
I am setting up a machine with a linear ATC. The script is based on the example in the Lua scripting guide in the documentation folder of Mach4. The script is working somehow, but there is an issue if you hit the Stop button during a tool change as this causes Mach4 to believe the tool change is finished even though it might haven't done anything yet.
Is there a way to make sure the macro is terminated if the Stop button is hit while the tool change is ongoing?
The only way I could think of solving this is to compare the requested tool change position with the actual machine position before and after the tool is but back or released - and if it doesn't reach that position I could return from the script. But if there is an easier way to see if the Stop button was hit that would be better.
package.path = wx.wxGetCwd() .. "\\Profiles\\Mach4Mill\\Modules\\?.lua;"
if(package.loaded.ToolChangePositions == nil) then
tcp = require "ToolChangePositions"
end
function m6()
local inst = mc.mcGetInstance()
local SelectedTool = mc.mcToolGetSelected(inst)
local CurrentTool = mc.mcToolGetCurrent(inst)
-- local xstart = mc.mcAxisGetMachinePos(inst,0)
-- local ystart = mc.mcAxisGetMachinePos(inst,1)
local en_axis = 0
repeat
local Is_Enabled = mc.mcAxisIsEnabled(inst, en_axis)
if Is_Enabled == 1 then
local is_Homed = mc.mcAxisIsHomed(inst, en_axis)
if is_Homed ~= 1 then
mc.mcCntlEnable(inst, 0)
wx.wxMessageBox("RESET: Machine was not referenced")
return
end
end
en_axis = en_axis + 1
until( en_axis == 6 )
if SelectedTool == CurrentTool then
mc.mcCntlSetLastError(inst, "No need for tool change!")
do return end
end
------ Get current state ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
------ Get position data for current tool ------
ToolData = tcp.GetToolData(CurrentTool)
if (ToolData ~= nil) then
Num1 = ToolData.Tool_Number
XPos1 = ToolData.X_Position
YPos1 = ToolData.Y_Position
ZPos1 = ToolData.Z_Position
else
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: No place for this tool. Tool number out of range!")
do return end
end
------ Get position data for next tool ------
ToolData = tcp.GetToolData(SelectedTool)
if (ToolData ~= nil) then
Num2 = ToolData.Tool_Number
XPos2 = ToolData.X_Position
YPos2 = ToolData.Y_Position
ZPos2 = ToolData.Z_Position
else
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Requested tool number out of range!")
do return end
end
------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z0.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos1, YPos1-100)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1)
GCode = GCode .. string.format("G01 G90 G53 Y%.4f F100\n", YPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
wx.wxMessageBox("Machine will now open drawbar")
------ Release drawbar ------
local DrawBarOut = mc.OSIG_OUTPUT10
local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 1)
------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1+20)
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f F100\n", ZPos2)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Clamp drawbar ------
mc.mcSignalSetState(hsig, 0)
------ Retract from tool holder ------
local GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2-100)
GCode = GCode .. "G00 G90 G53 Z0.0\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Reset state ------
mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
-- mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X"..xstart.." Y"..ystart) --back to initial position
mc.mcToolSetCurrent(inst, SelectedTool) -- change to new tool
mc.mcCntlSetPoundVar(inst, 2032, SelectedTool) -- set height offset number
mc.mcCntlGcodeExecuteWait(inst, "G43 H"..SelectedTool)
mc.mcCntlSetLastError(inst, string.format("Tool change finished - Tool: %.0f", SelectedTool))
end
if (mc.mcInEditor() == 1) then
m6()
end
-
Gonna comment on this so I can be sure to follow this thread.
I've got something at work that may be okay but I'll have to check tomorrow.
-
im interseted in the m6 atc linear macro . so you have code to share . Thanks
-
i think we talked about this issiue here at least 5 times
you must control in mach for every situation ,the sample in document its only start of work
you must control many event:
when spindle open ,if its real open
when tool lock if its real lock
then must act if some thing not as you plan
about kill the function you also must put in every action line to check if some reason the function should be cut
for example if you press stop ,because stop only stop movement not stop the function
hope i help you
-
the event i wrote its not all,for example:
must check if hood go up ,must check spindle stop ,must check there tool in the magazine in position you ask to take(i also add safety to be sure that there no tool in position you want unlod the tool)
one more point i add that the tool in magazie name is not its position on magazine ,this give me the option to work with much more tools
without freid that someone will mismach
good luck