Files
databeamnew/StrategyLibs/FACEBYBLADE.lua
T
luca.mazzoleni 74611f99c5 - in STR0003 correzione a restituzione risultati
- in STR0004 implementata restituzione risultati nuova
- in strategie di base corretto calcolo area lavorata (ora contempla che il percorso è in centro utensile e che l'area lavorata non può superare quella della faccia)
2025-04-23 12:12:00 +02:00

430 lines
18 KiB
Lua

-- Strategia: FACEBYBLADE
-- Descrizione
-- Strategia di base per la lavorazione delle facce con lama
-- carico librerie
local BeamLib = require( 'BeamLib')
local BeamData = require( 'BeamData')
local MachiningLib = require( 'MachiningLib')
-- Tabella per definizione modulo
local FACEBYBLADE = {}
-------------------------------------------------------------------------------------------------------------
local function GetLeadInOutType( Machining)
local sLeadInOutType = ''
if Machining.bIsStartClosed or Machining.bIsEndClosed then
sLeadInOutType = 'Perpendicular'
else
-- testa sopra
if TOOLS[Machining.nToolIndex].SetupInfo.HeadType.bTop then
if abs( Machining.vtToolDirection:getX()) < 0.7 then
if Machining.vtToolDirection:getZ() > -0.087
or abs( Machining.vtToolDirection:getX()) < 0.34202 then
sLeadInOutType = 'Perpendicular'
else
sLeadInOutType = 'Tangent'
end
elseif abs( Machining.vtEdgeDirection:getZ()) < 0.7 then
sLeadInOutType = 'Tangent'
else
-- TODO qui attacco tangenziale speciale tutto da un lato
sLeadInOutType = 'Tangent'
end
-- testa sotto
elseif TOOLS[Machining.nToolIndex].SetupInfo.HeadType.bBottom then
if abs( Machining.vtToolDirection:getX()) < 0.7 then
if Machining.vtToolDirection:getZ() < -GEO.EPS_SMALL
or abs( Machining.vtToolDirection:getX()) < 0.34202 then
sLeadInOutType = 'Perpendicular'
else
sLeadInOutType = 'Tangent'
end
elseif abs( Machining.vtEdgeDirection:getZ()) > 0.7 then
sLeadInOutType = 'Tangent'
else
-- TODO qui attacco tangenziale speciale tutto da un lato
sLeadInOutType = 'Tangent'
end
-- se testa senza preferenza Top e Bottom si fa sempre attacco tangenziale
else
sLeadInOutType = 'Tangent'
end
end
return sLeadInOutType
end
local function CalculateLeadInOut( Machining, EdgeToMachine, Part)
-- TODO implementare le funzioni di Tool Collision Avoidance (vedi wiki e FacesBysaw -> CalcLeadInOutPerpGeom)
-- si determina l'eventuale riduzione da applicare in caso di inizio o fine chiusi
local dAddLengthToReduce = sqrt( Machining.dDepthToMachine * TOOLS[Machining.nToolIndex].dDiameter - Machining.dDepthToMachine * Machining.dDepthToMachine)
if Machining.bInvert then
Machining.bIsStartClosed, Machining.bIsEndClosed = Machining.bIsEndClosed, Machining.bIsStartClosed
end
local LeadIn = {}
local LeadOut = {}
Machining.sLeadInOutType = ''
LeadIn.dStartAddLength = 0
LeadOut.dEndAddLength = 0
LeadIn.nType = MCH_MILL_LI.LINEAR
LeadOut.nType = MCH_MILL_LI.LINEAR
LeadIn.dPerpDistance = 0
LeadOut.dPerpDistance = 0
LeadIn.dTangentDistance = 0
LeadOut.dTangentDistance = 0
if Machining.bIsStartClosed
or Machining.bIsEndClosed
or Machining.Steps.nCount > 1 then
Machining.sLeadInOutType = 'Perpendicular'
if AreSameVectorApprox( Machining.vtToolDirection, EdgeToMachine.vtN) then
LeadIn.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset
LeadOut.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset
else
LeadIn.dPerpDistance = BeamData.CUT_SIC - Machining.dRadialOffset
LeadOut.dPerpDistance = BeamData.CUT_SIC - Machining.dRadialOffset
end
else
Machining.sLeadInOutType = GetLeadInOutType( Machining)
if Machining.sLeadInOutType == 'Perpendicular' then
LeadIn.dPerpDistance = 1
LeadOut.dPerpDistance = 1
else
LeadIn.dTangentDistance = TOOLS[Machining.nToolIndex].dDiameter / 2
LeadOut.dTangentDistance = TOOLS[Machining.nToolIndex].dDiameter / 2
end
end
LeadIn.dElevation = 0
LeadOut.dElevation = 0
LeadIn.dCompLength = 0
LeadOut.dCompLength = 0
if Machining.bIsStartClosed and Machining.bIsEndClosed then
LeadIn.dStartAddLength = -dAddLengthToReduce
LeadOut.dEndAddLength = -dAddLengthToReduce
elseif Machining.bIsStartClosed then
LeadIn.dStartAddLength = -dAddLengthToReduce
-- eventuale correzione per accorciamento maggiore di larghezza tasca
LeadOut.dEndAddLength = max( -LeadIn.dStartAddLength - EdgeToMachine.dLength + 10 * BeamData.CUT_EXTRA, BeamData.CUT_EXTRA)
elseif Machining.bIsEndClosed then
LeadOut.dEndAddLength = -dAddLengthToReduce
-- eventuale correzione per accorciamento maggiore di larghezza tasca
LeadIn.dStartAddLength = max( -LeadOut.dEndAddLength - EdgeToMachine.dLength + 10 * BeamData.CUT_EXTRA, BeamData.CUT_EXTRA)
else
LeadIn.dStartAddLength = BeamData.CUT_EXTRA
LeadOut.dEndAddLength = BeamData.CUT_EXTRA
end
-- stima lunghezza reale attacchi per calcolo lunghezza lavorata
local dEstimatedLeadInPerpDistance = 0
local dEstimatedLeadInTangentDistance = 0
local dEstimatedLeadOutPerpDistance = 0
local dEstimatedLeadOutTangentDistance = 0
if LeadIn.dPerpDistance > 0 then
dEstimatedLeadInPerpDistance = ( Machining.dDepthToMachine + min( Machining.CloneStepsRadial.dStep, Machining.dDepthToMachine)) / 2
end
if LeadIn.dTangentDistance > 0 then
dEstimatedLeadInTangentDistance = TOOLS[Machining.nToolIndex].dDiameter / 2
end
if LeadOut.dPerpDistance > 0 then
dEstimatedLeadOutPerpDistance = ( Machining.dDepthToMachine + min( Machining.CloneStepsRadial.dStep, Machining.dDepthToMachine)) / 2
end
if LeadOut.dTangentDistance > 0 then
dEstimatedLeadOutTangentDistance = TOOLS[Machining.nToolIndex].dDiameter / 2
end
LeadIn.dTotalEstimatedDistance = sqrt( dEstimatedLeadInPerpDistance ^ 2 + dEstimatedLeadInTangentDistance ^ 2) + Machining.dStartSafetyLength
LeadOut.dTotalEstimatedDistance = sqrt( dEstimatedLeadOutPerpDistance ^ 2 + dEstimatedLeadOutTangentDistance ^ 2) + Machining.dStartSafetyLength
return LeadIn, LeadOut
end
local function GetSCC( vtMachiningDirection)
-- TODO implementare SCC come per FacesBySaw
local nSCC = MCH_SCC.NONE
if vtMachiningDirection:getZ() < -0.9 then
nSCC = MCH_SCC.ADIR_ZM
elseif vtMachiningDirection:getZ() > 0.9 then
nSCC = MCH_SCC.ADIR_ZP
elseif vtMachiningDirection:getY() < -0.707 then
nSCC = MCH_SCC.ADIR_YM
elseif vtMachiningDirection:getY() > 0.707 then
nSCC = MCH_SCC.ADIR_YP
elseif vtMachiningDirection:getX() < -0.707 then
nSCC = MCH_SCC.ADIR_XM
elseif vtMachiningDirection:getX() > 0.707 then
nSCC = MCH_SCC.ADIR_XP
end
return nSCC
end
-- TODO calcolo area lavorata per completamento
-- TODO EdgeToMachineAlternative da gestire
-- TODO invert avanzato (direzione, Z, alternativa, ...) da gestire
-- TODO bilinea da gestire
function FACEBYBLADE.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalParameters)
local Cutting = MachiningLib.InitMachiningParameters( MCH_MY.MILLING)
Cutting.bIsApplicable = true
Cutting.dDepthToMachine = 0
Cutting.sMessage = ''
Cutting.idProc = Proc.id
Cutting.dResidualDepth = EdgeToMachine.dElevation
Cutting.dCompletionPercentage = 0
Cutting.dToolMarkLength = 0
Cutting.sEdgeType = EdgeToMachine.sType
Cutting.nFeatureSegment = 1
-- parametri opzionali
if not OptionalParameters then
OptionalParameters = {}
end
local bForceLongcutBlade = OptionalParameters.bForceLongcutBlade or false
local dExtendAfterTail = OptionalParameters.dExtendAfterTail or 10000
local dPocketHeight = OptionalParameters.dPocketHeight or 0
local dDepthToMachine = OptionalParameters.dDepthToMachine or EdgeToMachine.dElevation
local bIsSplitFeature = OptionalParameters.bIsSplitFeature or false
local bOppositeToolDirection = OptionalParameters.bOppositeToolDirection or false
local sDepth = OptionalParameters.sDepth or 0
local nToolIndex = OptionalParameters.nToolIndex
local dLongitudinalOffset = OptionalParameters.dLongitudinalOffset or 0
if OptionalParameters.dPocketHeight then
dLongitudinalOffset = 0
end
local dRadialStepSpan = OptionalParameters.dRadialStepSpan
local dMinNzDownUp = OptionalParameters.dMinNzDownUp
local sUserNotes = OptionalParameters.sUserNotes or ''
-- lunghezze, direzioni e punti caratteristici della lavorazione e del lato lavorato
Cutting.dEdgeLength = EdgeToMachine.dLength
if bOppositeToolDirection then
Cutting.vtToolDirection = -EdgeToMachine.vtN
else
Cutting.vtToolDirection = EdgeToMachine.vtN
end
Cutting.vtEdgeDirection = EdgeToMachine.vtN ^ FaceToMachine.vtN
-- TODO conviene spostare questi calcoli nel FaceData?
Cutting.ptEdge1, _, Cutting.ptEdge2 = EgtSurfTmFacetOppositeSide( Proc.id, FaceToMachine.id, -Cutting.vtToolDirection, GDB_ID.ROOT)
-- TODO gestire lama da sotto
-- se si conosce il limite downUp (utensile forzato o downUp forzato) si decide se invertire (ToolInvert)
-- TODO esiste un limite downUp massimo per la lama da sopra??
if nToolIndex and not dMinNzDownUp then
dMinNzDownUp = TOOLS[nToolIndex].SetupInfo.GetMinNzDownUp( Part.b3Raw, FaceToMachine.vtN, Cutting.vtToolDirection)
end
if dMinNzDownUp and FaceToMachine.vtN:getZ() < dMinNzDownUp then
Cutting.bToolInvert = true
else
Cutting.bToolInvert = false
end
-- ricerca utensile
if nToolIndex then
Cutting.nToolIndex = nToolIndex
else
local ToolSearchParameters = {}
ToolSearchParameters.dElevation = dDepthToMachine
if Cutting.bToolInvert then
ToolSearchParameters.vtN = -FaceToMachine.vtN
else
ToolSearchParameters.vtN = FaceToMachine.vtN
end
ToolSearchParameters.bAllowTopHead = true
-- TODO bisognerà implementare anche la lama da sotto
ToolSearchParameters.bAllowBottomHead = false
ToolSearchParameters.bForceLongcutBlade = bForceLongcutBlade
local ToolInfo = MachiningLib.FindBlade( Proc, ToolSearchParameters)
-- ora che l'utensile è scelto, se non era definito l'angolo di DownUp lo verifico per decidere se invertire
if ToolInfo.nToolIndex and not dMinNzDownUp then
dMinNzDownUp = TOOLS[ToolInfo.nToolIndex].SetupInfo.GetMinNzDownUp( Part.b3Raw, FaceToMachine.vtN, Cutting.vtToolDirection)
if FaceToMachine.vtN:getZ() < dMinNzDownUp then
Cutting.bToolInvert = true
end
end
Cutting.nToolIndex = ToolInfo.nToolIndex
end
if not TOOLS[Cutting.nToolIndex] or not TOOLS[Cutting.nToolIndex].sName then
Cutting.sMessage = 'Blade not found'
Cutting.bIsApplicable = false
EgtOutLog( Cutting.sMessage)
return Cutting, EdgeToMachine.dElevation
end
-- verifica dimensioni tasca compatibili
-- se tasca meno spessa della lama la lavorazione non è applicabile
if OptionalParameters.dPocketHeight and ( TOOLS[Cutting.nToolIndex].dThickness > dPocketHeight + 10 * GEO.EPS_SMALL) then
Cutting.sMessage = 'Pocket too narrow for blade thickness'
Cutting.bIsApplicable = false
EgtOutLog( Cutting.sMessage)
return Cutting, EdgeToMachine.dElevation
end
-- se tasca chiusa da entrambi i lati e più stretta della lama la lavorazione non è applicabile
if not ( EdgeToMachine.bIsStartOpen or EdgeToMachine.bIsEndOpen) then
if TOOLS[Cutting.nToolIndex].dDiameter > EdgeToMachine.dLength + 10 * GEO.EPS_SMALL then
Cutting.sMessage = 'Pocket too narrow for blade diameter'
Cutting.bIsApplicable = false
EgtOutLog( Cutting.sMessage)
return Cutting, EdgeToMachine.dElevation
end
end
-- parametri della lavorazione
-- profondità (parametro DEPTH)
Cutting.sDepth = sDepth
-- inizio e fine aperti o chiusi
Cutting.bIsStartClosed = not EdgeToMachine.bIsStartOpen
Cutting.bIsEndClosed = not EdgeToMachine.bIsEndOpen
-- lato di lavoro e inversione
if TOOLS[Cutting.nToolIndex].bIsCCW then
Cutting.nWorkside = MCH_MILL_WS.RIGHT
Cutting.bInvert = true
else
Cutting.nWorkside = MCH_MILL_WS.LEFT
Cutting.bInvert = false
end
if bOppositeToolDirection then
Cutting.bInvert = not Cutting.bInvert
end
if Cutting.bToolInvert then
Cutting.bInvert = not Cutting.bInvert
end
-- profondità da lavorare e offset radiale
if OptionalParameters.dPocketHeight then
if TOOLS[Cutting.nToolIndex].dMaxDepth > dDepthToMachine - 10 * GEO.EPS_SMALL then
-- TODO la depth dovrebbe essere quella del machining
Cutting.dDepthToMachine = dDepthToMachine
Cutting.dResidualDepth = 0
if bOppositeToolDirection then
Cutting.dRadialOffset = -dDepthToMachine
else
Cutting.dRadialOffset = EdgeToMachine.dElevation - dDepthToMachine
end
else
Cutting.dDepthToMachine = TOOLS[Cutting.nToolIndex].dMaxDepth - 1
Cutting.dResidualDepth = dDepthToMachine - Cutting.dDepthToMachine
if bOppositeToolDirection then
Cutting.dRadialOffset = -Cutting.dDepthToMachine
else
Cutting.dRadialOffset = EdgeToMachine.dElevation - Cutting.dDepthToMachine
end
end
else
Cutting.dDepthToMachine = dDepthToMachine
Cutting.dResidualDepth = 0
if bOppositeToolDirection then
Cutting.dRadialOffset = -dDepthToMachine
else
Cutting.dRadialOffset = EdgeToMachine.dElevation - dDepthToMachine
end
end
-- completamento
Cutting.dCompletionPercentage = ( 1 - Cutting.dResidualDepth / Cutting.dDepthToMachine) * 100
-- step verticale e offset longitudinale
Cutting.Steps = MachiningLib.GetMachiningSteps( dPocketHeight, TOOLS[Cutting.nToolIndex].dThickness)
Cutting.Steps.nStepType = MCH_MILL_ST.ONEWAY
Cutting.dMaxElev = Cutting.Steps.dStep * Cutting.Steps.nCount - 10 * GEO.EPS_SMALL
if Cutting.bToolInvert then
if Cutting.Steps.nCount > 1 then
Cutting.dLongitudinalOffset = - dPocketHeight
else
Cutting.dLongitudinalOffset = - TOOLS[Cutting.nToolIndex].dThickness - dLongitudinalOffset
end
else
Cutting.dLongitudinalOffset = dLongitudinalOffset
end
-- distanza di sicurezza
Cutting.dStartSafetyLength = BeamData.CUT_SIC
-- overlap
Cutting.dOverlap = 0
-- faceuse e frame lavorazione
if bOppositeToolDirection then
Cutting.nFaceuse = BeamLib.GetNearestOrthoOpposite( -Cutting.vtToolDirection)
Cutting.vtFaceUse = -Cutting.vtToolDirection
else
Cutting.nFaceuse = BeamLib.GetNearestOrthoOpposite( Cutting.vtToolDirection)
Cutting.vtFaceUse = Cutting.vtToolDirection
end
-- SCC
Cutting.nSCC = GetSCC( Cutting.vtToolDirection)
-- asse bloccato
Cutting.sBlockedAxis = BeamLib.GetBlockedAxis( Cutting.nToolIndex, 'perpendicular', Part.b3Raw, FaceToMachine.vtN, EgtIf( FaceToMachine.vtN:getX() > 0, X_AX(), -X_AX()))
-- eventuale step orizzontale
Cutting.CloneStepsRadial = {}
if not dRadialStepSpan then
dRadialStepSpan = Cutting.dDepthToMachine
end
if dRadialStepSpan > 10 * GEO.EPS_SMALL and TOOLS[Cutting.nToolIndex].dSideStep then
Cutting.CloneStepsRadial = MachiningLib.GetMachiningSteps( dRadialStepSpan, TOOLS[Cutting.nToolIndex].dSideStep)
else
Cutting.CloneStepsRadial.nCount = 1
Cutting.CloneStepsRadial.dStep = Cutting.dDepthToMachine
end
-- approccio e retrazione
Cutting.LeadIn, Cutting.LeadOut = CalculateLeadInOut( Cutting, EdgeToMachine, Part)
-- lunghezza lavorata
-- TODO per il calcolo del dLengthOnX si deve correggere con allungamento / accorciamento percorso
Cutting.dLengthToMachine = EdgeToMachine.dLength + Cutting.LeadIn.dStartAddLength + Cutting.LeadOut.dEndAddLength
local b3BoxEdge = BBox3d( Cutting.ptEdge1, Cutting.ptEdge2)
Cutting.dLengthOnX = b3BoxEdge:getDimX()
Cutting.dLengthToMachineAllStepsWithLeadInOut = MachiningLib.GetLengthToMachineAllStepsWithLeadInOut( Cutting)
-- lunghezza impronta lama
if Cutting.bIsStartClosed and Cutting.bIsEndClosed then
Cutting.dToolMarkLength = abs( min( Cutting.LeadIn.dStartAddLength, Cutting.LeadOut.dEndAddLength))
elseif Cutting.bIsStartClosed then
Cutting.dToolMarkLength = abs( Cutting.LeadIn.dStartAddLength)
elseif Cutting.bIsEndClosed then
Cutting.dToolMarkLength = abs( Cutting.LeadOut.dEndAddLength)
end
-- area lavorata
Cutting.dAreaToMachine = min( EdgeToMachine.dElevation, Cutting.dDepthToMachine) * ( min( Cutting.dEdgeLength, Cutting.dLengthToMachine + 2 * Cutting.dToolMarkLength))
-- geometria
Cutting.Geometry = {{Cutting.idProc, FaceToMachine.id}}
-- note utente
Cutting.sUserNotes = sUserNotes
-- nome operazione
Cutting.sOperationName = 'Cut_' .. ( EgtGetName( Cutting.idProc) or tostring( Cutting.idProc)) .. '_' .. tostring( FaceToMachine.id + 1)
-- se lavorazione aperta sulla coda, eventuali aggiustamenti
-- TODO valutare se fare funzione a parte
if Proc.AffectedFaces.bLeft and ( EdgeToMachine.sType == 'Bottom' or ( Cutting.vtToolDirection:getX() < 0.707)) then
local dLengthOnX = Cutting.dLengthOnX
-- se feature splittata non si considera la lunghezza della feature per il check spostamento dopo separazione
if bIsSplitFeature then
dLengthOnX = 0
end
local bStartLeft = MachiningLib.StartsLeftSide( Cutting)
local dAddLengthLeftSide = Cutting.LeadOut.dEndAddLength
local dAddLengthToReduce = sqrt( Cutting.dDepthToMachine * TOOLS[Cutting.nToolIndex].dDiameter - Cutting.dDepthToMachine * Cutting.dDepthToMachine)
if bStartLeft then
dAddLengthLeftSide = Cutting.LeadIn.dStartAddLength
end
if not AreSameOrOppositeVectorApprox( EdgeToMachine.vtN, Y_AX()) then
if MachiningLib.CanMoveAfterSplitcut( dLengthOnX, Part) then
Cutting.sStage = 'AfterTail'
else
Cutting.bIsApplicable = false
end
elseif dAddLengthLeftSide + dAddLengthToReduce > dExtendAfterTail then
if MachiningLib.CanMoveAfterSplitcut( dLengthOnX, Part) then
Cutting.sStage = 'AfterTail'
else
if bStartLeft then
Cutting.LeadIn.dStartAddLength = - dAddLengthToReduce + dExtendAfterTail
else
Cutting.LeadOut.dEndAddLength = - dAddLengthToReduce + dExtendAfterTail
end
end
end
end
return Cutting
end
-------------------------------------------------------------------------------------------------------------
return FACEBYBLADE