DataGunstock :
- modifiche per nuova macchina CMS di Beretta.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
-- EgtGunstockBase.lua by EgalTech s.r.l. 2016/09/29
|
||||
-- EgtGunstockBase.lua by EgalTech s.r.l. 2022/06/20
|
||||
-- Gunstock Base library
|
||||
|
||||
require( 'EgtBase')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- Main.lua by Egaltech s.r.l. 2020/09/30
|
||||
-- Main.lua by Egaltech s.r.l. 2022/06/20
|
||||
-- Main gestione lavorazioni Gunstock
|
||||
|
||||
-- Intestazioni
|
||||
@@ -268,7 +268,7 @@ local function GetGunRef()
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
local function GetMachining()
|
||||
local function GetMachining( bBeretta)
|
||||
-- inizio lavorazione
|
||||
local sLine = EGB.GetLine()
|
||||
if not sLine then return false end
|
||||
@@ -302,17 +302,19 @@ local function GetMachining()
|
||||
elseif sLine:find( '#TESTA_USCITA', 1, true) then
|
||||
--
|
||||
elseif sLine:find( '#PREP_ROT', 1, true) then
|
||||
local sParam = EgtTrim( sLine:gsub( '#PREP_ROT', ''))
|
||||
local vsTok = EgtSplitString( sParam, ' ')
|
||||
if #vsTok < 2 then return false end
|
||||
local PrepRot = {}
|
||||
PrepRot.sR1Expr = vsTok[1]
|
||||
PrepRot.dR1 = 0
|
||||
PrepRot.sR2Expr = vsTok[2]
|
||||
PrepRot.dR2 = 0
|
||||
PrepRot.sFeedExpr = vsTok[3]
|
||||
PrepRot.dFeed = 0
|
||||
vMach.PrepRot = PrepRot
|
||||
if not bBeretta then
|
||||
local sParam = EgtTrim( sLine:gsub( '#PREP_ROT', ''))
|
||||
local vsTok = EgtSplitString( sParam, ' ')
|
||||
if #vsTok < 2 then return false end
|
||||
local PrepRot = {}
|
||||
PrepRot.sR1Expr = vsTok[1]
|
||||
PrepRot.dR1 = 0
|
||||
PrepRot.sR2Expr = vsTok[2]
|
||||
PrepRot.dR2 = 0
|
||||
PrepRot.sFeedExpr = vsTok[3]
|
||||
PrepRot.dFeed = 0
|
||||
vMach.PrepRot = PrepRot
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
@@ -379,8 +381,11 @@ local function EvaluateExpr( sExpr)
|
||||
sTmp = AdjustFunction( sTmp, ')Q', 'pow(', ',2)')
|
||||
sTmp = AdjustFunction( sTmp, ')R', 'sqrt(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')S', 'sin(', ')')
|
||||
sTmp = AdjustFunction( sTmp, 'S)', 'sin(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')C', 'cos(', ')')
|
||||
sTmp = AdjustFunction( sTmp, 'C)', 'cos(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')T', 'tan(', ')')
|
||||
sTmp = AdjustFunction( sTmp, 'T)', 'tan(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')AS', 'asin(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')AC', 'acos(', ')')
|
||||
sTmp = AdjustFunction( sTmp, ')AT', 'atan(', ')')
|
||||
@@ -435,6 +440,45 @@ local function WriteOutLineFromIni( sSec, sKey, sDef, sIniFile)
|
||||
EGB.WriteOutLine( sLine:gsub( '<br/>', '\n'))
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
local function CncSplit( sCncFile, sSubDir)
|
||||
|
||||
local CncFh = io.open( sCncFile, 'r')
|
||||
if not CncFh then
|
||||
EgtOutLog( 'Errore nell\'apertura del file di input ' .. sCncFile)
|
||||
return false
|
||||
end
|
||||
|
||||
local SubFh
|
||||
local sLine = CncFh:read( '*l')
|
||||
while sLine do
|
||||
if not string.find( sLine, '%', 1, true) then
|
||||
if string.find( sLine, '(DIS,"CODICE=SUB', 1, true) then
|
||||
if SubFh then
|
||||
SubFh:close()
|
||||
SubFh = nil
|
||||
end
|
||||
local sSubName = string.sub( sLine, 14, -3)
|
||||
local sSubFile = sSubDir..sSubName
|
||||
SubFh = io.open( sSubFile, 'w')
|
||||
if not SubFh then
|
||||
EgtOutLog( 'Errore nell\'apertura del file di output ' .. sSubFile)
|
||||
CncFh:close()
|
||||
return false
|
||||
end
|
||||
end
|
||||
if SubFh then
|
||||
SubFh:write( sLine .. '\n')
|
||||
end
|
||||
end
|
||||
sLine = CncFh:read( '*l')
|
||||
end
|
||||
|
||||
if SubFh then SubFh:close() end
|
||||
CncFh:close()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- *** Read MOD params ***
|
||||
@@ -688,7 +732,25 @@ function GGD.CreateGunstock()
|
||||
local sMachIni = EgtGetCurrMachineDir() .. '\\' .. m_sMachName .. '.ini'
|
||||
local bTwoHeads = ( EgtGetStringFromIni( 'Gunstock', 'TwoHeads', '0', sMachIni) == '1')
|
||||
local bAddM6ToT3x = ( EgtGetStringFromIni( 'Gunstock', 'AddM6ToT3x', '1', sMachIni) == '1')
|
||||
local bMazak = ( EgtGetStringFromIni( 'Gunstock', 'Type', 'Cms', sMachIni) == 'Mazak')
|
||||
local sType = EgtGetStringFromIni( 'Gunstock', 'Type', 'Cms', sMachIni)
|
||||
local bBeretta = false
|
||||
local bMazak = false
|
||||
if sType == 'Beretta' then
|
||||
bBeretta = true
|
||||
elseif sType == 'Mazak' then
|
||||
bMazak = true
|
||||
end
|
||||
|
||||
-- In modalità Beretta recupero SUB dal file CNC omonimo di MOD
|
||||
if bBeretta then
|
||||
EgtEmptyDirectory( sSubDir)
|
||||
local sCncFile = EgtChangePathExtension( sModFile, 'CNC')
|
||||
if not CncSplit( sCncFile, sSubDir) then
|
||||
EGB.WriteErrLine( 'ERR=120\nErrore in CNC file split')
|
||||
GGD.ERR = 120
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Recupero parametri (opzionali)
|
||||
if not GetParams() then
|
||||
@@ -814,7 +876,7 @@ function GGD.CreateGunstock()
|
||||
|
||||
-- Recupero dati di lavorazione
|
||||
while not GetEndStdMachining() do
|
||||
if not GetMachining() then
|
||||
if not GetMachining( bBeretta) then
|
||||
EGB.WriteErrLine( 'ERR=114\nErrore in lettura Lavorazione (linea ' .. tostring( EGB.GetLineNumber()) ..')')
|
||||
GGD.ERR = 114
|
||||
return
|
||||
@@ -998,7 +1060,9 @@ function GGD.CreateGunstock()
|
||||
local tabOri = EgtGetTableRef( 1)
|
||||
-- Posizionamento delle morse per calcio
|
||||
local nFix
|
||||
if bMazak then
|
||||
if bBeretta then
|
||||
nFix = EgtAddFixture( 'ViseH75', Vector3d( 600, 339.1, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
|
||||
elseif bMazak then
|
||||
nFix = EgtAddFixture( 'ViseNew', Vector3d( 350, 250, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
|
||||
else
|
||||
if m_vRaw.dLen < LEN_MIN_RIFLE then
|
||||
@@ -1007,6 +1071,8 @@ function GGD.CreateGunstock()
|
||||
nFix = EgtAddFixture( 'ViseRifle', Vector3d( 600, 350-1.49, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
|
||||
end
|
||||
end
|
||||
-- Allargo area utile per movimenti grezzo per non avere problemi nelle fasi intermedie del movimento
|
||||
EgtSetTableAreaOffset( 500, 500, 500, 500)
|
||||
-- Posizionamento del grezzo in macchina
|
||||
local ColA = Color3d( 255, 165, 0, 30)
|
||||
local nRaw = EgtAddRawPartWithPart( Pz, Sol, 0, ColA) or GDB_ID.NULL
|
||||
@@ -1234,6 +1300,143 @@ function GGD.CreateGunstock()
|
||||
-- terminazione file
|
||||
EGB.WriteOutLine( 'M30')
|
||||
|
||||
-- altrimenti macchina CMS in Beretta
|
||||
elseif bBeretta then
|
||||
-- posizione Origine1 rispetto Zero Macchina (punto intersezione assi rotanti)
|
||||
local OffsX = -1598.00
|
||||
local OffsY = -2126.10
|
||||
local OffsZ = -670.65
|
||||
-- emissione intestazione
|
||||
EGB.WriteOutLine( '(DIS,"CODICE=PRG1")')
|
||||
EGB.WriteOutLine( '; ' .. EgtGetCurrMachineName():upper())
|
||||
EGB.WriteOutLine( '; ' .. sPezName:upper() .. sPezExt:upper() .. '-' .. sModName:upper() .. sModExt:upper())
|
||||
EGB.WriteOutLine( '; ' .. GGD.DESCR:upper())
|
||||
EGB.WriteOutLine( '; ' .. m_sAttr:upper())
|
||||
local sStart1Def = 'M70<br/>"CICLI"'
|
||||
if m_vRaw.dLen < LEN_MIN_RIFLE then
|
||||
WriteOutLineFromIni( 'Gunstock', 'Start1', sStart1Def, sMachIni)
|
||||
else
|
||||
WriteOutLineFromIni( 'Gunstock', 'Start1_R', sStart1Def, sMachIni)
|
||||
end
|
||||
for i = 1, #m_vParams do
|
||||
EGB.WriteOutLine( m_vParams[i].sVar .. '=' .. EgtNumToString( m_vParams[i].dVal, 3))
|
||||
end
|
||||
local sStart2Def = 'G79G0Z0<br/>G79X0Y0C0B0'
|
||||
if m_vRaw.dLen < LEN_MIN_RIFLE then
|
||||
WriteOutLineFromIni( 'Gunstock', 'Start2', sStart2Def, sMachIni)
|
||||
else
|
||||
WriteOutLineFromIni( 'Gunstock', 'Start2_R', sStart2Def, sMachIni)
|
||||
end
|
||||
EGB.WriteOutLine( '(UAO,0)')
|
||||
EGB.WriteOutLine( '(UTO,0,X0,Y0,Z0)')
|
||||
EGB.WriteOutLine( '(TCP)')
|
||||
EGB.WriteOutLine( '(UPR)')
|
||||
-- emissione dei posizionamenti e dei richiami delle lavorazioni
|
||||
if not EgtSetCalcTool( 'Calc', 'H1', 1) then
|
||||
EGB.WriteErrLine( 'ERR=204\nErrore nell\'impostazione dell\'utensile di calcolo')
|
||||
GGD.ERR = 204
|
||||
return
|
||||
end
|
||||
local dCalcLen = EgtTdbGetCurrToolParam( MCH_TP.LEN)
|
||||
local nNum = 0
|
||||
local dPrevR1, dPrevR2 = 9999, 9999
|
||||
for i = 1, #m_vMachs do
|
||||
-- lavorazione i-esima
|
||||
local vMach = m_vMachs[i]
|
||||
local frMach = EgtFR( vMach.nLay, GDB_ID.ROOT)
|
||||
-- emissione info di lavorazione
|
||||
nNum = nNum + 10
|
||||
if vMach.sInfo then
|
||||
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ' .. vMach.sInfo:upper())
|
||||
else
|
||||
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ***')
|
||||
end
|
||||
-- emissione info utensile
|
||||
local sToolInfo = ''
|
||||
local sTcPos = EgtGetInfo( vMach.nLay, 'TCPOS')
|
||||
if sTcPos == 'T00' then
|
||||
sToolInfo = sToolInfo .. 'T=PRECEDENTE'
|
||||
elseif sTcPos then
|
||||
sToolInfo = sToolInfo .. sTcPos:upper()
|
||||
end
|
||||
local sTcomp = EgtGetInfo( vMach.nLay, 'TCOMP')
|
||||
if sTcomp then sToolInfo = sToolInfo .. ' H' .. sTcomp:upper() end
|
||||
local sTname = EgtGetInfo( vMach.nLay, 'TNAME')
|
||||
if sTname then sToolInfo = sToolInfo .. ' ' .. sTname:upper() end
|
||||
EGB.WriteOutLine( '; ' .. sToolInfo)
|
||||
-- calcolo angoli
|
||||
local dNearR1, dNearR2 = 0, 0
|
||||
if vMach.Ang then
|
||||
dNearR1 = vMach.Ang.dR1
|
||||
dNearR2 = vMach.Ang.dR2
|
||||
end
|
||||
local bRaOk, dR1, dR2 = EGB.GetAngMach( frMach:getVersZ(), dNearR1, dNearR2)
|
||||
if not bRaOk then
|
||||
EGB.WriteOutLine( '; ERRORE CALC ROTAX DI ' .. vMach.sName:upper())
|
||||
EGB.WriteErrLine( 'ERR=205\nErrore nel calcolo assi rotanti di ' .. vMach.sName)
|
||||
GGD.ERR = 205
|
||||
return
|
||||
else
|
||||
vMach.Ang.dR1N = dR1
|
||||
vMach.Ang.dR2N = dR2
|
||||
if vMach.PrepRot and
|
||||
( abs( dR1 - dPrevR1) > GEO.EPS_ANG_SMALL or abs( dR2 - dPrevR2) > GEO.EPS_ANG_SMALL) then
|
||||
local sOut = 'G90G0'..'B'..EgtNumToString( dR1 - vMach.PrepRot.dR1, 3)..
|
||||
'C'..EgtNumToString( dR2 - vMach.PrepRot.dR2, 3)
|
||||
EGB.WriteOutLine( sOut)
|
||||
sOut = 'G90G1'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)..
|
||||
'F'..EgtNumToString( vMach.PrepRot.dFeed, 0)
|
||||
EGB.WriteOutLine( sOut)
|
||||
else
|
||||
local sOut = 'G90G0'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)
|
||||
EGB.WriteOutLine( sOut)
|
||||
end
|
||||
dPrevR1 = dR1
|
||||
dPrevR2 = dR2
|
||||
EGB.WriteOutLine( '(UAO,1)')
|
||||
-- calcolo posizione
|
||||
local bLa1Ok, _, dX1, dY1, dZ1 = EgtGetCalcPositions( frMach:getOrigin(), dR1, dR2)
|
||||
if not bLa1Ok then
|
||||
EGB.WriteOutLine( '; ERRORE CALC UTO DI ' .. vMach.sName:upper())
|
||||
EGB.WriteErrLine( 'ERR=206\nErrore nel calcolo UTO di ' .. vMach.sName)
|
||||
GGD.Err = 206
|
||||
return
|
||||
end
|
||||
local dX = dX1
|
||||
local dY = dY1
|
||||
local dZ = dZ1 - dCalcLen
|
||||
EGB.WriteOutLine( '(UTO,1,X' .. EgtNumToString( dX - OffsX, 3) ..
|
||||
',Y' .. EgtNumToString( dY - OffsY, 3) ..
|
||||
',Z' .. EgtNumToString( dZ - OffsZ, 3) .. ')')
|
||||
-- calcolo rotazione
|
||||
local bLa2Ok, _, dX2, dY2, dZ2 = EgtGetCalcPositions( frMach:getOrigin() + 100*frMach:getVersX(), dR1, dR2)
|
||||
if not bLa2Ok then
|
||||
EGB.WriteOutLine( '; ERRORE CALC ROT DI ' .. vMach.sName:upper())
|
||||
EGB.WriteErrLine( 'ERR=207\nErrore nel calcolo ROT di ' .. vMach.sName)
|
||||
GGD.Err = 207
|
||||
return
|
||||
end
|
||||
local dAng = atan2( dY2 - dY1, dX2 - dX1)
|
||||
if abs( dZ2 - dZ1) > GEO.EPS_SMALL then
|
||||
EgtOutLog( 'Differenza sensibile in Z per ROT :'..EgtNumToString( dZ1, 6)..'/'..EgtNumToString( dZ2, 6))
|
||||
end
|
||||
EGB.WriteOutLine( 'G17')
|
||||
EGB.WriteOutLine( '(AXO,-Z)')
|
||||
EGB.WriteOutLine( '(ROT,' .. EgtNumToString( dAng, 3) .. ')')
|
||||
EGB.WriteOutLine( '(CLS,SUB' .. vMach.sName .. ')')
|
||||
EGB.WriteOutLine( '(UAO,0)')
|
||||
EGB.WriteOutLine( '(ROT,0)')
|
||||
end
|
||||
end
|
||||
-- emissione terminazione
|
||||
local sEndDef = 'G79G0Z0<br/>G79X0Y0C0B0'
|
||||
if m_vRaw.dLen < LEN_MIN_RIFLE then
|
||||
WriteOutLineFromIni( 'Gunstock', 'End', sEndDef, sMachIni)
|
||||
else
|
||||
WriteOutLineFromIni( 'Gunstock', 'End_R', sEndDef, sMachIni)
|
||||
end
|
||||
EGB.WriteOutLine( 'M30')
|
||||
|
||||
-- altrimenti macchine CMS
|
||||
else
|
||||
-- emissione intestazione
|
||||
|
||||
Reference in New Issue
Block a user