From 0d9b7391387367c65fdb33dcf8bd9922e08eb1f3 Mon Sep 17 00:00:00 2001 From: DarioS Date: Fri, 16 Sep 2022 08:47:02 +0200 Subject: [PATCH] 3dPrinting : - modulo CalcMachParamFromSW riordinato come altri moduli per permettere la compilazione. --- CalcMachParamFromSW.lua | 18 +++ LuaLibs/CalcMachParamFromSW.lua | 170 --------------------------- LuaLibs/RunMachParamFromSWCalc.lua | 181 +++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+), 170 deletions(-) create mode 100644 CalcMachParamFromSW.lua delete mode 100644 LuaLibs/CalcMachParamFromSW.lua create mode 100644 LuaLibs/RunMachParamFromSWCalc.lua diff --git a/CalcMachParamFromSW.lua b/CalcMachParamFromSW.lua new file mode 100644 index 0000000..400bca9 --- /dev/null +++ b/CalcMachParamFromSW.lua @@ -0,0 +1,18 @@ +-- CalcMachParamFromSW.lua by Egaltech s.r.l. 2022/09/15 +-- Calcolo dei parametri di stampa + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +-- Imposto direttorio libreria specializzata per Stampa 3d +local sBaseDir = EgtGetSourceDir() +EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua') + +-- Librerie +_G.package.loaded.RunMachParamFromSWCalc = nil +local RMPFS = require( 'RunMachParamFromSWCalc') + +-- Calcolo +RMPFS.Exec() diff --git a/LuaLibs/CalcMachParamFromSW.lua b/LuaLibs/CalcMachParamFromSW.lua deleted file mode 100644 index c58f37f..0000000 --- a/LuaLibs/CalcMachParamFromSW.lua +++ /dev/null @@ -1,170 +0,0 @@ --- CalcMachParam.lua by Egaltech s.r.l. 2022/09/14 --- Calcolo dei parametri di stampa - --- Intestazioni -require( 'EgtBase') -_ENV = EgtProtectGlobal() -EgtEnableDebug( false) - -EgtOutLog( ' CalcMachParam started', 1) - ---local MATERIAL = {} ---MATERIAL.Name = 'AKROMIDĀ® B3 ICF 40' ---MATERIAL.K = 0.1 ---MATERIAL.C1 = 0.8742 ---MATERIAL.C2 = 0.8964 ---MATERIAL.Density = 1.31 ---MATERIAL.AMax = 48.33 ---MATERIAL.ATrg = 49.9 ---MATERIAL.AMin = 116.4 ---MATERIAL.BMax = 1.667 ---MATERIAL.BTrg = 2.2 ---MATERIAL.BMin = 7.273 ---MATERIAL.KW = 0.4 ---MATERIAL.KZ = 0.9 ---MATERIAL.KN = 0.3 - --- layer dei risultati -local nResultLayerId = EgtGetFirstNameInGroup( GDB_ID.ROOT, LAY_TFSCALC) -if not nResultLayerId then - nResultLayerId = EgtGroup( GDB_ID.ROOT) - EgtSetName( nResultLayerId, LAY_TFSCALC) - EgtSetLevel( nResultLayerId, GDB_LV.SYSTEM) -end --- recupero Speed minima e massima dalla macchina -local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini' -local dSMin = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_SPEED_MIN, 0, sMachIni)) -local dSMax = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_SPEED_MAX, 50000, sMachIni)) --- massa materiale utilizzato -local dPrintMass = 0 --- massimo indice di layer calcolato -local nMaxIndex = 0 --- ciclo sui pezzi -local nPartId = EgtGetFirstPart() -while nPartId do - if not EgtGetInfo( nPartId, KEY_PART_ON_TABLE, 'b') then - nPartId = EgtGetNextPart( nPartId) - goto continue - end - -- recupero i parametri di lavorazione del pezzo - local dSliceStep = EgtGetInfo( nPartId, KEY_SLICE_STEP, 'd') - local dStrand = EgtGetInfo( nPartId, KEY_STRAND, 'd') - local dStrandCount = EgtGetInfo( nPartId, KEY_SHELLS_NBR, 'd') - -- ciclo sui layer - local nLayerIndex = 1 - local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) - while nLayerId do - -- rimuovo eventuale info precedente del tempo di attesa - EgtRemoveInfo( nLayerId, KEY_WAITING_TIME) - -- calcolo lunghezza totale del layer - local dTotLayerLength = 0 - local dTotLayerArea = 0 - local nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*') - while nCrvId do - local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) - -- sommo lunghezze percorsi - local dTotCrvLength = 0 - nShellId = EgtGetFirstInGroup( nToolPathId) - while nShellId do - dTotCrvLength = dTotCrvLength + EgtCurveLength( nShellId) - nShellId = EgtGetNext( nShellId) - end - dTotLayerLength = dTotLayerLength + dTotCrvLength - -- recupero area - local nOuterCrvId = EgtGetFirstNameInGroup( nCrvId, OUTER_CRV) - local _, _, dTotCrvArea = EgtCurveArea( nOuterCrvId) - local dOuterLength = EgtCurveLength( nOuterCrvId) - -- recupero offset del part per aggiungerlo all'area interna - local dOffset = EgtGetInfo( nPartId, KEY_OFFSET_SLICE, 'd') - dTotCrvArea = dTotCrvArea + ( dOffset * dOuterLength) - dTotLayerArea = dTotLayerArea + dTotCrvArea - nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') - end - -- recupero feed del layer - local dLayerFeed = 0 - local nLayerResultId = EgtGetFirstNameInGroup( nResultLayerId, nLayerIndex) - if nLayerResultId then - dLayerFeed = EgtGetInfo( nLayerResultId, KEY_FCUR, 'd') or 0 - else - nLayerResultId = EgtGroup( nResultLayerId) - EgtSetName( nLayerResultId, nLayerIndex) - end - -- riporto riferimento a layer del solido in layer del calcolo - local nOrigLayers = EgtGetInfo( nLayerResultId, KEY_SLICEID, 'vi') or {} - local bFound = false - for nIndex = 1, #nOrigLayers do - if nOrigLayers[nIndex] == nLayerId then - bFound = true - end - end - if not bFound then - table.insert( nOrigLayers, nLayerId) - end - EgtSetInfo( nLayerResultId, KEY_SLICEID, nOrigLayers) - -- calcolo costante MF - local dMF = dTotLayerLength * dStrand / dTotLayerArea * 100 - -- calcolo tempi stimati del layer - local dTMin = ( dMF + MATERIAL.AMin) / MATERIAL.BMin * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) - local dTTrg = ( dMF + MATERIAL.ATrg) / MATERIAL.BTrg * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) - local dTMax = ( dMF + MATERIAL.AMax) / MATERIAL.BMax * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) - local dFMin = dTotLayerLength / dTMax * 60 - local dFTrg = dTotLayerLength / dTTrg * 60 - local dFMax = dTotLayerLength / dTMin * 60 - local dLayerTime = dTTrg - if dLayerFeed == 0 then - dLayerFeed = dFTrg - else - dLayerTime = dTotLayerLength / dLayerFeed * 60 - end - -- calcolo la portata - local Vf = dLayerFeed * ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) / 1000 - -- calcolo speed - local dSpeed = ( 1 + MATERIAL.K) * pow( Vf / MATERIAL.C1, 1 / MATERIAL.C2) - -- verifico se speed esce da minimo e massimo della macchina - local bSpeedOk = true - if dSpeed < dSMin then - bSpeedOk = false - dSpeed = dSMin - end - if dSpeed > dSMax then - bSpeedOk = false - dSpeed = dSMax - end - if not bSpeedOk then - dLayerFeed = ( MATERIAL.C1 * pow( ( dSpeed / ( 1 + MATERIAL.K)), MATERIAL.C2)) * 1000 / ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) - dLayerTime = dTotLayerLength / dLayerFeed * 60 - end - -- calcolo massa dello strato - local dLayerMass = dTotLayerLength * dSliceStep * dStrand * MATERIAL.Density * 1e-6 - if dLayerMass and dLayerMass > 0 then - dPrintMass = dPrintMass + dLayerMass - end - -- scrivo info feed e speed in group toolpath - nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*') - while nCrvId do - local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) or GDB_ID.NULL - EgtSetInfo( nToolPathId, KEY_FEED, dLayerFeed) - EgtSetInfo( nToolPathId, KEY_SPEED, dSpeed) - nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') - end - -- scrivo valori in struttura dati - --local nLayerResultId = EgtGetFirstNameInGroup( nResultLayerId, nLayerIndex) - EgtSetInfo( nLayerResultId, KEY_TMIN, dTMin) - EgtSetInfo( nLayerResultId, KEY_TTRG, dTTrg) - EgtSetInfo( nLayerResultId, KEY_TMAX, dTMax) - EgtSetInfo( nLayerResultId, KEY_FMIN, dFMin) - EgtSetInfo( nLayerResultId, KEY_FTRG, dFTrg) - EgtSetInfo( nLayerResultId, KEY_FMAX, dFMax) - EgtSetInfo( nLayerResultId, KEY_TCUR, dLayerTime) - EgtSetInfo( nLayerResultId, KEY_FCUR, dLayerFeed) - EgtSetInfo( nLayerResultId, KEY_LENGTH, dTotLayerLength) - EgtSetInfo( nLayerResultId, KEY_SPEED, dSpeed) - nLayerIndex = nLayerIndex + 1 - nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) - end - if nMaxIndex < nLayerIndex then nMaxIndex = nLayerIndex end - nPartId = EgtGetNextPart( nPartId) - ::continue:: -end --- imposto massa totale -EgtSetInfo( nResultLayerId, KEY_MASS, dPrintMass) diff --git a/LuaLibs/RunMachParamFromSWCalc.lua b/LuaLibs/RunMachParamFromSWCalc.lua new file mode 100644 index 0000000..22fb09e --- /dev/null +++ b/LuaLibs/RunMachParamFromSWCalc.lua @@ -0,0 +1,181 @@ +-- RunMachParamFromSWCalc.lua by Egaltech s.r.l. 2022/09/15 +-- Calcolo dei parametri di stampa + +-- Tabella per definizione modulo +local RunMachParamFromSWCalc = {} + +-- Intestazioni +require( 'EgtBase') + +EgtOutLog( ' RunMachParamFromSWCalc started', 1) + +-- Costanti generali +local AMD = require( 'AddManData') + +--local MATERIAL = {} +--MATERIAL.Name = 'AKROMIDĀ® B3 ICF 40' +--MATERIAL.K = 0.1 +--MATERIAL.C1 = 0.8742 +--MATERIAL.C2 = 0.8964 +--MATERIAL.Density = 1.31 +--MATERIAL.AMax = 48.33 +--MATERIAL.ATrg = 49.9 +--MATERIAL.AMin = 116.4 +--MATERIAL.BMax = 1.667 +--MATERIAL.BTrg = 2.2 +--MATERIAL.BMin = 7.273 +--MATERIAL.KW = 0.4 +--MATERIAL.KZ = 0.9 +--MATERIAL.KN = 0.3 + +--------------------------------------------------------------------- +function RunMachParamFromSWCalc.Exec() + + -- layer dei risultati + local nResultLayerId = EgtGetFirstNameInGroup( GDB_ID.ROOT, LAY_TFSCALC) + if not nResultLayerId then + nResultLayerId = EgtGroup( GDB_ID.ROOT) + EgtSetName( nResultLayerId, LAY_TFSCALC) + EgtSetLevel( nResultLayerId, GDB_LV.SYSTEM) + end + -- recupero Speed minima e massima dalla macchina + local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini' + local dSMin = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_SPEED_MIN, 0, sMachIni)) + local dSMax = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_SPEED_MAX, 50000, sMachIni)) + -- massa materiale utilizzato + local dPrintMass = 0 + -- massimo indice di layer calcolato + local nMaxIndex = 0 + -- ciclo sui pezzi + local nPartId = EgtGetFirstPart() + while nPartId do + if not EgtGetInfo( nPartId, KEY_PART_ON_TABLE, 'b') then + nPartId = EgtGetNextPart( nPartId) + goto continue + end + -- recupero i parametri di lavorazione del pezzo + local dSliceStep = EgtGetInfo( nPartId, KEY_SLICE_STEP, 'd') + local dStrand = EgtGetInfo( nPartId, KEY_STRAND, 'd') + local dStrandCount = EgtGetInfo( nPartId, KEY_SHELLS_NBR, 'd') + -- ciclo sui layer + local nLayerIndex = 1 + local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) + while nLayerId do + -- rimuovo eventuale info precedente del tempo di attesa + EgtRemoveInfo( nLayerId, KEY_WAITING_TIME) + -- calcolo lunghezza totale del layer + local dTotLayerLength = 0 + local dTotLayerArea = 0 + local nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*') + while nCrvId do + local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) + -- sommo lunghezze percorsi + local dTotCrvLength = 0 + nShellId = EgtGetFirstInGroup( nToolPathId) + while nShellId do + dTotCrvLength = dTotCrvLength + EgtCurveLength( nShellId) + nShellId = EgtGetNext( nShellId) + end + dTotLayerLength = dTotLayerLength + dTotCrvLength + -- recupero area + local nOuterCrvId = EgtGetFirstNameInGroup( nCrvId, OUTER_CRV) + local _, _, dTotCrvArea = EgtCurveArea( nOuterCrvId) + local dOuterLength = EgtCurveLength( nOuterCrvId) + -- recupero offset del part per aggiungerlo all'area interna + local dOffset = EgtGetInfo( nPartId, KEY_OFFSET_SLICE, 'd') + dTotCrvArea = dTotCrvArea + ( dOffset * dOuterLength) + dTotLayerArea = dTotLayerArea + dTotCrvArea + nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') + end + -- recupero feed del layer + local dLayerFeed = 0 + local nLayerResultId = EgtGetFirstNameInGroup( nResultLayerId, nLayerIndex) + if nLayerResultId then + dLayerFeed = EgtGetInfo( nLayerResultId, KEY_FCUR, 'd') or 0 + else + nLayerResultId = EgtGroup( nResultLayerId) + EgtSetName( nLayerResultId, nLayerIndex) + end + -- riporto riferimento a layer del solido in layer del calcolo + local nOrigLayers = EgtGetInfo( nLayerResultId, KEY_SLICEID, 'vi') or {} + local bFound = false + for nIndex = 1, #nOrigLayers do + if nOrigLayers[nIndex] == nLayerId then + bFound = true + end + end + if not bFound then + table.insert( nOrigLayers, nLayerId) + end + EgtSetInfo( nLayerResultId, KEY_SLICEID, nOrigLayers) + -- calcolo costante MF + local dMF = dTotLayerLength * dStrand / dTotLayerArea * 100 + -- calcolo tempi stimati del layer + local dTMin = ( dMF + MATERIAL.AMin) / MATERIAL.BMin * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) + local dTTrg = ( dMF + MATERIAL.ATrg) / MATERIAL.BTrg * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) + local dTMax = ( dMF + MATERIAL.AMax) / MATERIAL.BMax * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dStrandCount, MATERIAL.KN) + local dFMin = dTotLayerLength / dTMax * 60 + local dFTrg = dTotLayerLength / dTTrg * 60 + local dFMax = dTotLayerLength / dTMin * 60 + local dLayerTime = dTTrg + if dLayerFeed == 0 then + dLayerFeed = dFTrg + else + dLayerTime = dTotLayerLength / dLayerFeed * 60 + end + -- calcolo la portata + local Vf = dLayerFeed * ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) / 1000 + -- calcolo speed + local dSpeed = ( 1 + MATERIAL.K) * pow( Vf / MATERIAL.C1, 1 / MATERIAL.C2) + -- verifico se speed esce da minimo e massimo della macchina + local bSpeedOk = true + if dSpeed < dSMin then + bSpeedOk = false + dSpeed = dSMin + end + if dSpeed > dSMax then + bSpeedOk = false + dSpeed = dSMax + end + if not bSpeedOk then + dLayerFeed = ( MATERIAL.C1 * pow( ( dSpeed / ( 1 + MATERIAL.K)), MATERIAL.C2)) * 1000 / ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) + dLayerTime = dTotLayerLength / dLayerFeed * 60 + end + -- calcolo massa dello strato + local dLayerMass = dTotLayerLength * dSliceStep * dStrand * MATERIAL.Density * 1e-6 + if dLayerMass and dLayerMass > 0 then + dPrintMass = dPrintMass + dLayerMass + end + -- scrivo info feed e speed in group toolpath + nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*') + while nCrvId do + local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) or GDB_ID.NULL + EgtSetInfo( nToolPathId, KEY_FEED, dLayerFeed) + EgtSetInfo( nToolPathId, KEY_SPEED, dSpeed) + nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') + end + -- scrivo valori in struttura dati + --local nLayerResultId = EgtGetFirstNameInGroup( nResultLayerId, nLayerIndex) + EgtSetInfo( nLayerResultId, KEY_TMIN, dTMin) + EgtSetInfo( nLayerResultId, KEY_TTRG, dTTrg) + EgtSetInfo( nLayerResultId, KEY_TMAX, dTMax) + EgtSetInfo( nLayerResultId, KEY_FMIN, dFMin) + EgtSetInfo( nLayerResultId, KEY_FTRG, dFTrg) + EgtSetInfo( nLayerResultId, KEY_FMAX, dFMax) + EgtSetInfo( nLayerResultId, KEY_TCUR, dLayerTime) + EgtSetInfo( nLayerResultId, KEY_FCUR, dLayerFeed) + EgtSetInfo( nLayerResultId, KEY_LENGTH, dTotLayerLength) + EgtSetInfo( nLayerResultId, KEY_SPEED, dSpeed) + nLayerIndex = nLayerIndex + 1 + nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) + end + if nMaxIndex < nLayerIndex then nMaxIndex = nLayerIndex end + nPartId = EgtGetNextPart( nPartId) + ::continue:: + end + -- imposto massa totale + EgtSetInfo( nResultLayerId, KEY_MASS, dPrintMass) +end + +--------------------------------------------------------------------- +return RunMachParamFromSWCalc