Files
Saomad-Just3500/Saomad-Just3500.SIEMENS.mlpe
2024-07-17 13:02:09 +02:00

1361 lines
55 KiB
Plaintext

-- Special Operations macchina Saomad Just3500 by Egalware s.r.l. 15/01/2024
-- Intestazioni
require( 'EmtGenerator')
EgtEnableDebug( false)
-- Variabili di modulo
local MLE_INFO = 'Saomad Just3500 by Egalware s.r.l.'
---------------------------------------------------------------------
-- *** GENERATION ***
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnStart()
EMT.USETO1 = true -- abilitazione uso origine tavola
EMT.MODAL = true -- abilitazione emissione modale
EMT.INCHES = not EgtUiUnitsAreMM() -- unità di misura mm/inches
EMT.NUM = false -- abilitazione numerazione linee
--EMT.Nt = 'N' -- token per la numerazione di linea
--EMT.LINENBR = 0 -- numero di linea
--EMT.LINEINC = 1 -- incremento numerazione linee
--EMT.Ft = 'F' -- token per feed
--EMT.St = 'S' -- token per speed
bNotProcCN = false
bZMaxG4 = false
bWriteFirstJump = false
nCountShuttlelav = 0
dOffsetCuffia = 0
bEmitUprOnGenPlane = false
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnEnd()
-- Chiusura file altri processi (qui si passa sempre, anche in caso di errore)
CloseOutFile( 2)
CloseOutFile( 3)
CloseOutFile( 4)
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnProgramStart()
-- acquisizione nome attrezzaggio
local sSetupName = EgtGetInfo( EgtGetCurrSetup() or GDB_ID.NULL, 'Name')
-- Apertura file per altri processi (2, 3, 4)
local sDir, sName, sExt = EgtSplitPath( EMT.FILE)
OpenOutFile( 2, sDir .. sName .. '_2' .. sExt)
OpenOutFile( 3, sDir .. sName .. '_3' .. sExt)
OpenOutFile( 4, sDir .. sName .. '_4' .. sExt)
-- Intestazione processo 1
EmtOutput( EgtIf( EMT.INFO, ';'..EMT.INFO, ';Program Start'), 1)
EmtOutput( ';'.. MLE_INFO, 1)
EmtOutput( ';'.. 'ToolingSetUp:'..EgtIf(sSetupName, sSetupName, 'null'), 1)
EmtOutput( ';Process 1', 1)
-- Intestazione processo 2
EmtOutput( EgtIf( EMT.INFO, ';'..EMT.INFO, ';Program Start'), 2)
EmtOutput( ';'.. MLE_INFO, 2)
EmtOutput( ';Process 2', 2)
-- Intestazione processo 3
EmtOutput( EgtIf( EMT.INFO, ';'..EMT.INFO, ';Program Start'), 3)
EmtOutput( ';'.. MLE_INFO, 3)
EmtOutput( ';Process 3', 3)
-- Intestazione processo 4
EmtOutput( EgtIf( EMT.INFO, ';'..EMT.INFO, ';Program Start'), 4)
EmtOutput( ';'.. MLE_INFO, 4)
EmtOutput( ';Process 4', 4)
-- Flag attivazione navette
EMT.SHUTTLE_ON = false
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnProgramEnd()
-- Sono in processo P1, se chiamata/e di P4 in sospeso, eseguo
if EMT.P1CALLP4 then
for i = 1, #EMT.P1CALLP4 do
local bNoMach
local sFilter = EMT.P1CALLP4[i]
-- se trovo il prefisso NOMACH filtro la stringa prima di scriverla
if sFilter:find( 'NOMACH', 1, true) then
sFilter = string.sub( sFilter, 7)
bNoMach = true
end
EmtOutput( sFilter, 1)
if not bNoMach then
EmtOutput( 'E100=0', 1)
EmtOutput( '#(CLS,P1CALLP4)', 1)
end
end
EMT.P1CALLP4 = nil
end
-- Sono in processo P1, se non avviate le navette lo faccio ora
if not EMT.SHUTTLE_ON then
EmitShuttleRun(true)
end
-- Deselezione ultimo utensile
EMT.NEXTHEAD = ''
OnToolDeselect()
-- Eventuale abbassamento (da P1) di rulliera rimasta alta per sfinestrature
if EMT.WINSTART then
EmtOutput( ';', 1)
EmtOutput( '#(CLS,WINSTOP)', 1)
EMT.WINSTART = nil
end
-- Terminazione dei processi 2, 3 e 4
if bNotProcCN then
EmtOutput( 'M810', 2)
end
EmtOutput( ';', 2)
EmtOutput( '#(CLS,ENDP2)', 2)
EmtOutput( ';--M2', 2)
if bNotProcCN then
EmtOutput( 'M810', 3)
end
EmtOutput( ';', 3)
EmtOutput( '#(CLS,ENDP3)', 3)
EmtOutput( ';--M2', 3)
if bNotProcCN then
EmtOutput( 'M6', 4)
end
EmtOutput( ';', 4)
EmtOutput( '#(CLS,ENDP4)', 4)
EmtOutput( ';--M2', 4)
-- Attesa termine degli altri processi
EmtOutput( ';', 1)
EmtOutput( '#(CLS,ENDP1)', 1)
if not bNotProcCN then
if not bWriteFirstJump then
EmtOutput( '(GTO,DD3)', 1)
EmtOutput( '"DD1"', 1)
if #sPos5aHead > 0 then
EmtOutput( sPos5aHead, 1)
end
EmtOutput( '(GTO,DD2)', 1)
EmtOutput( '"DD3"', 1)
bWriteFirstJump = true
end
end
EmtOutput( ';', 1)
-- Scarico
-- era CLS,UNLD_LFT
if not bNotProcCN then
EmtOutput( '#(CLS,UNLD_RGT)', 1)
end
EmtOutput( ';', 1)
-- da togliere per funzionamento con PROD
EmtOutput( ';---M30', 1)
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnToolData()
-- emissione dati utensile come commento
local nGroup = EgtIf( EMT.HEAD == 'H8', 1, tonumber( EMT.HEAD:sub( 2, 2)))
local sExit = EgtIf( EMT.HEAD == 'H42',' EXIT:'..EgtNumToString( EMT.EXIT, 0), nil) or
EgtIf( EMT.HEAD == 'H43',' EXIT:'..EgtNumToString( EMT.EXIT, 0), nil) or
EgtIf( EMT.HEAD == 'H44',' EXIT:'..EgtNumToString( EMT.EXIT, 0), nil)
EmtOutput( ';'..EMT.TCPOS..EgtIf( sExit, sExit, '')..' '..EMT.TOOL..' C'..EMT.TCOMP..
' D'..EmtLenToString(EMT.TDIAM,4)..' L'..EmtLenToString(EMT.TLEN,4), nGroup)
end
-- DISPOSITION
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnDispositionStart()
--EmtOutput( '(Disposition '..EMT.DISPIND..' = '..EMT.DISPID..')')
EMT.OPEISDISP = true
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnDispositionEnd()
-- Se termine disposizione iniziale
if EMT.DISPIND == 1 then
-- mi faccio dare il padre l'id della macchinata
local nMachGroup = EgtGetCurrMachGroup() -- EgtGetParent( EgtGetParent( EMT.DISPID))
if nMachGroup then -- se ho la macchinata prendo le note della stima tempi e spazio
nEstTime = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ttot', 'd') or 0.0
nEstTimePr = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ttotpr', 'd') or 0.0
nEstTime1 = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ttot1', 'd') or 0.0
nEstTime2 = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ttot2', 'd') or 0.0
nEstTime3 = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ttot3', 'd') or 0.0
nEstSpace = EgtGetInfo( nMachGroup or GDB_ID.NULL, 'Ltot', 'd') or 0.0
local nHour = modf(nEstTime/3600)
local mMinute = modf( (nEstTime-(nHour*60))/60)
local nSecond = nEstTime - (nHour * 3600) - ( mMinute * 60)
EmtOutput( ';'.. 'Estimate Total Time(hr:min:sec): '.. string.format( '%d:%d:%d', nHour, mMinute, nSecond), 1)
nHour = modf(nEstTimePr/3600)
mMinute = modf( (nEstTimePr-(nHour*60))/60)
nSecond = nEstTimePr - (nHour * 3600) - ( mMinute * 60)
EmtOutput( ';'.. 'Nearest Real Estimate Total Time(hr:min:sec): '.. string.format( '%d:%d:%d', nHour, mMinute, nSecond), 1)
nHour = modf(nEstTime1/3600)
mMinute = modf( (nEstTime1-(nHour*60))/60)
nSecond = nEstTime1 - (nHour * 3600) - ( mMinute * 60)
EmtOutput( ';'.. 'Process 1 and 4 Estimate Total Time(hr:min:sec): '.. string.format( '%d:%d:%d', nHour, mMinute, nSecond), 1)
nHour = modf(nEstTime2/3600)
mMinute = modf( (nEstTime2-(nHour*60))/60)
nSecond = nEstTime2 - (nHour * 3600) - ( mMinute * 60)
EmtOutput( ';'.. 'Process 2 Estimate Total Time(hr:min:sec): '.. string.format( '%d:%d:%d', nHour, mMinute, nSecond), 1)
nHour = modf(nEstTime3/3600)
mMinute = modf( (nEstTime3-(nHour*60))/60)
nSecond = nEstTime3 - (nHour * 3600) - ( mMinute * 60)
EmtOutput( ';'.. 'Process 3 Estimate Total Time(hr:min:sec): '.. string.format( '%d:%d:%d', nHour, mMinute, nSecond), 1)
EmtOutput( ';'.. 'Estimate Total Length('.. EgtIf( EMT.INCHES, 'ft', 'meter') ..'): '..
EgtIf( EMT.INCHES, string.format( '%.2f', (nEstSpace/(12*25.4))), string.format( '%.3f', (nEstSpace/1000))), 1)
EmtOutput( ';', 1)
end
-- ottengo id pezzo
local nPartId = EgtGetFirstPartInRawPart( EMT.RAWID)
-- leggo la nota relativa al codice speciale
local sSpecialCmd = EgtGetInfo( nPartId or GDB_ID.NULL, 'SpecialCmd') or ''
if sSpecialCmd == 'p0' or sSpecialCmd == 'p1' or sSpecialCmd == 'p2' or
sSpecialCmd == 'p3' or sSpecialCmd == 'p4' or sSpecialCmd == 'p5' then
bNotProcCN = true
end
-- leggo la nota relativa all'utilizzo forzato di una sola navetta
local sForceShuttle = EgtGetInfo( nPartId or GDB_ID.NULL, 'ForceShuttle')
EmtOutput( 'L121=' .. EgtIf( sForceShuttle, sForceShuttle, '0'), 1)
-- leggo la nota relativa alla pressione
local sPressure = EgtGetInfo( nPartId or GDB_ID.NULL, 'P') or '0'
-- leggo le note relativa allo spostamento in Y della porta per appoggio su ruferimento
dExtraYPos = EgtGetInfo( nPartId or GDB_ID.NULL, 'ExtraCalcMoveY', 'd') or 0.0
dDoorProbeErrorY = EgtGetInfo( nPartId or GDB_ID.NULL, 'DoorProbeErrorY', 'd') or 0.0
-- leggo la nota relativa alla disposizione porta
nSideDisp = EgtGetInfo( nPartId or GDB_ID.NULL, 'SideDisposition', 'i') or 0
-- se a 0 do errore perchè non ha disposizione accettabile
if nSideDisp == 0 then error( "Bad disposition") end
-- leggo la nota relativa alla disabilitazione cuffia
sDisableHood = EgtGetInfo( nPartId or GDB_ID.NULL, 'ForceDisableHood') or '0'
-- leggo la nota relativa alla lavorazione del lato cerniere
sSideHingeMach = EgtGetInfo( nPartId or GDB_ID.NULL, 'SideHingeMach') or '0'
sSideHingeProf = EgtGetInfo( nPartId or GDB_ID.NULL, 'SideHingeProf') or '-1'
-- leggo la nota relativa alla lavorazione del lato serratura
sSideLockMach = EgtGetInfo( nPartId or GDB_ID.NULL, 'SideLockMach') or '0'
-- Recupero dimensioni grezzo
b3Raw = EgtGetBBoxGlob( EgtGetFirstNameInGroup( EMT.RAWID or GDB_ID.NULL, 'RawSolid'), GDB_BB.STANDARD)
-- dimensioni della porta
EmtOutput( ';', 1)
EmtOutput( 'L56=' .. EmtLenToString( b3Raw:getDimX(), 3), 1)
EmtOutput( 'L57=' .. EmtLenToString( b3Raw:getDimY(), 3), 1)
EmtOutput( 'L58=' .. EmtLenToString( b3Raw:getDimZ(), 3), 1)
EmtOutput( ';', 1)
-- Inizializzazioni processo 1
EmitInit( nSideDisp, dExtraYPos, dDoorProbeErrorY)
-- posizione della barra mobile con le ventose
EmitMobile()
-- posizione degli spintori
EmitPusher( nSideDisp)
-- posizione delle ventose
EmitVacuum()
-- tipo di riferimenti da usare
EmitRefType()
if not bNotProcCN then
-- setto le variabili lavorazione profilo lato hinge
EmtOutput( '; Hinge side machined', 1)
EmtOutput( 'L135='..sSideHingeMach, 1)
EmtOutput( ';', 1)
EmtOutput( '; Hinge side profile', 1)
EmtOutput( 'L136='..sSideHingeProf, 1)
EmtOutput( ';', 1)
-- setto le variabili lavorazione profilo lato lock
EmtOutput( '; Lock side machined', 1)
EmtOutput( 'L137='..sSideLockMach, 1)
EmtOutput( ';', 1)
end
-- avvio altri processi
EmitProcStart()
-- codici speciali
if bNotProcCN then
EmtOutput( '; Special Command:'.. string.upper(sSpecialCmd), 1)
if sSpecialCmd == 'p1' then
EmtOutput( 'M405', 1)
elseif sSpecialCmd == 'p2' then
EmtOutput( 'M401', 1)
elseif sSpecialCmd == 'p3' then
EmtOutput( 'M402', 1)
elseif sSpecialCmd == 'p4' then
EmtOutput( 'M403', 1)
elseif sSpecialCmd == 'p5' then
EmtOutput( 'M404', 1)
elseif sSpecialCmd == 'p6' then
EmtOutput( 'M206', 1)
end
else
-- setto la variabile per la pressione
EmtOutput( '; Pressure value (0-20)')
EmtOutput( 'L41='..sPressure)
EmtOutput( ';')
-- richiamo carico
EmtOutput( '(GTO,DD1)')
EmtOutput( '"DD2"')
EmtOutput( '#(CLS,LD_LFT_RGT)')
EmtOutput( ';')
EmtOutput( '#(CLS,WAITIN)')
-- Inizializzazioni processo 2 (shuttle 1)
EmtOutput( EgtIf( EMT.INCHES, 'G70', 'G71'), 2)
EmtOutput( ';', 2)
--EmtOutput( 'M810 ; SHUTTLE PARK', 2)
EmtOutput( '#(CLS,INITP2)', 2)
EmtOutput( ';', 2)
-- Inizializzazioni processo 3 (shuttle 2)
EmtOutput( EgtIf( EMT.INCHES, 'G70', 'G71'), 3)
EmtOutput( ';', 3)
--EmtOutput( 'M810 ; SHUTTLE PARK', 3)
EmtOutput( '#(CLS,INITP3)', 3)
EmtOutput( ';', 3)
-- Inizializzazioni processo 4 (teste dietro)
EmtOutput( EgtIf( EMT.INCHES, 'G70', 'G71'), 4)
EmtOutput( ';', 4)
EmtOutput( '#(CLS,INITP4)', 4)
EmtOutput( ';', 4)
end
end
EMT.OPEISDISP = false
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnTableData()
-- Se prima fase, origine su angolo basso-destra della tavola
if EMT.PHASE == 1 then
-- correzioni origine tavola per dimensioni riferimenti grandi
EMT.TABORI1[1] = EMT.TABORI1[1] + 32
EMT.TABORI1[2] = EMT.TABORI1[2] + 32
EMT.TABORI1[3] = EMT.TABORI1[3] + 110
-- emissione dati su processo 1
local sOra1 = ''
sOra1 = ';ORIG' ..' X'..EmtLenToString( EMT.TABORI1[1] + DistRif, 3)..
' Y'..EmtLenToString( EMT.TABORI1[2], 3)..
' Z'..EmtLenToString( EMT.TABORI1[3], 3)
EmtOutput( sOra1, 1)
EmtOutput( '!ORIGIN=2 ;ORIGIN SELECT', 1)
EmtOutput( '!SH_X=0 ;SHIFT X', 1)
EmtOutput( '!SH_Y=0 ;SHIFT Y', 1)
EmtOutput( '!SH_Z=0 ;SHIFT Z', 1)
EmtOutput( ';', 1)
-- emissione dati su processo 2
local sOra2 = ''
sOra2 = ';ORIG' ..' X'..EmtLenToString( EMT.TABORI1[1] - H21:getX() + DistRif, 3)..
' Y'..EmtLenToString( EMT.TABORI1[3] - H21:getZ(), 3)..
' Z'..EmtLenToString( - ( EMT.TABORI1[2] - H21:getY()), 3)
EmtOutput( sOra2, 2)
EmtOutput( '!ORIGIN=2 ;ORIGIN SELECT', 2)
EmtOutput( '!SH_X=0 ;SHIFT X', 2)
EmtOutput( '!SH_Y=0 ;SHIFT Y', 2)
EmtOutput( '!SH_Z=0 ;SHIFT Z', 2)
EmtOutput( ';', 2)
-- emissione dati su processo 3
local sOra3 = ''
sOra3 = ';ORIG' ..' X'..EmtLenToString( EMT.TABORI1[1] - H31:getX() + DistRif, 3)..
' Y'..EmtLenToString( EMT.TABORI1[3] - H31:getZ(), 3)..
' Z'..EmtLenToString( - ( EMT.TABORI1[2] - H31:getY()), 3)
EmtOutput( sOra3, 3)
EmtOutput( '!ORIGIN=2 ;ORIGIN SELECT', 3)
EmtOutput( '!SH_X=0 ;SHIFT X', 3)
EmtOutput( '!SH_Y=0 ;SHIFT Y', 3)
EmtOutput( '!SH_Z=0 ;SHIFT Z', 3)
EmtOutput( ';', 3)
-- emissione dati su processo 4
local sOra4 = ''
sOra4 = ';ORIG' ..' X'..EmtLenToString( EMT.TABORI1[1] - H41:getX() + DistRif, 3)..
' Y'..EmtLenToString( EMT.TABORI1[2] - H41:getY(), 3)..
' Z'..EmtLenToString( EMT.TABORI1[3] - H41:getZ(), 3)
EmtOutput( sOra4, 4)
EmtOutput( '!ORIGIN=2 ;ORIGIN SELECT', 4)
EmtOutput( '!SH_X=0 ;SHIFT X', 4)
EmtOutput( '!SH_Y=0 ;SHIFT Y', 4)
EmtOutput( '!SH_Z=0 ;SHIFT Z', 4)
EmtOutput( ';', 4)
end
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnFixtureData()
--EmtOutput( '(Fixture '..EMT.FIXIND..' = '..EMT.FIXID..' Name = '..EMT.FIXNAME..
-- ' Pos = '..EmtNum3ToString( EMT.FIXPOS)..' Ang = '..EgtNumToString(EMT.FIXANG)..')')
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnRawMoveData()
--EmtOutput( '(RawMove '..EMT.RAWIND..' Id = '..EMT.RAWID..' Type = '..EMT.RAWTYPE..
-- ' Pos = '..EmtNum3ToString( EMT.RAWPOS)..' Flag = '..EMT.RAWFLAG..')')
-- Se prima fase, origine su angolo basso-destra della tavola
end
-- MACHINING
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnToolSelect()
if bNotProcCN then return end
-- se utensile definito (non definito per disposizioni con movimento)
if EMT.TOOL ~= '' then
-- verifiche su utensile
local sTool = EgtTdbGetToolFromUUID( EgtGetMachiningParam( MCH_MP.TUUID) or "")
if sTool ~= EMT.TOOL then error( "Tool name mismatch") end
-- predefinite EMT.HEAD EMT.EXIT
EMT.TOOLTYPE = EgtTdbGetCurrToolParam( MCH_TP.TYPE)
if EMT.HEAD == 'H11' or EMT.HEAD == 'H12' or EMT.HEAD == 'H13' or EMT.HEAD == 'H8' then
EMT.TOOLSEL = 'M6 T' .. EMT.TCPOS:sub(3)
elseif EMT.HEAD == 'H21' then
EMT.TOOLSEL = 'M6 T1'
elseif EMT.HEAD == 'H22' then
EMT.TOOLSEL = 'M6 T2'
elseif EMT.HEAD == 'H23' then
EMT.TOOLSEL = 'M6 T3'
elseif EMT.HEAD == 'H24' then
EMT.TOOLSEL = 'M6 T4'
elseif EMT.HEAD == 'H25' then
EMT.TOOLSEL = 'M6 T5'
elseif EMT.HEAD == 'H31' then
EMT.TOOLSEL = 'M6 T1'
elseif EMT.HEAD == 'H32' then
EMT.TOOLSEL = 'M6 T2'
elseif EMT.HEAD == 'H33' then
EMT.TOOLSEL = 'M6 T3'
elseif EMT.HEAD == 'H34' then
EMT.TOOLSEL = 'M6 T4'
elseif EMT.HEAD == 'H35' then
EMT.TOOLSEL = 'M6 T5'
elseif EMT.HEAD == 'H41' then
EMT.TOOLSEL = 'M6 T1'
elseif EMT.HEAD == 'H42' then
EMT.TOOLSEL = 'M6 T' .. EgtNumToString( EMT.EXIT + 1, 0)
elseif EMT.HEAD == 'H43' then
EMT.TOOLSEL = 'M600 T' .. EgtNumToString( EMT.EXIT, 0)
elseif EMT.HEAD == 'H44' then
EMT.TOOLSEL = 'M610 T' .. EgtNumToString( EMT.EXIT, 0)
end
EMT.GROUP = EgtIf( EMT.HEAD == 'H8', 1, tonumber( EMT.HEAD:sub( 2, 2)))
-- imposto offset per testa
if EMT.HEAD == 'H11' or EMT.HEAD == 'H12' or EMT.HEAD == 'H13' or EMT.HEAD == 'H8' then
EmtSetAdditionalOrig( 0 + DistRif, 0, 0)
elseif EMT.HEAD == 'H21' then
EmtSetAdditionalOrig( -H21:getX() + DistRif, -H21:getY(), -H21:getZ())
elseif EMT.HEAD == 'H22' then
EmtSetAdditionalOrig( -H22:getX() + DistRif, -H22:getY(), -H22:getZ())
elseif EMT.HEAD == 'H23' then
EmtSetAdditionalOrig( -H23:getX() + DistRif, -H23:getY(), -H23:getZ())
elseif EMT.HEAD == 'H24' then
EmtSetAdditionalOrig( -H24:getX() + DistRif, -H24:getY(), -H24:getZ())
elseif EMT.HEAD == 'H25' then
EmtSetAdditionalOrig( -H25:getX() + DistRif, -H25:getY(), -H25:getZ())
elseif EMT.HEAD == 'H31' then
EmtSetAdditionalOrig( -H31:getX() + DistRif, -H31:getY(), -H31:getZ())
elseif EMT.HEAD == 'H32' then
EmtSetAdditionalOrig( -H32:getX() + DistRif, -H32:getY(), -H32:getZ())
elseif EMT.HEAD == 'H33' then
EmtSetAdditionalOrig( -H33:getX() + DistRif, -H33:getY(), -H33:getZ())
elseif EMT.HEAD == 'H34' then
EmtSetAdditionalOrig( -H34:getX() + DistRif, -H34:getY(), -H34:getZ())
elseif EMT.HEAD == 'H35' then
EmtSetAdditionalOrig( -H35:getX() + DistRif, -H35:getY(), -H35:getZ())
elseif EMT.HEAD == 'H41' then
EmtSetAdditionalOrig( -H41:getX() + DistRif, -H41:getY(), -H41:getZ())
elseif EMT.HEAD == 'H42' then
if EMT.EXIT == 1 then
EmtSetAdditionalOrig( -C4:getX() + DistRif, -C4:getY(), -H421:getZ())
elseif EMT.EXIT == 2 then
EmtSetAdditionalOrig( -C4:getX() + DistRif, -C4:getY(), -H422:getZ())
elseif EMT.EXIT == 3 then
EmtSetAdditionalOrig( -C4:getX() + DistRif, -C4:getY(), -H423:getZ())
elseif EMT.EXIT == 4 then
EmtSetAdditionalOrig( -C4:getX() + DistRif, -C4:getY(), -H424:getZ())
end
elseif EMT.HEAD == 'H43' then
if EMT.EXIT == 1 then
EmtSetAdditionalOrig( -H4301:getX() + DistRif, -H4301:getY(), -H4301:getZ())
elseif EMT.EXIT == 2 then
EmtSetAdditionalOrig( -H4302:getX() + DistRif, -H4302:getY(), -H4302:getZ())
elseif EMT.EXIT == 3 then
EmtSetAdditionalOrig( -H4303:getX() + DistRif, -H4303:getY(), -H4303:getZ())
elseif EMT.EXIT == 4 then
EmtSetAdditionalOrig( -H4304:getX() + DistRif, -H4304:getY(), -H4304:getZ())
elseif EMT.EXIT == 5 then
EmtSetAdditionalOrig( -H4305:getX() + DistRif, -H4305:getY(), -H4305:getZ())
elseif EMT.EXIT == 6 then
EmtSetAdditionalOrig( -H4306:getX() + DistRif, -H4306:getY(), -H4306:getZ())
elseif EMT.EXIT == 7 then
EmtSetAdditionalOrig( -H4307:getX() + DistRif, -H4307:getY(), -H4307:getZ())
elseif EMT.EXIT == 8 then
EmtSetAdditionalOrig( -H4308:getX() + DistRif, -H4308:getY(), -H4308:getZ())
elseif EMT.EXIT == 9 then
EmtSetAdditionalOrig( -H4309:getX() + DistRif, -H4309:getY(), -H4309:getZ())
elseif EMT.EXIT == 10 then
EmtSetAdditionalOrig( -H4310:getX() + DistRif, -H4310:getY(), -H4310:getZ())
elseif EMT.EXIT == 11 then
EmtSetAdditionalOrig( -H4311:getX() + DistRif, -H4311:getY(), -H4311:getZ())
end
elseif EMT.HEAD == 'H44' then
if EMT.EXIT == 1 then
EmtSetAdditionalOrig( -H441:getX() + DistRif, -H441:getY(), -H441:getZ())
elseif EMT.EXIT == 2 then
EmtSetAdditionalOrig( -H442:getX() + DistRif, -H442:getY(), -H442:getZ())
elseif EMT.EXIT == 3 then
EmtSetAdditionalOrig( -H443:getX() + DistRif, -H443:getY(), -H443:getZ())
end
end
end
end
---------------------------------------------------------------------
function OnToolDeselect()
if bNotProcCN then return end
-- spegnimento mandrino
EmitSpeedOff()
-- se cambia testa o utensile
local sRotAxes = ''
if EMT.HEAD ~= EMT.NEXTHEAD or EMT.TCPOS ~= EMT.NEXTTCPOS then
-- eventuale rotazione in home
if EMT.R1n and EMT.GROUP ~= 2 and EMT.GROUP ~= 3 then
local nR1h = EgtGetAxisHomePos( EMT.R1n)
-- su richiesta di Loris, disabilito la rotazione in Home del gruppo 4
if abs( EMT.R1 - nR1h) > GEO.EPS_ANG_SMALL and EMT.GROUP ~= 4 then
sRotAxes = ' ' .. EMT.R1t .. EgtNumToString( nR1h, 3)
end
end
if EMT.R2n then
local nR2h = EgtGetAxisHomePos( EMT.R2n)
if abs( EMT.R2 - nR2h) > GEO.EPS_ANG_SMALL then
sRotAxes = ' ' .. EMT.R2t .. EgtNumToString( nR2h, 3)
end
end
if #sRotAxes > 0 then
EmtOutput( 'G0 G79'..sRotAxes, EMT.GROUP)
end
-- se gruppo 1 porto Y in home
if EMT.GROUP == 1 then
local nL2h = EgtGetAxisHomePos( EMT.L2n)
local sAxes = ' ' .. EMT.L2t .. EmtLenToString( nL2h, 3)
EmtOutput( 'G0 G79'..sAxes, EMT.GROUP)
end
end
-- se gruppi 2 o 3 e cambia testa, vado in Yhome (token Z)
if ( EMT.GROUP == 2 or EMT.GROUP == 3) and EMT.HEAD ~= EMT.NEXTHEAD then
EmtOutput( 'G0 G79 Z0', EMT.GROUP)
end
-- se gruppi 2 o 3 e utensile probe, scrivo istruzioni fine salto
if ( EMT.GROUP == 2 or EMT.GROUP == 3) and
string.find( string.upper(EMT.TOOL), 'PROBE') then
EmtOutput( '"EE'..EgtNumToString(nCountShuttlelav,0)..'"', EMT.GROUP)
end
-- salvo testa corrente come precedente
EMT.PREVHEAD = EMT.HEAD
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnMachiningStart()
if bNotProcCN then return end
EMT.MCHNAME = EgtGetMachiningParam( MCH_MP.NAME)
EMT.MCHTYPE = EgtGetMachiningParam( MCH_MP.TYPE)
local sNotes = EgtGetMachiningParam( MCH_MP.USERNOTES)
-- se processo P1 e chiamata/e di P4 in sospeso, eseguo
if EMT.GROUP == 1 and EMT.P1CALLP4 then
for i = 1, #EMT.P1CALLP4 do
local bNoMach
local sFilter = EMT.P1CALLP4[i]
-- se trovo il prefisso NOMACH filtro la stringa prima di scriverla
if sFilter:find( 'NOMACH', 1, true) then
sFilter = string.sub( sFilter, 7)
bNoMach = true
end
EmtOutput( sFilter, 1)
if i == 1 and not bWriteFirstJump then
EmtOutput( '(GTO,DD3)', 1)
EmtOutput( '"DD1"', 1)
end
if not bNoMach then
EmtOutput( 'E100=' .. EMT.TCPOS:sub(3), 1)
end
if i == 1 and not bWriteFirstJump then
EmtOutput( '(GTO,DD2)', 1)
EmtOutput( '"DD3"', 1)
bWriteFirstJump = true
end
if not bNoMach then
EmtOutput( '#(CLS,P1CALLP4)', 1)
end
end
EMT.P1CALLP4 = nil
elseif EMT.GROUP == 1 then
if #sPos5aHead == 0 then
sPos5aHead = 'E105=' .. EMT.TCPOS:sub(3)
end
end
-- se lav. su proc. P1 o P4 e navette in attesa di start
if ( EMT.GROUP == 1 or EMT.GROUP == 4) and not EMT.SHUTTLE_ON then
-- se la lavorazione non inibisce la partenza delle navette
if not sNotes or not sNotes:find( 'NO_SHUTTLE', 1, true) then
EmitShuttleRun()
end
end
-- se lav. su proc. P1
EMT.USEHOODNOTE = nil
if EMT.GROUP == 1 then
if sNotes then
if sNotes:find( 'HALF_NR_HOOD', 1, true) then -- se trovato parametro apertura parte stretta cuffia (parte di destra)
EMT.USEHOODNOTE = 3
elseif sNotes:find( 'HALF_WD_HOOD', 1, true) then -- se trovato parametro apertura parte larga cuffia (parte di sinistra)
EMT.USEHOODNOTE = 2
elseif sNotes:find( 'OPEN_HOOD', 1, true) then -- se trovato parametro apertura di tutta la cuffia
EMT.USEHOODNOTE = 1
elseif sNotes:find( 'CLOSE_HOOD', 1, true) then -- se trovato parametro apertura di tutta la cuffia
EMT.USEHOODNOTE = 4
end
end
end
-- recupero ingombro della lavorazione rispetto allo zero tavola
b3Lav = EgtGetBBoxGlob( EgtGetFirstNameInGroup( EMT.MCHID or GDB_ID.NULL, 'CL'), GDB_BB.STANDARD)
if not b3Lav or b3Lav:isEmpty() then
error( "Machining without BBox")
end
b3Lav:move( - Vector3d( TabX, TabY, TabZ))
-- per le navette, emetto opportuno ingombro e richiesta accupazione area
if EMT.GROUP == 2 then
-- se sono su una tastatura scrivo istruzioni per il salto
if string.find( string.upper(EMT.TOOL), 'PROBE') then
nCountShuttlelav = nCountShuttlelav + 1
EmtOutput( '(GTO,EE'.. EgtNumToString(nCountShuttlelav,0)..',L1005=0)' , EMT.GROUP)
end
-- 22_02_2018 inserito calcolo per portare il valore di ingombro lavorazione di E35 sulla testa 2
-- (quella più lontana dallo shuttle opposto) dello shuttle 1
local dOffsToHeadH22 = 0
if bEnMacBoxOnShExtremHeads then
if EMT.HEAD == 'H21' then
dOffsToHeadH22 = H22:getX()-H21:getX()
elseif EMT.HEAD == 'H23' then
dOffsToHeadH22 = H22:getX()-H23:getX()
elseif EMT.HEAD == 'H24' then
dOffsToHeadH22 = H22:getX()-H24:getX()
elseif EMT.HEAD == 'H25' then
dOffsToHeadH22 = H22:getX()-H25:getX()
end
end
EmtOutput( '#E35=' .. EmtLenToString( ( b3Lav:getMax():getX() + dOffsToHeadH22), 3), EMT.GROUP)
EmtOutput( '#(CLS,P2CHK)', EMT.GROUP)
elseif EMT.GROUP == 3 then
-- se sono su una tastatura scrivo istruzioni per il salto
if string.find( string.upper(EMT.TOOL), 'PROBE') then
nCountShuttlelav = nCountShuttlelav + 1
EmtOutput( '(GTO,EE'.. EgtNumToString(nCountShuttlelav,0)..',L1005=0)' , EMT.GROUP)
end
-- 22_02_2018 inserito calcolo per portare il valore di ingombro lavorazione di E35 sulla testa 1
-- (quella più lontana dallo shuttle opposto) dello shuttle 2
local dOffsToHeadH31 = 0
if bEnMacBoxOnShExtremHeads then
if EMT.HEAD == 'H32' then
dOffsToHeadH31 = H31:getX()-H32:getX()
elseif EMT.HEAD == 'H33' then
dOffsToHeadH31 = H31:getX()-H33:getX()
elseif EMT.HEAD == 'H34' then
dOffsToHeadH31 = H31:getX()-H34:getX()
elseif EMT.HEAD == 'H35' then
dOffsToHeadH31 = H31:getX()-H35:getX()
end
end
EmtOutput( '#E35=' .. EmtLenToString( ( b3Lav:getMin():getX() + dOffsToHeadH31), 3), EMT.GROUP)
EmtOutput( '#(CLS,P3CHK)', EMT.GROUP)
end
-- preselezione utensile solo su gruppo 4
PreEmitTool()
-- emetto dati lavorazione
EmtOutput( ';'..EMT.MCHNAME..'/'..EMT.TOOL, EMT.GROUP)
-- se processo P4, P1 deve lanciare P4 e questi deve attendere ok da P1
if EMT.GROUP == 4 then
if not EMT.P1CALLP4 then EMT.P1CALLP4 = {} end
local sLines = ';'..EMT.MCHNAME..'/'..EMT.TOOL
-- se richiede rulliera alta e non è tale, la alzo
if sNotes and sNotes:find( 'ROLLER_UP', 1, true) and not EMT.WINSTART then
sLines = sLines ..'\r\n#(CLS,WINSTART)'
EMT.WINSTART = true
-- se altrimenti alta e non da tenere alta, la abbasso
elseif sNotes and not sNotes:find( 'ROLLER_UP', 1, true) and EMT.WINSTART then
sLines = sLines ..'\r\n#(CLS,WINSTOP)'
EMT.WINSTART = nil
end
table.insert( EMT.P1CALLP4, sLines)
-- if EMT.PREVGROUP ~= 4 then
EmtOutput( '#(CLS,P4WAITP1)', 4)
-- end
end
-- se processo P1
if EMT.GROUP == 1 then
-- se richiede rulliera alta e non è tale, la alzo
if sNotes and sNotes:find( 'ROLLER_UP', 1, true) and not EMT.WINSTART then
EmtOutput( '#(CLS,WINSTART)', EMT.GROUP)
EMT.WINSTART = true
-- se altrimenti alta e non da tenere alta, la abbasso
elseif sNotes and not sNotes:find( 'ROLLER_UP', 1, true) and EMT.WINSTART then
EmtOutput( '#(CLS,WINSTOP)', EMT.GROUP)
EMT.WINSTART = nil
end
end
-- non ancora iniziata la lavorazione
EMT.MCHFIRST = true
EMT.PREVGROUP = EMT.GROUP
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnMachiningEnd()
if bNotProcCN then return end
-- se attivo DANGER, lo termino
if EMT.DANGER then
-- se gruppo 4 e non sono ancora risalito, salgo in Z.
-- N.B. in ogni caso il cambio utensile fa risalire lo stesso in Z la testa
if EMT.GROUP == 4 and not bZMaxG4 then
EmtOutput( 'G0 G79 Z0', EMT.GROUP)
bZMaxG4 = false
end
EmtOutput( '#(CLS,ENDDAN)', EMT.GROUP)
EMT.DANGER = nil
end
-- se processo P2, dichiaro fine necessità occupazione
if EMT.GROUP == 2 then
EmtOutput( '#(CLS,P2ENDCHK)', 2)
-- se processo P3, dichiaro fine necessità occupazione
elseif EMT.GROUP == 3 then
EmtOutput( '#(CLS,P3ENDCHK)', 3)
-- se processo P4, devo ritornare a P1
elseif EMT.GROUP == 4 then
EmtOutput( '#(CLS,P4RETP1)', 4)
end
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnPathStart()
if bNotProcCN then return end
-- per le lavorazioni con le teste del carro X, verifico se interferiscono con le navette solo se sono avviate
if EMT.PATHIND == 1 and ( EMT.GROUP == 1 or EMT.GROUP == 4) and EMT.SHUTTLE_ON then
-- se lavorazioni verticali
if EMT.EXTR[3] > SIN_DIR_VERT_APPROX then
if ( EMT.PMIN[2] - TabY) < SAFE_DIST_VERTLAV then
--EmtOutput( '#L83=1', EMT.GROUP) -- disabilitato su richiesta CV on 05/02/2018
EmtOutput( '#(CLS,DANGER)', EMT.GROUP)
EMT.DANGER = true
end
-- altrimenti lavorazioni orizzontali
else
-- lato serratura
if EMT.EXTR[2] > 0.5 then
-- non serve impostare area pericolosa
-- lato cerniere
elseif EMT.EXTR[2] < - 0.5 then
-- richiesto sempre parcheggio esterno
--EmtOutput( '#L83=1', EMT.GROUP) -- disabilitato su richiesta CV on 05/02/2018
EmtOutput( '#(CLS,DANGER)', EMT.GROUP)
EMT.DANGER = true
-- lato sinistro
elseif EMT.EXTR[1] < - 0.5 then
if ( EMT.HEAD == 'H11' and ( EMT.PMIN[2] - TabY) < SAFE_DIST_HORIZLAV_A) or
( EMT.HEAD == 'H42' and ( EMT.PMIN[2] - TabY) < SAFE_DIST_HORIZLAV_B) then
--EmtOutput( '#L83=2', EMT.GROUP) -- disabilitato su richiesta CV on 05/02/2018
EmtOutput( '#(CLS,DANGER_L)', EMT.GROUP)
EMT.DANGER = true
end
-- lato destro
elseif EMT.EXTR[1] > 0.5 then
if ( EMT.PMIN[2] - TabY) < SAFE_DIST_HORIZLAV_A then
--EmtOutput( '#L83=1', EMT.GROUP) -- disabilitato su richiesta CV on 05/02/2018
EmtOutput( '#(CLS,DANGER_R)', EMT.GROUP)
EMT.DANGER = true
end
end
end
end
-- se testa 5 assi con testa H11 ( no aggregati) rilevo lunghezza utensile e elevazione
EMT.USEHOOD = nil
EMT.USEHOODBYANGLE = 0
if EMT.GROUP == 1 and ( EMT.HEAD == 'H11' or EMT.HEAD == 'H12' or EMT.HEAD == 'H13' or EMT.HEAD == 'H8') then
if EMT.HEAD == 'H11' and EMT.ELEV and sDisableHood ~= '1' then
local dToolLength = EgtTdbGetCurrToolParam( MCH_TP.LEN)
-- uso cuffia, inteso se uso ( risulta true) si allora cuffia chiusa, se non uso (risulta false) allora cuffia aperta
EMT.USEHOOD = ( dToolLength - EMT.ELEV > dMinDistNewHood) or EMT.EXTR[3] < 0.707
-- 2019/02/21 per verificare il superamento dell'angolo limite anche con uso cuffia dalle note lavorazione
-- setto la variabile EMT.USEHOODBYANGLE a 1 se devo forzare la chiusura della cuffia
EMT.USEHOODBYANGLE = EgtIf( EMT.EXTR[3] < 0.707, 1, 0) -- setto a 1 (forzo cuffia chiusa) se testa va troppo in orizzontale
else
EMT.USEHOOD = false -- cuffia aperta
end
end
-- reset valori precedenti (per forzare emissione di tutti gli assi del 1° movimento)
EmtResetPrev()
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnPathEnd()
if bNotProcCN then return end
-- se non ancora tolto piano interpolazione locale
if EMT.IPLGL then
EMT.IPLGL = false
EmtResetPrevLinear()
EmtOutput('(DAN)', EMT.GROUP)
EmtOutput('(UPR)', EMT.GROUP)
EmtOutput( GetUOT( 0, 0, 0), EMT.GROUP)
end
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnRapid()
if bNotProcCN then return end
EmtAdjustLinearAxes()
EmtAdjustRotaryAxes()
AdjustForShuttle()
AdjustForChisel()
-- se standard
if EMT.FLAG == 0 or EMT.FLAG == 1 or EMT.FLAG == 2 then
-- se primo movimento della lavorazione, gestione speciale
if EMT.MCHFIRST then
-- selezione utensile e avvio rotazione
EmitToolAndSpeed()
-- Se rinvio da sotto e appena cambiato
if ( EMT.HEAD == 'H12' or EMT.HEAD == 'H13') and EMT.HEAD ~= EMT.PREVHEAD then
-- porto Y in home
local nL2h = EgtGetAxisHomePos( EMT.L2n)
local sAxes = ' ' .. EMT.L2t .. EmtLenToString( nL2h, 3)
EmtOutput( 'G0 G79'..sAxes, EMT.GROUP)
-- porto asse A a - 37.5
EmtOutput( 'G0 G79 A-37.5', EMT.GROUP)
end
-- annullamento correttore ed emissione piano di interpolazione
EmtOutput( 'h0', EMT.GROUP)
EmitInterpPlane()
if EMT.GROUP == 4 then -- se gruppo 1 e 4 muovo gli assi XY assieme agli assi rotanti
-- movimento assi lineari in XY e eventuali assi rotanti
local sLinRotAxes = EmtGetRapidAxis('L1')..EmtGetRapidAxis('L2')..EmitRotAxeR1()..EmtGetRapidAxis('R2')
if #sLinRotAxes > 0 then
EmtOutput( "G0"..sLinRotAxes, EMT.GROUP)
end
-- movimento eventuali assi rotanti e Z
local sLinAxes = EmtGetRapidAxis('L3')
if #sLinAxes > 0 then
EmtOutput( "G0"..sLinAxes, EMT.GROUP)
end
else -- se altri gruppi faccio i movimenti standard
-- movimento soli assi lineari in XY
local sLinAxes = EmtGetRapidAxis('L1')..EmtGetRapidAxis('L2')
if #sLinAxes > 0 then
--if EMT.QVAL then
-- sLinAxes = sLinAxes..' Q'.. EmtLenToString(EMT.QVAL,3)
-- EMT.QRET = EMT.QVAL + 50
-- EMT.QVAL = nil
--end
EmtOutput( "G0"..sLinAxes, EMT.GROUP)
end
-- movimento eventuali assi rotanti e Z
local sRotAxes = EmtGetRapidAxis('L3')..EmitRotAxeR1()..EmtGetRapidAxis('R2')
if #sRotAxes > 0 then
EmtOutput( "G0"..sRotAxes, EMT.GROUP)
end
end
EMT.MCHFIRST = false
-- caso standard
else
local sAxes = EmtGetRapidAxis('L1')..EmtGetRapidAxis('L2')..EmtGetRapidAxis('L3')..
EmitRotAxeR1()..EmtGetRapidAxis('R2')
if #sAxes > 0 then
--if EMT.QVAL then
-- sAxes = sAxes..' Q'.. EmtLenToString(EMT.QVAL,3)
-- EMT.QRET = EMT.QVAL + 50
-- EMT.QVAL = nil
--end
EmtOutput( "G0"..sAxes, EMT.GROUP)
end
end
-- se rapido sopra inizio e piano locale
if EMT.FLAG == 1 and EMT.IPLGLFR then
for i = 1, #EMT.IPLGLSTR do
EmtOutput( EMT.IPLGLSTR[i], EMT.GROUP)
end
EMT.IPLGL = true
EmtResetPrevLinear()
end
-- se altrimenti risalita a Z max a fine lavorazione
elseif EMT.FLAG == 3 then
-- tolgo piano di interpolazione locale
if EMT.IPLGL then
EMT.IPLGL = false
EmtResetPrevLinear()
EmtOutput('(DAN)', EMT.GROUP)
EmtOutput('(UPR)', EMT.GROUP)
EmtOutput( GetUOT( 0, 0, 0), EMT.GROUP)
end
-- risalita compresa eventuale cuffia
local sAxes = EmtGetHomeAxis('L3')..EmtGetHomeAxis('R2')
if #sAxes > 0 then
--if EMT.QRET then
-- sAxes = sAxes..' Q'.. EmtLenToString(EMT.QRET,3)
-- EMT.QRET = nil
--end
EmtOutput( 'G0 G79'..sAxes, EMT.GROUP)
end
if EMT.GROUP == 4 then bZMaxG4 = true end
-- se altrimenti movimento in Home (non si muove la X)
elseif EMT.FLAG == 4 then
local sAxes = EmtGetHomeAxis('L2')..EmtGetHomeAxis('L3')..EmitRotAxeR1()..
EmtGetHomeAxis('R2')
EmtOutput( 'G0 G79'..sAxes, EMT.GROUP)
if EMT.GROUP == 4 then bZMaxG4 = true end
-- altrimenti errore
else
error( "Unknown Rapid flag")
end
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnLinear()
if bNotProcCN then return end
EmtAdjustLinearAxes()
EmtAdjustRotaryAxes()
AdjustForShuttle()
AdjustForChisel()
-- valori degli assi
local sAxes = EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3')..
EmitRotAxeR1()..EmtGetAxis('R2')
-- se nulla da emettere, esco
if #sAxes == 0 then
return
end
-- aggiungo feed
local sFeed = EmtGetFeed()
-- emetto linea
EmtOutput( "G1" .. sAxes .. sFeed, EMT.GROUP)
-- eventuale gestione fondo foro
if EMT.FLAG == 101 then
if EMT.HEAD == 'H25' or EMT.HEAD == 'H35' and
string.find( string.upper(EMT.TOOL), 'PROBE') then
EmtOutput( 'M820', EMT.GROUP)
else
EmtOutput( '(DLY,0.1)', EMT.GROUP)
end
end
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function OnArc()
if bNotProcCN then return end
-- non modale su archi
EmtResetPrevLinear()
-- valori degli assi
EmtAdjustLinearAxes()
EmtAdjustRotaryAxes()
AdjustForShuttle()
AdjustForChisel()
local sAxes = EmtGetAxis( 'L1')..EmtGetAxis( 'L2')..EmtGetAxis( 'L3')..
EmitRotAxeR1()..EmtGetAxis( 'R2')
-- se nulla da emettere, esco
if #sAxes == 0 then
return
end
-- valori delle coordinate del centro
EmtAdjustCenterAxes()
-- coordinate centro (per ora solo archi nel piano XY)
--local sCen = ' ' .. EMT.C1t .. EmtLenToString(EMT.C1,3) ..
-- ' ' .. EMT.C2t .. EmtLenToString(EMT.C2,3)
-- raggio
local sRad = ' ' .. EMT.RRt .. EmtLenToString(EMT.RR,3)
-- aggiungo feed
local sFeed = EmtGetFeed()
-- tipo arco
local nMove = EmtGetArcType( EMT.MOVE, EMT.IPLSX)
local sArc = 'G' .. EgtNumToString(nMove,0)
-- emetto arco
EmtOutput( sArc .. sAxes .. sRad .. sFeed, EMT.GROUP)
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
function GetUOT( dX, dY, dZ)
local sUot
sUot = '(UOT,2,X'..EmtLenToString(dX,3)..',Y'..EmtLenToString(dY,3)..',Z'..EmtLenToString(dZ,3)..')'
return sUot
end
---------------------------------------------------------------------
function EmitInterpPlane()
-- Reset piano globale di interpolazione
EMT.IPLGLFR = nil
-- Imposto piano di interpolazione
EMT.IPLSX = false
-- Caso standard (riferimento XYZ come globale)
if EMT.GROUP ~= 2 and EMT.GROUP ~= 3 then
local vtE = Vector3d( EMT.EXTR)
-- a seconda del piano di interpolazione (tagli di lama sempre nel piano top e testa 42.2)
if vtE:isSmall() or AreSameVectorApprox( vtE, Z_AX()) or EMT.MCHTYPE == MCH_MY.SAWING or
(EMT.HEAD == 'H42' and EMT.EXIT == 2) or EMT.HEAD == 'H44' then
EmtOutput( 'G16 '..EMT.L1t..EMT.L2t, EMT.GROUP)
EmtOutput( '(AXO,-'..EMT.L3t..')', EMT.GROUP)
elseif AreSameVectorApprox( vtE, - Z_AX()) then
EmtOutput( 'G16 '..EMT.L1t..EMT.L2t, EMT.GROUP)
EmtOutput( '(AXO,'..EMT.L3t..')', EMT.GROUP)
EMT.IPLSX = true
elseif AreSameVectorApprox( vtE, X_AX()) then
EmtOutput( 'G16 '..EMT.L2t..EMT.L3t, EMT.GROUP)
EmtOutput( '(AXO,-'..EMT.L1t..')', EMT.GROUP)
elseif AreSameVectorApprox( vtE, - X_AX()) then
EmtOutput( 'G16 '..EMT.L2t..EMT.L3t, EMT.GROUP)
EmtOutput( '(AXO,'..EMT.L1t..')', EMT.GROUP)
EMT.IPLSX = true
elseif AreSameVectorApprox( vtE, Y_AX()) then
EmtOutput( 'G16 '..EMT.L3t..EMT.L1t, EMT.GROUP)
EmtOutput( '(AXO,-'..EMT.L2t..')', EMT.GROUP)
elseif AreSameVectorApprox( vtE, - Y_AX()) then
EmtOutput( 'G16 '..EMT.L3t..EMT.L1t, EMT.GROUP)
EmtOutput( '(AXO,'..EMT.L2t..')', EMT.GROUP)
EMT.IPLSX = true
else
-- emetto subito piano globale
EmtOutput( 'G16 '..EMT.L1t..EMT.L2t, EMT.GROUP)
EmtOutput( '(AXO,-'..EMT.L3t..')', EMT.GROUP)
if bEmitUprOnGenPlane then
local ptS = Point3d( EMT.START)
if EMT.USETO1 then
ptS[1] = ptS[1] - EMT.TABORI1[1] - EMT.ADDORI[1]
ptS[2] = ptS[2] - EMT.TABORI1[2] - EMT.ADDORI[2]
ptS[3] = ptS[3] - EMT.TABORI1[3] - EMT.ADDORI[3]
end
-- stampa di debug
--local sStart = ';Start='..EmtNum3ToString( ptS, 3)
--EmtOutput( sStart)
-- calcolo per piano generico da emettere a vero inizio lavorazione
EMT.IPLGLFR = Frame3d( ptS, vtE)
local _, dAngV, dAngO = SphericalFromVector( vtE)
local dAngO2 = EmtGetAngO2( EMT.IPLGLFR:getVersZ(), EMT.IPLGLFR:getVersX(), dAngV, dAngO)
EMT.IPLGLSTR = { GetUOT( ptS:getX(), ptS:getY(), ptS:getZ()),
'(UPR,0,'..EMT.L1t..EMT.L2t..EMT.L3t..',UVW,0,0,'..EgtNumToString(dAngO,3)..')',
'(UPR,1,'..EMT.L1t..EMT.L2t..EMT.L3t..',UVW,0,'..EgtNumToString(dAngV,3)..','..'0)',
'(UPR,1,'..EMT.L1t..EMT.L2t..EMT.L3t..',UVW,0,0,'..EgtNumToString(dAngO2,3)..')',
'(DAN,'..EMT.L1t..'U,'..EMT.L2t..'V,'..EMT.L3t..'W)',
'G16 '..EMT.L1t..EMT.L2t,
'(AXO,-'..EMT.L3t..')'}
EMT.IPLGL = false
EMT.IPLSX = false
--for i = 1, #EMT.IPLGLSTR do
-- EmtOutput( EMT.IPLGLSTR[i])
--end
end
end
-- Speciale per shuttle P3 e P4 (riferimento con X standard, Y come Z e Z come Y-)
else
EmtOutput( 'G16 '..EMT.L1t..EMT.L3t, EMT.GROUP)
EmtOutput( '(AXO,-'..EMT.L2t..')', EMT.GROUP)
end
end
---------------------------------------------------------------------
function AdjustForChisel()
-- se la testa non è la chisel esco subito
if EMT.HEAD ~= 'H44' then return end
-- non emetto l'asse rotante
EMT.R1t = nil
end
---------------------------------------------------------------------
function AdjustForShuttle()
-- se non sono nei gruppi delle navette, esco
if EMT.GROUP ~= 2 and EMT.GROUP ~= 3 then return end
-- non emetto l'asse rotante
EMT.R1t = nil
-- inverto il secondo asse lineare
if EMT.L2 then
EMT.L2 = - EMT.L2
end
end
---------------------------------------------------------------------
function EmitToolAndSpeed()
if EMT.GROUP == 1 then
-- se tipo utensile chisel emetto il codice soffiatura
if EMT.TOOLTYPE == 4096 then
EmtOutput( 'L120=1', EMT.GROUP)
end
EmtOutput( EMT.TOOLSEL, EMT.GROUP)
if EMT.USEHOODNOTE then -- se ho delle note nella lavorazione utilizzo quelle
if EMT.USEHOODNOTE == 3 then -- se utilizzo apertura parte stretta cuffia (parte di destra)
if EMT.USEHOODBYANGLE == 1 then -- se per angolo eccessivo dalla verticale forza chiusura cuffia
EmtOutput( 'M304', EMT.GROUP) -- chiusura cuffia
else
EmtOutput( 'M303', EMT.GROUP)
end
elseif EMT.USEHOODNOTE == 2 then -- se utilizzo apertura parte larga cuffia (parte di sinistra)
if EMT.USEHOODBYANGLE == 1 then -- se per angolo eccessivo dalla verticale forza chiusura cuffia
EmtOutput( 'M304', EMT.GROUP) -- chiusura cuffia
else
EmtOutput( 'M302', EMT.GROUP)
end
elseif EMT.USEHOODNOTE == 1 then -- se utilizzo apertura completa cuffia
if EMT.USEHOODBYANGLE == 1 then -- se per angolo eccessivo dalla verticale forza chiusura cuffia
EmtOutput( 'M304', EMT.GROUP) -- chiusura cuffia
else
EmtOutput( 'M301', EMT.GROUP)
end
elseif EMT.USEHOODNOTE == 4 then -- se utilizzo chiusura completa cuffia
-- controllo in ogni caso che ci sia la sicurezza di discesa
if EMT.USEHOOD ~= nil then
-- se flag true chiudo la cuffia se falso apro la cuffia
EmtOutput( EgtIf( EMT.USEHOOD, 'M304', 'M301'), EMT.GROUP)
else -- se non ho il controllo profondità applico il codice delle note
EmtOutput( 'M304', EMT.GROUP) -- chiusura cuffia
end
end
else -- altrimenti se c'è utilizzo la verifica profondità
if EMT.USEHOOD ~= nil then
-- se flag true chiudo la cuffia se falso apro la cuffia
EmtOutput( EgtIf( EMT.USEHOOD, 'M304', 'M301'), EMT.GROUP)
end
end
EmitSpeed()
-- posizione sicura per rinvii da sotto
--if EMT
elseif EMT.GROUP == 2 or EMT.GROUP == 3 then
local sSpeed = ' S' .. EgtNumToString( abs( EMT.S), 0) .. EgtIf( EMT.S > 0, ' R0', ' R1')
local vtE = Vector3d( EMT.EXTR)
local sAxA = EgtIf( abs( vtE[3]) < GEO.EPS_ANG_SMALL, ' A0', EgtIf( vtE[3] > 0, ' A-3', ' A3'))
if EMT.HEAD == 'H24' or EMT.HEAD == 'H25' or
EMT.HEAD == 'H34' or EMT.HEAD == 'H35' then -- se testa chisel non emetto la speed
EmtOutput( EMT.TOOLSEL .. sAxA, EMT.GROUP)
else
EmtOutput( EMT.TOOLSEL .. sSpeed .. sAxA, EMT.GROUP)
end
elseif EMT.GROUP == 4 then
if EMT.HEAD == 'H41' or EMT.HEAD == 'H42' then
local sSpeed = ' S' .. EgtNumToString( abs( EMT.S), 0) .. EgtIf( EMT.S > 0, ' R0', ' R1')
EmtOutput( EMT.TOOLSEL .. sSpeed, EMT.GROUP)
elseif EMT.HEAD == 'H43' then
-- non emetto speed
EmtOutput( EMT.TOOLSEL, EMT.GROUP)
elseif EMT.HEAD == 'H44' then
local vtE = Vector3d( EMT.EXTR)
local sAxA = EgtIf( abs( vtE[3]) < GEO.EPS_ANG_SMALL, ' A0', EgtIf( vtE[3] > 0, ' A-3', ' A3'))
-- non emetto speed
EmtOutput( EMT.TOOLSEL .. sAxA, EMT.GROUP)
end
end
end
---------------------------------------------------------------------
function PreEmitTool()
if EMT.GROUP == 4 then
local sPreSel = EMT.TOOLSEL
if EMT.HEAD == 'H41' or EMT.HEAD == 'H42' then
sPreSel = sPreSel:gsub('M6 ', 'M6[80] ')
EmtOutput( sPreSel, EMT.GROUP)
elseif EMT.HEAD == 'H43' then
sPreSel = sPreSel:gsub('M600 ', 'M600[80] ')
-- non emetto speed
EmtOutput( sPreSel, EMT.GROUP)
elseif EMT.HEAD == 'H44' then
sPreSel = sPreSel:gsub('M610 ', 'M610[80] ')
-- non emetto speed
EmtOutput( sPreSel, EMT.GROUP)
end
end
end
---------------------------------------------------------------------
function EmitSpeed()
-- sistemazione rotazione per rinvii
local Speed = EMT.S
-- se valore assoluto maggiore di un minimo allora emetto effettiva rotazione
if abs(Speed) > 2 then
-- avvio rotazione
if Speed > 0 then
EmtOutput( 'M3 [1,' .. EgtNumToString( Speed, 0) .. ']', EMT.GROUP)
else
EmtOutput( 'M4 [1,' .. EgtNumToString( -Speed, 0) .. ']', EMT.GROUP)
end
else -- altrimenti se vicino allo zero emetto nessuna rotazione
EmtOutput( 'M5' , EMT.GROUP)
end
end
---------------------------------------------------------------------
function EmitSpeedOff()
-- arresto rotazione
EmtOutput( 'M5 [80]', EMT.GROUP)
end
---------------------------------------------------------------------
function EmitMeasUnit()
if EMT.INCHES then
EmtOutput( 'L55=70 ;ALL PROG INCH', 1)
EmtOutput( 'G70', 1)
else
EmtOutput( 'L55=71 ;ALL PROG MM', 1)
EmtOutput( 'G71', 1)
end
end
---------------------------------------------------------------------
function EmitInit( nSideDisp, dExtraYPos, dDoorProbeErrorY)
EmitMeasUnit()
-- emetto variabile che indice dove è riferita (0: a destra, 1: a sinistra)
if nSideDisp > 0 then -- se Porta in battuta a sinistra
EmtOutput( ';', 1)
EmtOutput( 'L117=1 ; door to left reference', 1)
else
EmtOutput( ';', 1)
EmtOutput( 'L117=0 ; door to right reference', 1)
end
EmtOutput( ';', 1)
EmtOutput( 'L122=' .. EmtLenToString( dExtraYPos, 3) .. ' ; Extra Y Position with profiles (bevel, bullnose,convex)', 1)
EmtOutput( 'L123=' .. EmtLenToString( dDoorProbeErrorY, 3) .. ' ; Door probe error on profiles (bevel, bullnose, convex)', 1)
EmtOutput( ';', 1)
EmtOutput( '#(CLS,INIT)', 1)
EmtOutput( ';', 1)
end
---------------------------------------------------------------------
function EmitMobile()
-- Emetto la posizione della barra mobile con le ventose
local dMobVal = EgtGetInfo( EMT.DISPID, 'MOB', 'd')
EmtOutput( 'L50=' .. EmtLenToString( dMobVal, 3), 1)
end
---------------------------------------------------------------------
function EmitPusher( nSideDisp)
-- Emissione dipendente dalla lunghezza
if nSideDisp and nSideDisp > 0 then -- se Porta in battuta a sinistra
if b3Raw:getDimX() < 480 then
EmtOutput( 'L51=0', 1)
elseif b3Raw:getDimX() < 700 then
EmtOutput( 'L51=1', 1)
elseif b3Raw:getDimX() < 1450 then
EmtOutput( 'L51=3', 1)
elseif b3Raw:getDimX() < 2600 then
EmtOutput( 'L51=7', 1)
elseif b3Raw:getDimX() < 2820 then
EmtOutput( 'L51=15', 1)
else
EmtOutput( 'L51=31', 1)
end
else
-- Porta in battuta a destra
if b3Raw:getDimX() < 350 then
EmtOutput( 'L51=0', 1)
elseif b3Raw:getDimX() < 600 then
EmtOutput( 'L51=16', 1)
elseif b3Raw:getDimX() < 1520 then
EmtOutput( 'L51=24', 1)
elseif b3Raw:getDimX() < 1990 then
EmtOutput( 'L51=28', 1)
elseif b3Raw:getDimX() < 2440 then
EmtOutput( 'L51=30', 1)
else
EmtOutput( 'L51=31', 1)
end
end
end
---------------------------------------------------------------------
function EmitVacuum()
local nVal = 0
local nW = 1
for nInd = 1, 13 do
local dVacOn = EgtGetInfo( EMT.DISPID, 'VAC'..tostring( nInd), 'd')
if dVacOn then
nVal = nVal + nW
end
nW = nW * 2
end
EmtOutput( 'L52=' .. EgtNumToString( nVal, 0), 1)
end
---------------------------------------------------------------------
function EmitRefType()
end
---------------------------------------------------------------------
function EmitProcStart()
local _, sName, sExt = EgtSplitPath( EMT.FILE)
sName = sName:upper()
sExt = sExt:upper()
EmtOutput( 'LS12="' .. sName .. '_2' .. sExt .. '"', 1)
EmtOutput( 'LS13="' .. sName .. '_3' .. sExt .. '"', 1)
EmtOutput( 'LS14="' .. sName .. '_4' .. sExt .. '"', 1)
EmtOutput( '(EXE,?LS12,P2)', 1)
EmtOutput( '(EXE,?LS13,P3)', 1)
EmtOutput( '(EXE,?LS14,P4)', 1)
EmtOutput( ';', 1)
end
---------------------------------------------------------------------
function EmitShuttleRun( bForceEmit)
if bNotProcCN then return end
if bForceEmit then
EmtOutput( ';', 1)
EmtOutput( '#(CLS,P1STARTSH)', 1)
else
-- se gruppo 4 e ho la tabella delle lavorazioni non vuota
-- invece di scrivere lo start degli shuttle nel processo 1 lo metto in coda nella tabella
if EMT.GROUP == 4 and EMT.P1CALLP4 and #EMT.P1CALLP4 > 0 then
table.insert( EMT.P1CALLP4, 'NOMACH;')
table.insert( EMT.P1CALLP4, 'NOMACH#(CLS,P1STARTSH)')
else
EmtOutput( ';', 1)
EmtOutput( '#(CLS,P1STARTSH)', 1)
end
end
EMT.SHUTTLE_ON = true
end
---------------------------------------------------------------------
function EmitRotAxeR1()
local sOneRotAxes = EmtGetRapidAxis('R1')
if not bEmitUprOnGenPlane and #sOneRotAxes > 0 then
sOneRotAxes = string.gsub( sOneRotAxes, string.sub( sOneRotAxes, 1, 2), string.sub( sOneRotAxes, 1, 2)..'(').. '+L913)'
end
return sOneRotAxes
end
---------------------------------------------------------------------
-- *** END GENERATION ***
---------------------------------------------------------------------