From 87d2641ab1c9b2667f347fdd609738af0534411e Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Mon, 25 Sep 2023 15:48:10 +0200 Subject: [PATCH] - gestito calcolo F e S con strand di differente larghezza --- .vscode/settings.json | 34 +++++++++ LuaLibs/RunMachParamFromSWCalc.lua | 108 ++++++++++++++++++++++++----- 2 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..af36d14 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,34 @@ +{ + "Lua.diagnostics.globals": [ + "MATERIAL", + "EgtGetFirstNameInGroup", + "GDB_ID", + "EgtGroup", + "EgtSetLevel", + "EgtSetName", + "GDB_LV", + "EgtGetCurrMachineDir", + "EgtGetCurrMachineName", + "EgtGetStringFromIni", + "EgtGetFirstPart", + "EgtGetInfo", + "EgtGetNextPart", + "EgtGetLastNameInGroup", + "EgtRemoveInfo", + "EgtGetFirstInGroup", + "EgtGetName", + "EgtCurveLength", + "EgtGetNext", + "EgtCurveArea", + "EgtGetNextName", + "EgtSetInfo", + "floor", + "pi", + "pow", + "EgtProcessEvents", + "EgtEmptyGroup", + "EgtOutLog", + "EgtIf", + "EgtProtectGlobal" + ] +} \ No newline at end of file diff --git a/LuaLibs/RunMachParamFromSWCalc.lua b/LuaLibs/RunMachParamFromSWCalc.lua index f0e332f..81f3bc4 100644 --- a/LuaLibs/RunMachParamFromSWCalc.lua +++ b/LuaLibs/RunMachParamFromSWCalc.lua @@ -62,7 +62,7 @@ function RunMachParamFromSWCalc.Exec() while nPartId do if not EgtGetInfo( nPartId, KEY_PART_ON_TABLE, 'b') then nPartId = EgtGetNextPart( nPartId) - goto continue + goto continue end -- recupero i parametri di lavorazione del pezzo local dSliceStep = EgtGetInfo( nPartId, KEY_SLICE_STEP, 'd') @@ -77,6 +77,8 @@ function RunMachParamFromSWCalc.Exec() while nLayerId do -- rimuovo eventuale info precedente del tempo di attesa EgtRemoveInfo( nLayerId, KEY_WAITING_TIME) + -- divido curve in base alla larghezza strand + local LengthCrvList = {} -- calcolo lunghezza totale del layer local dTotLayerLength = 0 local dTotLayerLengthForMass = 0 @@ -84,14 +86,29 @@ function RunMachParamFromSWCalc.Exec() local nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*') while nCrvId do local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) - -- sommo lunghezze percorsi + -- recupero lunghezze percorsi local dTotCrvLength = 0 local dTotCrvLengthForMass = 0 - nShellId = EgtGetFirstInGroup( nToolPathId) + local nShellId = EgtGetFirstInGroup( nToolPathId) while nShellId do - dTotCrvLength = dTotCrvLength + EgtCurveLength( nShellId) + local dShellWidth = EgtGetInfo( nShellId, KEY_CRV_STRAND, "d") + local dShellLength = EgtCurveLength( nShellId) + local bFound = false + for LengthIndex = 1, #LengthCrvList do + if LengthCrvList[LengthIndex].Width == dShellWidth then + table.insert( LengthCrvList[LengthIndex].IdList, nShellId) + LengthCrvList[LengthIndex].Length = LengthCrvList[LengthIndex].Length + dShellLength + bFound = true + break + end + end + if not bFound then + table.insert( LengthCrvList, { Width = dShellWidth, IdList = { nShellId}, Length = dShellLength}) + end + -- sommo per lunghezza totale + dTotCrvLength = dTotCrvLength + dShellLength if EgtGetName( nShellId) ~= WIPE_CRV then - dTotCrvLengthForMass = dTotCrvLengthForMass + EgtCurveLength( nShellId) + dTotCrvLengthForMass = dTotCrvLengthForMass + dShellLength end nShellId = EgtGetNext( nShellId) end @@ -109,6 +126,44 @@ function RunMachParamFromSWCalc.Exec() end nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') end + + + -- -- rimuovo eventuale info precedente del tempo di attesa + -- EgtRemoveInfo( nLayerId, KEY_WAITING_TIME) + -- -- calcolo lunghezza totale del layer + -- local dTotLayerLength = 0 + -- local dTotLayerLengthForMass = 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 + -- local dTotCrvLengthForMass = 0 + -- local nShellId = EgtGetFirstInGroup( nToolPathId) + -- while nShellId do + -- dTotCrvLength = dTotCrvLength + EgtCurveLength( nShellId) + -- if EgtGetName( nShellId) ~= WIPE_CRV then + -- dTotCrvLengthForMass = dTotCrvLengthForMass + EgtCurveLength( nShellId) + -- end + -- nShellId = EgtGetNext( nShellId) + -- end + -- dTotLayerLength = dTotLayerLength + dTotCrvLength + -- dTotLayerLengthForMass = dTotLayerLengthForMass + dTotCrvLengthForMass + -- -- recupero area + -- local nOuterCrvId = EgtGetFirstNameInGroup( nCrvId, OUTER_CRV) + -- if nOuterCrvId and dStrandCount > 0.5 then + -- 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 + -- end + -- nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') + -- end + + -- recupero feed del layer local dLayerFeed = 0 local dLayerWait = 0 @@ -132,11 +187,18 @@ function RunMachParamFromSWCalc.Exec() table.insert( nOrigLayers, nLayerId) end EgtSetInfo( nLayerResultId, KEY_SLICEID, nOrigLayers) + -- calcolo strand medio (media ponderata sulla lunghezza) + local dStrandMean = 0 + for nMeanIndex = 1, #LengthCrvList do + dStrandMean = dStrandMean + LengthCrvList[nMeanIndex].Width * LengthCrvList[nMeanIndex].Length + end + dStrandMean = dStrandMean / dTotLayerLength -- calcolo costante MF local dMF = 1 local dSC = 1 if dTotLayerArea > 1 then - dMF = dTotLayerLength * dStrand / dTotLayerArea * 100 + -- dMF = dTotLayerLength * dStrand / dTotLayerArea * 100 + dMF = dTotLayerLength * dStrandMean / dTotLayerArea * 100 dSC = dStrandCount else dMF = 100 @@ -151,9 +213,9 @@ function RunMachParamFromSWCalc.Exec() end end -- calcolo tempi stimati del layer - local dTMin = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.AMin) / MATERIAL.BMin * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) - local dTTrg = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.ATrg) / MATERIAL.BTrg * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) - local dTMax = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.AMax) / MATERIAL.BMax * pow( 0.25 * dStrand, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) + local dTMin = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.AMin) / MATERIAL.BMin * pow( 0.25 * dStrandMean, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) + local dTTrg = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.ATrg) / MATERIAL.BTrg * pow( 0.25 * dStrandMean, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) + local dTMax = ( MATERIAL.K_LAYERTIME / 100.0) * ( dMF + MATERIAL.AMax) / MATERIAL.BMax * pow( 0.25 * dStrandMean, MATERIAL.KW) * pow( dSliceStep, MATERIAL.KZ) * pow( dSC, MATERIAL.KN) local dFMin = dTotLayerLength / dTMax * 60 local dFTrg = dTotLayerLength / dTTrg * 60 local dFMax = dTotLayerLength / dTMin * 60 @@ -165,7 +227,7 @@ function RunMachParamFromSWCalc.Exec() end dLayerWait = floor( dTMin + 0.5) - floor( dLayerTime + 0.5) -- calcolo la portata - local Vf = dLayerFeed * ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) / 1000 + local Vf = dLayerFeed * ( ( dStrandMean - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) / 1000 -- calcolo speed local dSpeed = ( MATERIAL.K_EXTRUSION / 100.0) * ( MACHINING.K / 100.0) * pow( Vf / MATERIAL.C1, 1 / MATERIAL.C2) -- verifico se speed esce da minimo e massimo della macchina @@ -179,20 +241,32 @@ function RunMachParamFromSWCalc.Exec() dSpeed = dSMax end if not bSpeedOk then - dLayerFeed = ( MATERIAL.C1 * pow( ( dSpeed / (( MATERIAL.K_EXTRUSION / 100.0) * ( MACHINING.K / 100.0))), MATERIAL.C2)) * 1000 / ( ( dStrand - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) + dLayerFeed = ( MATERIAL.C1 * pow( ( dSpeed / (( MATERIAL.K_EXTRUSION / 100.0) * ( MACHINING.K / 100.0))), MATERIAL.C2)) * 1000 / ( ( dStrandMean - dSliceStep) * dSliceStep + pi * pow( dSliceStep / 2, 2)) dLayerTime = dTotLayerLength / dLayerFeed * 60 dLayerWait = floor( dTMin + 0.5) - floor( dLayerTime + 0.5) end -- calcolo massa dello strato - local dLayerMass = dTotLayerLengthForMass * dSliceStep * dStrand * MATERIAL.Density * 1e-6 + local dLayerMass = dTotLayerLengthForMass * dSliceStep * dStrandMean * MATERIAL.Density * 1e-6 if dLayerMass and dLayerMass > 0 then dPrintMass = dPrintMass + dLayerMass end - -- scrivo info feed e speed in group toolpath + -- scrivo info feed su tutti i tratti + local dFeedMax = 0 + for nWidthIndex = 1, #LengthCrvList do + local CurrWidth = LengthCrvList[nWidthIndex] + local CurrFeed = EgtIf( CurrWidth.Width > 0, dLayerFeed * dStrandMean / CurrWidth.Width, dLayerFeed) + for nCurveIdIndex = 1, #CurrWidth.IdList do + EgtSetInfo( CurrWidth.IdList[nCurveIdIndex], KEY_FEED, CurrFeed) + end + if CurrFeed > dFeedMax then + dFeedMax = CurrFeed + end + end + -- scrivo info 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_FEED, dLayerFeed) EgtSetInfo( nToolPathId, KEY_SPEED, dSpeed) nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*') end @@ -206,9 +280,11 @@ function RunMachParamFromSWCalc.Exec() 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_FMAX, dFeedMax) + -- 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)