From f1805625d3e869630505836f61aeffe0aedfbffe Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Mon, 22 Dec 2025 11:19:03 +0100 Subject: [PATCH] - per lama implementata verifica finecorsa (PreSimulationLib, MachiningLib) con funzione Machine Calc - nei timer si logga il tempo di apertura Json --- BatchProcessNew.lua | 2 + LuaLibs/BeamExec.lua | 2 + LuaLibs/LeadInOutLib.lua | 4 +- LuaLibs/MachiningLib.lua | 16 +-- LuaLibs/PreSimulationLib.lua | 222 ++++++++++++++++------------------- Process.lua | 2 +- 6 files changed, 120 insertions(+), 128 deletions(-) diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index 4d4f4aa..5222c62 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -636,8 +636,10 @@ if bToProcess then GENERAL_PARAMETERS.PROJECT.sAISetupConfig or nil -- si carica configurazione lavorazioni + TIMER:startElapsed('Json') BeamExec.GetStrategiesFromJSONinBD( PARTS[i].sAISetupConfig) PARTS[i].GeneralParameters = BeamLib.GetPieceGeneralParameters( PARTS[i], GENERAL_PARAMETERS_JSON) + TIMER:stopElapsed('Json') PARTS[i].CombinationList = BeamExec.GetAvailableCombinations( PARTS[i], bCalcBestPieceUnloadPosition) -- sovramateriale in testa al pezzo diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 2398c77..4bb12fc 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -498,8 +498,10 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS, b GENERAL_PARAMETERS.PROJECT.sAISetupConfig or nil -- si carica configurazione lavorazioni + TIMER:startElapsed('Json') BeamExec.GetStrategiesFromJSONinBD( PARTS[i].sAISetupConfig) PARTS[i].GeneralParameters = BeamLib.GetPieceGeneralParameters( PARTS[i], GENERAL_PARAMETERS_JSON) + TIMER:stopElapsed('Json') PARTS[i].CombinationList = BeamExec.GetAvailableCombinations( PARTS[i], bCalcBestPieceUnloadPosition) PARTS[i].idTempGroup = idTempGroup diff --git a/LuaLibs/LeadInOutLib.lua b/LuaLibs/LeadInOutLib.lua index 945eafc..cb8f14e 100644 --- a/LuaLibs/LeadInOutLib.lua +++ b/LuaLibs/LeadInOutLib.lua @@ -172,8 +172,8 @@ function LeadInOutLib.CalculateLeadInOut( sLeadInOutType, Parameters) LeadOut.dTangentDistance = dLeadOutLength -- punti dell'attacco - LeadIn.ptPoint = Point3d( ptStartAtDepth) ; LeadIn.ptPoint = ptStartAtDepth - Edge.vtEdge * dLeadInLength - LeadOut.ptPoint = Point3d( ptEndAtDepth) ; LeadOut.ptPoint = ptEndAtDepth + Edge.vtEdge * dLeadOutLength + LeadIn.ptPoint = Point3d( ptStartAtDepth - Edge.vtEdge * dLeadInLength) + LeadOut.ptPoint = Point3d( ptEndAtDepth + Edge.vtEdge * dLeadOutLength) end -- lunghezza totale attacco diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/MachiningLib.lua index 9e86b23..b2e443e 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/MachiningLib.lua @@ -327,11 +327,13 @@ local function TestEngagement( sBladeEngagement, Parameters, OptionalParameters) Tool = Tool } - local CheckOutOfStrokeOptionalParameters = {} - -- check punti lavorazione -- lavorazione oltre le corse: non fattibile - local bOutOfStroke = PreSimulationLib.CheckOutOfStroke( CheckOutOfStrokeParameters) + local PointsToCheck = { + Edge.ptStart + Edge.vtN * ( Edge.dElevation - dDepthToMachine), + Edge.ptEnd + Edge.vtN * ( Edge.dElevation - dDepthToMachine) + } + local bOutOfStroke = PreSimulationLib.CheckOutOfStroke( PointsToCheck, CheckOutOfStrokeParameters) if bOutOfStroke then return false end @@ -347,8 +349,8 @@ local function TestEngagement( sBladeEngagement, Parameters, OptionalParameters) -- attacco perpendicolare local PerpendicularLeadInOut = LeadInOutLib.CalculateLeadInOut( 'Perpendicular', Parameters) -- check extracorsa nei punti di attacco - CheckOutOfStrokeOptionalParameters.PointsToCheck = { PerpendicularLeadInOut.LeadIn.ptPoint, PerpendicularLeadInOut.LeadOut.ptPoint} - local bOutOfStrokePerpendicular = PreSimulationLib.CheckOutOfStroke( CheckOutOfStrokeParameters, CheckOutOfStrokeOptionalParameters) + PointsToCheck = { PerpendicularLeadInOut.LeadIn.ptPoint, PerpendicularLeadInOut.LeadOut.ptPoint} + local bOutOfStrokePerpendicular = PreSimulationLib.CheckOutOfStroke( PointsToCheck, CheckOutOfStrokeParameters) -- se non è in extracorsa si aggiunge come attacco possibile if not bOutOfStrokePerpendicular then LeadInOut.Perpendicular = PerpendicularLeadInOut @@ -367,8 +369,8 @@ local function TestEngagement( sBladeEngagement, Parameters, OptionalParameters) -- attacco tangenziale local TangentLeadInOut = LeadInOutLib.CalculateLeadInOut( 'Tangent', Parameters) -- check extracorsa nei punti di attacco - CheckOutOfStrokeOptionalParameters.PointsToCheck = { TangentLeadInOut.LeadIn.ptPoint, TangentLeadInOut.LeadOut.ptPoint} - local bOutOfStrokeTangent = PreSimulationLib.CheckOutOfStroke( CheckOutOfStrokeParameters, CheckOutOfStrokeOptionalParameters) + PointsToCheck = { TangentLeadInOut.LeadIn.ptPoint, TangentLeadInOut.LeadOut.ptPoint} + local bOutOfStrokeTangent = PreSimulationLib.CheckOutOfStroke( PointsToCheck, CheckOutOfStrokeParameters) -- attacco tangenziale non in extracorsa: si verifica se è in collisione if not bOutOfStrokeTangent then local bCollisionFoundTangent, bMoveAfterSplitTangent = PreSimulationLib.CheckCollision( sBladeEngagement, CheckCollisionParameters, CheckCollisionOptionalParameters) -- TODO passare punti custom attacco tangenziale diff --git a/LuaLibs/PreSimulationLib.lua b/LuaLibs/PreSimulationLib.lua index 5d983b6..dd0c206 100644 --- a/LuaLibs/PreSimulationLib.lua +++ b/LuaLibs/PreSimulationLib.lua @@ -79,18 +79,114 @@ local function GetPointsToCheck( Edge, dDepthToMachine) end ------------------------------------------------------------------------------------------------------------- -local function CheckOutOfStrokePoint( ptToolExitToCheck, vtC, vtHead, PreCollisionData) +local function CheckOutOfStrokePoint( ptOnFace, vtHead, vtNFace, vtNEdge, nSCC, Tool) - local bOutOfStroke = false - local ptPivot = GetGlobalPivot( ptToolExitToCheck, vtC, vtHead, PreCollisionData.vtMovePivot) + local bIsDownUp = AreOppositeVectorApprox( vtNFace, vtHead) + local ptOnToolTipCenter = ptOnFace + vtNEdge * Tool.dDiameter / 2 + vtNFace * EgtIf( bIsDownUp, Tool.dThickness, 0) - return bOutOfStroke + -- TODO come gestire EXIT????? + -- impostazione utensile + EgtSetCalcTool( Tool.sName, Tool.sHead, 1) + EgtLoadTool( Tool.sHead, 1, Tool.sName) + + -- settaggio SCC per discriminare soluzioni multiple + EgtSetCalcSolCh( nSCC) + + -- si recuperano tutti gli assi, lineari e rotativi + local AxesNames = EgtGetAllCurrAxesNames() + local LinearAxes = {} + local RotativeAxes = {} + for i = 1, #AxesNames do + -- EgtGetAxisType restituisce vero se asse lineare, false se asse rotativo + if EgtGetAxisType( AxesNames[i]) then + LinearAxes[#LinearAxes + 1] = {} + LinearAxes[#LinearAxes].sName = AxesNames[i] + else + RotativeAxes[#RotativeAxes + 1] = {} + RotativeAxes[#RotativeAxes].sName = AxesNames[i] + end + end + + -- se più di 3 assi lineari e 2 assi rotativi, macchina non supportata + if #LinearAxes > 3 or #RotativeAxes > 2 then + + error(' CheckOutOfStrokePoint : too many axes') + end + + -- calcolo assi rotativi + local bOkAngles, nSolutionsAngles, dRot1, dRot2 = EgtGetCalcAngles( vtHead) + RotativeAxes[1].dValue = dRot1 + RotativeAxes[2].dValue = dRot2 + + if not bOkAngles then + error( ' CheckOutOfStrokePoint : error') + end + + -- se nessuna soluzione dagli assi rotativi, è in extracorsa + if nSolutionsAngles == 0 then + + local idTempGroup = BeamLib.GetTempGroup() + local idVector = EgtVector( idTempGroup, vtHead, ptOnToolTipCenter, GDB_RT.GLOB) + EgtSetColor( idVector, RED()) + EgtOutLog( ' Presimulation : OutStroke Rotative axis, vtHead = ' .. tostring( vtHead) .. ', id = ' .. idVector) + EgtOutLog( ' ' .. RotativeAxes[1].sName .. ' = ' .. tostring( RotativeAxes[1].dValue) .. ', ' .. RotativeAxes[2].sName .. ' = ' .. tostring( RotativeAxes[2].dValue)) + + return true + end + + -- calcolo assi lineari + local bOkPositions, _, dLinear1, dLinear2, dLinear3 = EgtGetCalcPositions( ptOnToolTipCenter, RotativeAxes[1].dValue, RotativeAxes[2].dValue) + LinearAxes[1].dValue = dLinear1 + LinearAxes[2].dValue = dLinear2 + LinearAxes[3].dValue = dLinear3 + + if not bOkPositions then + + error( ' CheckOutOfStrokePoint : error') + end + + -- verifica finecorsa per tutti gli assi + -- siccome non si sa a priori il numero di assi lineari e rotativi, si aggiungono tutti a Args in ordine + -- Args viene poi esplosa in modo da passare a EgtVerifyOutstroke i valori separati + local Args = {} + + for i = 1, #LinearAxes do + Args[#Args+1] = LinearAxes[i].dValue + end + + for i = 1, #RotativeAxes do + Args[#Args+1] = RotativeAxes[i].dValue + end + + local bAllAxesInStroke = EgtVerifyOutstroke( table.unpack( Args)) + + if not bAllAxesInStroke then + + local idTempGroup = BeamLib.GetTempGroup() + local idPoint = EgtPoint( idTempGroup, ptOnToolTipCenter, GDB_RT.GLOB) + local idVector = EgtVector( idTempGroup, vtHead, ptOnToolTipCenter, GDB_RT.GLOB) + EgtSetColor( idPoint, RED()) + EgtSetColor( idVector, RED()) + EgtOutLog( ' Presimulation : OutStroke Axes, Tip Point = ' .. tostring( ptOnToolTipCenter) .. ', id = ' .. idPoint .. ', vtHead = ' .. tostring( vtHead) .. ', id = ' .. idVector) + EgtOutLog( ' ' .. LinearAxes[1].sName .. ' = ' .. LinearAxes[1].dValue .. ', ' .. LinearAxes[2].sName .. ' = ' .. LinearAxes[2].dValue .. ', ' .. LinearAxes[3].sName .. ' = ' .. LinearAxes[3].dValue) + EgtOutLog( ' ' .. RotativeAxes[1].sName .. ' = ' .. tostring( RotativeAxes[1].dValue) .. ', ' .. RotativeAxes[2].sName .. ' = ' .. tostring( RotativeAxes[2].dValue)) + + return true + end + + -- EgtSetAxisPos( 'T', dT) + -- EgtSetAxisPos( 'Y', dY) + -- EgtSetAxisPos( 'Z', dZ) + -- EgtSetAxisPos( 'C', dC1) + -- EgtSetAxisPos( 'A', dA1) + + return false end ------------------------------------------------------------------------------------------------------------- -- check extracorsa: se non vengono passati punti si controllano inizio e fine del lato -function PreSimulationLib.CheckOutOfStroke( Parameters, OptionalParameters ) +function PreSimulationLib.CheckOutOfStroke( PointsToCheck, Parameters) -- parametri obbligatori local Edge = Parameters.Edge @@ -98,22 +194,13 @@ function PreSimulationLib.CheckOutOfStroke( Parameters, OptionalParameters ) local vtHead = Parameters.vtHead local Tool = Parameters.Tool - -- parametri opzionali - OptionalParameters = OptionalParameters or {} - local PointsToCheck = OptionalParameters.PointsToCheck or { Edge.ptStart, Edge.ptEnd} - - local bIsDownUp = AreOppositeVectorApprox( vtNFace, vtHead) - - -- punti curva collisione e direzioni check da macchina - -- TODO serve pivot??? - local vtMovePivot = nil + -- SCC + local nSCC = Tool.SetupInfo.GetSCC( Edge.vtN, Edge.vtEdge, vtNFace) -- check collisione sui punti in centro lama su naso mandrino o aggregato. In base a direzione e punto for i = 1, #PointsToCheck do - local ToolExitPoint = GetToolExitPoint( PointsToCheck[i], Edge.vtN, vtHead, Tool, bIsDownUp) - - --local bOutOfStroke = CheckOutOfStrokePoint( ptToolExitToCheck, vtC, vtHead, vtMovePivot) + local bOutOfStroke = CheckOutOfStrokePoint( PointsToCheck[i], vtHead, vtNFace, Edge.vtN, nSCC, Tool) -- se trovato extracorsa inutile procedere con gli altri punti if bOutOfStroke then @@ -238,43 +325,6 @@ local function CheckCollisionWithAxis( sAxis, MachiningParameters, OptionalParam vtC = -vtC end - - - - - - -- TEST - -- for i = 1, #ToolExitPoints do - -- EgtSetCalcTool( Tool.sName, Tool.sHead, 1) - -- EgtLoadTool( Tool.sHead, 1, Tool.sName) - - -- EgtSetCalcSolCh( nSCC) - -- local bOkAngles, nSolutionsAngles, dC1, dA1, dC2, dA2 = EgtGetCalcAngles( vtHead, vtSCC) - -- local bOkPositions, _, dT, dY, dZ = EgtGetCalcPositions( ToolExitPoints[i] - vtHead * ( Tool.dLength - Tool.dThickness), dC1, dA1) -- ATTENZIONE qui il punto è sul Tip - - -- EgtSetAxisPos( 'T', dT) - -- EgtSetAxisPos( 'Y', dY) - -- EgtSetAxisPos( 'Z', dZ) - -- EgtSetAxisPos( 'C', dC1) - -- EgtSetAxisPos( 'A', dA1) - - -- local idPoint = EgtPoint( 0, PointsToCheck[i], 0) - -- EgtOutLog( 'Point id ' .. idPoint) - -- EgtOutLog( 'SCC = ' .. tostring(nSCC) .. ', vtHead = ' .. tostring( vtHead) .. ', vtAux = ' .. tostring(vtSCC)) - -- EgtOutLog( 'Solutions found = ' .. tostring( nSolutionsAngles) .. ', T = ' .. dT .. ', Y = ' .. dY .. ', Z = ' .. dZ .. ', C1 = ' .. dC1 .. ', A1 = ' .. dA1 .. ' (C2 = ' .. dC2 .. ', A2 = ' .. dA2 ..')') - -- end - - -- FINE TEST - - - - - - - - - - -- punti curva collisione e direzioni check da macchina local PreCollisionData = Tool.SetupInfo.GetPreCollisionData( sAxis, vtC, vtHead) @@ -337,68 +387,4 @@ function PreSimulationLib.CheckCollision( sBladeEngagement, Parameters, Optional end ------------------------------------------------------------------------------------------------------------- --- nel piano perpendicolare alla direzione di taglio, se c'è intersezione tra motore e trave c'è collisione --- ATTENZIONE NON PIU' USATA, verificare ed eliminare -function PreSimulationLib.CheckCollisionAxisAB( Edge, vtNFace, vtHead, Part, Tool, dDepthToMachine) - - -- se direzione utensile parallela ad uno degli assi principali non serve alcuna verifica - if AreSameOrOppositeVectorApprox( Edge.vtN, X_AX()) - or AreSameOrOppositeVectorApprox( Edge.vtN, Y_AX()) - or AreSameOrOppositeVectorApprox( Edge.vtN, Z_AX()) then - - return false - end - - -- riferimento perpendicolare al taglio, X nel verso della normale al lato e Y verso il motore - local ptMachining = Point3d( ( Edge.ptStart + Edge.ptEnd) / 2) + Edge.vtN * ( Edge.dElevation - dDepthToMachine) - - -- costruzione flat region del pezzo e del grezzo restante nel piano perpendicolare al taglio - local idPartSurfFr = GetPartSurfFrInPlane( Part, Edge.vtEdge) - local idRestlengthSurfFr = GetRestlengthSurfFrInPlane( Part, Edge.vtEdge) - - -- costruzione flat region approssimata del motore nel piano perpendicolare al taglio - -- punto di congiunzione tra motore e lama - local ptMaxElev = ptMachining + Edge.vtN * Tool.dMaxMaterial - -- se taglio standard (no DownUp) il punto va spostato dello spessore lama - if AreSameVectorApprox( vtNFace, vtHead) then - ptMaxElev = ptMaxElev + vtNFace * Tool.dThickness - end - -- TODO qui sostituire con il valore reale letto dal SetupInfo - -- per Fast si dovrà aggiungere la lunghezza del massimo utensile utilizzabile con lama - local dHeadDepth = 480 - local dHeadWidth = 480 - local ptOpposite = ptMaxElev + Edge.vtN * dHeadWidth - local ptCross = ptOpposite + vtHead * dHeadDepth - local idHeadRectangle = EgtRectangle3P( Part.idTempGroup, ptMaxElev, ptCross, ptOpposite, GDB_RT.GLOB) - -- flat region dal rettangolo - local idHeadSurfFr = EgtSurfFlatRegion( Part.idTempGroup, idHeadRectangle) - - -- intersezione tra pezzo e motore - local bCollisionFoundPiece = not EgtSurfFrTestExternal( idPartSurfFr, idHeadSurfFr) - - -- intersezione tra grezzo restante e motore, se con il pezzo non c'è collisione - local bCollisionFoundRestLength - if not bCollisionFoundPiece then - bCollisionFoundRestLength = not EgtSurfFrTestExternal( idRestlengthSurfFr, idHeadSurfFr) - end - - return bCollisionFoundPiece, bCollisionFoundRestLength -end - - - - - - - - - - - - - - - - - return PreSimulationLib \ No newline at end of file diff --git a/Process.lua b/Process.lua index b4c9670..1ef58aa 100644 --- a/Process.lua +++ b/Process.lua @@ -390,7 +390,7 @@ if not GetDataConfig() then return end -- Abilito Vmill EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1') -if not MyProcessFeatures() then return end +MyProcessFeatures() -- log tempi di esecuzione if EgtGetDebugLevel() >= 3 then