Hallo Thomas,
hier einmal die M6 Makro version wie sie zur Zeit auf der Maschine ist.
--- Erstellt für Higma CNC Ver. 1.d--
--------------------------------------------------------------ACHTUNG INPUT ZEITEN GEÄNDERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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, "Next tool = Current tool")
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, "ERROR: Tool number out of range!")
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, "ERROR: Tool number out of range!")
do return end
end
------ Fahre zur Wechsel-Position "aktuelles Werkzeug" ------
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z300.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 + 0.5) -- 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, 3) --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 Z300.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f A%.4f\n", XPos2, YPos2, APos2)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos2 +0.5) -- 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", 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, 2) --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.mcCntlSetLastError(inst, string.format("Tool change - Tool: %.0f", SelectedTool))
------ 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
Dazu gibt es noch die Tool Change Position.Lua
local TC_Positions = {}
local inst = mc.mcGetInstance()
local CSVPath = wx.wxGetCwd() .. "\\Modules\\ToolChangePositions.csv"
local ToolNum = 0;
--[[
Open the file and read out the data
--]]
io.input(io.open(CSVPath,"r"))
local line;
for line in io.lines(CSVPath) do
local tkz = wx.wxStringTokenizer(line, ",");
TC_Positions[ToolNum] = {}-- make a blank table in the positions table to hold the tool table data
local token = tkz:GetNextToken();
TC_Positions[ToolNum] ["Tool_Number"] = token;
TC_Positions[ToolNum] ["X_Position"] = tkz:GetNextToken();
TC_Positions[ToolNum] ["Y_Position"] = tkz:GetNextToken();
TC_Positions[ToolNum] ["Z_Position"] = tkz:GetNextToken();
TC_Positions[ToolNum] ["A_Position"] = tkz:GetNextToken();
TC_Positions["Max"] = ToolNum
ToolNum = ToolNum + 1;
end
io.close()
function TC_Positions.GetToolData(SelectToolNum)
local MaxToolNum = TC_Positions["Max"]
if (SelectToolNum <= MaxToolNum) and (SelectToolNum > 0) then
return TC_Positions[SelectToolNum]
else
return nil
end
end
return TC_Positions
Wie gesagt ist das Makro mit viel halbwissen und ganz viel Glück enstanden, daher ist es vermutlich alles Stümperhaft und für leute die sich mit Lua auskennen eine katastrophe.
Gruß Rene aus Oberfranken