Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Toecutter on November 02, 2023, 08:25:29 AM
-
Hello,
I have now created an M6 macro that at least does what I need, it is not perfect and I still have to invest work in the security of the macro. I still have the problem that the program doesn't continue running automatically after changing the tool (It is an ATC and the tools are in the magazine) , I always have to press Cycle Start first when the new tool is in the spindle, I can't find the error or is it not the macro?
If someone could help me I would be very grateful.
greeting Rene
--- Erstellt für Higma CNC Ver. 1.d---
local inst = mc.mcGetInstance()
package.path = wx.wxGetCwd() .. "\\Modules\\?.lua"
if (package.loaded.ToolChangePositions == nil) then
tcp = require "ToolChangePositions"
end
function m6()
------ Vergleich aktuelles und nächstes Werkzeug ------
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
if (selectedTool == currentTool) then
mc.mcCntlSetLastError(inst, "Werkzeugwechsel nicht erforderlich!")
do return end
end
------ Lese aktuellen Maschinenstatus ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
------ Lese Positionsdaten vom aktuellen Werkzeug ------
ToolData = tcp.GetToolData(currentTool)
if (ToolData ~= nil) then
Num1 = ToolData.Tool_Number
XPos1 = ToolData.X_Position
YPos1 = ToolData.Y_Position
ZPos1 = ToolData.Z_Position
APos1 = ToolData.A_Position
else
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "Fehler Falsche Werkzeug-Nr.in Spindel!")
do return end
end
------ Lese Positionsdaten für nächstes Werkzeug ------
ToolData = tcp.GetToolData(selectedTool)
if (ToolData ~= nil) then
Num2 = ToolData.Tool_Number
XPos2 = ToolData.X_Position
YPos2 = ToolData.Y_Position
ZPos2 = ToolData.Z_Position
APos2 = ToolData.A_Position
else
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "Fehler Aufruf Falsche Werkzeug-Nr.!")
do return end
end
------ Fahre zur Wechsel-Position "aktuelles Werkzeug" ------
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z129.0 \n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f A%.4f\n", XPos1, YPos1, APos1)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1) -- Ab +0.5 mm über Ablagehöhe wird mit G01 verfahren, hier Wert einstellen.
--GCode = GCode .. string.format("G01 G90 G53 Z%.4f F250.0\n", ZPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Tor Auf ------
inst = mc.mcGetInstance()
local TorAuf = mc.OSIG_OUTPUT12
hSig, rc = mc.mcSignalGetHandle(inst, TorAuf) -- Get handle for output 12
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Tor Fehler")
end
rc = mc.mcSignalSetState(hSig, 1) --turn on output 12
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Tor Fehler 1")
end
------ Pruefen ob Tor Auf ------
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT14, 1, 0) --Wait 5 seconds for input 14 to become active
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Fehler Tor Geschlossen")
end
-- Magazin Auf ------
inst = mc.mcGetInstance()
local MagAuf = mc.OSIG_OUTPUT10
hSig, rc = mc.mcSignalGetHandle(inst, MagAuf) -- Get handle for output 10
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Magazin Fehler")
end
rc = mc.mcSignalSetState(hSig, 1) --turn on output 10
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Magazin Fehler 1")
end
------ Pruefen ob Magazin Auf ------
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT6, 1, 5) --Wait for input 5 to become active
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Fehler Magazin Auf")
end
----Werkzeugklemmung Auf Zu----
inst = mc.mcGetInstance()
hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT14) -- Get handle for output 14
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Klemmung Fehler")
end
rc = mc.mcSignalSetState(hSig, 1) --turn on output 14
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Klemmung Fehler 1")
end
------ Naechster Werkzeugposition anfahren und Klemmung Zu ------
GCode = ""
GCode = GCode .. "G00 G90 G53 Z129.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f A%.4f\n", XPos2, YPos2, APos2)
GCode = GCode .. "G04 P200\n" --Wartezeit 2000 milisekunden, nur optional
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos2 +5) -- Ab +5 mm über Ablagehöhe wird mit G01 verfahren, hier Wert einstellen
GCode = GCode .. string.format("G01 G90 G53 Z%.4f F750.0\n", ZPos2)
mc.mcCntlGcodeExecuteWait(inst, GCode)
rc = mc.mcSignalSetState(hSig, 0) --Turn the output off
if (rc ~= 0) then --There was error
mc.mcCntlSetLastError(inst, "Klemmung Fehler 1.a")
end
--Pruefen ob WZ Klemmung Auf---
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT12, 1, 0) --Wait for input 12 to become active
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Fehler Magazin Auf")
end
----Magazin Zu---
inst = mc.mcGetInstance()
local MagAuf = mc.OSIG_OUTPUT10
hSig, rc = mc.mcSignalGetHandle(inst, MagAuf) -- Get handle for output 10
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Magazin Zu Fehler")
end
rc = mc.mcSignalSetState(hSig, 0) --turn off output 10
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Magazin Zu Fehler 1")
end
------ Pruefen ob Magazin Zu ------
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT7, 1, 5) --Wait for input 5 to become active
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Fehler Magazin Auf")
end
-----Tor Zu----
inst = mc.mcGetInstance()
local TorAuf = mc.OSIG_OUTPUT12
hSig, rc = mc.mcSignalGetHandle(inst, TorAuf) -- Get handle for output 12
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Tor Fehler")
end
rc = mc.mcSignalSetState(hSig, 0) --turn on output 12
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Tor Fehler 1")
end
----Setze Neues Werkzeug ------
mc.mcToolSetCurrent (inst, selectedTool)
mc.mcCntlGcodeExecuteWait(inst, GCode)
mc.mcSignalSetState(hsig1,0)
mc.mcCntlSetLastError(inst, "Werkzeugwechsel beendet")
GCode = ""
GCode = GCode .. string.format("G43 H%.4f\n", SelectedTool)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Ursprünglichen Maschinenstatus wiederherstellen ------
mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
end
if (mc.mcInEditor() == 1) then
m6()
end