Files
databeamnew/Strategies/Standard/STR0006/STR0006.lua
T

362 lines
19 KiB
Lua

-- Strategia: STR0006
-- Descrizione
-- Lama + fresa tenone
-- Feature: 50,1
-- carico librerie
local BeamLib = require( 'BeamLib')
local BeamData = require( 'BeamDataNew')
local MachiningLib = require( 'MachiningLib')
local FeatureLib = require( 'FeatureLib')
local PreSimulationLib = require( 'PreSimulationLib')
-- strategie di base
local BladeToWaste = require( 'BLADETOWASTE')
-- Tabella per definizione modulo
local STR0006 = {}
local Strategy = {}
-------------------------------------------------------------------------------------------------------------
local function GetTenonStrategy( Proc, Part)
local Machining = {}
Machining.Milling = MachiningLib.InitMachiningParameters( MCH_MY.MILLING)
Machining.Cutting = MachiningLib.InitMachiningParameters( MCH_MY.MILLING)
local Result = {}
Result.Milling = {}
Result.Cutting = {}
local ToolSearchParameters = {}
-- scelta automatica lavorazione. Non viene mai scelta la motosega
if Strategy.Parameters.sCuttingStrategy == 'AUTO' then
-- creo piano di taglio sulla testa del tenone
local OptionalParameters = { dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume,
dMaxWasteLength = Strategy.Parameters.dMaxWasteLength,
bReduceBladePath = Strategy.Parameters.bReduceBladePath
}
Machining.Cutting, Result.Cutting = BladeToWaste.Make( Strategy.idTenonCutPlane, Part, OptionalParameters)
-- se presente almeno una lavorazione e completo, il taglio è applicabile
if #Machining.Cutting > 0 and Result.Cutting and Result.Cutting.sStatus == 'Completed' then
Machining.Cutting.bIsApplicable = true
end
-- se non possibile di lama si prova con fresa
if not Machining.Cutting or Result.Cutting.sStatus ~= 'Completed' then
Machining.bCuttingWithMill = true
end
-- lavorazione forzata con utensile lama
elseif Strategy.Parameters.sCuttingStrategy == 'BLADE_FORCED' then
local OptionalParameters = { dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume,
dMaxWasteLength = Strategy.Parameters.dMaxWasteLength,
bReduceBladePath = Strategy.Parameters.bReduceBladePath
}
Machining.Cutting, Result.Cutting = BladeToWaste.Make( Strategy.idTenonCutPlane, Part, OptionalParameters)
-- se presente almeno una lavorazione e completo, il taglio è applicabile
if #Machining.Cutting > 0 and Result.Cutting.sStatus == 'Completed' then
Machining.Cutting.bIsApplicable = true
end
-- lavorazione forzata con utensile fresa
elseif Strategy.Parameters.sCuttingStrategy == 'MILL_FORCED' then
Machining.bCuttingWithMill = true
-- lavorazione forzata con utensile motosega
elseif Strategy.Parameters.sCuttingStrategy == 'CHAINSAW_FORCED' then
-- DA FARE!!
end
-- === ricerca utensile per lavorare tenone ===
Machining.Milling.bIsApplicable = false
-- se tenone in testa oppure se di coda ma è possibile lavorare dopo separazione
if not( Proc.AffectedFaces.bLeft) or Strategy.bCanMoveAfterSplit then
ToolSearchParameters.dElevation = Proc.FeatureInfo.dTenonLength
ToolSearchParameters.vtToolDirection = Proc.FeatureInfo.vtTenonN
ToolSearchParameters.sMillShape = 'STANDARD'
ToolSearchParameters.AvailableToolList = MachiningLib.GetAvailableToolList( Proc, Strategy.Parameters.sMillingList, 'Milling')
Machining.Milling.ToolInfo = {}
Machining.Milling.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
if Machining.Milling.ToolInfo.nToolIndex then
local bMachIsOk = true
if ( Proc.FeatureInfo.vtTenonN:getZ() < 0 and TOOLS[Machining.Milling.ToolInfo.nToolIndex].SetupInfo.HeadType.bTop) or
( Proc.FeatureInfo.vtTenonN:getZ() > 0 and TOOLS[Machining.Milling.ToolInfo.nToolIndex].SetupInfo.HeadType.bBottom) then
-- TODO questo test va sostituito con check collisione asse Z (PreCollision)
local dTotalLen = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dLength + TOOLS[Machining.Milling.ToolInfo.nToolIndex].SetupInfo.dPivot
local dHorizSpace = dTotalLen * sqrt( 1 - ( Proc.FeatureInfo.vtTenonN:getZ() * Proc.FeatureInfo.vtTenonN:getZ()))
if dHorizSpace - ( TOOLS[Machining.Milling.ToolInfo.nToolIndex].SetupInfo.dCAxisSideEncumbrance / 2) < Proc.b3Box:getDimX() then
bMachIsOk = false
end
end
if bMachIsOk then
Machining.Milling.bIsApplicable = true
-- calcolo passate necessarie
if Proc.FeatureInfo.dTenonMaxDist > TOOLS[Machining.Milling.ToolInfo.nToolIndex].dDiameter * 0.8 then
Machining.nMillingPathsNeeded = ceil( Proc.FeatureInfo.dTenonMaxDist / TOOLS[Machining.Milling.ToolInfo.nToolIndex].dSideStep)
else
Machining.nMillingPathsNeeded = 1
end
local ParametersMRR = {}
ParametersMRR.nToolIndex = Machining.Milling.ToolInfo.nToolIndex
Result.Milling.dMRR = MachiningLib.GetToolMRR( ParametersMRR)
if Machining.Milling.ToolInfo.dResidualDepth < 10 * GEO.EPS_SMALL then
Result.Milling.sStatus = 'Completed'
else
Result.Milling.sStatus = 'Not-Completed'
Result.Milling.sInfo = 'Tenon not complete, left ' .. ceil( Machining.Milling.ToolInfo.dResidualDepth) .. 'mm'
end
-- aggiungo geometria
Machining.Milling.Geometry = {{ Proc.FeatureInfo.idAddAuxGeom, -1}}
Machining.Milling.nToolIndex = Machining.Milling.ToolInfo.nToolIndex
Machining.Milling.nType = MCH_MY.MILLING
Machining.Milling.vtToolDirection = Proc.FeatureInfo.vtTenonN
Machining.Milling.sDepth = min( -Machining.Milling.ToolInfo.dResidualDepth, 0)
Machining.Milling.dStartSafetyLength = BeamData.COLL_SIC
Machining.Milling.Steps = {}
-- se servono passate con sovramateriale e lunghezza tenone entro il massimo materiale, si annulla lo step
if Machining.nMillingPathsNeeded > 1 and Proc.FeatureInfo.dTenonLength < TOOLS[Machining.Milling.ToolInfo.nToolIndex].dMaxMaterial - BeamData.COLL_SIC then
Machining.Milling.Steps.dStep = 0
else
Machining.Milling.Steps.dStep = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dStep
end
Machining.Milling.Steps.nStepType = MCH_MILL_ST.ONEWAY
-- LeadIn / LeadOut
Machining.Milling.LeadIn = {}
Machining.Milling.LeadOut = {}
Machining.Milling.LeadIn.nType = MCH_MILL_LI.TANGENT
Machining.Milling.LeadOut.nType = MCH_MILL_LI.TANGENT
Machining.Milling.LeadIn.dTangentDistance = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dDiameter / 2 + BeamData.COLL_SIC
Machining.Milling.LeadIn.dPerpDistance = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dSideStep
Machining.Milling.LeadOut.dTangentDistance = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dDiameter / 2 + BeamData.COLL_SIC
Machining.Milling.LeadOut.dPerpDistance = TOOLS[Machining.Milling.ToolInfo.nToolIndex].dSideStep
Machining.Milling.dLengthToMachine = Proc.FeatureInfo.dTenonPathLength
if Proc.AffectedFaces.bLeft and Strategy.bCanMoveAfterSplit then
Machining.Milling.sStage = 'AfterTail'
end
-- sistemo il lato e la direzione di lavoro
Machining.Milling.bInvert = EgtIf( TOOLS[Machining.Milling.ToolInfo.nToolIndex].bIsCCW, false, true)
Machining.Milling.nWorkside = EgtIf( TOOLS[Machining.Milling.ToolInfo.nToolIndex].bIsCCW, MCH_MILL_WS.RIGHT, MCH_MILL_WS.LEFT)
Machining.Milling.sUserNotes = EgtSetVal( 'MaxElev', EgtNumToString( Proc.FeatureInfo.dTenonLength, 1)) .. ';'
-- SCC : si tiene il motore sempre più verso l'esterno
if Proc.AffectedFaces.bLeft then
Machining.Milling.nSCC = MCH_SCC.ADIR_XM
else
Machining.Milling.nSCC = MCH_SCC.ADIR_XP
end
-- passate con sovramateriale
Machining.Milling.AuxiliaryData = {}
Machining.Milling.AuxiliaryData.Clones = {}
for i = Machining.nMillingPathsNeeded, 1, -1 do
-- il primo è il passaggio più esterno
local nIndexClones = Machining.nMillingPathsNeeded - i + 1
-- suddivido step in base al numero passate da fare
local dRealSideStep = floor( Proc.FeatureInfo.dTenonMaxDist / Machining.nMillingPathsNeeded)
-- cambia solo sovrmateriale radiale
Machining.Milling.AuxiliaryData.Clones[nIndexClones] = {}
-- ultima passata con sovramateriale impostato
if i == 1 then
Machining.Milling.AuxiliaryData.Clones[nIndexClones].dRadialOffset = Strategy.Parameters.dOverMatOnRadius
else
Machining.Milling.AuxiliaryData.Clones[nIndexClones].dRadialOffset = ( i - 1) * dRealSideStep
end
end
-- test finecorsa sulla passata più esterna: se extracorsa, la lavorazione non è fattibile
-- TODO sostituire con applicazione della lavorazione?
-- TODO funzione per allungare il percorso??????
local idGeomMaxOffset = EgtCopyGlob( Proc.FeatureInfo.idAddAuxGeom, Part.idTempGroup)
EgtOffsetCurve( idGeomMaxOffset, Machining.Milling.AuxiliaryData.Clones[1].dRadialOffset + TOOLS[Machining.Milling.ToolInfo.nToolIndex].dDiameter / 2, Part.idTempGroup)
local vtCurveStart = EgtSV( idGeomMaxOffset, GDB_ID.ROOT)
local vtCurveEnd = EgtEV( idGeomMaxOffset, GDB_ID.ROOT)
local ptCurveStart = EgtSP( idGeomMaxOffset, GDB_ID.ROOT) + -vtCurveStart * Machining.Milling.LeadIn.dTangentDistance + ( Proc.FeatureInfo.vtTenonN ^ -vtCurveStart) * Machining.Milling.LeadIn.dPerpDistance
local ptCurveEnd = EgtEP( idGeomMaxOffset, GDB_ID.ROOT) + vtCurveEnd * Machining.Milling.LeadOut.dTangentDistance + ( vtCurveEnd ^ Proc.FeatureInfo.vtTenonN) * Machining.Milling.LeadOut.dPerpDistance
EgtAddCurveCompoArcTg( idGeomMaxOffset, ptCurveStart, false, GDB_RT.GLOB)
EgtAddCurveCompoArcTg( idGeomMaxOffset, ptCurveEnd, true, GDB_RT.GLOB)
local bOutOfStroke = PreSimulationLib.CheckOutOfStrokeFromGeometry( idGeomMaxOffset, Proc.FeatureInfo.vtTenonN, Machining.Milling.nSCC, TOOLS[Machining.Milling.ToolInfo.nToolIndex])
if bOutOfStroke then
Machining.Milling.bIsApplicable = false
end
-- tempo di svuotatura
Result.Milling.dTimeToMachine = MachiningLib.GetTimeToMachineAllStepsWithLeadInOut( Machining.Milling, Part)
end
end
-- se cutting da fare come svuotatura, copio i dati dell'utensile scelto per lavorare il tenone
if Machining.bCuttingWithMill and Machining.Milling.bIsApplicable then
Machining.Cutting.bIsApplicable = true
Machining.Cutting.ToolInfo = Machining.Milling.ToolInfo
Result.Cutting.dMRR = Result.Milling.dMRR
Machining.Cutting.Steps = {}
Machining.Cutting.LeadIn = {}
Machining.Cutting.nType = MCH_MY.POCKETING
Machining.Cutting.nSubType = MCH_POCK_SUB.SPIRALIN
Machining.Cutting.LeadIn.nType = MCH_POCK_LI.ZIGZAG
Machining.Cutting.Steps.dStep = TOOLS[Machining.Cutting.ToolInfo.nToolIndex].dStep
Machining.Cutting.Steps.dSideStep = TOOLS[Machining.Cutting.ToolInfo.nToolIndex].dSideStep
Machining.Cutting.nToolIndex = Machining.Cutting.ToolInfo.nToolIndex
Machining.Cutting.LeadIn.dTangentDistance = TOOLS[Machining.Cutting.ToolInfo.nToolIndex].dDiameter/2
Machining.Cutting.LeadIn.dElevation = TOOLS[Machining.Cutting.ToolInfo.nToolIndex].dDiameter/2
Machining.Cutting.sDepth = 0
Machining.Cutting.Geometry = {{ Strategy.idTenonCutPlane, 0}}
Machining.Cutting.vtToolDirection = Proc.FeatureInfo.vtTenonN
if Proc.AffectedFaces.bLeft and Strategy.bCanMoveAfterSplit then
Machining.Cutting.sStage = 'AfterTail'
end
-- tempo di svuotatura
Result.Cutting.dTimeToMachine = MachiningLib.GetTimeToMachineAllStepsWithLeadInOut( Machining.Cutting, Part)
end
end
return Machining, Result
end
-------------------------------------------------------------------------------------------------------------
local function GetFeatureRotationIndex( Proc)
local nVoteIndex
-- se fatto con testa sopra
if TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].SetupInfo.HeadType.bTop then
if Proc.FeatureInfo.vtTenonN:getZ() < 0 then
nVoteIndex = 2
elseif Proc.FeatureInfo.vtTenonN:getZ() > abs( Proc.FeatureInfo.vtTenonN:getY()) then
nVoteIndex = 4
else
nVoteIndex = 3
end
-- se fatto con testa sotto
elseif TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].SetupInfo.HeadType.bBottom then
if Proc.FeatureInfo.vtTenonN:getZ() > 0 then
nVoteIndex = 2
elseif Proc.FeatureInfo.vtTenonN:getZ() < - abs( Proc.FeatureInfo.vtTenonN:getY()) then
nVoteIndex = 4
else
nVoteIndex = 3
end
end
return nVoteIndex
end
-------------------------------------------------------------------------------------------------------------
-- TODO vedere se leggere direttamente la quality dell'utensile e mediarle nel caso di utensile doppio
local function GetTenonMachiningResult( Proc, Result)
local TotalResult = {}
-- setto il risultato in base agli utensili trovati
-- lavorazione completa
if Strategy.Machining.Milling.bIsApplicable and Strategy.Machining.Cutting.bIsApplicable then
TotalResult.sStatus = Result.Milling.sStatus
TotalResult.dCompletionIndex = FeatureLib.GetFeatureCompletionIndex( 100)
TotalResult.dMRR = ( Result.Milling.dMRR + Result.Cutting.dMRR) / 2
TotalResult.dQuality = FeatureLib.GetStrategyQuality( EgtIf( Strategy.Machining.bCuttingWithMill, 'STD', 'FINE'))
TotalResult.nFeatureRotationIndex = GetFeatureRotationIndex( Proc)
TotalResult.dTimeToMachine = Result.Milling.dTimeToMachine + Result.Cutting.dTimeToMachine
TotalResult.sInfo = ''
-- lavorazione incompleta
elseif Strategy.Machining.Cutting.bIsApplicable then
TotalResult.sStatus = 'Not-Completed'
TotalResult.dCompletionIndex = FeatureLib.GetFeatureCompletionIndex( 50)
TotalResult.dMRR = Result.Cutting.dMRR
TotalResult.dQuality = FeatureLib.GetStrategyQuality( EgtIf( Strategy.Machining.bCuttingWithMill, 'MILL', 'SAWBLADE'))
TotalResult.sInfo = 'Tenon not completed'
TotalResult.dTimeToMachine = Result.Cutting.dTimeToMachine
-- strategia non applicabile, manca il taglio di lama sulla lunghezza del tenone
else
TotalResult = FeatureLib.GetStrategyResultNotApplicable( 'Error on Tenon cutting')
end
return TotalResult
end
-------------------------------------------------------------------------------------------------------------
function STR0006.Make( bAddMachining, Proc, Part, CustomParameters)
-- carico parametri de default e li aggiorno con quelli passati dal chiamante (potrebbero non essere congruenti)
local StrategyLib = {}
StrategyLib.Config = STRATEGIES_CONFIG[CustomParameters.sStrategyId]
Strategy.sName = StrategyLib.Config.sStrategyId
Strategy.Parameters = BeamLib.LoadCustomParametersInStrategy( Proc, Part, CustomParameters, StrategyLib.Config)
Strategy.Machining = {}
Strategy.Result = {}
local Results = {}
local bAreAllMachiningsAdded = true
-- controllo conformità offset tenone
Strategy.Parameters.dOverMatOnRadius = EgtClamp( Strategy.Parameters.dOverMatOnRadius, -5, 5)
Strategy.Parameters.dOverMatOnLength = EgtClamp( Strategy.Parameters.dOverMatOnLength, -5, 5)
-- calcolo se la lavorazione del tenone può essere spostata dopo taglio di coda
local dLengthOnX = Proc.b3Box:getDimX()
Strategy.bCanMoveAfterSplit = MachiningLib.CanMoveAfterSplitcut( dLengthOnX, Part)
-- aggiunta superficie di taglio sulla lunghezza del tenone
local nAddGrpId = BeamLib.GetAddGroup( Part.id)
local ptCenterAddSurf = Proc.FeatureInfo.ptTenonCenter + ( Proc.FeatureInfo.vtTenonN * Strategy.Parameters.dOverMatOnLength)
Strategy.idTenonCutPlane = EgtSurfTmPlaneInBBox( nAddGrpId, ptCenterAddSurf, Proc.FeatureInfo.vtTenonN, Part.b3Part, GDB_RT.GLOB)
Strategy.Machining, Results = GetTenonStrategy( Proc, Part)
Strategy.Result = GetTenonMachiningResult( Proc, Results)
-- applicazione delle lavorazioni
if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then
-- taglio in lunghezza sul tenone
if Strategy.Machining.Cutting.bIsApplicable then
OptionalParameters = {}
-- se cutting da fare come svuotatura
if Strategy.Machining.bCuttingWithMill then
bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, Strategy.Machining.Cutting)
-- taglio di lama
else
for i = 1, #Strategy.Machining.Cutting do
if Strategy.Machining.Cutting.bIsApplicable then
if Proc.AffectedFaces.bLeft and Strategy.bCanMoveAfterSplit then
Strategy.Machining.Cutting[i].sStage = 'AfterTail'
end
local bIsMachiningAdded = MachiningLib.AddMachinings( Proc, Strategy.Machining.Cutting[i])
if not bIsMachiningAdded then
bAreAllMachiningsAdded = false
end
end
end
end
end
-- passaggio sul profilo
if Strategy.Machining.Milling.bIsApplicable then
-- se molti passaggi richiesti, si fa svuotatura
-- TODO in attesa delle svuotature, si fanno passaggi senza limiti sul numero massimo. Poi togliere il FALSE nella condizione.
if false and Strategy.Machining.nMillingPathsNeeded > Strategy.Parameters.nMaxMillingPaths then
-- TODO. SERVONO NUOVE SVUOTATURE!!!!
else
local nNearSide -- +3 = Z+, -3 = Z-
local bShortPart = ( Part.b3Part:getDimX() < BeamData.LEN_SHORT_PART)
if TOOLS[Strategy.Machining.Milling.nToolIndex].SetupInfo.HeadType.bTop then
if bShortPart and Proc.FeatureInfo.vtTenonN:getX() < 0 and Proc.FeatureInfo.vtTenonN:getZ() > 0 then
nNearSide = -3
else
nNearSide = 3
end
else
if bShortPart and Proc.FeatureInfo.vtTenonN:getX() < 0 and Proc.FeatureInfo.vtTenonN:getZ() < 0 then
nNearSide = 3
else
nNearSide = -3
end
end
BeamLib.PutStartNearestToEdge( Proc.FeatureInfo.idAddAuxGeom, Part.b3Raw, Proc.FeatureInfo.dTenonMaxDist, nNearSide)
-- aggiunge lavorazione
bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, Strategy.Machining.Milling, Strategy.Machining.Milling.AuxiliaryData)
end
end
end
return bAreAllMachiningsAdded, Strategy.Result
end
-------------------------------------------------------------------------------------------------------------
return STR0006