Files
databeamnew/LuaLibs/MachiningLib.lua
T
luca.mazzoleni 7165db47f6 - modifiche per aggiunta strategia BladePlusChain
- in BeamExec versione  primordiale di FindBlade
2024-05-17 18:45:36 +02:00

194 lines
7.6 KiB
Lua

-- MachiningLib.lua by Egalware s.r.l. 2024/04/02
-- Libreria ricerca lavorazioni per Travi
-- 2024/04/02 PRIMA VERSIONE CALCOLO LAVORAZIONI CON STRATEGIE
-- Tabella per definizione modulo
local MachiningLib = {}
-- Include
require( 'EgtBase')
-- Carico i dati globali
local BeamData = require( 'BeamData')
EgtOutLog( ' MachiningLib started', 1)
---------------------------------------------------------------------
---
---@param Proc table la feature
---@param vtTool Vector3d il vettore direzione utensile
---@return number dAngle angolo tra la faccia d'ingresso e la direzione utensile
local function GetToolEntryAngle( Proc, vtTool)
local dSinAngle = -10 * GEO.EPS_SMALL
local vtNorm
if Proc.AffectedFaces.bTop then
vtNorm = Z_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
if Proc.AffectedFaces.bBottom then
vtNorm = -Z_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
if Proc.AffectedFaces.bFront then
vtNorm = -Y_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
if Proc.AffectedFaces.bBack then
vtNorm = Y_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
if Proc.AffectedFaces.bLeft then
vtNorm = -X_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
if Proc.AffectedFaces.bRight then
vtNorm = X_AX()
dSinAngle = max( dSinAngle, vtTool * vtNorm)
end
local dCosAngle = sqrt( 1 - sqr( dSinAngle))
local dAngle = acos( dCosAngle)
return dAngle
end
-------------------------------------------------------------------------------------------------------------
function MachiningLib.GetMachiningSteps( dMachiningDepth, dStep)
local MachiningSteps = {}
MachiningSteps.StepLength = 0
MachiningSteps.Count = ceil( ( dMachiningDepth - 10 * GEO.EPS_SMALL) / dStep)
if MachiningSteps.Count > 1 then
MachiningSteps.StepLength = ( dMachiningDepth - dStep) / ( MachiningSteps.Count - 1)
end
return MachiningSteps
end
-------------------------------------------------------------------------------------------------------------
-- funzione per cercare utensile tipo FRESA con certe caratteristiche
function MachiningLib.FindMill( Proc, sMillType, sMillShape, dMaxToolDiameter, dElevation, vtToolDir)
local ToolInfo = {}
for nCurrIndex=1, #TOOLS do
-- prima verifico che utensile sia compatibile
local bCompatibleTool = true
if TOOLS[nCurrIndex].sType ~= sMillType then
bCompatibleTool = false
elseif TOOLS[nCurrIndex].dDiameter > dMaxToolDiameter then
bCompatibleTool = false
elseif sMillShape == 'STANDARD' and ( TOOLS[nCurrIndex].dSideAngle ~= 0 or TOOLS[nCurrIndex].bIsPen) then
bCompatibleTool = false
elseif sMillShape == 'DOVETAIL' and not TOOLS[nCurrIndex].bIsDoveTail then
bCompatibleTool = false
elseif sMillShape == 'TSHAPEMILL' and not TOOLS[nCurrIndex].bIsTMill then
bCompatibleTool = false
elseif sMillShape == 'PEN' and not TOOLS[nCurrIndex].bIsPen then
bCompatibleTool = false
-- TODO controllare montaggio e verificare se direzione utensile raggiungibile. Serve funzione in BeamData
end
-- scelgo il migliore
if bCompatibleTool then
-- calcolo riduzione del massimo materiale utilizzabile
local dToolEntryAngle = GetToolEntryAngle( Proc, vtToolDir)
-- se ToolHolder più grande dell'utensile, il primo oggetto in collisione è il ToolHolder. Altrimenti il motore.
local dDimObjToCheck = EgtIf( TOOLS[nCurrIndex].ToolHolder.dDiameter > TOOLS[nCurrIndex].dDiameter, TOOLS[nCurrIndex].ToolHolder.dDiameter, BeamData.C_SIMM_ENC)
local dCurrMaxMatReduction = BeamData.COLL_SIC or 5
-- calcolo riduzione per non toccare con ToolHolder / Motore
if dToolEntryAngle > 0 and dToolEntryAngle < 90 then
dCurrMaxMatReduction = dCurrMaxMatReduction / cos( 90 - dToolEntryAngle) + ( ( dDimObjToCheck - TOOLS[nCurrIndex].dDiameter) / 2) / tan( dToolEntryAngle)
end
-- dCurrMachReduction = negativo -> limitare, positivo -> mm extra disponibili
local dCurrMachReduction = TOOLS[nCurrIndex].dMaxDepth - dElevation - dCurrMaxMatReduction
-- se non ancora trovato, oppure se completo e il migliore fino ad ora non è completo: corrente è il migliore
if not ToolInfo.idTool or ( ToolInfo.dMaxMatReduction <= 0 and dCurrMachReduction > 0) then
ToolInfo.idTool = nCurrIndex
ToolInfo.dMaxMatReduction = dCurrMachReduction
-- altrimenti scelgo il migliore
else
-- se entrambi completi
if ToolInfo.dMaxMatReduction > 0 and dCurrMachReduction > 0 then
-- scelgo utensile con rapporto lunghezza / diametro minore
if ( TOOLS[nCurrIndex].dLength / pow( TOOLS[nCurrIndex].dDiameter, 1.5)) < ( TOOLS[ToolInfo.idTool].dLength / pow( TOOLS[ToolInfo.idTool].dDiameter, 1.5)) then
ToolInfo.idTool = nCurrIndex
ToolInfo.dMaxMatReduction = dCurrMachReduction
end
-- se entrambi incompleti
elseif ToolInfo.dMaxMatReduction < 0 and dCurrMachReduction < 0 then
--scelgo quello che lavora di più
if dCurrMachReduction > ToolInfo.dMaxMatReduction then
ToolInfo.idTool = nCurrIndex
ToolInfo.dMaxMatReduction = dCurrMachReduction
end
end
end
end
end
return ToolInfo
end
-------------------------------------------------------------------------------------------------------------
-- funzione per cercare utensile tipo LAMA con certe caratteristiche
-- TODO da completare
function MachiningLib.FindBlade( Proc, ToolSearchParameters)
local Tool = {}
-- parametri obbligatori
if type( ToolSearchParameters.vtToolDirection) ~= 'table' then
error( 'FindBlade : missing tool direction')
end
if type( ToolSearchParameters.bAllowTopHead) ~= 'boolean' then
error( 'FindBlade : missing top head info')
end
if type( ToolSearchParameters.bAllowBottomHead) ~= 'boolean' then
error( 'FindBlade : missing bottom head info')
end
if not ToolSearchParameters.bAllowTopHead and not ToolSearchParameters.bAllowBottomHead then
error( 'FindBlade : wrong head info')
end
-- parametri opzionali
ToolSearchParameters.dElevation = ToolSearchParameters.dElevation or 0
ToolSearchParameters.bForceLongcutBlade = ToolSearchParameters.bForceLongcutBlade or false
local nChosenToolIndex
for i = 1, #TOOLS do
local bIsToolCompatible = true
if ToolSearchParameters.bAllowTopHead and not ToolSearchParameters.bAllowBottomHead then
bIsToolCompatible = TOOLS[i].bIsTopHead
elseif ToolSearchParameters.bAllowBottomHead and not ToolSearchParameters.bAllowTopHead then
bIsToolCompatible = TOOLS[i].bIsBottomHead
end
if bIsToolCompatible then
nChosenToolIndex = i
break
end
end
Tool = TOOLS[nChosenToolIndex]
return Tool
end
-------------------------------------------------------------------------------------------------------------
-- funzione per cercare utensile tipo PUNTA A FORARE con certe caratteristiche
-- TODO da fare
function MachiningLib.FindDrill()
end
-------------------------------------------------------------------------------------------------------------
-- funzione per cercare utensile tipo PUNTA A FORARE con certe caratteristiche
-- TODO da fare
function MachiningLib.FindChainSaw()
end
-------------------------------------------------------------------------------------------------------------
return MachiningLib