Hello Guest it is April 27, 2024, 07:38:52 PM

Author Topic: Security Monitoring in M6 Makro  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

Security Monitoring in M6 Makro
« on: October 01, 2023, 04:28:44 AM »
Hello
I would like to create an M6 macro for my machine. As a basis, I took an already existing macro to adapt it for myself.
Roughly, the tool change should work like this:

1. All axles move to a fixed change position

2. The magazine door opens

3. A limit switch checks if the door is open, if that is ok then

4. The magazine moves into the working chamber and grips the tool in the spindle

5. Limit switch checks if the magazine is in position, if that's ok then

6. The tool clamp is opened

7. The Z axis moves upwards

8. The magazine turns to the next tool

9. Z axis moves downwards

10. Tool clamp is closed

11. Switch in the spindle checks if the tool is in the spindle, if ok then

12. Magazine moves out of the workspace

13. Limit switch checks whether the magazine has moved out of the working area, if ok then

14. Magazine door is closed

I'm stuck at point 3 right now, I can't get it that after opening the magazine door the limit switch in Lua is taken into account, it doesn't matter if the switch is triggered or not.

The macro should only continue to run when the limit switch has switched to high or stop immediately after waiting 2 seconds and an error message should appear.

It would be nice if someone could help me with this.
Thank you
Greetings Rene
Code: [Select]
------ Tor Auf ------
local TorAuf = mc.OSIG_OUTPUT12 -- Open the Door
local hsig = mc.mcSignalGetHandle(inst, TorAuf)
mc.mcSignalSetState(hsig, 0)

------ Pruefen ob Tor Auf ------
   
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT14, WAIT_MODE_HIGH, 1) -- 1 Wait 1 Sec.
if (rc== 0) then -- prüfen ob Tor Auf
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ALARM: Tor Zu !")
do return end
else
        mc.mcCntlSetLastError(inst, "Tor Auf")
Re: Security Monitoring in M6 Makro
« Reply #1 on: November 07, 2023, 06:30:52 AM »
Gude Rene,

wir könnten auch auf Deutsch..... :)

To solve your problem it might be the best way to use a step chain structure in your Software and place the code in the PLC-Script. In this way you can eliminate all timing problems only by check the limit switches.
All you need is an global integer variable like "iStep". This Variable must be initialised with 0 in ScreenLoadScript.

In your M6 Macro you can start the Tool change by setting iStep to 1.

iStep=1 start the chain similar to yor steps in the basic Thread with the first move of cylinders or whatever. In the same Step you increase iStep by 1.

All following Steps first check the limit switches are reached from the last move Command. If this is ok give the next move command and increase iStep.

At the end, or last step, you set iStep to 0 so the step chain waits on next start.

For example:
if (iStep == 1) then
    do some things;
    iStep = iStep +1;
elseif (iStep == 2) then
   if (check limit switches) then
      do some things;
      iStep = iStep +1;
   end if
elseif (iStep == 3) then
   if (check limit switches) then
.
.
elseif (iStep == 14) then
        do some things;
        iStep =0;
end

Timers and delays are only usefull for surveillance runtime issues. In your case it is usefull if you mount on every actuator limit switches to check the position. So you don't need any timer.

I hope the answer is usefull.

Viele Grüße
Thomas
« Last Edit: November 07, 2023, 06:32:46 AM by StallionP51 »
Re: Security Monitoring in M6 Makro
« Reply #2 on: November 07, 2023, 12:22:41 PM »
Hallo Thomas,
leider verstehe ich viel zu wenig von Lua um das alles zu verstehen. Inzwischen habe ich mein Makro mit Try and Error und Copy and Past hinbekommen, einzige Baustelle ist noch Mach4 beizubringen, beim Aufrufen von Werkzeug 0 das Werkzeug abzulegen ohne ein neues aufzunehmen, also einfach die Spindel Leeren.
Bist du zufällig der Thomas R. der mir sein Makro bei FB zur verfügung gestellt hat?

Gruß Rene
Re: Security Monitoring in M6 Makro
« Reply #3 on: November 07, 2023, 12:44:05 PM »
Hallo Rene,

bin ich leider nicht. Aber wenn Du Dein Macro mal postest, dann kann ich Dir eventuell helfen.

Grüße aus dem Lahntal
Thomas S.
Re: Security Monitoring in M6 Makro
« Reply #4 on: November 08, 2023, 12:30:00 PM »
Hallo Thomas,
hier einmal die M6 Makro version wie sie zur Zeit auf der Maschine ist.
Code: [Select]
--- 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

Code: [Select]
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
Re: Security Monitoring in M6 Makro
« Reply #5 on: November 10, 2023, 03:19:05 AM »
Gude Rene,

Wenn ich das richtig sehe, dann hast Du den Toolchange Code aus dem Scripthandbuch genommen und angepasst. Das finde ich grundsätzlich nicht schlecht. Das Problem bei Dir ist allerdings, dass Du Zylinder usw. bewegen musst. Grundsätzlich sollte so etwas in einer SPS abgebildet werden. Wie von Dir beschrieben müssen Laufzeiten abgewartet werden usw. Du hast dazu Wartezeiten verwendet. Grundsätzlich sind Zeiten in Mach 4 kritisch, weil damit das gesamte System angehalten wird. Beim Werkzeugwechsel ist das unkritisch, da die Maschine eh steht. 
Ich habe es schon einmal geschrieben. So einen Toolwechsel mit Laufzeiten für Zylinder, Türen, was auch immer gehört normalerweise ins PLC-Script des Screens. Das wird zyklisch abgearbeitet und erlaubt den Einsatz von Schrittketten. Damit werden auch Zeiten oder Zeitverzögerungen überflüssig.
Ich selbst baue gerade eine Zeitfunktion in Lua, die das Gesamtsystem nicht anhält. Sozusagen ein frei laufender Timer. Ich komme allerdings beruflich bedingt nicht dazu in der kürze der Zeit sowas komplett fertig zu machen.
Der Werkzeugwechsel steht bei mir auch noch an und dann werde ich das im PLC-Script abbilden. Der M6 befehl würde dann nur noch das Script triggern.
Ich dachte zuerst ich könnte Dir schnell helfen bei der Implementierung von Tool 0. Dazu wären aber große Teile des Scriptes neu zu schreiben, weil es sich um einen anderen Ablauf handelt.
Wenn Du Dir bis dahin helfen kannst würde ich Dich per PN informieren.

Gruß Thomas

Re: Security Monitoring in M6 Makro
« Reply #6 on: November 10, 2023, 09:30:53 AM »
Hallo Thomas,
danke für deine Infos, das Makro funktioniert erst einmal so und bei PLC bin ich ganz raus. Von den  Zwei Jahre Bauzeit meiner Maschine,  war das Makro für mich die große ungewisse.
Danke nochmal, Gruß
René