-- Strategia: STR0006 -- Descrizione -- Lama + fresa tenone -- Feature: 50,1 -- carico librerie local BeamLib = require( 'BeamLib') local BeamData = require( 'BeamData') local MachiningLib = require( 'MachiningLib') local FeatureLib = require( 'FeatureLib') -- strategie di base local BladeToWaste = require( 'BLADETOWASTE') -- Tabella per definizione modulo local STR0006 = {} local Strategy = {} ------------------------------------------------------------------------------------------------------------- function GetTenonStrategy( Proc, Part) local Machining = {} Machining.Milling = {} Machining.Cutting = {} 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 } 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 } 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' 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 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 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 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 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.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( 100) TotalResult.dMRR = ( Result.Milling.dMRR + Result.Cutting.dMRR) / 2 TotalResult.nQuality = FeatureLib.GetFeatureQuality( EgtIf( Strategy.Machining.bCuttingWithMill, 'Mill,Mill', 'Mill,Blade')) TotalResult.nFeatureRotationIndex = GetFeatureRotationIndex( Proc) TotalResult.sInfo = '' -- lavorazione incompleta elseif Strategy.Machining.Cutting.bIsApplicable then TotalResult.sStatus = 'Not-Completed' TotalResult.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( 50) TotalResult.dMRR = Result.Cutting.dMRR TotalResult.nQuality = FeatureLib.GetFeatureQuality( EgtIf( Strategy.Machining.bCuttingWithMill, 'Mill', 'Blade')) TotalResult.sInfo = 'Tenon not completed' -- 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, 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 Strategy.Machining.Cutting.Steps = {} Strategy.Machining.Cutting.LeadIn = {} Strategy.Machining.Cutting.nType = MCH_MY.POCKETING Strategy.Machining.Cutting.nSubType = MCH_POCK_SUB.SPIRALIN Strategy.Machining.Cutting.LeadIn.nType = MCH_POCK_LI.ZIGZAG Strategy.Machining.Cutting.Steps.dStep = TOOLS[Strategy.Machining.Cutting.ToolInfo.nToolIndex].dStep Strategy.Machining.Cutting.Steps.dSideStep = TOOLS[Strategy.Machining.Cutting.ToolInfo.nToolIndex].dSideStep Strategy.Machining.Cutting.nToolIndex = Strategy.Machining.Cutting.ToolInfo.nToolIndex Strategy.Machining.Cutting.LeadIn.dTangentDistance = TOOLS[Strategy.Machining.Cutting.ToolInfo.nToolIndex].dDiameter/2 Strategy.Machining.Cutting.LeadIn.dElevation = TOOLS[Strategy.Machining.Cutting.ToolInfo.nToolIndex].dDiameter/2 Strategy.Machining.Cutting.sDepth = 0 Strategy.Machining.Cutting.Geometry = {{ Strategy.idTenonCutPlane, 0}} Strategy.Machining.Cutting.vtToolDirection = Proc.FeatureInfo.vtTenonN if Proc.AffectedFaces.bLeft and Strategy.bCanMoveAfterSplit then Strategy.Machining.Cutting.sStage = 'AfterTail' end 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 local AuxiliaryData = {} -- 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 -- aggiungo geometria Strategy.Machining.Milling.Geometry = {{ Proc.FeatureInfo.idAddAuxGeom, -1}} Strategy.Machining.Milling.nToolIndex = Strategy.Machining.Milling.ToolInfo.nToolIndex Strategy.Machining.Milling.nType = MCH_MY.MILLING Strategy.Machining.Milling.vtToolDirection = Proc.FeatureInfo.vtTenonN Strategy.Machining.Milling.sDepth = min( -Strategy.Machining.Milling.ToolInfo.dResidualDepth, 0) Strategy.Machining.Milling.dStartSafetyLength = BeamData.COLL_SIC Strategy.Machining.Milling.Steps = {} -- se servono passate con sovramateriale e lunghezza tenone entro il massimo materiale, si annulla lo step if Strategy.Machining.nMillingPathsNeeded > 1 and Proc.FeatureInfo.dTenonLength < TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dMaxMaterial - BeamData.COLL_SIC then Strategy.Machining.Milling.Steps.dStep = 0 else Strategy.Machining.Milling.Steps.dStep = TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dStep end Strategy.Machining.Milling.Steps.nStepType = MCH_MILL_ST.ONEWAY 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) -- LeadIn / LeadOut Strategy.Machining.Milling.LeadIn = {} Strategy.Machining.Milling.LeadOut = {} Strategy.Machining.Milling.LeadIn.nType = MCH_MILL_LI.TANGENT Strategy.Machining.Milling.LeadOut.nType = MCH_MILL_LI.TANGENT Strategy.Machining.Milling.LeadIn.dTangentDistance = TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dDiameter / 2 + BeamData.COLL_SIC Strategy.Machining.Milling.LeadIn.dPerpDistance = TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dSideStep Strategy.Machining.Milling.LeadOut.dTangentDistance = TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dDiameter / 2 + BeamData.COLL_SIC Strategy.Machining.Milling.LeadOut.dPerpDistance = TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].dSideStep if Proc.AffectedFaces.bLeft and Strategy.bCanMoveAfterSplit then Strategy.Machining.Milling.sStage = 'AfterTail' end -- sistemo il lato e la direzione di lavoro Strategy.Machining.Milling.bInvert = EgtIf( TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].bIsCCW, false, true) Strategy.Machining.Milling.nWorkside = EgtIf( TOOLS[Strategy.Machining.Milling.ToolInfo.nToolIndex].bIsCCW, MCH_MILL_WS.RIGHT, MCH_MILL_WS.LEFT) Strategy.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 Strategy.Machining.Milling.nSCC = MCH_SCC.ADIR_XM else Strategy.Machining.Milling.nSCC = MCH_SCC.ADIR_XP end -- passate con sovramateriale AuxiliaryData.Clones = {} for i = Strategy.Machining.nMillingPathsNeeded, 1, -1 do -- il primo è il passaggio più esterno local nIndexClones = Strategy.Machining.nMillingPathsNeeded - i + 1 -- suddivido step in base al numero passate da fare local dRealSideStep = floor( Proc.FeatureInfo.dTenonMaxDist / Strategy.Machining.nMillingPathsNeeded) -- cambia solo sovrmateriale radiale AuxiliaryData.Clones[nIndexClones] = {} -- ultima passata con sovramateriale impostato if i == 1 then AuxiliaryData.Clones[nIndexClones].dRadialOffset = Strategy.Parameters.dOverMatOnRadius else AuxiliaryData.Clones[nIndexClones].dRadialOffset = ( i - 1) * dRealSideStep end end -- aggiunge lavorazione bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, Strategy.Machining.Milling, AuxiliaryData) end end end return bAreAllMachiningsAdded, Strategy.Result end ------------------------------------------------------------------------------------------------------------- return STR0006