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

214 lines
11 KiB
Lua

-- Strategia: STR0013
-- Descrizione
-- foratura
-- Feature: foro con fresa
-- carico librerie
local BeamLib = require( 'BeamLib')
local BeamData = require( 'BeamDataNew')
local MachiningLib = require( 'MachiningLib')
local FeatureLib = require( 'FeatureLib')
-- strategie di base
-- Tabella per definizione modulo
local STR0013 = {}
local Strategy = {}
-------------------------------------------------------------------------------------------------------------
local function GetDrillingWithMillStrategy( Proc, Part)
local ToolSearchParameters = {}
local Machining = {}
local Milling = { ToolInfo = {}}
local Milling2 = { ToolInfo = {}}
-- si cerca fresa con direzione standard
ToolSearchParameters = {}
ToolSearchParameters.dElevation = Proc.FeatureInfo.dDrillLen + BeamData.MILL_OVERLAP
ToolSearchParameters.vtToolDirection = Proc.FeatureInfo.vtDrillExtrusion
ToolSearchParameters.dMaxToolDiameter = Proc.FeatureInfo.dDrillDiam + Strategy.Parameters.dDiameterTolerance
ToolSearchParameters.sType = 'MILL_STD'
ToolSearchParameters.sMillShape = 'STANDARD'
ToolSearchParameters.AvailableToolList = MachiningLib.GetAvailableToolList( Proc, Strategy.Parameters.sMillList, 'Milling')
Milling.vtToolDirection = -Proc.FeatureInfo.vtDrillExtrusion
Milling.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
-- se foro aperto, si cerca anche fresa con direzione invertita
if Proc.FeatureInfo.bIsDrillOpen then
ToolSearchParameters = {}
ToolSearchParameters.dElevation = Proc.FeatureInfo.dDrillLen + BeamData.MILL_OVERLAP
ToolSearchParameters.vtToolDirection = -Proc.FeatureInfo.vtDrillExtrusion
ToolSearchParameters.dMaxToolDiameter = Proc.FeatureInfo.dDrillDiam + Strategy.Parameters.dDiameterTolerance
ToolSearchParameters.sType = 'MILL_STD'
ToolSearchParameters.sMillShape = 'STANDARD'
ToolSearchParameters.AvailableToolList = MachiningLib.GetAvailableToolList( Proc, Strategy.Parameters.sMillList, 'Milling')
Milling2.vtToolDirection = -Proc.FeatureInfo.vtDrillExtrusion
Milling2.bInvert = true
Milling2.bToolInvert = true
Milling2.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
end
local bDouble = false
-- se ho trovato entrambi gli utensili e non è forzato da eseguire solo da un lato e una punta lo fa completo, si fa foratura in doppio
if Milling.ToolInfo.nToolIndex and Milling2.ToolInfo.nToolIndex and
not ( Strategy.Parameters.sDrillingMode == 'PREFER_ONE' and ( Milling.ToolInfo.dResidualDepth < 0 or Milling2.ToolInfo.dResidualDepth < 0)) then
bDouble = true
-- se entrambe le punte lavorano più della metà del foro, si cerca un altro utensile che possa lavorare fino alla metà del foro
-- è possibile che si possa trovare fresa più corta che lavora a sufficienza
if Milling.ToolInfo.dResidualDepth < ( Proc.FeatureInfo.dDrillLen - BeamData.MILL_OVERLAP) / 2 and
Milling2.ToolInfo.dResidualDepth < ( Proc.FeatureInfo.dDrillLen - BeamData.MILL_OVERLAP) / 2 then
ToolSearchParameters = {}
ToolSearchParameters.dElevation = ( Proc.FeatureInfo.dDrillLen + BeamData.MILL_OVERLAP) / 2
ToolSearchParameters.vtToolDirection = Proc.FeatureInfo.vtDrillExtrusion
ToolSearchParameters.dMaxToolDiameter = Proc.FeatureInfo.dDrillDiam + Strategy.Parameters.dDiameterTolerance
ToolSearchParameters.AvailableToolList = MachiningLib.GetAvailableToolList( Proc, Strategy.Parameters.sMillList, 'Milling')
local HalfMilling = {}
HalfMilling.ToolInfo = {}
HalfMilling.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
ToolSearchParameters.vtToolDirection = -Proc.FeatureInfo.vtDrillExtrusion
ToolSearchParameters.AvailableToolList = MachiningLib.GetAvailableToolList( Proc, Strategy.Parameters.sMillList, 'Milling')
local HalfMilling2 = {}
HalfMilling2.ToolInfo = {}
HalfMilling2.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
-- se entrambi gli utensili lavorano in modo completo fino alla metà del foro, li sostituisco a qeulli trovati in precedenza
if HalfMilling.ToolInfo.dResidualDepth and HalfMilling2.ToolInfo.dResidualDepth and HalfMilling.ToolInfo.dResidualDepth < 0 and HalfMilling2.ToolInfo.dResidualDepth < 0 then
if Milling.ToolInfo.nToolIndex ~= HalfMilling.ToolInfo.nToolIndex then
Milling.ToolInfo.nToolIndex, Milling.ToolInfo.dResidualDepth = HalfMilling.ToolInfo.nToolIndex, HalfMilling.ToolInfo.dResidualDepth
end
if Milling2.ToolInfo.nToolIndex ~= HalfMilling2.ToolInfo.nToolIndex then
Milling2.ToolInfo.nToolIndex, Milling2.ToolInfo.dResidualDepth = HalfMilling2.ToolInfo.nToolIndex, HalfMilling2.ToolInfo.dResidualDepth
end
end
end
end
local dResidual = Proc.FeatureInfo.dDrillLen
-- aggiunta lavorazioni a lista
-- se foro doppio
if bDouble then
dResidual = Milling.ToolInfo.dResidualDepth + Milling2.ToolInfo.dResidualDepth - Proc.FeatureInfo.dDrillLen
Strategy.Result.dMRR = ( MachiningLib.GetToolMRR( Milling.ToolInfo) + MachiningLib.GetToolMRR( Milling2.ToolInfo)) / 2
local dExtraDrill = ( Proc.FeatureInfo.dDrillLen - BeamData.MILL_OVERLAP - ( Milling.ToolInfo.dResidualDepth + Milling2.ToolInfo.dResidualDepth)) / 2
Milling.sDepth = Proc.FeatureInfo.dDrillLen - Milling.ToolInfo.dResidualDepth - dExtraDrill
table.insert( Machining, Milling)
Milling2.sDepth = Proc.FeatureInfo.dDrillLen - Milling2.ToolInfo.dResidualDepth - dExtraDrill
table.insert( Machining, Milling2)
-- altrimenti singolo
else
local BestMilling
if not Milling.ToolInfo.nToolIndex then
BestMilling = Milling2
elseif not Milling2.ToolInfo.nToolIndex then
BestMilling = Milling
else
if Milling.ToolInfo.dResidualDepth < 0 then
BestMilling = Milling
elseif Milling2.ToolInfo.dResidualDepth < 0 then
BestMilling = Milling2
else
BestMilling = EgtIf( Milling.ToolInfo.dResidualDepth < Milling2.ToolInfo.dResidualDepth, Milling, Milling2)
end
end
if BestMilling.ToolInfo.nToolIndex then
dResidual = BestMilling.ToolInfo.dResidualDepth
if dResidual < 0 then
BestMilling.sDepth = Proc.FeatureInfo.dDrillLen + EgtIf( Proc.FeatureInfo.bIsDrillOpen, BeamData.MILL_OVERLAP, 0)
else
BestMilling.sDepth = Proc.FeatureInfo.dDrillLen - BestMilling.ToolInfo.dResidualDepth
end
Strategy.Result.dMRR = MachiningLib.GetToolMRR( BestMilling.ToolInfo)
table.insert( Machining, BestMilling)
end
end
-- se c'è almeno una lavorazione, si calcola voto
if #Machining > 0 then
if dResidual < 0 then
Strategy.Result.sStatus = 'Completed'
Strategy.Result.dCompletionIndex = 5
Strategy.Result.sInfo = ''
Strategy.Result.dQuality = FeatureLib.GetStrategyQuality( 'MILL')
else
Strategy.Result.sStatus = 'Not-Completed'
local dResidualPrercentage = 100 * ( dResidual / Proc.FeatureInfo.dDrillLen)
Strategy.Result.dCompletionIndex = FeatureLib.GetFeatureCompletionIndex( 100 - dResidualPrercentage)
Strategy.Result.sInfo = 'Machining not complete, left ' .. tostring( ceil( dResidualPrercentage)) .. '%'
Strategy.Result.dQuality = FeatureLib.GetStrategyQuality( 'MILL')
end
-- se son state trovate frese compatibili
else
local sMessage = 'Mill not found'
Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( sMessage)
end
return Machining, Strategy.Result
end
-------------------------------------------------------------------------------------------------------------
function STR0013.Make( bAddMachining, Proc, Part, CustomParameters)
-- carico parametri da 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.Machinings = {}
Strategy.Result = {}
local bAreAllMachiningsAdded
Strategy.Machinings, Strategy.Result = GetDrillingWithMillStrategy( Proc, Part)
if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then
-- aggiunge lavorazione
for j = 1, #Strategy.Machinings do
local MachiningToAdd
local nIndexTool = Strategy.Machinings[j].ToolInfo.nToolIndex
-- se diametro fresa differisce al massimo della tolleranza si fa foratura con fresa (se ammesso)
if abs( TOOLS[nIndexTool].dDiameter - Proc.FeatureInfo.dDrillDiam) < Strategy.Parameters.dDiameterTolerance and Strategy.Parameters.bUseMillAsDrill then
MachiningToAdd = MachiningLib.InitMachiningParameters( MCH_MY.DRILLING)
MachiningToAdd = BeamLib.MergeTables( MachiningToAdd, Strategy.Machinings[j])
MachiningToAdd.Steps.dStep = TOOLS[nIndexTool].dStep / 3
-- se diametro foro più grande della fresa, ma non oltre il doppio del diametro, si fa contornatura a spirale
elseif Proc.FeatureInfo.dDrillDiam < ( TOOLS[nIndexTool].dDiameter * 0.75) * 2 or Strategy.Parameters.bOnlyContouring then
MachiningToAdd = MachiningLib.InitMachiningParameters( MCH_MY.MILLING)
MachiningToAdd = BeamLib.MergeTables( MachiningToAdd, Strategy.Machinings[j])
-- il diametro deve essere almeno 1mm più grande del foro, altrimenti la macchina non riesce ad interpolare
MachiningToAdd.dRadialOffset = min( 0, Proc.FeatureInfo.dDrillDiam - ( TOOLS[nIndexTool].dDiameter + 1))
MachiningToAdd.Steps.nStepType = MCH_MILL_ST.SPIRAL
MachiningToAdd.Steps.dStep = TOOLS[nIndexTool].dStep / 3
MachiningToAdd.LeadOut.nType = MCH_MILL_LI.TANGENT
MachiningToAdd.LeadOut.dTangentDistance = 0.5
MachiningToAdd.LeadOut.dPerpDistance = 0.5
MachiningToAdd.LeadOut.dElevation = Proc.FeatureInfo.dDrillLen
-- se diametro foro più grande del doppio del diametro fresa, si fa svuotatura
else
MachiningToAdd = MachiningLib.InitMachiningParameters( MCH_MY.POCKETING)
MachiningToAdd = BeamLib.MergeTables( MachiningToAdd, Strategy.Machinings[j])
MachiningToAdd.Steps.dStep = TOOLS[nIndexTool].dStep
MachiningToAdd.Steps.dSideStep = TOOLS[nIndexTool].dSideStep
MachiningToAdd.nSubType = MCH_POCK_SUB.SPIRALOUT
MachiningToAdd.LeadIn.nType = MCH_POCK_LI.HELIX
MachiningToAdd.LeadIn.dTangentDistance = TOOLS[nIndexTool].dDiameter / 2
MachiningToAdd.LeadIn.dElevation = MachiningToAdd.Steps.dStep / 2
end
MachiningToAdd.nToolIndex = nIndexTool
MachiningToAdd.Geometry = {{ Proc.FeatureInfo.idAddAuxGeom, -1}}
if Proc.AffectedFaces.bLeft and not Proc.FeatureInfo.bIsDrillOpen then
MachiningToAdd.sStage = 'AfterTail'
end
bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, MachiningToAdd)
end
end
return bAreAllMachiningsAdded, Strategy.Result
end
-------------------------------------------------------------------------------------------------------------
return STR0013