diff --git a/Common_FAST.mlpe b/Common_FAST.mlpe index 944a857..ed34918 100644 --- a/Common_FAST.mlpe +++ b/Common_FAST.mlpe @@ -148,6 +148,30 @@ function OnSimulStart() end -- Preparo lista collisioni vuota EMT.COLLIDE = {} + + -- si crea gruppo temporaneo appoggio controllo clamping + CLAMP_CHECK_GROUP = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'CLAMP_CHECK') + CLAMP_CHECK_INTERS = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'CLAMP_INTERS') + + if CLAMP_CHECK_GROUP then + EgtEmptyGroup( CLAMP_CHECK_GROUP) + else + local frClampCheckGroup = Frame3d( ORIG(), GDB_FR.FRONT) + CLAMP_CHECK_GROUP = EgtGroup( GDB_ID.ROOT, frClampCheckGroup) + EgtSetName( CLAMP_CHECK_GROUP, 'CLAMP_CHECK') + EgtSetLevel( CLAMP_CHECK_GROUP, GDB_LV.TEMP) + EgtSetStatus( CLAMP_CHECK_GROUP, GDB_ST.OFF) + end + + if CLAMP_CHECK_INTERS then + EgtEmptyGroup( CLAMP_CHECK_INTERS) + else + CLAMP_CHECK_INTERS = EgtGroup( GDB_ID.ROOT) + EgtSetName( CLAMP_CHECK_INTERS, 'CLAMP_INTERS') + EgtSetLevel( CLAMP_CHECK_INTERS, GDB_LV.TEMP) + EgtSetStatus( CLAMP_CHECK_INTERS, GDB_ST.OFF) + end + end --------------------------------------------------------------------- @@ -296,18 +320,24 @@ function OnSimulDispositionStart() local nOrd = GetPhaseOrd( EMT.PHASE) local nScrapOrd = GetPhaseOrd( EgtGetPhaseCount()) + 1 local b3Raw = BBox3d() + local b3Bar = BBox3d() + local b3Part = BBox3d() local nPartRawId, nScrapRawId local nRawId = EgtGetFirstRawPart() while nRawId do local nNextRawId = EgtGetNextRawPart( nRawId) if EgtVerifyRawPartPhase( nRawId, EMT.PHASE) then EmtLinkRawPartToGroup( nRawId, 'Tab') + local b3Tmp = EgtGetRawPartBBox( nRawId) + b3Bar:Add( b3Tmp) local nRawOrd = EgtGetInfo( nRawId, 'ORD', 'i') if nRawOrd == nOrd then - b3Raw = EgtGetRawPartBBox( nRawId) + --b3Raw = EgtGetRawPartBBox( nRawId) + b3Raw:Add( b3Tmp) + b3Part:Add( b3Tmp) nPartRawId = nRawId elseif nRawOrd == nOrd + 1 and nRawOrd == nScrapOrd then - local b3Tmp = EgtGetRawPartBBox( nRawId) or BBox3d() + --local b3Tmp = EgtGetRawPartBBox( nRawId) or BBox3d() b3Raw:Add( b3Tmp) nScrapRawId = nRawId end @@ -321,6 +351,9 @@ function OnSimulDispositionStart() else EMT.SCRAP = nil end + EMT.LB = b3Bar:getDimX() + EMT.LR = b3Raw:getDimX() + EMT.LT = b3Part:getDimX() -- recupero CutId del pezzo in lavorazione EMT.CUTID = EgtGetInfo( EgtGetFirstPartInRawPart( nPartRawId or GDB_ID.NULL) or GDB_ID.NULL, 'CUTID', 'i') or 0 EMT.YSPEC = nil @@ -392,6 +425,7 @@ function OnSimulDispositionStart() if EgtVerifyRawPartPhase( nRawId, EMT.PHASE) then if EgtGetInfo( nRawId, 'ORD', 'i') == nOrd then EmtLinkRawPartToGroup( nRawId, 'Tab') + b3Bar = EgtGetRawPartBBox( nRawId) else EgtMove( nRawId, vtMove, GDB_RT.GLOB) EgtSetStatus( nRawId, GDB_ST.OFF) @@ -399,6 +433,8 @@ function OnSimulDispositionStart() end nRawId = nNextRawId end + EMT.LB = b3Bar:getDimX() + -- altrimenti fase finale, aggancio primo grezzo alla tavola e gli altri in posizione carico al carro Y else -- verifico posizione di carico @@ -416,12 +452,14 @@ function OnSimulDispositionStart() nRawId = EgtGetNextRawPart( nRawId) end -- eseguo + local b3Bar = BBox3d() nRawId = EgtGetFirstRawPart() while nRawId do local nNextRawId = EgtGetNextRawPart( nRawId) if EgtVerifyRawPartPhase( nRawId, EMT.PHASE) then if EgtGetInfo( nRawId, 'ORD', 'i') == nOrd then EmtLinkRawPartToGroup( nRawId, 'Tab') + b3Bar = EgtGetRawPartBBox( nRawId) else EgtMove( nRawId, vtMove, GDB_RT.GLOB) EmtLinkRawPartToGroup( nRawId, 'Y') @@ -429,6 +467,7 @@ function OnSimulDispositionStart() end nRawId = nNextRawId end + EMT.LB = b3Bar:getDimX() end -- Indicazione angolo rotazione pezzo EMT.ROT = EgtGetInfo( EMT.DISPID, 'ROT', 'i') or 0 @@ -460,6 +499,7 @@ function OnSimulDispositionEnd() EMT.POSTROT = true end end + EMT.SPLIT = false EMT.OPEISDISP = false end @@ -714,6 +754,7 @@ function OnSimulMachiningEnd() EMT.UNLOADING = false EMT.FALL = false end + EMT.SPLIT = nil EMT.PREVHEAD = EMT.HEAD EMT.PREVTOOL = EMT.TOOL EMT.PREVEXIT = EMT.EXIT @@ -902,6 +943,8 @@ function ExecAuxCmd( sCmd) if Cmd[1] == '0' then if Cmd[2] == 'Unloading' then EMT.UNLOADING = true + elseif Cmd[2] == 'Split' then + EMT.SPLIT = true elseif Cmd[2] == 'Fall' then EMT.FALL = true end @@ -943,19 +986,9 @@ function ExecAuxCmd( sCmd) end end elseif Cmd[1] == '11' then - local dPY = MaxOpen - if Cmd[2] ~= '0' then - dPY = EgtIf( EMT.ROT == -1, EMT.HT, EMT.ST) - end - SimulMoveAxis( 'PY', dPY, MCH_SIM_STEP.RAPID) - SetPYLight( Cmd[2] ~= '0') + ExecMovePY( Cmd[2] ~= '0') elseif Cmd[1] == '12' then - local dPV = MaxOpen - if Cmd[2] ~= '0' then - dPV = EgtIf( EMT.ROT == -1, EMT.HT, EMT.ST) - end - SimulMoveAxis( 'PV', dPV, MCH_SIM_STEP.RAPID) - SetPVLight( Cmd[2] ~= '0') + ExecMovePV( Cmd[2] ~= '0') elseif Cmd[1] == '21' then local nYDelta = tonumber( Cmd[2]) local nVDelta = tonumber( Cmd[3]) @@ -1064,6 +1097,181 @@ function ExecUnloading() end end +--------------------------------------------------------------------- +function CheckClamping( sClampName) + nIndexClamp = EgtGetAxisId( sClampName) + local idClampPath = EgtGetFirstInGroup( EgtGetFirstNameInGroup( nIndexClamp, 'CLAMP_CHECK') or GDB_ID.NULL) + local b3ClampingArea = EgtGetBBoxGlob( idClampPath or GDB_ID.NULL, GDB_BB.STANDARD) + -- se non trovo percorso area di clamping, esco subito + if not idClampPath or not EMT.VMILL or not ClampingCoeffMin then + return + end + + local function GetCurveListFromIntersection( sPosIntersPlane, sIntersPlane, dDepth) + local idCurveList = {} + local vtIntersPlane + -- piano di interpolazione + if sIntersPlane == 'X' then + vtIntersPlane = X_AX() + elseif sIntersPlane == 'Y' then + vtIntersPlane = Y_AX() + elseif sIntersPlane == 'Z' then + vtIntersPlane = Z_AX() + end + + for i = 1, #EMT.VMILL do + local b3VMill = EgtGetBBoxGlob( EMT.VMILL[i], GDB_BB.EXACT) + local ptPosIntersPlane + if sPosIntersPlane == 'MIN' then + ptPosIntersPlane = b3VMill:getMin() + dDepth * vtIntersPlane + elseif sPosIntersPlane == 'MAX' then + ptPosIntersPlane = b3VMill:getMax() - dDepth * vtIntersPlane + end + + local idLoop, nLoopCnt = EgtPlaneVolZmapInters( ptPosIntersPlane, vtIntersPlane, EMT.VMILL[i], CLAMP_CHECK_INTERS, GDB_RT.GLOB) + -- se c'è almeno una curva + if idLoop then + for j = 1, nLoopCnt do + local idLoopTemp = idLoop + j - 1 + table.insert( idCurveList, idLoopTemp) + end + end + end + return idCurveList + end + + local function CalculateIntersectionArea( sPosIntersPlane, sIntersPlane, dDepth) + -- test piano frontale + local idCurveList = GetCurveListFromIntersection( sPosIntersPlane, sIntersPlane, dDepth) + + -- si copia curva intersezione e curva pinza in gruppo di confronto + local idFlatSurf, nFlatSurfCnt = EgtSurfFlatRegion( CLAMP_CHECK_GROUP, idCurveList) + local idClampSurf = EgtSurfFlatRegion( CLAMP_CHECK_GROUP, idClampPath) + + if idFlatSurf then + local dTotalArea = 0 + local dTotalXLenght = 0 + for k = 1, nFlatSurfCnt do + local idTempSurf = idFlatSurf + k - 1 + EgtSurfFrIntersect( idTempSurf, idClampSurf) + if idTempSurf then + dTotalArea = dTotalArea + ceil( EgtSurfArea( idTempSurf) or 0) + local b3BoxIntersectionBox = EgtGetBBoxGlob( idTempSurf, GDB_BB.STANDARD) + if b3BoxIntersectionBox then + dTotalXLenght = dTotalXLenght + ceil( b3BoxIntersectionBox:getDimX()) -- somma lunghezze (x) delle aree pinzate + end + end + end + return dTotalArea, dTotalXLenght + end + return 0 + end + + -- minima area considerata per un corretto pinzaggio + DistZClampToTable = DistZClampToTable or 0 + local MinJoin = BD.GetMinJoin( EMT.ST, EMT.HT, EgtIf( EMT.SPLIT, EMT.LT, EMT.LB)) + local MinZClamping = min( b3ClampingArea:getDimZ() + DistZClampToTable, EMT.HT) - DistZClampToTable + local dMinClamping = ( MinJoin * MinZClamping) + -- si moltiplica per un coefficiente minimo sotto al quale si da l'errore di pinzaggio + ClampingCoeffMin = EgtClamp( ClampingCoeffMin, 0.01, 1) + if MinZClamping > 116 then + dMinClamping = MinJoin * 116 + ( math.pow( MinJoin, 2) / 2) + if MinJoin > 280 then + dMinClamping = dMinClamping + ( math.pow( MinJoin - 280, 2)) + end + end + + local dMinClampingAreaWarn = dMinClamping * ClampingCoeffMin + local dMinClampingAreaErr = dMinClamping * ( ClampingCoeffMin / 3) + + local bError = true + local sWrn, sErr + local bWriteWarnMessage = false + local bWriteErrMessage = false + -- controllo faccia frontale + local dArea, dXClampedLenght = CalculateIntersectionArea( 'MIN', 'Y', 3) + -- ERRORE: pinza troppo poco (meno di 1/3 del minimo richiesto) + if dArea and dArea < dMinClampingAreaErr then + -- solo se pinza almeno 1cm2, e la somma della lunghezza pinzata è maggiore della lunghezza minima pinzabile da Warning e non errore + if dXClampedLenght >= MinJoin * ClampingCoeffMin and dArea > 1000 then + bError = false + end + -- pinzaggio non fattibile, errore + if bError then + sErr = 'ERROR CLAMPING ' .. sClampName .. ' : '..tostring( ceil( ( dArea / dMinClampingAreaWarn) * 100))..'% ( '.. tostring( dArea/1000)..'cm2)' + bWriteErrMessage = true + end + end + -- WARNING: pinza meno del minimo richiesto + if dArea and dArea < dMinClampingAreaWarn and not bWriteErrMessage then + sWrn = 'WARNING CLAMPING ' .. sClampName .. ' : '..tostring( ceil( ( dArea / dMinClampingAreaWarn) * 100))..'% ( '.. tostring( dArea/1000)..'cm2)' + bWriteWarnMessage = true + end + EgtEmptyGroup( CLAMP_CHECK_GROUP) + EgtEmptyGroup( CLAMP_CHECK_INTERS) + + -- controllo altro lato solo se non sono già in errore + if not bWriteErrMessage then + -- controllo faccia posteriore + dArea = CalculateIntersectionArea( 'MAX', 'Y', 3) + -- ERRORE: pinza troppo poco (meno di 1/3 del minimo richiesto) + if dArea and dArea < dMinClampingAreaErr then + -- solo se pinza almeno 1cm2, e la somma della lunghezza pinzata è maggiore della lunghezza minima pinzabile da Warning e non errore + if dXClampedLenght >= MinJoin * ClampingCoeffMin and dArea > 1000 then + bError = false + end + -- pinzaggio non fattibile, errore + if bError then + sErr = 'ERROR CLAMPING ' .. sClampName .. ' : '..tostring( ceil( ( dArea / dMinClampingAreaWarn) * 100))..'% ( '.. tostring( dArea/1000)..'cm2)' + bWriteErrMessage = true + end + end + -- WARNING: pinza meno del minimo richiesto + if dArea and dArea < dMinClampingAreaWarn and not bWriteWarnMessage and not bWriteErrMessage then + sWrn = 'WARNING CLAMPING ' .. sClampName .. ' : '..tostring( ceil( ( dArea / dMinClampingAreaWarn) * 100))..'% ( '.. tostring( dArea/1000)..'cm2)' + bWriteWarnMessage = true + end + EgtEmptyGroup( CLAMP_CHECK_GROUP) + EgtEmptyGroup( CLAMP_CHECK_INTERS) + end + + if bWriteErrMessage then + EmtSetLastError( 1213, sErr, EgtGetEnableUI()) + EgtOutBox( sErr, 'CLAMPING', 'ERROR', 'OK') + EmtSetSimulPause() + elseif bWriteWarnMessage then + EgtOutLog( sWrn) + EgtOutBox( sWrn, 'CLAMPING', 'WARNING', 'OK') + EmtSetSimulPause() + end +end + +--------------------------------------------------------------------- +function ExecMovePY( bClose) + local dPY = MaxOpen + if bClose then + dPY = EgtIf( EMT.ROT == -1, EMT.HT, EMT.ST) + end + SimulMoveAxis( 'PY', dPY, MCH_SIM_STEP.RAPID) + SetPYLight( bClose) + if bClose then + CheckClamping( 'PY') + end +end + +--------------------------------------------------------------------- +function ExecMovePV( bClose) + local dPV = MaxOpen + if bClose then + dPV = EgtIf( EMT.ROT == -1, EMT.HT, EMT.ST) + end + SimulMoveAxis( 'PV', dPV, MCH_SIM_STEP.RAPID) + SetPVLight( bClose) + if bClose then + CheckClamping( 'PV') + end +end + --------------------------------------------------------------------- function VerifyYSlide( sName1, dVal1, sName2, dVal2) -- Se movimento trave agganciata con carrello Y diff --git a/UpdateLog.txt b/UpdateLog.txt index 80ab973..c1a99a3 100644 --- a/UpdateLog.txt +++ b/UpdateLog.txt @@ -1,5 +1,8 @@ ==== Common_FAST Update Log ==== +Versione 2.7l2 (18/12/2025) +- (SIM) Aggiunta funzione CheckClamping + Versione 2.7l1 (10/12/2025) - (SIM) Aggiornata risoluzione VMillTol in funzione dello spessore lama - (EST) Modifiche a calcolo stima tempi, da verificare. diff --git a/Version.lua b/Version.lua index e914a70..338d0c4 100644 --- a/Version.lua +++ b/Version.lua @@ -3,7 +3,7 @@ local InfoCommon_STD_PP = { NAME = 'Common_FAST', -- nome script PP standard - VERSION = '2.7l1', -- versione script + VERSION = '2.7l2', -- versione script MIN_MACH_VER_PP_COMMON = '2.5k1' -- versione minima kernel }