Files
Masterwood-TF600KST/Masterwood-woodWOP.mlpe
Dario Sassi 9c1256940d Masterwood-TF600KST 2.7h1 :
- modifiche per evitare collisioni in simulazione con gruppo a forare.
2025-08-22 17:41:20 +02:00

514 lines
18 KiB
Plaintext

-- Processore generico Masterwood woodWOP 2025/08/22
-- by EgalWare s.r.l.
--
-- Intestazioni
require( 'EmtGenerator')
EgtEnableDebug( false)
-- Variabili di modulo
local MLE_INFO = 'Egalware-CAM5-MwW-V'..PP_VER
---------------------------------------------------------------------
function OnStart()
EMT.USETO1 = true -- abilitazione uso origine tavola
EMT.MODAL = true -- abilitazione emissione modale
EMT.INCHES = false -- unità di misura mm/inches
EMT.DECNUM = EgtIf( EMT.INCHES, 4, 3) -- numero di decimali dopo la virgola
EMT.NUM = false -- abilitazione numerazione linee
end
---------------------------------------------------------------------
function OnEnd()
-- Estensione impostata nel file INI di macchina
end
---------------------------------------------------------------------
function OnProgramStart()
-- Definizione Tabella dati da emettere alla fine
EMT.PROCESS = {}
-- Contatore contorni
EMT.CTR = 0
end
---------------------------------------------------------------------
function OnProgramEnd()
-- Emissione linee posticipate
for i = 1, #EMT.PROCESS do
EmtOutput( EMT.PROCESS[i])
end
-- Chiusura file
EmtOutput( '')
EmtOutput( '!')
end
---------------------------------------------------------------------
function OnToolData()
end
---------------------------------------------------------------------
function OnDispositionStart()
end
---------------------------------------------------------------------
function OnDispositionEnd()
-- se prima fase
if EMT.PHASE == 1 then
-- Header
EmtOutput( '[H')
EmtOutput( 'VERSION="4.0 Alpha" \\' .. MLE_INFO .. ' ' .. os.date( '%Y.%m.%d-%H:%M:%S', os.time()) .. '\\')
EmtOutput( 'HP="1"')
EmtOutput( 'IN="0"')
EmtOutput( 'GX="0"')
EmtOutput( 'BFS="1"')
EmtOutput( 'GY="0"')
EmtOutput( 'GXY="0"')
EmtOutput( 'UP="0"')
EmtOutput( 'FM="1"')
EmtOutput( 'FW="' .. EmtLenToString( XAxisHome, EMT.DECNUM) .. '"')
EmtOutput( 'ZS="50"')
EmtOutput( 'HS="0"')
EmtOutput( 'OP="0"')
EmtOutput( 'MAT="HOMAG"')
EmtOutput( 'INCH="0"')
EmtOutput( 'VIEW="NOMIRROR"')
EmtOutput( 'ANZ="1"')
EmtOutput( '_BSX=' .. EmtLenToString( EMT.LP, EMT.DECNUM))
EmtOutput( '_BSY=' .. EmtLenToString( EMT.WP, EMT.DECNUM))
EmtOutput( '_BSZ=' .. EmtLenToString( EMT.TP, EMT.DECNUM))
EmtOutput( '_FNX=0')
EmtOutput( '_FNY=0')
EmtOutput( '_RNX=0')
EmtOutput( '_RNY=0')
EmtOutput( '_RNZ=0')
EmtOutput( '_RX=' .. EmtLenToString( EMT.LP, EMT.DECNUM))
EmtOutput( '_RY=' .. EmtLenToString( EMT.WP, EMT.DECNUM))
-- Tabella delle variabili
EmtOutput( '')
EmtOutput( '[001')
EmtOutput( 'l="' .. EmtLenToString( EMT.LP, EMT.DECNUM) .. '"')
EmtOutput( 'KM="Length"')
EmtOutput( 'w="' .. EmtLenToString( EMT.WP, EMT.DECNUM) .. '"')
EmtOutput( 'KM="Width"')
EmtOutput( 'th="' .. EmtLenToString( EMT.TP, EMT.DECNUM) .. '"')
EmtOutput( 'KM="Thickness"')
-- Assegno dati pezzo (da emettere dopo)
PostOutput( '')
PostOutput( '<100 \\WerkStck\\')
PostOutput( 'LA="l"')
PostOutput( 'BR="w"')
PostOutput( 'DI="th"')
PostOutput( 'FNX="0.0"')
PostOutput( 'FNY="0.0"')
PostOutput( 'RNX="0"')
PostOutput( 'RNY="0"')
PostOutput( 'RNZ="0"')
PostOutput( 'AX="0"')
PostOutput( 'AY="0"')
end
end
---------------------------------------------------------------------
function OnTableData()
end
---------------------------------------------------------------------
function OnTableAxisData()
end
---------------------------------------------------------------------
function OnFixtureData()
end
---------------------------------------------------------------------
function OnRawMoveData()
-- Assegno dimensioni del grezzo
local b3Sol = EgtGetRawPartBBox( EMT.RAWID) or BBox3d( ORIG())
EMT.LP = b3Sol:getDimX()
EMT.WP = b3Sol:getDimY()
EMT.TP = b3Sol:getDimZ()
-- Assegno Posizione del Grezzo rispetto all'Origine Tavola (le coordinate sono riferite ad essa)
EMT.PP = b3Sol:getMin() - Point3d( EMT.TABORI1[1], EMT.TABORI1[2], EMT.TABORI1[3])
end
---------------------------------------------------------------------
function OnToolSelect()
EMT.TOOLTYPE = EgtTdbGetCurrToolParam( MCH_TP.TYPE)
EMT.TDIAM = EgtTdbGetCurrToolParam( MCH_TP.DIAM)
EMT.TTOTDIAM = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM)
EMT.TLEN = EgtTdbGetCurrToolParam( MCH_TP.LEN)
EMT.TTOTLEN = EgtTdbGetCurrToolParam( MCH_TP.TOTLEN)
EMT.TUSERNOTES = EgtTdbGetCurrToolParam( MCH_TP.USERNOTES)
local vsTok = EgtSplitString( EMT.TOOL, '_') or {}
EMT.TNO = tonumber( vsTok[1]) or 0
end
---------------------------------------------------------------------
function OnToolDeselect()
end
---------------------------------------------------------------------
function OnMachiningStart()
EMT.MCHNAME = EgtGetOperationName( EMT.MCHID)
EMT.MCHTYPE = EgtGetMachiningParam( MCH_MP.TYPE)
EMT.MCHLEADIN = EgtGetMachiningParam( MCH_MP.LEADINTYPE)
EMT.MCHLEADOUT = EgtGetMachiningParam( MCH_MP.LEADOUTTYPE)
EMT.MCHFEED = EgtGetMachiningParam( MCH_MP.FEED)
EMT.MCHUSERNOTES = EgtGetMachiningParam( MCH_MP.USERNOTES)
EMT.MCHFIRST = true
EMT.MCHMINZ = 999
end
---------------------------------------------------------------------
function OnMachiningEnd()
-- Se foratura
if EMT.MCHTYPE == MCH_MY.DRILLING then
-- recupero l'elenco dei fori da fare e di quelli saltati
local vGeom = EgtGetMachiningGeometry() or {}
local vSkipped = EgtGetMachiningSkippedGeometry() or {}
-- calcolo il riferimento pezzo
local ptS = Point3d( EMT.PP)
local vtE = Vector3d( EMT.EXTR)
local refPart = Frame3d( ptS, Z_AX())
-- per ogni foro emetto la relativa lavorazione
for i = 1, #vGeom do
local nEntId = vGeom[i][1]
for j = 1, #vSkipped do
if nEntId == vSkipped[j][1] then
nEntId = nil
break
end
end
if nEntId and EgtGetType( nEntId) == GDB_TY.CRV_ARC then
local ptCen = EgtCP( nEntId, GDB_ID.ROOT)
ptCen:toLoc( refPart)
local dDiam = 2 * EgtArcRadius( nEntId)
local dDepth = abs( EgtCurveThickness( nEntId))
-- fori da sopra
if vtE:isSmall() or AreSameVectorApprox( vtE, Z_AX()) then
PostOutput( '')
PostOutput( '<102 \\BohrVert\\')
PostOutput( 'XA="' .. EmtLenToString( ptCen:getX(), EMT.DECNUM) .. '"')
PostOutput( 'YA="' .. EmtLenToString( ptCen:getY(), EMT.DECNUM) .. '"')
PostOutput( 'BM="SS"')
PostOutput( 'TI="' .. EmtLenToString( dDepth, EMT.DECNUM) .. '"')
PostOutput( 'DU="' .. EmtLenToString( dDiam, EMT.DECNUM) .. '"')
PostOutput( 'MNM="' .. EMT.MCHNAME .. '"')
-- fori da sotto
elseif AreSameVectorApprox( vtE, -Z_AX()) then
PostOutput( '')
PostOutput( '<131 \\UfluBohr\\')
PostOutput( 'XA="' .. EmtLenToString( ptCen:getX(), EMT.DECNUM) .. '"')
PostOutput( 'YA="' .. EmtLenToString( ptCen:getY(), EMT.DECNUM) .. '"')
PostOutput( 'DU="' .. EmtLenToString( dDiam, EMT.DECNUM) .. '"')
PostOutput( 'TI="' .. EmtLenToString( dDepth, EMT.DECNUM) .. '"')
PostOutput( 'BM="SS"')
PostOutput( 'MNM="' .. EMT.MCHNAME .. '"')
-- fori orizzontali
else
PostOutput( '')
PostOutput( '<103 \\BohrHoriz\\')
PostOutput( 'XA="' .. EmtLenToString( ptCen:getX(), EMT.DECNUM) .. '"')
PostOutput( 'YA="' .. EmtLenToString( ptCen:getY(), EMT.DECNUM) .. '"')
PostOutput( 'ZA="' .. EmtLenToString( ptCen:getZ(), EMT.DECNUM) .. '"')
if AreSameVectorApprox( vtE, -Y_AX()) then
PostOutput( 'BM="YP"')
elseif AreSameVectorApprox( vtE, X_AX()) then
PostOutput( 'BM="XM"')
elseif AreSameVectorApprox( vtE, Y_AX()) then
PostOutput( 'BM="YM"')
elseif AreSameVectorApprox( vtE, -X_AX()) then
PostOutput( 'BM="XP"')
else
EmtSetLastError( 1201, 'Drilling direction not allowed')
end
PostOutput( 'TI="' .. EmtLenToString( dDepth, EMT.DECNUM) .. '"')
PostOutput( 'DU="' .. EmtLenToString( dDiam, EMT.DECNUM) .. '"')
PostOutput( 'MNM="' .. EMT.MCHNAME .. '"')
end
end
end
-- altrimenti se taglio con lama
elseif EMT.MCHTYPE == MCH_MY.SAWING then
-- recupero la geometria dei percorsi
local vGeom = EgtGetMachiningGeometry() or {}
-- recupero angolo di sbandamento
local dSideAng = EgtGetMachiningParam( MCH_MP.SIDEANGLE)
if abs( dSideAng) > 0.1 then
EmtSetLastError( 1201, 'Sawing inclination not allowed')
end
-- recupero lato di lavoro
local nWorkSide = EgtGetMachiningParam( MCH_MP.WORKSIDE)
local sWorkSide = 'NOWRK'
if nWorkSide == MCH_SAW_WS.LEFT then
sWorkSide = 'WRKL'
elseif nWorkSide == MCH_SAW_WS.RIGHTT then
sWorkSide = 'WRKR'
end
-- recupero tipo di attacco
local nLeadIn = EgtGetMachiningParam( MCH_MP.LEADINTYPE)
local sMode = 'MOD2'
if nLeadIn == MCH_SAW_LI.STRICT then
sMode = 'MOD1'
elseif nLeadIn == MCH_SAW_LI.CENT then
sMode = 'MOD0'
end
-- recupero allungamenti iniziale e finale
local dAddLenSta = EgtGetMachiningParam( MCH_MP.STARTADDLEN)
local dAddLenEnd = EgtGetMachiningParam( MCH_MP.ENDADDLEN)
-- calcolo il riferimento pezzo
local ptS = Point3d( EMT.PP)
local refPart = Frame3d( ptS, Z_AX())
-- per ogni linea emetto la relativa lavorazione
for i = 1, #vGeom do
local nEntId = vGeom[i][1]
if nEntId and EgtGetType( nEntId) == GDB_TY.CRV_LINE then
local vtDir = EgtSV( nEntId, GDB_ID.ROOT)
local ptSta = EgtSP( nEntId, GDB_ID.ROOT)
ptSta = ptSta - dAddLenSta * vtDir
ptSta:toLoc( refPart)
local ptEnd = EgtEP( nEntId, GDB_ID.ROOT)
ptEnd = ptEnd + dAddLenEnd * vtDir
ptEnd:toLoc( refPart)
local dDepth = ptSta:getZ() - EMT.MCHMINZ
PostOutput( '')
PostOutput( '<109 \\Nuten\\')
PostOutput( 'XA="' .. EmtLenToString( ptSta:getX(), EMT.DECNUM) .. '"')
PostOutput( 'YA="' .. EmtLenToString( ptSta:getY(), EMT.DECNUM) .. '"')
PostOutput( 'XE="' .. EmtLenToString( ptEnd:getX(), EMT.DECNUM) .. '"')
PostOutput( 'YE="' .. EmtLenToString( ptEnd:getY(), EMT.DECNUM) .. '"')
PostOutput( 'AN="0"')
PostOutput( 'TI="' .. EmtLenToString( dDepth, EMT.DECNUM) .. '"')
PostOutput( 'RK="' .. sWorkSide .. '"')
PostOutput( 'EM="' .. sMode .. '"')
PostOutput( 'MNM="' .. EMT.MCHNAME .. '"')
end
end
end
end
---------------------------------------------------------------------
function OnPathStart()
-- Reset valori precedenti (per forzare emissione di tutti gli assi del 1° movimento)
EmtResetPrev()
EMT.IPLGL = false
EMT.IPLGLFR = nil
-- Verifico se lavorazione da sotto
EMT.FROMBELOW = AreSameVectorApprox( Vector3d( EMT.EXTR), -Z_AX())
-- Se fresatura o svuotatura
if EMT.MCHTYPE == MCH_MY.MILLING or EMT.MCHTYPE == MCH_MY.POCKETING then
-- Inizio percorso di lavorazione
EmitStartContour()
EMT.ENT = 0
-- in tutti gli altri casi
else
EMT.ENT = nil
end
end
---------------------------------------------------------------------
function OnPathEnd()
-- Assegno dati lavorazione (da emettere dopo)
if EMT.ENT and EMT.ENT > 0 then
-- Dichiarazione lavorazione
EmitMilling()
end
end
---------------------------------------------------------------------
function OnRapid()
-- se primo movimento del percorso, calcolo piano di interpolazione
if not EMT.IPLGL then
CalcInterpPlane()
EMT.IPLGL = true
end
MyAdjustLinearAxes()
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
function OnLinear()
MyAdjustLinearAxes()
-- se entità di lavorazione con contorno e non approccio o retrazione
if EMT.ENT then
-- se non approccio o retrazione
if not IsSafeMoveIO( EMT.MOVEID) then
-- se inizio, emetto punto di partenza
if EMT.ENT == 0 then
EmtOutput( '$E0')
EmtOutput( 'KP')
EmtOutput( 'X='..EmtLenToString( EMT.L1p, EMT.DECNUM))
EmtOutput( 'Y='..EmtLenToString( EMT.L2p, EMT.DECNUM))
EmtOutput( 'Z='..EmtLenToString( EMT.L3p, EMT.DECNUM))
EmtOutput( 'KO=' .. EMT.KO)
end
-- emetto segmento di retta
EMT.ENT = EMT.ENT + 1
EmtOutput( '')
EmtOutput( '$E' .. tostring( EMT.ENT))
EmtOutput( 'KL')
EmtOutput( 'X='..EmtLenToString( EMT.L1, EMT.DECNUM))
EmtOutput( 'Y='..EmtLenToString( EMT.L2, EMT.DECNUM))
EmtOutput( 'Z='..EmtLenToString( EMT.L3, EMT.DECNUM))
-- se approccio
elseif IsSafeMoveIn( EMT.MOVEID) then
if EMT.ENT == -1 then
-- Inizio percorso di lavorazione
EmitStartContour()
EMT.ENT = 0
end
-- se retrazione
elseif IsSafeMoveOut( EMT.MOVEID) then
if EMT.ENT and EMT.ENT > 0 then
-- Dichiarazione lavorazione
EmitMilling()
EMT.ENT = -1
end
end
end
-- aggiorno minimo in Z
EMT.MCHMINZ = min( EMT.MCHMINZ, EMT.L3)
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
function OnArc()
MyAdjustLinearAxes()
-- se entità di lavorazione con contorno ( non può mai essere approccio o retrazione)
if EMT.ENT then
-- se inizio, emetto punto di partenza
if EMT.ENT == 0 then
EmtOutput( '$E0')
EmtOutput( 'KP')
EmtOutput( 'X='..EmtLenToString( EMT.L1p, EMT.DECNUM))
EmtOutput( 'Y='..EmtLenToString( EMT.L2p, EMT.DECNUM))
EmtOutput( 'Z='..EmtLenToString( EMT.L3p, EMT.DECNUM))
EmtOutput( 'KO=' .. EMT.KO)
end
-- emetto arco
EMT.ENT = EMT.ENT + 1
EmtOutput( '')
EmtOutput( '$E' .. tostring( EMT.ENT))
EmtOutput( 'KA')
EmtOutput( 'X='..EmtLenToString( EMT.L1, EMT.DECNUM))
EmtOutput( 'Y='..EmtLenToString( EMT.L2, EMT.DECNUM))
EmtOutput( 'Z='..EmtLenToString( EMT.L3, EMT.DECNUM))
EmtOutput( 'DS='..EgtIf( EMT.AC < 0, '0', '1'))
EmtOutput( 'R='..EmtLenToString( EMT.RR, EMT.DECNUM))
end
-- aggiorno minimo in Z
EMT.MCHMINZ = min( EMT.MCHMINZ, EMT.L3)
-- aggiorno valori come precedenti
EmtUpdatePrev()
end
---------------------------------------------------------------------
---------------------------------------------------------------------
function IsSafeMoveIO( nEntId)
local sName = EgtGetName( nEntId)
return ( sName == 'SI' or sName == 'SO')
end
---------------------------------------------------------------------
function IsSafeMoveIn( nEntId)
local sName = EgtGetName( nEntId)
return ( sName == 'SI')
end
---------------------------------------------------------------------
function IsSafeMoveOut( nEntId)
local sName = EgtGetName( nEntId)
return ( sName == 'SO')
end
---------------------------------------------------------------------
function IsLeadIO( nEntId)
local sName = EgtGetName( nEntId)
return ( sName == 'LI' or sName == 'LO')
end
---------------------------------------------------------------------
function CalcInterpPlane()
-- Reset
EMT.IPLGLFR = nil
-- Recupero vettore direzione utensile
local vtE = Vector3d( EMT.EXTR)
-- a seconda del piano di interpolazione (solo standard Homag 00, A0, B0, C0, D0)
if vtE:isSmall() or AreSameVectorApprox( vtE, Z_AX()) or EMT.FROMBELOW then
local ptS = Point3d( EMT.PP)
EMT.IPLGLFR = Frame3d( ptS, Z_AX())
EMT.KO = '00'
elseif AreSameVectorApprox( vtE, -Y_AX()) then
local ptS = Point3d( EMT.PP)
EMT.IPLGLFR = Frame3d( ptS, vtE)
EMT.KO = 'A0'
elseif AreSameVectorApprox( vtE, X_AX()) then
local ptS = Point3d( EMT.PP) + Vector3d( EMT.LP, 0, 0)
EMT.IPLGLFR = Frame3d( ptS, vtE)
EMT.KO = 'B0'
elseif AreSameVectorApprox( vtE, Y_AX()) then
local ptS = Point3d( EMT.PP) + Vector3d( EMT.LP, EMT.WP, 0)
EMT.IPLGLFR = Frame3d( ptS, vtE)
EMT.KO = 'C0'
elseif AreSameVectorApprox( vtE, -X_AX()) then
local ptS = Point3d( EMT.PP) + Vector3d( 0, EMT.WP, 0)
EMT.IPLGLFR = Frame3d( ptS, vtE)
EMT.KO = 'D0'
else
EmtSetLastError( 1201, 'Tool direction not allowed')
end
end
---------------------------------------------------------------------
function MyAdjustLinearAxes()
local MyL1o = EMT.L1
local MyL2o = EMT.L2
local MyL3o = EMT.L3
-- porto le coordinate sulla punta utensile
local bBottom = ( EMT.MCHTYPE == MCH_MY.SAWING)
local ptTip = EgtGetCalcTipFromPositions( EMT.L1, EMT.L2, EMT.L3, EMT.R1 or 0, EMT.R2 or 0, bBottom)
EMT.L1 = ptTip:getX()
EMT.L2 = ptTip:getY()
EMT.L3 = ptTip:getZ()
EmtAdjustLinearAxes()
EMT.L1o = MyL1o
EMT.L2o = MyL2o
EMT.L3o = MyL3o
end
---------------------------------------------------------------------
function EmitStartContour()
EMT.CTR = EMT.CTR + 1
EmtOutput( '')
EmtOutput( ']' .. tostring( EMT.CTR))
end
---------------------------------------------------------------------
function EmitMilling()
PostOutput( '')
PostOutput( EgtIf( EMT.FROMBELOW, '<113 \\Unterflurfraesen\\', '<105 \\Konturfraesen\\'))
PostOutput( 'EA="' .. tostring( EMT.CTR) .. ':0"')
PostOutput( 'MDA="SEN"')
PostOutput( 'RK="NOWRK"')
PostOutput( 'EE="' .. tostring( EMT.CTR) .. ':' .. tostring( EMT.ENT) .. '"')
PostOutput( 'MDE="SEN_AB"')
PostOutput( 'TNO="' .. tostring( EMT.TNO) .. '"')
PostOutput( 'SM="0"')
PostOutput( 'S_="STANDARD"')
PostOutput( 'F_="' .. EgtNumToString( EMT.MCHFEED, 1) .. '"')
PostOutput( 'ZA="@0"')
PostOutput( 'MNM="' .. EMT.MCHNAME .. '"')
end
---------------------------------------------------------------------
function PostOutput( sLine)
table.insert( EMT.PROCESS, sLine)
end