commit 818bd1650a16e85229ecad1b76d61878fa4ebe3f Author: DarioS Date: Fri Mar 3 10:13:29 2023 +0100 Essetre-TURN 2.5b1 : - primo commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..196fc23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +/Tools +/Machinings +/SetUp +/Beam/Ts3Data.bak +/Beam/CutData.lua +/Beam/DrillData.lua +/Beam/MillingData.lua +/Beam/PocketingData.lua +/Beam/SawingData.lua +/Beam/Ts3Data.lua +/Wall/Ts3Data.bak +/Wall/CutData.lua +/Wall/DrillData.lua +/Wall/MillingData.lua +/Wall/PocketingData.lua +/Wall/SawingData.lua +/Wall/Ts3Data.lua diff --git a/Beam/BeamData.lua b/Beam/BeamData.lua new file mode 100644 index 0000000..ea860e1 --- /dev/null +++ b/Beam/BeamData.lua @@ -0,0 +1,125 @@ +-- BeamData.lua by Egaltech s.r.l. 2022/04/04 +-- Raccolta dati generali per Travi + +EgtOutLog( ' TURN-BeamData started', 1) + +-- Tabella per definizione modulo +local BeamData = { + SIMUL_VIEW_DIR = 4, -- direzione di vista predefinita per la simulazione (1=NW, 2=SW, 3=NE, 4=SE) + GO_FAST = 0, -- flag abilitazione modalità veloce (0=no, 1=carrelli, 2=anche cambio utensili) + MIN_WIDTH = 40, -- larghezza minima del grezzo + MIN_HEIGHT = 40, -- altezza minima del grezzo + MAX_WIDTH = 650, -- larghezza massima del grezzo + MAX_HEIGHT = 400, -- altezza massima del grezzo + LEN_SHORT_PART = 1200, -- lunghezza massima pezzo corto + LEN_VERY_SHORT_PART = 400, -- lunghezza massima pezzo molto corto (molto probabile lo scarico a caduta) + MAX_RAW = 30000, -- massima lunghezza grezzo (deve essere minore di LenTable - RAW_OFFSET) + STD_RAW = 14000, -- lunghezza standard della barra di grezzo + OVM_HEAD = 10, -- sovramateriale testa + OVM_MID = 5.4, -- sovramateriale intermedio (spessore lama) + MINRAW_S = 750, -- minimo grezzo in coda scaricabile per sezioni piccole + MINRAW_L = 1070, -- minimo grezzo in coda scaricabile per sezioni grandi + MAX_LEN_SCRAP = 270, -- massima lunghezza scarto di coda + MAX_LEN_SCRAP_START = 270, -- massima lunghezza scarto di testa + MAX_DIM_HTCUT = 200, -- larghezza massima taglio di testa o coda + MAX_DIM_HTCUT_HBEAM = 180, -- larghezza massima taglio di testa o coda con trave alta + MIN_DIM_HBEAM = 360, -- altezza minima di trave alta + MAX_DIM_DICE = 110, -- dimensione trasversale massima cubetto + MAX_LEN_DICE = 400, -- lunghezza massima cubetto + COLL_SIC = 5, -- distanza di sicurezza per collisioni + CUT_SIC = 60, -- distanza di sicurezza per tagli + CUT_EXTRA = 5, -- affondamento extra standard per tagli di lama e fresature + CUT_EXTRA_MIN = 1, -- affondamento extra ridotto per tagli di lama e fresature + NZ_MINA = -2, -- componente limite in Z normale di una faccia (-36.8deg) + NZ_MINB = -2, -- componente limite in Z normale di un insieme di facce (-23deg) + DRILL_TOL = 0.2, -- tolleranza tra diametro foro e diametro punta + DRILL_RANGE = 100, -- distanza max tra fori da raggruppare + DRILL_RANGE_SP = 75, -- distanza max tra fori da raggruppare se pezzo corto + DRILL_VZ_MIN = -2, -- componente limite in Z del versore di un foro + DRILL_VX_MAX = 0.867, -- componente limite in X del versore di un foro sulle facce laterali + DRILL_OVERLAP = 5, -- sovrapposizione tra due mezze forature + MILL_OVERLAP = 5, -- sovrapposizione tra due mezze fresature + MAX_DIST_HTFEA = 50.0, -- massima distanza di feature da testa o coda per essere considerata tale + MAX_LEN_HTFEA = 2000.0, -- massima lunghezza di feature di testa o coda + LONGCUT_ENDLEN = 800, -- lunghezza lavoro estremi iniziale e finale + LONGCUT_MAXLEN = 1200, -- lunghezza massima sezione di taglio longitudinale + MAX_LEN_RIDGELAP_FROM_BOTTOM = 141, -- massima lunghezza ridgelap lavorabile da sotto + MAX_LEN_RIDGELAP_FROM_BOTTOM_HBEAM = 96, -- massima lunghezza ridgelap lavorabile da sotto con trave alta + DIM_TO_CENTER_STRIP = 0, -- larghezza minima trave per inseriemento codolo nel centro del trave; 0 = automatico + DIM_STRIP = -1, -- dimensione codolo sostegno parti lasciate su contorno libero o archi (-1 = da Q...) + DIM_STRIP_SMALL = 1, -- dimensione codolo piccolo (quando le parti sostenute sono sicuramente sulla parte sopra del pezzo) + RAWCOL = { 255, 160, 32, 30}, -- colore del grezzo + RAW_OFFSET = 2000, -- spostamento grezzo rimanente dopo split + VICE_MINH = 110, -- altezza minima della morsa + OFFSET_DRILL_TENON = 0, -- offset fori su tenoni verso base degli stessi (0=non fare) + USER_HOLE_DIAM = 0, -- diametro foro per L20 + MAX_TOOL_LEN_FOR_HOR_MACH = 311, -- massima lunghezza utensile per poter fare forature (fresature) oltre i 10 gradi dalla verticale + DRILL_VZ_MIN_LONG_TOOL = 0.984, -- componente limite per lavorazioni con punta lunga + MAX_TOOL_LEN_BACK_HOR_MACH = 500, -- massima lunghezza utensile per poter eseguire lavorazioni (forature/svuotature) da dietro (faccia 4) + TURN = true, -- macchina tipo Turn + TWO_EQUAL_HEADS = true, -- macchina con due teste equivalenti + KIOTP = 3.5, -- coefficiente moltiplicativo per attacco/uscita lama tangente anzichè perpendicolare + MAXDIAM_POCK_CORNER = 30, -- diametro massimo utensile ammesso per tasche con angoli interni + HEAD_DIM_FOR_BH = 190 -- dimensione di ingombro della testa per block haus +} + +-- Aggiornamento con dati da TechnoEssetre7 +local sTs3Data = EgtGetStringFromIni( 'Beam', 'DATA_DIR', "C:\\TechnoEssetre7\\EgtData", EgtGetIniFile()).."\\Essetre-TURN.qqq.data" +local sData = EgtGetSourceDir().."\\Ts3Data.qqq.lua" +if EgtExistsFile( sTs3Data) then + EgtCopyFile( sTs3Data, sData) + local sTs3DataOld = sTs3Data..'.old' + EgtEraseFile( sTs3DataOld) + EgtRenameFile( sTs3Data, sTs3DataOld) +end +if EgtExistsFile( sData) then + local Machine = dofile( sData) + if Machine then + if Machine.Offsets then + BeamData.ANG_TRASM = ( Machine.Offsets.SECSUP and Machine.Offsets.SECSUP >= 2) + end + if Machine.Trave then + BeamData.MIN_WIDTH = Machine.Trave.XMIN or BeamData.MIN_WIDTH + BeamData.MIN_HEIGHT = Machine.Trave.ZMIN or BeamData.MIN_HEIGHT + BeamData.MAX_WIDTH = Machine.Trave.XMAX or BeamData.MAX_WIDTH + BeamData.MAX_HEIGHT = Machine.Trave.ZMAX or BeamData.MAX_HEIGHT + end + if Machine.User then + BeamData.OFFSET_DRILL_TENON = Machine.User.L040_OFFSET_P1 or BeamData.OFFSET_DRILL_TENON + if Machine.User.OPTIMIZATIONS_ENABLE_SLICES_F5 == 1 then + BeamData.MAX_LEN_SCRAP = Machine.User.OPTIMIZATIONS_LENGTH_SLICES or BeamData.MAX_LEN_SCRAP + else + BeamData.MAX_LEN_SCRAP = 100000 + end + if Machine.User.OPTIMIZATIONS_ENABLE_SLICES_F6 == 1 then + BeamData.MAX_LEN_SCRAP_START = Machine.User.OPTIMIZATIONS_LENGTH_SLICES or BeamData.MAX_LEN_SCRAP_START + else + BeamData.MAX_LEN_SCRAP_START = 100000 + end + BeamData.USER_HOLE_DIAM = Machine.User.L020_DIAM_HOLE or BeamData.USER_HOLE_DIAM + end + end +end + +--------------------------------------------------------------------- +local function GetMaxLenRidgeLapFromBottom( dHRaw) + if dHRaw < BeamData.MIN_DIM_HBEAM then + return BeamData.MAX_LEN_RIDGELAP_FROM_BOTTOM + 0.01 + else + return BeamData.MAX_LEN_RIDGELAP_FROM_BOTTOM_HBEAM + 0.01 + end +end +BeamData.GetMaxLenRidgeLapFromBottom = GetMaxLenRidgeLapFromBottom + +--------------------------------------------------------------------- +local function GetChainSawBlockedAxis( nInd) + if nInd == 1 then + return 'Q=-90' + else + return 'Q=0' + end +end +BeamData.GetChainSawBlockedAxis = GetChainSawBlockedAxis + +--------------------------------------------------------------------- +return BeamData diff --git a/Beam/BeamTableTemplate.ini b/Beam/BeamTableTemplate.ini new file mode 100644 index 0000000..ccb02c1 --- /dev/null +++ b/Beam/BeamTableTemplate.ini @@ -0,0 +1,9 @@ +-- %TABLE_NAME%.lua by Egaltech s.r.l. %DATE_TIME% +-- Gestione dati lavorazioni per Travi + +-- Tabella per definizione modulo +local %TABLE_NAME% = { +} + +--------------------------------------------------------------------- +return %TABLE_NAME% diff --git a/Beam/MachData.ini b/Beam/MachData.ini new file mode 100644 index 0000000..4c6b013 --- /dev/null +++ b/Beam/MachData.ini @@ -0,0 +1,62 @@ +; PIndex = Type, PName, Default, Description +; Type : d=double, l=length, s=string + +[1] +Name=Offsets +1=l,X1_NEG,0,X1_NEG +2=l,X1_POS,1185,X1_POS +3=l,PARK_X1,0,PARK_X1 +4=l,Z1_NEG,-1690,Z1_NEG +5=l,Z1_POS,0.0,Z1_POS +6=l,PARK_Z1,0,PARK_Z1 +7=l,DIST_FTZERO,1880.5,DIST_FTZERO +8=l,DELTA_CARICZERO,269.5,DELTA_CARICZERO +9=l,DIST_UNLOAD,-2400,DIST_UNLOAD +10=l,CNTRRLL_T1_X1,710.75,CNTRRLL_T1_X1 +11=l,CNTRRLL_T1_Z1,-903.5,CNTRRLL_T1_Z1 +12=l,OFFSETXT1,391.1,OFFSETXT1 +13=l,OFFSETZT1,-924.8,OFFSETZT1 +14=d,A1_NEG,-270,A1_NEG +15=d,A1_POS,270,A1_POS +16=l,CNTRRLL_T2_X2,711.5,CNTRRLL_T2_X2 +17=l,CNTRRLL_T2_Z2,-904.3,CNTRRLL_T2_Z2 +18=l,OFFSETXT2,393.081,OFFSETXT2 +19=l,OFFSETZT2,-806.2,OFFSETZT2 +20=l,X2_NEG,0,X2_NEG +21=l,X2_POS,1185,X2_POS +22=l,PARK_X2,0,PARK_X2 +23=l,Z2_NEG,-1690,Z2_NEG +24=l,Z2_POS,0,Z2_POS +25=l,PARK_Z2,0,PARK_Z2 +26=d,A2_NEG,-270,A2_NEG +27=d,A2_POS,270,A2_POS +28=d,B_NEG,-91,B_NEG +29=d,B_POS,271,B_POS +30=l,PIVOTFRESAT1,176.5,PIVOTFRESAT1 +31=l,PIVOTLAMAT1,-242.35,PIVOTLAMAT1 +32=l,PIVOTFRESAT2,178.05,PIVOTFRESAT2 +33=l,PIVOTLAMAT2,-252.2,PIVOTLAMAT2 +34=d,PARK_A1,0,PARK_A1 +35=d,PARK_A2,0,PARK_A2 +36=l,MIN_Y,55,MIN_Y +37=l,MAX_Y,5545,MAX_Y +38=l,PARK_Y,600,PARK_Y +39=l,MIN_V,-5559,MIN_V +40=l,MAX_V,-67,MAX_V +41=l,PARK_V,-500,PARK_V +42=l,DIREZ_SXDX,1,DIREZ_SXDX + +[2] +Name=Trave +1=l,XMIN,30,XMIN +2=l,XMAX,651,XMAX +3=l,ZMIN,30,ZMIN +4=l,ZMAX,300,ZMAX + +[3] +Name=User +1=d,OPTIMIZATIONS_ENABLE_SLICES_F5,1,OPTIMIZATIONS_ENABLE_SLICES_F5 +2=d,OPTIMIZATIONS_ENABLE_SLICES_F6,1,OPTIMIZATIONS_ENABLE_SLICES_F6 +3=l,OPTIMIZATIONS_LENGTH_SLICES,100,OPTIMIZATIONS_LENGTH_SLICES +4=d,L020_DIAM_HOLE,12,L020_DIAM_HOLE +5=l,L040_OFFSET_P1,0,L040_OFFSET_P1 diff --git a/Beam/MachiningTypes.ini b/Beam/MachiningTypes.ini new file mode 100644 index 0000000..37306b5 --- /dev/null +++ b/Beam/MachiningTypes.ini @@ -0,0 +1,37 @@ +[Cut] +1=HeadSide +2=TailSide + +[Drill] +1=Drill +2=Pocket + +[Milling] +1=Prof +2=FreeContour +3=Tenon +4=DtTenon +5=DtMortise +6=BirdsMouth +7=Chamfer +8=Mark +9=Text +10=Decor01 +11=Long2Cut +12=Long2CutDown +13=LongSmallCut +14=BHSideMill +15=SideMillAsBlade +16=CleanCorner +17=ProfTCone +18=Long2CutSide +19=SmallToolContour +20=AntiSplintMillCut + +[Pocketing] +1=Pocket +2=OpenPocket +3=Mortise + +[Sawing] +1=Sawing diff --git a/Essetre-TURN.NUM.mlpe b/Essetre-TURN.NUM.mlpe new file mode 100644 index 0000000..136d7be --- /dev/null +++ b/Essetre-TURN.NUM.mlpe @@ -0,0 +1,1787 @@ +-- Processore macchina Essetre-TURN by EgalTech s.r.l. 2022/09/30 +-- Con controllo numerico NUM + +-- Variabili di modulo +local MLE_INFO = 'Essetre-TURN.NUM.mlpe ver.'..PP_VER..' by EgalTech s.r.l.' +local TEST_USE = false +local OPT_UNLOAD_BAR = true + +--------------------------------------------------------------------- +-- *** GENERATION *** +--------------------------------------------------------------------- +function OnStart() + EMT.USETO1 = false -- abilitazione uso origine tavola + EMT.MODAL = true -- abilitazione emissione modale + EMT.INCHES = false -- unità di misura mm/inches + EMT.NUM = false -- abilitazione numerazione linee + --EMT.Nt = 'N' -- token per la numerazione di linea + --EMT.LINENBR = 0 -- numero di linea + --EMT.LINEINC = 1 -- incremento numerazione linee + --EMT.Ft = 'F' -- token per feed + --EMT.St = 'S' -- token per speed + EMT.FMAXHEAD = 70000 -- feed massima testa + EMT.FMAXPINZE = 154000 -- feed massima pinze +end + +--------------------------------------------------------------------- +function OnEnd() + -- Ripristino fase iniziale come corrente + EgtSetCurrPhase( 1) +end + +--------------------------------------------------------------------- +function OnProgramStart() + -- Intestazioni + local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or EgtGetCurrMachGroup() or GDB_ID.NULL + local nPatt = EgtGetInfo( BtlInfoId, 'PATTID', 'i') or 40 + EmtOutput( '%'..EgtNumToString( nPatt, 0)..'.0') + if EMT.INFO then + EmtOutput( '('..EMT.INFO..')') + else + EmtOutput( '(Program Start)') + end + EmtOutput( '('.. MLE_INFO..')\n') + -- Se modalità test, aggiungo linee per muovere tappeto e alzare la testa (in automatico viene fatto dal main residente) + if TEST_USE then + EmtOutput( 'M28') + EmtOutput( 'N1 G101 Z-100'..' EF'..GetFmaxHead()..' L0=0') + EmtOutput( 'N1 G101 ET1001') + EmtOutput( 'N1 G101 ET2001\n') + end + -- Cerco primo utensile su testa 1 + EMT.TOOL_1, EMT.TLEN_1 = FindFirstToolOnHead( 'H11') + -- Dichiaro inizio + EMT.FIRST = true + EMT.TLAST = nil +end + +--------------------------------------------------------------------- +function OnProgramEnd() + -- Arresto mandrino + EmtOutput( 'M05') + -- Emissione scarico + --for i = 1, #EMT.AUXCMD do + -- EmtOutput( '( ' .. EMT.AUXCMD[i] .. ' )') + --end + EMT.AUXCMD = {} + local sET = EgtIf( EMT.AUXTYPE == 'U' and not EMT.CHY_ON, ' ET2', '') + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i] .. sET) + end + if #EMT.AUXSTR > 0 then + if EMT.AUXTYPE == 'S' or EMT.AUXTYPE == 'R' then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + elseif EMT.AUXTYPE == 'U' then + local sP1x = EgtIf( EMT.CHY_ON, '4', '2') + EmtOutput( 'G111 ET100'..sP1x) + if OPT_UNLOAD_BAR and not EMT.CHY_ON then + EmtOutput( '(G111 ET200'..sP1x..')') + else + EmtOutput( 'G111 ET200'..sP1x) + end + -- emissione conclusione pezzo precedente (se non si è in test) + if not TEST_USE and EMT.PRODID then + local sEnd= 'G113 EA'..tostring( EMT.PRODID)..' EB'..tostring( EMT.PATTID)..' EC'..tostring( EMT.CUTID)..' ED2' + EmtOutput( sEnd) + end + end + end + EMT.AUXSTR = {} + EMT.AUXTYPE = nil + EMT.U_STD = nil + EMT.UNL = nil + EMT.PREROT = nil + EMT.SPLITROT = nil + EMT.CHY_ON = nil + EMT.FALL = nil + EMT.RELOAD = nil + EMT.RELOAD2 = nil + -- Se modalità test, termino il programma + if TEST_USE then + EmtOutput( 'M02') + end +end + +--------------------------------------------------------------------- +function OnToolData() + -- emissione dati utensile (esclusa lama) + if EMT.HEAD == 'H11' or EMT.HEAD == 'H21' then + -- output info + local sPos + if #EMT.TCPOS == 2 then + sPos = EMT.TCPOS:gsub( 'T', 'N20') + elseif #EMT.TCPOS == 3 then + sPos = EMT.TCPOS:gsub( 'T', 'N2') + else + sPos = EMT.TCPOS:gsub( 'T1', 'N3') + end + local sOut = 'L1='..EgtNumToString( EMT.SMAX, 0)..' L2='..EmtLenToString( EMT.TTOTLEN, 1)..' G76H9998.2'..sPos..sPos + EmtOutput( sOut) + -- cerco posizione di attrezzaggio del primo utensile di lavorazione + if EMT.TOOL == EMT.TOOL_1 and EMT.TLEN_1 < 215.5 then + EMT.TCPOS_1 = EMT.TCPOS + end + -- emissione dati sega a catena + elseif EMT.HEAD == 'H13' then + if EMT.TDIST and abs( EMT.TDIST) < 0.1 then EMT.TDIST = nil end + local sOut = 'L1='..EgtNumToString( EMT.SMAX, 0)..' L2='..EmtLenToString( ( EMT.TDIST or ChSawLen), 1)..' G76H9998.2N301N302' + EmtOutput( sOut) + end +end + +--------------------------------------------------------------------- +function OnDispositionStart() + --EmtOutput( '(Disposition '..EMT.DISPIND..' = '..EMT.DISPID..')') + EMT.OPEISDISP = true + -- Assegnazione parametri disposizione + EMT.TPOS = EgtGetInfo( EMT.DISPID, 'TPOS', 'd') + EMT.YPOS = EgtGetInfo( EMT.DISPID, 'YPOS', 'd') + -- Se prima disposizione + if EMT.PHASE == 1 then + -- emissione dati di macchina + local sOut = 'G114 EA'..EmtLenToString( LoadT, 2)..' EB'..EmtLenToString( MinY, 2)..' EC'..EmtLenToString( MaxY, 2).. + ' ED'..EmtLenToString( MinV, 2)..' EE'..EmtLenToString( MaxV, 2)..' EF'..EmtLenToString( MillOffs, 2).. + ' EG'..EmtLenToString( SawOffs, 2)..' EI'..EmtLenToString( ParkY, 2)..' EL'..EmtLenToString( ParkV, 2).. + ' EM'..EmtLenToString( TurnerOffs, 2)..' EN'..EmtLenToString( -Mill2Offs, 2)..' EO'..EmtLenToString( -Saw2Offs, 2).. + ' EP'..EmtLenToString( -RallaOffsZ, 2)..' EQ'..EmtLenToString( -RallaOffsY - MillOffs, 2).. + ' ER'..EmtLenToString( Ralla2OffsZ, 2)..' ES'..EmtLenToString( Ralla2OffsY + Mill2Offs, 2).. + ' ET'..EmtLenToString( RallaOffsY - RallaOffsZ - DeltaTabY, 2)..' EU'..EmtLenToString( -RallaOffsZ - RallaOffsY + DeltaTabZ, 2).. + ' EV'..EmtLenToString( -Ralla2OffsY - Ralla2OffsZ - Delta2TabY, 2)..' EW'..EmtLenToString( Ralla2OffsY - Ralla2OffsZ + Delta2TabZ, 2) + EmtOutput( sOut) + -- carico barra + EMT.LOAD = true + else + EMT.LOAD = false + if IsEnd2Phase( EMT.PHASE - 1) then + EMT.RELOAD = true + EMT.RELOAD2 = false + elseif IsStartPhase( EMT.PHASE) then + EMT.YDELTA = EMT.YPOS - LoadT + EMT.VDELTA = nil + end + end +end + +--------------------------------------------------------------------- +function OnDispositionEnd() + -- Se disposizione inizio o rimanenza + if IsStartOrRestPhase( EMT.PHASE) then + -- reset recupero sovramateriale in X non più presente + EMT.X_OFF = nil + -- dati del grezzo + local LBarra = EMT.LB + -- dati del pezzo + local IdTrave = EMT.IT + local LTrave = EMT.LT + local HTrave = EMT.HT + local STrave = EMT.ST + local HOverM = EMT.HOVM + -- calcolo dati pinze + local MinAccPinze = 0.3 + local MaxAccPinze = 4 + local KgMtCubo= 550 -- densità legno in Kg / metro cubo + local Massa = ( HTrave * STrave * LBarra * KgMtCubo ) / 1000000000 + local FMaxPinze = EMT.FMAXPINZE + local ForzaAtrito = 700 / 2 -- Serve per regolare P32 (700 valore reale pistone) + local TempoAcc = ( ( Massa * FMaxPinze) / ( 60 * ForzaAtrito) / 1000) + if ( TempoAcc < MinAccPinze) then TempoAcc = MinAccPinze end + if ( TempoAcc > MaxAccPinze) then TempoAcc = MaxAccPinze end + local AccPinze = FMaxPinze / ( 60 * TempoAcc) + local RidFeed = 100 / Massa * 100 + if ( RidFeed > 100) then RidFeed = 100 end + if IdTrave >= 0 then + local sOut = '( SN='..IdTrave..' LBarra='..EmtLenToString(LBarra,3)..' L='..EmtLenToString(LTrave,3).. + ' H='..EmtLenToString(HTrave,3)..' S='..EmtLenToString(STrave,3)..' Acc='..EmtLenToString(TempoAcc,1).. + ' RidFeed='..EmtLenToString(RidFeed,3)..' FeedMax='..EmtLenToString(FMaxPinze / 100 * RidFeed,3)..' )' + MyOutputNoNum( sOut) + sOut = 'G115 EA'..EmtLenToString( AccPinze, 0)..' EB8555'..' EC'..EmtLenToString( AccPinze, 0).. + ' ED8555'..' EE'..EmtLenToString( AccPinze, 0)..' EF'..EmtLenToString( RidFeed, 0).. + ' EG'..EmtLenToString( RidFeed, 0)..' EH500'..' EI500'..' EL1'.. + ' EM'..EmtLenToString( LBarra, 3)..' EN'..EmtLenToString( HTrave, 3)..' EO'..EmtLenToString( STrave, 3).. + ' EP'..EmtLenToString( LTrave, 3)..' EQ'..EmtLenToString( HOverM, 3)..' ER0' + MyOutputNoNum( sOut) + local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or EgtGetCurrMachGroup() or GDB_ID.NULL + EMT.PRODID = EgtGetInfo( BtlInfoId, 'PRODID', 'i') or 0 + EMT.PATTID = EgtGetInfo( BtlInfoId, 'PATTID', 'i') or 0 + EMT.CUTID = EgtGetInfo( EMT.IDT, 'CUTID', 'i') or 0 + local sStart = 'G113 EA'..tostring( EMT.PRODID)..' EB'..tostring( EMT.PATTID)..' EC'..tostring( EMT.CUTID)..' ED1' + EmtOutput( sStart) + else + MyOutputNoNum( '(REMAIN UNLOAD)') + EMT.PRODID = nil + EMT.PATTID = nil + EMT.CUTID = nil + end + -- se carico barra + if EMT.LOAD then + -- verifico se sezione già caricata + local sOut = 'IF E30012<'..EmtLenToString(HTrave*1000,0)..' OR E30013<'..EmtLenToString(STrave*1000,0)..' THEN' + EmtOutput( sOut) + sOut = ' M111 E30011=0' + EmtOutput( sOut) + sOut = ' M115' + EmtOutput( sOut) + sOut = ' M141 E30014=0' + EmtOutput( sOut) + sOut = ' M145' + EmtOutput( sOut) + sOut = 'ENDI' + EmtOutput( sOut) + -- assegnazione dati trave e barra + sOut = 'E30012='..EmtLenToString(HTrave*1000,0)..' E30013='..EmtLenToString(STrave*1000,0).. + ' E30005='..EmtLenToString(LBarra*1000,0) + EmtOutput( sOut) + -- preselezione prima fresa (della testa 1) + sOut = 'IF E30001=0 THEN' + EmtOutput( sOut) + sOut = ' M6' .. ( EMT.TCPOS_1 or 'T1') + -- va scritto 2 volte + EmtOutput( sOut) + EmtOutput( sOut) + sOut = 'ENDI' + EmtOutput( sOut) + -- ora abilito numerazione linee + EMT.NUM = true + EMT.LINENBR = 0 + -- se altrimenti ricarico barra dopo rotazione speciale + elseif EMT.RELOAD then + -- assegnazione dati trave e barra + sOut = 'E30012='..EmtLenToString(HTrave*1000,0)..' E30013='..EmtLenToString(STrave*1000,0).. + ' E30005='..EmtLenToString(LBarra*1000,0) + EmtOutput( sOut) + -- altrimenti recupero rimanenza + else + EmtOutput( 'G112 EC1'..' Y'..EmtLenToString( LoadT, 3).. ' EY'..EmtLenToString( EMT.YPOS, 3)..' EV'..EmtLenToString( ParkV, 3) ..' EF'..GetFmaxClamp()) + -- aggiorno dati aggancio carrelli alla trave + EMT.YDELTA = EMT.YPOS - LoadT + EMT.VDELTA = nil + end + -- eventuale preparazione per rotazione immediata + if IsStartPhase( EMT.PHASE) and EMT.AUXSTR then + -- emissione movimento carrelli per rotazione + EMT.AUXCMD = {} + if #EMT.AUXSTR > 0 then + EmtOutput( '(ROTATION)') + end + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i]) + end + if #EMT.AUXSTR > 0 then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + end + EMT.AUXSTR = {} + EMT.AUXTYPE = nil + end + -- se altrimenti disposizione intermedia, eventuale rotazione + elseif IsMidPhase( EMT.PHASE) or IsEnd2Phase( EMT.PHASE) then + -- se rotazioni diverse, emetto il comando e aggiorno lo stato + if VerifyEmitRotation() then + -- imposto stato post-rotazione + EMT.POSTROT = true + -- imposto recupero sovramateriale in X non più presente + EMT.X_OFF = EMT.HOVM + end + -- se altrimenti disposizione intermedia speciale con eventuale rotazione + elseif IsMid2Phase( EMT.PHASE) then + -- emissione movimento carrelli + EMT.AUXCMD = {} + if #EMT.AUXSTR > 0 then + EmtOutput( '(ROTATION)') + end + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i]) + end + if #EMT.AUXSTR > 0 then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + end + EMT.AUXSTR = {} + EMT.AUXTYPE = nil + -- se rotazioni diverse, emetto il comando e aggiorno lo stato + if VerifyEmitRotation() then + -- imposto stato post-rotazione + EMT.POSTROT = true + -- imposto recupero sovramateriale in X non più presente + EMT.X_OFF = EMT.HOVM + end + -- altrimenti disposizione finale, eventuale scarico pezzo lavorato se non ci sono lavorazioni + else + EMT.AUXCMD = {} + if #EMT.AUXSTR > 0 then + MyOutputNoNum( '(PART UNLOAD)') + end + local sET = ' ET2' + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i] .. sET) + end + if #EMT.AUXSTR > 0 then + EmtOutput( 'G111 ET1002') + if OPT_UNLOAD_BAR then + EmtOutput( '(G111 ET2002)') + else + EmtOutput( 'G111 ET2002') + end + -- emissione conclusione pezzo precedente + if EMT.PRODID then + local sEnd= 'G113 EA'..tostring( EMT.PRODID)..' EB'..tostring( EMT.PATTID)..' EC'..tostring( EMT.CUTID)..' ED2' + EmtOutput( sEnd) + end + end + EMT.AUXSTR = {} + EMT.AUXTYPE = nil + EMT.U_STD = nil + end + + EMT.OPEISDISP = false +end + +--------------------------------------------------------------------- +function OnTableData() +end + +--------------------------------------------------------------------- +function OnFixtureData() +end + +--------------------------------------------------------------------- +function OnRawMoveData() + -- Se disposizione inizio o rimanenza + if IsStartOrRestPhase( EMT.PHASE) then + -- se primo grezzo, reset lunghezza barra + if EMT.RAWIND == 1 then EMT.LB = 0 end + -- aggiungo la lunghezza del grezzo (solo se movimento in corner) + if EMT.RAWTYPE == 1 then + local b3Raw = EgtGetBBoxGlob( EgtGetFirstNameInGroup( EMT.RAWID, 'RawSolid'), GDB_BB.STANDARD) + local LBarra = b3Raw:getDimX() + EMT.LB = EMT.LB + LBarra + end + -- se primo grezzo, calcolo dati del pezzo + if EMT.RAWIND == 1 then + local PartId = EgtGetFirstPartInRawPart( EMT.RAWID) + if PartId then + EMT.IDT = PartId + EMT.IT = EgtGetInfo( PartId, 'PDN', 'i') or 0 + local b3Part = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PartId, 'Box'), GDB_BB.STANDARD) + EMT.LT = b3Part:getDimX() + EMT.HT = b3Part:getDimY() + EMT.ST = b3Part:getDimZ() + EMT.HOVM = EgtGetInfo( EMT.RAWID, 'HOVM', 'd') or 0 + else + EMT.IDT = GDB_ID.NULL + EMT.IT = -1 + EMT.LT = 0 + EMT.HT = EMT.HT or 0 + EMT.ST = EMT.ST or 0 + EMT.HOVM = 0 + end + end + end +end + +--------------------------------------------------------------------- +function OnToolSelect() + -- se utensile definito (non definito per disposizioni con movimento) + if EMT.TOOL ~= '' then + -- verifiche su utensile + local sTool = EgtTdbGetToolFromUUID( EgtGetMachiningParam( MCH_MP.TUUID) or "") + if sTool ~= EMT.TOOL then error( "Tool name mismatch") end + -- predefinite EMT.TCPOS EMT.HEAD EMT.EXIT + EMT.TOOLTYPE = EgtTdbGetCurrToolParam( MCH_TP.TYPE) + EMT.TOOLSEL = EMT.TCPOS..' M06' + EMT.TDIAM = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + EMT.TTOTDIAM = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) + EMT.TLEN = EgtTdbGetCurrToolParam( MCH_TP.LEN) + EMT.TTOTLEN = EgtTdbGetCurrToolParam( MCH_TP.TOTLEN) + if MCH_TP.DIST then EMT.TDIST = EgtTdbGetCurrToolParam( MCH_TP.DIST) end + if EMT.TDIST and abs( EMT.TDIST) < 0.1 then EMT.TDIST = nil end + end +end + +--------------------------------------------------------------------- +function OnToolDeselect() +end + +--------------------------------------------------------------------- +function OnMachiningStart() + --EMT.MCHNAME = EgtGetMachiningParam(MCH_MP.NAME) + EMT.MCHNAME = EgtGetOperationName( EMT.MCHID) + EMT.MCHTYPE = EgtGetMachiningParam(MCH_MP.TYPE) + EMT.MCHUSERNOTES = EgtGetMachiningParam( MCH_MP.USERNOTES) + -- non ancora iniziata la lavorazione + EMT.MCHFIRST = true + -- sistemazione speed + if EMT.HEAD == 'H12' or EMT.HEAD == 'H22' then + EMT.S = EMT.S * -6 + end + -- determino subito se taglio di separazione di pezzo a caduta + EMT.PREFALLCUT = nil + if EMT.MCHUSERNOTES and EMT.MCHUSERNOTES:find( 'Split') then + local ClId = EgtGetFirstNameInGroup( EMT.MCHID, 'CL') + local P1Id = EgtGetFirstNameInGroup( ClId or GDB_ID.NULL, 'P1') + local sAE1 = EgtGetInfo( P1Id or GDB_ID.NULL, 'AE1') or '' + if sAE1 == '0,Fall' then + EMT.PREFALLCUT = true + end + end +end + +--------------------------------------------------------------------- +function OnMachiningEnd() + --EmtOutput( ';Mach End') + -- Emissione split + --for i = 1, #EMT.AUXCMD do + -- EmtOutput( '( ' .. EMT.AUXCMD[i] .. ' )') + --end + EMT.AUXCMD = {} + if #EMT.AUXSTR > 0 then + if EMT.AUXTYPE == 'S' then + MyOutputNoNum( '(PART SPLIT)') + elseif EMT.AUXTYPE == 'U' then + if not EMT.HOME then + EmitZmax( true) + EMT.ZMAX = true + EMT.HOME = true + end + MyOutputNoNum( '(PART UNLOAD)') + elseif EMT.AUXTYPE == 'P' then + if EMT.PREROT then + if not EMT.HOME then + EmitZmax( true) + EMT.ZMAX = true + EMT.HOME = true + end + MyOutputNoNum( '(PART ROTATION)') + elseif EMT.FALL then + if not EMT.HOME then + EmitZmax( true) + EMT.ZMAX = true + EMT.HOME = true + end + EmtOutput( '(FALL)') + else + if not EMT.HOME then + EmitZmax( true) + EMT.ZMAX = true + EMT.HOME = true + end + EmtOutput( '(SPLIT 2)') + end + end + end + local sET = EgtIf( EMT.AUXTYPE == 'U' and not EMT.CHY_ON, ' ET2', '') + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i] .. sET) + end + if #EMT.AUXSTR > 0 then + if EMT.AUXTYPE == 'S' then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + elseif EMT.AUXTYPE == 'U' then + local sP1x = EgtIf( EMT.CHY_ON, '4', '2') + EmtOutput( 'G111 ET100'..sP1x) + -- se è ultimo pezzo e dopo non c'è spezzone + if OPT_UNLOAD_BAR and not EMT.CHY_ON and not IsStartOrRestPhase( EMT.PHASE + 1) then + EmtOutput( '(G111 ET200'..sP1x..')') + else + EmtOutput( 'G111 ET200'..sP1x) + end + -- emissione conclusione pezzo precedente + if not TEST_USE and EMT.PRODID then + local sEnd= 'G113 EA'..tostring( EMT.PRODID)..' EB'..tostring( EMT.PATTID)..' EC'..tostring( EMT.CUTID)..' ED2' + EmtOutput( sEnd) + end + elseif EMT.AUXTYPE == 'P' then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + if EMT.FALL then + EmtOutput( 'M155') + EmtOutput( 'M28') + -- emissione conclusione pezzo (se non in modalità test) + if not TEST_USE and EMT.PRODID then + local sEnd= 'G113 EA'..tostring( EMT.PRODID)..' EB'..tostring( EMT.PATTID)..' EC'..tostring( EMT.CUTID)..' ED2' + EmtOutput( sEnd) + end + elseif not EMT.PREROT then + EmtOutput( 'M77') + end + end + end + EMT.AUXSTR = {} + EMT.AUXTYPE = nil + EMT.U_STD = nil + EMT.PREVTOOL = EMT.TOOL +end + +--------------------------------------------------------------------- +function OnPathStart() + -- non ancora iniziata la lavorazione + EMT.MCHFIRST = true + -- primo posizionamento sempre in globale + EMT.REFLOC = nil + EMT.IPLGL = false + -- salvo gli assi rotanti correnti + EMT.R1pp = EMT.R1 + EMT.R2pp = EMT.R2 + EMT.R3pp = EMT.R3 + -- salvo precedente Z rispetto a ZeroMacchina + local MyL2op = EMT.L2op + -- reset valori precedenti (per forzare emissione di tutti gli assi del 1° movimento) + EmtResetPrev() + -- ripristino precedente Z rispetto a ZeroMacchina + EMT.L2op = MyL2op + EMT.AUXCMD = {} + EMT.AUXSTR = {} +end + +--------------------------------------------------------------------- +function OnPathEnd() + EMT.AUXTYPE = nil + EMT.UNL = nil + EMT.PREROT = nil + EMT.SPLITROT = nil + EMT.CHY_ON = nil + EMT.FALL = nil + EMT.AUXCMD = {} + EMT.AUXSTR = {} +end + +--------------------------------------------------------------------- +function OnPathStartAux() + --EgtOutLog( 'OnPathStartAux - ' .. EgtNumToString( EMT.AUXIND, 0) .. ' - ' .. EMT.AUX) + + -- se richiesto, preparo il carico barra + if EMT.LOAD or EMT.RELOAD then + PrepareLoad( EMT.AUX, true) + -- se altrimenti carico dopo rotazione + elseif EMT.POSTROT then + PreparePostRotation( EMT.AUX) + -- altrimenti, preparo lo spostamento carrelli + else + PrepareMoveChar( EMT.AUX) + end +end + +--------------------------------------------------------------------- +function OnPathEndAux() + --EgtOutLog( 'OnPathEndAux - ' .. EgtNumToString( EMT.AUXIND, 0) .. ' - ' .. EMT.AUX) + -- verifico tipo di emissione + if EMT.OPEISDISP then + if not EMT.AUXTYPE then + local Cmd = EgtSplitString( EMT.AUX) + if Cmd[1] == '0' and Cmd[2] == 'Unloading' then + EMT.AUXTYPE = 'U' + elseif EgtGetInfo( EMT.DISPID, 'TYPE') == 'REST' then + EMT.AUXTYPE = 'R' + else + EMT.AUXTYPE = 'P' + end + end + else + if not EMT.AUXTYPE then + local Cmd = EgtSplitString( EMT.AUX) + if Cmd[1] == '0' and Cmd[2] == 'Split' then + EMT.AUXTYPE = 'S' + elseif Cmd[1] == '0' and Cmd[2] == 'Unloading' then + EMT.AUXTYPE = 'U' + else + EMT.AUXTYPE = 'P' + if Cmd[1] == '0' and Cmd[2] == 'Fall' then + EMT.FALL = true + end + end + elseif EMT.AUXTYPE == 'P' then + local Cmd = EgtSplitString( EMT.AUX) + if Cmd[1] == '0' and Cmd[2] == 'Unloading' then + EMT.CHY_ON = true + EMT.AUXTYPE = 'U' + end + end + end + -- preparo a seconda del tipo + if EMT.AUXTYPE == 'R' then + -- per il carico della rimanenza dopo rotazione speciale + if EMT.RELOAD and not EMT.RELOAD2 then + PrepareLoad( EMT.AUX, false) + -- per lo scarico della rimanenza + else + PrepareResidue( EMT.AUX) + end + elseif EMT.AUXTYPE == 'S' then + -- per lo split + PrepareSplit( EMT.AUX) + elseif EMT.AUXTYPE == 'U' then + -- per lo scarico + PrepareUnload( EMT.AUX) + elseif EMT.AUXTYPE == 'P' then + -- per la pre-rotazione + PreparePreRotation( EMT.AUX) + end +end + +--------------------------------------------------------------------- +function OnRapid() + MyBackupAxes() + -- gruppo della testa + local nHSet = GetHeadSet( EMT.HEAD) + -- se primo movimento della lavorazione, gestione speciale + if EMT.MCHFIRST and not EMT.OPEISDISP then + -- decido se muovere prima testa o carrelli (standard prima testa) + local bHeadFirst = true + local sLateG101 + if not ( EMT.LOAD or EMT.RELOAD) and not EMT.ZMAX then + local DeltaT = EMT.L1 - EMT.TLAST + if ( DeltaT < -GEO.EPS_SMALL and EMT.VDELTA) or ( DeltaT > GEO.EPS_SMALL and EMT.YDELTA) then + bHeadFirst = false + end + end + -- sistemo movimenti + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + if not ( EMT.LOAD or EMT.RELOAD) then + if not EMT.HOME and #EMT.AUXSTR > 0 then + EmitZmax( true) + EMT.ZMAX = true + EMT.HOME = true + end + end + if not EMT.LOAD then + local sOut = string.gsub( string.gsub( EMT.MCHNAME..'/'..EMT.TOOL, '%(', '-'), '%)', '-') + EmtOutput( '( *** ' .. sOut .. ' *** )') + end + -- primo posizionamento + EmtResetPrev() + local bZmax = ( #EMT.AUXSTR > 0 or EMT.TOOL ~= EMT.PREVTOOL or EMT.L3 > -1) + local sEL = ' EL' .. EmtLenToString( EgtIf( EMT.HEAD ~= 'H13', EMT.TLEN, ( EMT.TDIST or ChSawLen)), 3) + local sER = ' ER' .. EmtLenToString( EgtIf( EMT.HEAD ~= 'H13', EMT.TDIAM / 2, EMT.TLEN), 3) + local sET = ' ET0' if nHSet == 1 then sET = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sES = ' ES0' if nHSet == 1 then sES = ' ES'..EgtNumToString( EMT.S, 0) end + local sEU = ' EU0' if nHSet == 2 then sEU = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sEA = ' EA0' if nHSet == 2 then sEA = ' EA'..EgtNumToString( EMT.S, 0) end + local sEF = ' EF'..GetFmaxHead() + local sOut + if nHSet == 1 then + if EMT.HOME then + local HomeX1 = -EgtGetAxisHomePos( 'X1') + local HomeZ1 = -EgtGetAxisHomePos( 'Z1') + sOut = 'G101' .. ' X' .. EmtLenToString( HomeX1, 3) .. ' Z' .. EmtLenToString( HomeZ1, 3) .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + elseif EMT.ZMAX then + local HomeX1 = -EgtGetAxisHomePos( 'X1') + local HomeZ1 = -EgtGetAxisHomePos( 'Z1') + local CurrR1 = ( EMT.R1p or EMT.R1pp) + local CurrR2 = ( EMT.R2p or EMT.R2pp) + if abs( CurrR1 - EMT.R1) > 30 then + sOut = 'G101' .. ' X' .. EmtLenToString( HomeX1, 3) .. ' Z' .. EmtLenToString( HomeZ1, 3) .. + ' A'..EgtNumToString( CurrR2, 3) .. ' B'..EgtNumToString( CurrR1 + 90, 3) .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + sOut = 'G101' .. ' X' .. EmtLenToString( HomeX1, 3) .. ' Z' .. EmtLenToString( HomeZ1, 3) .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + end + sOut = 'G101' .. ' X' .. EmtLenToString( HomeX1, 3) .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + else + sOut = 'G101' .. EmtGetAxis( 'L3') .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + end + else + if EMT.HOME then + local HomeX2 = -EgtGetAxisHomePos( 'X2') + local HomeZ2 = -EgtGetAxisHomePos( 'Z2') + sOut = 'G101' .. ' U' .. EmtLenToString( HomeX2, 3) .. ' W' .. EmtLenToString( HomeZ2, 3) .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + elseif EMT.ZMAX then + local HomeX2 = -EgtGetAxisHomePos( 'X2') + local HomeZ2 = -EgtGetAxisHomePos( 'Z2') + local CurrR1 = ( EMT.R1p or EMT.R1pp) + local CurrR2 = ( EMT.R2p or EMT.R2pp) + if abs( CurrR1 - EMT.R1) > 30 then + sOut = 'G101' .. ' U' .. EmtLenToString( HomeX2, 3) .. ' W' .. EmtLenToString( HomeZ2, 3) .. + ' C'..EgtNumToString( CurrR2, 3) .. ' B'..EgtNumToString( CurrR1 + 90, 3) .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + sOut = 'G101' .. ' U' .. EmtLenToString( HomeX2, 3) .. ' W' .. EmtLenToString( HomeZ2, 3) .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + end + sOut = 'G101' .. ' U' .. EmtLenToString( HomeX2, 3) .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + else + sOut = 'G101' .. EmtGetAxis( 'L3') .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + end + end + if EMT.LOAD or bHeadFirst then + sOut = sOut..' L0=0' + EmtOutput( sOut) + sOut = 'G101 ET1001' + EmtOutput( sOut) + else + -- va ritardata anche l'emissione del comando + sLateG101 = sOut..' L0=0' + end + -- se prima lavorazione + if EMT.LOAD then + local nJump = 9 + sOut = 'G79 E80060<>0 N' .. EgtNumToString( nJump, 0) .. ' E10015=0' + EmtOutput( sOut) + --for i = 1, #EMT.AUXCMD do + -- EmtOutput( '( ' .. EMT.AUXCMD[i] .. ' )') + --end + EMT.AUXCMD = {} + if #EMT.AUXSTR > 2 then + EmtOutput( EMT.AUXSTR[1] .. ' ET1') + EmtOutput( EMT.AUXSTR[2] .. 'ET1') + EmtOutput( 'G111 ET1001') + EmtOutput( 'G79 N' .. EgtNumToString( nJump, 0)) + EmtOutput( 'E80060=1') + EmtOutput( 'G111 ET2001') + for i = 3, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i]) + end + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + else + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i]) + end + EmtOutput( 'G111 ET1001') + EmtOutput( 'G79 N' .. EgtNumToString( nJump, 0)) + EmtOutput( 'E80060=1') + EmtOutput( 'G111 ET2001') + end + EMT.AUXSTR = {} + sOut = string.gsub( string.gsub( EMT.MCHNAME..'/'..EMT.TOOL, '%(', '-'), '%)', '-') + EmtOutput( '( *** ' .. sOut .. ' *** )') + sOut = 'G101 ET2001' + EmtOutput( sOut) + local sY, sA + if EMT.YDELTA then + sY = EmtLenToString( EMT.L1 + EMT.YDELTA) + sA = '1' + else + sY = EmtLenToString( ParkY) + sA = '2' + end + local sV, sB + if EMT.VDELTA then + sV = EmtLenToString( EMT.L1 + EMT.VDELTA) + sB = '1' + else + sV = EmtLenToString( ParkV) + sB = '2' + end + sOut = 'G112 EA'..sA..' EB'..sB..''..EmtGetAxis('L1')..' EY'..sY..' EV'..sV..' EF'..GetFmaxClamp() + EmtOutput( sOut) + EMT.LOAD = false + -- altrimenti lavorazione successiva + else + -- eventuale G111 + EMT.AUXCMD = {} + for i = 1, #EMT.AUXSTR do + EmtOutput( EMT.AUXSTR[i]) + end + if #EMT.AUXSTR > 0 then + if not ( EMT.POSTROT or EMT.RELOAD) then + EmtOutput( 'G111 ET1004') + EmtOutput( 'G111 ET2004') + else + EmtOutput( 'G111 ET1001') + EmtOutput( 'G111 ET2001') + end + end + EMT.AUXSTR = {} + local sY, sA + if EMT.YDELTA then + sY = EmtLenToString( EMT.L1 + EMT.YDELTA - ( EMT.X_OFF or 0)) + sA = '1' + else + sY = EmtLenToString( EgtIf( EMT.YPOS, EMT.YPOS, ParkY)) + sA = '2' + end + local sV, sB + if EMT.VDELTA then + sV = EmtLenToString( EMT.L1 + EMT.VDELTA - ( EMT.X_OFF or 0)) + sB = '1' + else + sV = EmtLenToString( ParkV) + sB = '2' + end + if bHeadFirst then + sOut = 'G101 ET2001' + EmtOutput( sOut) + end + sOut = 'G112 EA'..sA..' EB'..sB..EmtGetAxis('L1')..' EY'..sY..' EV'..sV..' EF'..GetFmaxClamp() + EmtOutput( sOut) + if not bHeadFirst then + EmtOutput( sLateG101) + sOut = 'G101 ET1001' + EmtOutput( sOut) + sOut = 'G101 ET2001' + EmtOutput( sOut) + end + EMT.POSTROT = false + EMT.RELOAD = false + EMT.RELOAD2 = nil + end + -- se sono a Zmax, mi porto in posizione voluta + if EMT.ZMAX then + if nHSet == 1 then + local HomeX1 = -EgtGetAxisHomePos( 'X1') + if abs( HomeX1 - EMT.L3) > 1 then + sOut = 'G101' .. ' X' .. EmtLenToString( HomeX1, 3) .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + end + else + local HomeX2 = -EgtGetAxisHomePos( 'X2') + if abs( HomeX2 - EMT.L3) > 1 then + sOut = 'G101' .. ' U' .. EmtLenToString( HomeX2, 3) .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF + EmtOutput( sOut) + end + end + end + EMT.REFLOC = 0 + EMT.MCHFIRST = false + EMT.ZMAX = false + EMT.HOME = false + -- se alto in Z (non serve l'avvicinamento finale) + if EMT.FLAG == 2 then + -- aggiorno valori come precedenti + EMT.TLAST = EMT.L1b + EmtUpdatePrev() + return + -- altrimenti ripristino i valori originali degli assi + else + MyRestoreAxes() + end + end + -- se standard + if ( EMT.FLAG == 0 or EMT.FLAG == 1 or EMT.FLAG == 2) and EMT.FLAG2 ~= 1 then + -- se necessario, impostazione riferimento locale + if EMT.REFLOC == 0 then + -- emissione movimento Z + local sEL = ' EL' .. EmtLenToString( EgtIf( EMT.HEAD ~= 'H13', EMT.TLEN, ( EMT.TDIST or ChSawLen)), 3) + local sER = ' ER' .. EmtLenToString( EgtIf( EMT.HEAD ~= 'H13', EMT.TDIAM / 2, EMT.TLEN), 3) + local sET = ' ET0' if nHSet == 1 then sET = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sES = ' ES0' if nHSet == 1 then sES = ' ES'..EgtNumToString( EMT.S, 0) end + local sEU = ' EU0' if nHSet == 2 then sEU = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sEA = ' EA0' if nHSet == 2 then sEA = ' EA'..EgtNumToString( EMT.S, 0) end + local sEF = ' EF'..GetFmaxHead() + local OldL1 = EMT.L1 + local OldL2 = EMT.L2 + local OldL3 = EMT.L3 + EMT.L2 = -EMT.L2o + EMT.L3 = -EMT.L3o + EMT.L1p = nil + EMT.L2p = nil + EMT.L3p = nil + EMT.R1p = nil + EMT.R2p = nil + if nHSet == 1 then + sOut = 'G101' .. EmtGetAxis( 'L3') .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF.. ' L0=0' + else + sOut = 'G101' .. EmtGetAxis( 'L3') .. EmtGetAxis( 'L2') .. + EmtGetAxis( 'R2') .. MyGetAxis( 'R1') .. ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sEL .. sER .. sET .. sES .. sEU .. sEA .. sEF.. ' L0=0' + end + EMT.L2 = OldL2 + EMT.L3 = OldL3 + EmtOutput( sOut) + sOut = 'G101 ET1001' + EmtOutput( sOut) + sOut = 'G101 ET2001' + EmtOutput( sOut) + EMT.G101_OPEN = nil + -- se taglio di separazione prima di scarico a caduta, emissione stop tappeto scarico trucioli + if EMT.PREFALLCUT then + EmtOutput( 'M29') + EMT.PREFALLCUT = nil + end + -- calcolo per piano generico + CalcInterpPlane() + EMT.REFLOC = 1 + -- trasformo i punti nel piano + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + EMT.L1p = nil + EMT.L2p = nil + EMT.L3p = nil + EmtOutput( 'G102'..EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3')..EMT.IPLGLSTR..sET..sEU) + else + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + end + -- emissione movimento + local sOut = 'G0'..EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3') + if EMT.HEAD ~= 'H12' then sOut = sOut..EmtGetAxis('R2')..MyGetAxis('R1') end + EmtOutput( sOut) + -- se altrimenti risalita a Z max a fine lavorazione + elseif EMT.FLAG == 3 or EMT.FLAG2 == 1 then + EMT.REFLOC = nil + EMT.IPLGL = false + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + local sNextTool = GetNextTool( EMT.MCHID) + local bHome = ( sNextTool ~= EMT.TOOL and EMT.FLAG == 3) + EmitZmax( bHome) + EMT.ZMAX = true + EMT.HOME = bHome + -- se altrimenti movimento in Home + elseif EMT.FLAG == 4 then + -- non previsto + -- se altrimenti rotazione a Z max + elseif EMT.FLAG == 5 then + -- viene gestito all'inizio della lavorazione successiva + -- errore perchè caso non gestito su NUM + EmtSetLastError( 1212, "Rotate at Zmax not managed") + -- altrimenti errore + else + EmtSetLastError( 1212, "Unknown Rapid flag") + end + -- aggiorno valori come precedenti + EMT.TLAST = EMT.L1b + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +function OnLinear() + MyBackupAxes() + EMT.TLAST = EMT.L1 + -- se necessario, impostazione riferimento locale + if EMT.REFLOC == 0 then + -- eventuale terminazione movimenti in rapido della testa + if EMT.G101_OPEN then + EmtOutput( sOut) + sOut = 'G101 ET1001' + EmtOutput( sOut) + sOut = 'G101 ET2001' + EmtOutput( sOut) + end + -- se taglio di separazione prima di scarico a caduta, emissione stop tappeto scarico trucioli + if EMT.PREFALLCUT then + EmtOutput( 'M29') + EMT.PREFALLCUT = nil + end + -- calcolo per piano generico + CalcInterpPlane() + EMT.REFLOC = 1 + -- salvo posizione attuale + local OldL1 = EMT.L1 + local OldL2 = EMT.L2 + local OldL3 = EMT.L3 + -- imposto posizione precedente (non contiene l'offset in X per sovramateriale di testa EMT.X_OFF) + EMT.L1 = EMT.L1o + EMT.L2 = EMT.L2o + EMT.L3 = EMT.L3o + -- trasformo i punti nel piano + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + EMT.L1p = nil + EMT.L2p = nil + EMT.L3p = nil + local sET = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) + local sEU = ' EU0' + EmtOutput( 'G102'..EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3')..EMT.IPLGLSTR..sET..sEU) + -- emissione movimento + local sOut = 'G0'..EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3') + if EMT.HEAD ~= 'H12' then sOut = sOut..EmtGetAxis('R2')..MyGetAxis('R1') end + EmtOutput( sOut) + -- ripristino posizione attuale + EMT.L1 = OldL1 + EMT.L2 = OldL2 + EMT.L3 = OldL3 + end + + -- aggiustamento valori + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + + -- valori degli assi + local sAxes = EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3') + if EMT.HEAD ~= 'H12' then sAxes = sAxes..EmtGetAxis('R2')..MyGetAxis('R1') end + -- se nulla da emettere, esco + if string.len( sAxes) == 0 then + return + end + -- aggiungo feed + local sFeed = EmtGetFeed() + -- eventuale aggiunta arresto preciso in fondo al foro + local sExact = EgtIf( EMT.FLAG == 101, ' G9', '') + -- emetto linea + EmtOutput( "G1"..sExact..sAxes..sFeed) + + -- aggiorno valori come precedenti + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +function OnArc() + MyBackupAxes() + EMT.TLAST = EMT.L1 + -- non modale su archi + EmtResetPrevLinear() + -- aggiustamento valori + MyAdjustLinearAxes() + EmtAdjustRotaryAxes() + + -- valori degli assi + local sAxes = EmtGetAxis('L1')..EmtGetAxis('L2')..EmtGetAxis('L3') + if EMT.HEAD ~= 'H12' then sAxes = sAxes..EmtGetAxis('R2')..MyGetAxis('R1') end + -- se nulla da emettere, esco + if string.len( sAxes) == 0 then + return + end + -- valori delle coordinate del centro + EmtAdjustCenterAxes() + -- coordinate centro (per ora solo archi nel piano XY) + --local sCen = ' ' .. EMT.C1t .. EmtLenToString(EMT.C1,3) .. + -- ' ' .. EMT.C2t .. EmtLenToString(EMT.C2,3) + -- raggio + local sRad = ' ' .. EMT.RRt .. EmtLenToString(EMT.RR,3) + -- aggiungo feed + local sFeed = EmtGetFeed() + -- tipo arco + local sArc = 'G' .. EgtNumToString(EMT.MOVE,0) + -- emetto arco + EmtOutput( sArc..sAxes..sRad..sFeed) + + -- aggiorno valori come precedenti + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +function CalcCharStatus( sCmd, bSkipPress) + -- aperto + if sCmd == '0' then + return '1' + -- chiuso + elseif sCmd == '1' then + return '2' + -- chiuso con pressore attivato + elseif sCmd == '2' then + return EgtIf( bSkipPress, '2', '0') + end +end + +--------------------------------------------------------------------- +function PrepareLoad( sCmd, bStart) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- se inizio + if EMT.AUXIND == 1 then + -- imposto stato pinze + EMT.SA = ' EA111' + EMT.SB = ' EB111' + EMT.SC = ' EC141' + EMT.SD = ' ED141' + EMT.SE = ' EE0' + end + -- se dichiarazione inizio riposizionamento carrelli + if Cmd[2] == 'CARR_MOVE' then + if bStart then + EMT.RELOAD = false + else + EMT.RELOAD2 = true + end + for i = 1, #EMT.AUXSTR do + EMT.AUXSTR[i] = string.gsub( EMT.AUXSTR[i], 'ET1', '') + end + end + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] ~= 'Z' then + local sOut = 'G111 '..Cmd[2]..Cmd[3]..EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + if Cmd[2] == 'Y' then EMT.YPOS = tonumber( Cmd[3]) end + end + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] == 'Y' then + local sYTaking = ' Y'..EmtLenToString( Cmd[3] + TurnerOffs) + local sBeamRot = '0' + if StartRotation and EMT.LB >= AutoRotMinLen then + local nRot = GetPhaseRot( EMT.PHASE) + local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or EgtGetCurrMachGroup() or GDB_ID.NULL + local nLoad90 = EgtGetInfo( BtlInfoId, 'LOAD90', 'i') or 0 + sBeamRot = tostring( nLoad90) + end + local sOut = 'G111'..sYTaking..' EA75'..EMT.SB..' EE0 EF'..GetFmaxClamp()..' ET1 E80057='..sBeamRot..' E80058=0' + table.insert( EMT.AUXSTR, sOut) + end + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + (EgtIf( Cmd[6] ~= 'T', ' '..Cmd[6]..Cmd[7], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + local bPrevEA76 = ( #EMT.AUXSTR > 0 and EMT.AUXSTR[#EMT.AUXSTR]:find( 'EA76', 1, true)) + if #EMT.AUXSTR > 0 and not bPrevEA76 then + local sVal = ' EB11' .. CalcCharStatus( Cmd[2]) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SB, sVal) + end + if not bPrevEA76 then + EMT.SA = ' EA11' .. CalcCharStatus( Cmd[2]) + end + EMT.SB = ' EB11' .. CalcCharStatus( Cmd[2]) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE1', ' EE2') + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' ED14' .. CalcCharStatus( Cmd[2]) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SD, sVal) + end + EMT.SC = ' EC14' .. CalcCharStatus( Cmd[2]) + EMT.SD = ' ED14' .. CalcCharStatus( Cmd[2]) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE2', ' EE1') + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + if not FindG111EA76( EMT.AUXSTR) then + local sYLoad = ' Y'..EmtLenToString( LoadT) + local sOut = 'G111'..sYLoad..' EA76'..EMT.SB..' EE0 EF'..GetFmaxClamp()..' ET1' + table.insert( EMT.AUXSTR, sOut) + end + end +end + +--------------------------------------------------------------------- +function PrepareMoveChar( sCmd) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- se inizio + if EMT.AUXIND == 1 then + -- imposto stato pinze + EMT.SA = EgtIf( EMT.YDELTA, ' EA112', ' EA111') + EMT.SB = EgtIf( EMT.YDELTA, ' EB112', ' EB111') + EMT.SC = EgtIf( EMT.VDELTA, ' EC142', ' EC141') + EMT.SD = EgtIf( EMT.VDELTA, ' ED142', ' ED141') + EMT.SE = EgtIf( EMT.YDELTA, ' EE1', ' EE2') + end + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] ~= 'Z' then + local sOut = 'G111 '..Cmd[2]..Cmd[3]..EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + if Cmd[2] == 'Y' then EMT.YPOS = tonumber( Cmd[3]) end + end + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..'EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + (EgtIf( Cmd[6] ~= 'T', ' '..Cmd[6]..Cmd[7], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' EB11' .. CalcCharStatus( Cmd[2]) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SB, sVal) + end + EMT.SA = ' EA11' .. CalcCharStatus( Cmd[2]) + EMT.SB = ' EB11' .. CalcCharStatus( Cmd[2]) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE1', ' EE2') + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' ED14' .. CalcCharStatus( Cmd[2]) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SD, sVal) + end + EMT.SC = ' EC14' .. CalcCharStatus( Cmd[2]) + EMT.SD = ' ED14' .. CalcCharStatus( Cmd[2]) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE2', ' EE1') + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + end +end + +--------------------------------------------------------------------- +function PrepareResidue( sCmd) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- se non è scarico + if Cmd[2] ~= 'Unloading' then + -- se inizio o subito dopo, imposto stato iniziale pinze + if EMT.AUXIND <= 2 then + EMT.SA = EgtIf( EMT.YDELTA, ' EA112', ' EA111') + EMT.SB = EgtIf( EMT.YDELTA, ' EB112', ' EB111') + EMT.SC = EgtIf( EMT.VDELTA, ' EC142', ' EC141') + EMT.SD = EgtIf( EMT.VDELTA, ' ED142', ' ED141') + EMT.SE = EgtIf( EMT.YDELTA, ' EE1', ' EE2') + end + else + EMT.UNL = true + end + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] ~= 'Z' then + local sOut + if not EMT.UNL then + sOut = 'G111 '..Cmd[2]..Cmd[3]..EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + else + sOut = 'G111 '..Cmd[2]..Cmd[3]..' EC141 ED83 EE0 EF'..GetFmaxClamp() + end + table.insert( EMT.AUXSTR, sOut) + end + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + (EgtIf( Cmd[6] ~= 'T', ' '..Cmd[6]..Cmd[7], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' EB11' .. CalcCharStatus( Cmd[2], true) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SB, sVal) + end + EMT.SA = ' EA11' .. CalcCharStatus( Cmd[2], true) + EMT.SB = ' EB11' .. CalcCharStatus( Cmd[2], true) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE1', ' EE2') + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' ED14' .. CalcCharStatus( Cmd[2], true) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SD, sVal) + end + EMT.SC = ' EC14' .. CalcCharStatus( Cmd[2], true) + EMT.SD = ' ED14' .. CalcCharStatus( Cmd[2], true) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE2', ' EE1') + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + end +end + +--------------------------------------------------------------------- +function PrepareSplit( sCmd) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- non interessa + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] == 'Y' then + local sOut = 'G111 '..Cmd[2]..Cmd[3]..' EA110 EB110 EC142 ED142 EE2 EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + EMT.YPOS = tonumber( Cmd[3]) + end + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + end +end + +--------------------------------------------------------------------- +function PrepareUnload( sCmd) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- non interessa + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] == 'V' then + -- se non è ultima fase c'è una barra sulla pinza Y (1) + local sEE = EgtIf( EMT.PHASE == EgtGetPhaseCount(), '0', '1') + local sOut = 'G111 '..Cmd[2]..Cmd[3]..' EC141 ED83 EE'..sEE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + end + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[4] == 'V' then + -- se non è ultima fase c'è una barra sulla pinza Y (1) + local sEAB = EgtIf( EMT.PHASE == EgtGetPhaseCount(), '111', '112') + local sOut = 'G111 '..Cmd[4]..Cmd[5]..' EA'..sEAB..' EB'..sEAB..' EC142 ED141 EE2 EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + EMT.U_STD = true + end + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '21' then + -- non interessa + end +end + +--------------------------------------------------------------------- +function PreparePreRotation( sCmd) + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- se inizio o subito dopo, imposto stato iniziale pinze + if EMT.AUXIND <= 2 then + EMT.SA = EgtIf( EMT.YDELTA, ' EA112', ' EA111') + EMT.SB = EgtIf( EMT.YDELTA, ' EB112', ' EB111') + EMT.SC = EgtIf( EMT.VDELTA, ' EC142', ' EC141') + EMT.SD = EgtIf( EMT.VDELTA, ' ED142', ' ED141') + EMT.SE = EgtIf( EMT.YDELTA, ' EE1', ' EE2') + end + -- se è pre-rotazione + if Cmd[2] == 'Pre-Rotation' then + EMT.PREROT = true + elseif Cmd[2] == 'SplitRot' then + EMT.SPLITROT = true + end + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] ~= 'Z' then + local sOut + if not EMT.PREROT then + sOut = 'G111 '..Cmd[2]..Cmd[3]..EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + else + sOut = 'G111 '..Cmd[2]..Cmd[3]..' EA86 EB87 EC141 EE0 EF'..GetFmaxClamp() + end + table.insert( EMT.AUXSTR, sOut) + end + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + local sOut = 'G111'..(EgtIf( Cmd[2] ~= 'T', ' '..Cmd[2]..Cmd[3], '')).. + (EgtIf( Cmd[4] ~= 'T', ' '..Cmd[4]..Cmd[5], '')).. + (EgtIf( Cmd[6] ~= 'T', ' '..Cmd[6]..Cmd[7], '')).. + EMT.SA..EMT.SB..EMT.SC..EMT.SD..EMT.SE..' EF'..GetFmaxClamp() + table.insert( EMT.AUXSTR, sOut) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' EB11' .. CalcCharStatus( Cmd[2], true) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SB, sVal) + end + if EMT.SPLITROT then + EMT.SA = EgtIf( Cmd[2] ~= '0', ' EA11' .. CalcCharStatus( Cmd[2], true), ' EA86') + EMT.SB = EgtIf( Cmd[2] ~= '0', ' EB11' .. CalcCharStatus( Cmd[2], true), ' EB87') + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE1', ' EE2') + else + EMT.SA = ' EA11' .. CalcCharStatus( Cmd[2], true) + EMT.SB = ' EB11' .. CalcCharStatus( Cmd[2], true) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE1', ' EE2') + end + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + if #EMT.AUXSTR > 0 then + local sVal = ' ED14' .. CalcCharStatus( Cmd[2], true) + local sOut = EMT.AUXSTR[#EMT.AUXSTR] + EMT.AUXSTR[#EMT.AUXSTR] = sOut:gsub( EMT.SD, sVal) + end + EMT.SC = ' EC14' .. CalcCharStatus( Cmd[2], true) + EMT.SD = ' ED14' .. CalcCharStatus( Cmd[2], true) + EMT.SE = EgtIf( Cmd[2] ~= '0', ' EE2', ' EE1') + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + end +end + +--------------------------------------------------------------------- +function PreparePostRotation( sCmd) + -- è sostanzialmente un carico + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + -- se inizio + if EMT.AUXIND == 1 then + -- imposto stato pinze + EMT.SB = ' EB112' + end + -- se dichiarazione inizio riposizionamento carrelli + if Cmd[2] == 'CARR_MOVE' then + EMT.POSTROT = false + for i = 1, #EMT.AUXSTR do + EMT.AUXSTR[i] = string.gsub( EMT.AUXSTR[i], 'ET1', '') + end + end + elseif Cmd[1] == '1' then + local sMsg = Cmd[2] .. Cmd[3] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '2' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] + table.insert( EMT.AUXCMD, sMsg) + if Cmd[2] == 'Y' then + -- tolgo eventuale sovramateriale presente sul pezzo in posizione iniziale (la misura laser è ora col finito) + local sYTaking = ' Y'..EmtLenToString( Cmd[3] - EMT.HOVM) + local sOut = 'G111'..sYTaking..' EA75 EB112 EE0 EF'..GetFmaxClamp()..' ET1 E80058=0' + table.insert( EMT.AUXSTR, sOut) + end + elseif Cmd[1] == '3' then + local sMsg = Cmd[2] .. Cmd[3] ..' '.. Cmd[4] .. Cmd[5] ..' '.. Cmd[6] .. Cmd[7] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '11' then + local sMsg = 'PY' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + EMT.SB = ' EB11' .. CalcCharStatus( Cmd[2]) + elseif Cmd[1] == '12' then + local sMsg = 'PV' .. ' ' .. Cmd[2] + table.insert( EMT.AUXCMD, sMsg) + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0 and nVDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + local sYLoad = ' Y'..EmtLenToString( LoadT) + local sOut = 'G111'..sYLoad..' EA76'..EMT.SB..' EE0 EF'..GetFmaxClamp()..' ET1' + table.insert( EMT.AUXSTR, sOut) + end +end + +--------------------------------------------------------------------- +function MyBackupAxes() + EMT.L1b = EMT.L1 + EMT.L2b = EMT.L2 + EMT.L3b = EMT.L3 + EMT.R1b = EMT.R1 + EMT.R2b = EMT.R2 + EMT.R3b = EMT.R3 + EMT.R4b = EMT.R4 + EMT.RRb = EMT.RR + EMT.C1b = EMT.C1 + EMT.C2b = EMT.C2 + EMT.C3b = EMT.C3 +end + +--------------------------------------------------------------------- +function MyRestoreAxes() + EMT.L1 = EMT.L1b + EMT.L2 = EMT.L2b + EMT.L3 = EMT.L3b + EMT.R1 = EMT.R1b + EMT.R2 = EMT.R2b + EMT.R3 = EMT.R3b + EMT.R4 = EMT.R4b + EMT.RR = EMT.RRb + EMT.C1 = EMT.C1b + EMT.C2 = EMT.C2b + EMT.C3 = EMT.C3b +end + +--------------------------------------------------------------------- +function MyAdjustLinearAxes() + local MyL1o = EMT.L1 + local MyL2o = EMT.L2 + local MyL3o = EMT.L3 + + local nHSet = GetHeadSet( EMT.HEAD) + + if EMT.REFLOC then + local ptTip = EgtGetCalcTipFromPositions( 0, EMT.L2, EMT.L3, EMT.R1, EMT.R2, EMT.R3 or 0.0, false) + local vtOffs = V_NULL() + -- per la sega a catena la correzione NUM è come per gli utensili : la lunghezza della catena è vista come raggio e non è recuperata + if EMT.HEAD == 'H13' then + vtOffs = Vector3d( EMT.TDIR) * EMT.TLEN + end + EMT.L1 = ptTip:getX() + vtOffs:getX() + EMT.L1 + EMT.L2 = ptTip:getY() + vtOffs:getY() - DeltaTabY + EMT.L3 = ptTip:getZ() + vtOffs:getZ() - DeltaTabZ + end + + if EMT.X_OFF then EMT.L1 = EMT.L1 + EMT.X_OFF end + + EmtAdjustLinearAxes() + + EMT.L1o = MyL1o + EMT.L2o = MyL2o + EMT.L3o = MyL3o + + if not EMT.REFLOC then + EMT.L2 = - EMT.L2 + EMT.L3 = - EMT.L3 + EMT.L1t = 'Y' + if nHSet == 1 then + EMT.L2t = 'Z' + EMT.L3t = 'X' + EMT.R2t = 'A' + else + EMT.L2t = 'W' + EMT.L3t = 'U' + EMT.R2t = 'C' + end + else + EMT.L1t = 'X' + EMT.L2t = 'Y' + EMT.L3t = 'Z' + EMT.R2t = 'A' + end +end + +--------------------------------------------------------------------- +function MyGetAxis( Ax) + if Ax == 'R1' then + if EMT.R1p then EMT.R1p = EMT.R1p + 90 end + EMT.R1 = EMT.R1 + 90 + local sV, bR = EmtGetAxis( 'R1') + if EMT.R1p then EMT.R1p = EMT.R1p - 90 end + EMT.R1 = EMT.R1 - 90 + return sV, bR + else + return EmtGetAxis( Ax) + end +end + +--------------------------------------------------------------------- +function MyOutputNoNum( sOut) + local bNum = EMT.NUM + EMT.NUM = false + EmtOutput( sOut) + EMT.NUM = bNum +end + +--------------------------------------------------------------------- +function CalcInterpPlane() + -- origine del piano + local xS = EMT.START[1] + LoadT + if EMT.X_OFF then xS = xS + EMT.X_OFF end + local ptS = Point3d( xS, 0, 0) + -- calcolo per piano generico + local vtE + if EMT.HEAD ~= 'H13' then + vtE = Vector3d( EMT.EXTR) + else + vtE = EgtGetCalcAuxDirFromAngles( EMT.R1, EMT.R2, EMT.R3) + end + EMT.IPLGLFR = Frame3d( ptS, vtE) + --EmtOutput( 'IPLGLFR='..tostring(EMT.IPLGLFR)) + local _, dAngV, dAngO = SphericalFromVector( vtE) + local dAngO2 = EmtGetAngO2( EMT.IPLGLFR:getVersZ(), EMT.IPLGLFR:getVersX(), dAngV, dAngO) + dAngO = dAngO + 90 + while dAngO >= 360 do + dAngO = dAngO - 360 + end + EMT.IPLGLSTR = ' EX0 EY'..EmtLenToString( xS)..' EZ0'.. + ' EA0'..' EB'..EgtNumToString(dAngV)..' EC'..EgtNumToString(dAngO)..' ED'..EgtNumToString(dAngO2) + EMT.IPLGL = true +end + +--------------------------------------------------------------------- +function VerifyEmitRotation() + -- recupero le rotazioni delle fasi corrente e precedente + local nRot = GetPhaseRot( EMT.PHASE) + local nPrevRot = GetPhaseRot( EMT.PHASE - 1) + -- se sono uguali non devo fare alcunchè + if nRot == nPrevRot then + return false + end + -- determino quanto ruotare + local nDeltaRot = nRot - nPrevRot + -- se rotazione automatica richiesta e possibile + if AutomaticRotation and EMT.LB >= AutoRotMinLen then + local sOut = 'M180 L0=' .. tostring( nDeltaRot) + EmtOutput( sOut) + else + local sOut + if nDeltaRot == 1 then + sOut = 'M151' + elseif nDeltaRot == 2 then + sOut = 'M152' + elseif nDeltaRot == 3 then + sOut = 'M153' + end + EmtOutput( sOut) + EmtOutput( 'M86') + EmtOutput( 'G4F.5') + end + return true +end + +--------------------------------------------------------------------- +function EmitZmax( bHome) + -- gruppo della testa + local nHSet = GetHeadSet( EMT.HEAD) + -- quote parcheggio + local HomeX1 = -EgtGetAxisHomePos( 'X1') + local HomeZ1 = -EgtGetAxisHomePos( 'Z1') + local HomeX2 = -EgtGetAxisHomePos( 'X2') + local HomeZ2 = -EgtGetAxisHomePos( 'Z2') + -- movimenti + local sET = ' ET0' if nHSet == 1 then sET = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sES = ' ES0' if nHSet == 1 then sES = ' ES'..EgtNumToString( EMT.S, 0) end + local sEU = ' EU0' if nHSet == 2 then sEU = GetET( EMT.HEAD, EMT.TCPOS, EMT.R3) end + local sEA = ' EA0' if nHSet == 2 then sEA = ' EA'..EgtNumToString( EMT.S, 0) end + local sEF = ' EF' .. GetFmaxHead() + if nHSet == 1 then + local sOut = 'G101 X' .. EmtLenToString( HomeX1, 3) .. ' Z' .. EmtLenToString( -EMT.L2op, 3) .. + ' A' .. EgtNumToString( EMT.R2p or EMT.R2pp, 3) .. ' B' .. EgtNumToString( ( EMT.R1p or EMT.R1pp) + 90, 3) .. + ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sET .. sES .. sEU .. sEA .. sEF .. ' L0=0' + EmtOutput( sOut) + if bHome then + sOut = 'G101 X' .. EmtLenToString( HomeX1, 3) .. ' Z' .. EmtLenToString( HomeZ1, 3) .. + ' A' .. EgtNumToString( EMT.R2p or EMT.R2pp, 3) .. ' B' .. EgtNumToString( ( EMT.R1p or EMT.R1pp) + 90, 3) .. + ' U0 W0' .. ' C' .. EgtNumToString( ParkA2, 3) .. sET .. sES .. sEU .. sEA .. sEF .. ' L0=0' + EmtOutput( sOut) + end + else + local sOut = 'G101 U' .. EmtLenToString( HomeX2, 3) .. ' W' .. EmtLenToString( -EMT.L2op, 3) .. + ' C' .. EgtNumToString( EMT.R2p or EMT.R2pp, 3) .. ' B' .. EgtNumToString( ( EMT.R1p or EMT.R1pp) + 90, 3) .. + ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sET .. sES .. sEU .. sEA .. sEF .. ' L0=0' + EmtOutput( sOut) + if bHome then + sOut = 'G101 U' .. EmtLenToString( HomeX2, 3) .. ' W' .. EmtLenToString( HomeZ2, 3) .. + ' C' .. EgtNumToString( EMT.R2p or EMT.R2pp, 3) .. ' B' .. EgtNumToString( ( EMT.R1p or EMT.R1pp) + 90, 3) .. + ' X1 Z0' .. ' A' .. EgtNumToString( ParkA1, 3) .. sET .. sES .. sEU .. sEA .. sEF .. ' L0=0' + EmtOutput( sOut) + end + end + sOut = 'G101 ET1001' + EmtOutput( sOut) + sOut = 'G101 ET2001' + EmtOutput( sOut) +end + +--------------------------------------------------------------------- +function GetET( sHead, sTcPos, dAxR3) + if sHead == 'H11' then + return ' E'..sTcPos + elseif sHead == 'H12' then + return ' ET42' + elseif sHead == 'H13' then + if dAxR3 and abs( dAxR3 - 0) < 0.1 then + return ' ET101' + elseif dAxR3 and abs( dAxR3 + 90) < 0.1 then + return ' ET102' + else + EmtSetLastError( 1210, 'Chain saw orientation not allowed') + end + elseif sHead == 'H21' then + return ' E'..sTcPos:gsub( 'T', 'U') + elseif sHead == 'H22' then + return ' EU43' + else + EmtSetLastError( 1211, "Unknown Head") + end +end + +--------------------------------------------------------------------- +function GetFmaxHead() + return EmtLenToString( EMT.FMAXHEAD, 0) +end + +--------------------------------------------------------------------- +function GetFmaxClamp() + return EmtLenToString( EMT.FMAXPINZE, 0) +end + +--------------------------------------------------------------------- +function FindG111EA76( vStr) + for i = 1, #vStr do + if vStr[i]:find( 'G111', 1, true) and vStr[i]:find( 'EA76', 1, true) then + return true + end + end + return false +end + +--------------------------------------------------------------------- +-- *** END GENERATION *** +--------------------------------------------------------------------- diff --git a/Essetre-TURN.ini b/Essetre-TURN.ini new file mode 100644 index 0000000..530adef --- /dev/null +++ b/Essetre-TURN.ini @@ -0,0 +1,151 @@ +; Commento per evitare BOM con UTF-8 +[General] +Material=Beam +NCType=4 ; 1=Tpa, 2=Num Flexium, 3=Num Axium APServer, 4=Num Axium PCToolkit +Flow=2 +ConnectionString=XIP01,0,63,0,0,0 + +[Axes] +; 1 = Type, Id, Name +; Type => l=linear;r=rotational +1=l,0,X +2=l,1,Y +3=l,2,Z +4=l,3,U +5=l,4,V +6=l,5,W +7=r,6,A +8=r,7,B +9=r,8,C + +[Channels] +1=0,Channel 1 + +[MainVariables] +; 1 = Name, Variable Path, ReadType, Type +; ReadType => o=one time;c=continuous +; Type => plc;cn +1=P_Prod,E81295,c,cn +2=P_Machgroup,E81296,c,cn +3=P_Part,E81297,c,cn +4=P_State,E81298,c,cn +5=Reset_State,E80048,c,cn +6=ISO_Num,E80045,c,cn +7=ISO_Sent,E80046,c,cn +8=Running,E80047,c,cn +9=Start_State,%R3.2,c,plc +10=Stop_State,%R3.1,c,plc +11=MachIndex,E80000,c,cn +12=PLC_Messages1,%V800.L,c,plc +13=PLC_Messages2,%V804.L,c,plc +14=PLC_Messages3,%V808.L,c,plc +15=PLC_Messages4,%V80C.L,c,plc +16=PLC_Messages5,%V810.L,c,plc +17=PLC_Messages6,%V814.L,c,plc + +[MDI] +; 1 = Command, Description +1=M6T1,1 +2=M6T2,2 +3=M6T3,3 +4=M6T4,4 +5=M6T5,5 +6=M6T6,6 +7=M6T7,7 +8=M6T8,8 +9=M6T9,9 +10=M6T10,10 +11=M6T11,11 +12=M6T12,12 +13=M6T13,13 +14=M6T14,14 +15=M6T15,15 +16=M6T16,16 +17=M6T17,17 +18=M6T18,18 +19=M6T50,19 +20=M6T101,20 +21=M90,21 +22=M198T1,22 +23=M199T1,23 +24=M198T2,24 +25=M199T2,25 +26=M196,26 +27=M197,27 +28=M111,28 +29=M112,29 +30=M113,30 +31=M114,31 +32=M151,32 +33=M152,33 +34=M153,34 +35=M154,35 +36=M155,36 +37=E80001=0,37 + +[Languages] +Enable=1 +Language1=Italiano,Ita.txt +Language2=English,Eng.txt + +[Tools] +Drillbit=1 +Sawblade=1 +Mill=1 +Mortise=1 +Chisel=0 +DrillMaker=MakeWoodDrill.lua +SawbladeMaker=MakeSawblade.lua +MillMaker=MakeWoodCylMill.lua +MortiseMaker=MakeMortise.lua +ChiselMaker=MakeChisel.lua +Active=1 + +[ToolHolder] +H11.1=Standard.nge +H11.1:MILL_NOTIP=MillNoTip.nge +H12.1=Saw.nge +H13.1=ChainSaw.nge +H21.1=Standard.nge +H21.1:MILL_NOTIP=MillNoTip.nge +H22.1=Saw.nge + +[Machinings] +Drilling=1 +Sawing=1 +Milling=1 +Pocketing=1 +Mortising=1 +Chiseling=0 +SawRoughing=0 +SawFinishing=0 + +[Machining] +InitScript=InitMach.lua +ExitScript=ExitMach.lua + +[Disposition] +;InitScript=InitDisp.lua + +[Heads] +; 5 axis head +H11=6608 +; 5 axis saw +H12=6615 +; Chainsaw +H13=6616 +; 2nd 5 axis head +H21=6620 +; 2nd 5 axis saw +H22=6623 + +[SetUp] +Default=Standard + +[Estimations] +Enable=1 +WinPlace=0,458,111,669,906 + +[VMill] +Enable=1 +Save=0 diff --git a/Essetre-TURN.mlde b/Essetre-TURN.mlde new file mode 100644 index 0000000..caa9f19 --- /dev/null +++ b/Essetre-TURN.mlde @@ -0,0 +1,734 @@ +-- Descrizione macchina Essetre-TURN by EgalTech s.r.l. 2023/02/16 +-- 2022/04/04 DS ver 2.4d1 Solo con controllo NUM. +-- 2022/06/07 DS ver 2.4f1 +-- 2022/06/10 DS ver 2.4f3 Modifica G115. Limitato massimo corsa X a -0.5. +-- 2022/06/16 DS ver 2.4f4 Modifica per approcci e retrazioni con movimenti Z e X opportunamente ordinati. +-- 2022/07/25 DS ver 2.4g1 Modifica per conservare Zzeromacch precedente in generazione. +-- 2022/07/29 DS ver 2.4g2 Aggiunta gestione punte lunghe con limiti su corsa asse A1. +-- 2022/08/25 DS ver 2.4h1 Modificati limiti per tagli a cubetti e attacchi/uscite lame. +-- 2022/08/29 DS ver 2.4h2 Aggiunta seconda testa (solo per verifica di collisione con la prima e con ParkA2=90). +-- 2022/09/21 DS ver 2.4i1 Migliorata corrispondenza simulatore-generazione CN. +-- 2022/09/26 DS ver 2.4i3 Modifica radicale della gestione delle teste tramite offset asse B. +-- 2022/09/28 DS ver 2.4i11 Aggiunta gestione seconda testa. +-- 2022/09/30 DS ver 2.4i14 Modifiche varie. Migliorata gestione collisioni. +-- 2022/10/04 DS ver 2.4j1 Sistemazione gestione collisioni testa 2. +-- 2022/10/20 DS ver 2.4j2 Modifiche per lavorazione tipo BH. +-- 2022/11/28 DS ver 2.4k1 Correzione simulazione per controllo collisioni. +-- 2023/01/20 DS ver 2.5a1 Migliorato avvio simulazione. +-- 2023/01/24 MS ver 2.5a2 Aggiunto coefficiente moltiplicativo speed fresone come lama. +-- 2023/02/16 DS ver 2.5b1 In tavola ora TiltingLike riceve valore 1 (asse tilting parallelo a X). + +require( 'EmtGenerator') +EgtEnableDebug( false) + +PP_VER = '2.5b1' + +-- Parametri macchina +NumericalControl = 'NUM' -- solo NUM +MinB = -90 +MaxB = 270 +MinX1 = -1180 +MaxX1 = 0 +ParkX1 = -1.0 +MinZ1 = 0 +MaxZ1 = 1810 +ParkZ1 = 0 +MinA1 = -180 +MaxA1 = 360 +ParkA1 = 0 +ParkH11_A1 = 0 +MillOffs = 177.0 +SawOffs = -242.55 +SawBOffs = 0 +SawAOffs = 0 +ChSawLen = 91.0 +MinX2 = -1180 +MaxX2 = 0 +ParkX2 = -1.0 +MinZ2 = 0 +MaxZ2 = 1810 +ParkZ2 = 0 +MinA2 = -180 +MaxA2 = 360 +ParkA2 = 0 +ParkH21_A2 = 0 +Mill2Offs = -177.0 +Saw2Offs = 242.55 +Saw2BOffs = 0 +Saw2AOffs = 0 +MinY = 80.0 +MaxY = 5500.0 +ParkY = 700.0 +MinV = -5500.0 +MaxV = -80.0 +ParkV = -700.0 +LoadT = 1867.0 +TurnerOffs = 100 +UnloadT = -1700 +MaxOpen = 655 +RallaOffsY = 900.0 - MillOffs +RallaOffsZ = -709.0 +Ralla2OffsY = -903.50 - Mill2Offs +Ralla2OffsZ = 710.75 +DeltaTabY = 1050.0 +DeltaTabZ = -909.0 +Delta2TabY = -386.0 +Delta2TabZ = 509.0 +DimTabX = 34000 +DimTabY = 800 +Head2X = 0 +Head2Y = DeltaTabY - Delta2TabY +Head2Z = DeltaTabZ - Delta2TabZ +LenToPress = 900 +DefTc1Pos = 'T2' +DefTc2Pos = 'T14' +MaxUnloadLen = 0 +LONG_TOOL_MINLEN = 241 +BIG_TOOL_DIAM = 300 +CoeffVM = 0.5 + +-- Aggiornamento con dati da BeamData.lua +local sBeamData = EgtGetSourceDir().."\\Beam\\BeamData.lua" +if EgtExistsFile( sBeamData) then + local BD = dofile( sBeamData) + if BD then + BeamHeightForFixRot = BD.MAX_HEIGHT_ROT_B_ABOVE or BeamHeightForFixRot + end +end + +-- Aggiornamento con dati da TechnoEssetre7 +local sTs3Data = EgtGetStringFromIni( 'Beam', 'DATA_DIR', "C:\\TechnoEssetre7\\EgtData", EgtGetIniFile()).."\\Essetre-TURN.data" +local sData = EgtGetSourceDir().."\\Beam\\Ts3Data.lua" +if EgtExistsFile( sTs3Data) then + EgtCopyFile( sTs3Data, sData) + local sTs3DataOld = sTs3Data..'.old' + EgtEraseFile( sTs3DataOld) + EgtRenameFile( sTs3Data, sTs3DataOld) +end +if EgtExistsFile( sData) then + local Machine = dofile( sData) + if Machine then + if Machine.Offsets then + --NumericalControl = EgtIf( Machine.Offsets.TIPO_CN == 0, 'NUM', 'TPA') + if Machine.Offsets.B_NEG then MinB = Machine.Offsets.B_NEG end + if Machine.Offsets.B_POS then MaxB = Machine.Offsets.B_POS end + if Machine.Offsets.X1_POS then MinX1 = -Machine.Offsets.X1_POS end + if Machine.Offsets.X1_NEG then MaxX1 = min( MaxX1, -Machine.Offsets.X1_NEG) end + if Machine.Offsets.PARK_X1 then ParkX1 = min( ParkX1, -Machine.Offsets.PARK_X1) end + if Machine.Offsets.Z1_NEG then MinZ1 = -Machine.Offsets.Z1_POS end + if Machine.Offsets.Z1_POS then MaxZ1 = -Machine.Offsets.Z1_NEG end + if Machine.Offsets.PARK_Z1 then ParkZ1 = -Machine.Offsets.PARK_Z1 end + if Machine.Offsets.A1_NEG then MinA1 = Machine.Offsets.A1_NEG end + if Machine.Offsets.A1_POS then MaxA1 = Machine.Offsets.A1_POS end + if Machine.Offsets.PARK_A1 then ParkA1 = Machine.Offsets.PARK_A1 end + MinY = Machine.Offsets.MIN_Y or Machine.Offsets.MINY or MinY + MaxY = Machine.Offsets.MAX_Y or Machine.Offsets.MAXY or MaxY + ParkY = Machine.Offsets.PARK_Y or ParkY + MinV = Machine.Offsets.MIN_V or Machine.Offsets.MINV or MinV + MaxV = Machine.Offsets.MAX_V or Machine.Offsets.MAXV or MaxV + ParkV = Machine.Offsets.PARK_V or ParkV + if Machine.Offsets.DIST_FTZERO then LoadT = Machine.Offsets.DIST_FTZERO end + if Machine.Offsets.DELTA_CARICZERO then TurnerOffs = Machine.Offsets.DELTA_CARICZERO end + if Machine.Offsets.DIST_UNLOAD then UnloadT = Machine.Offsets.DIST_UNLOAD end + if Machine.Offsets.PIVOTFRESAT1 then MillOffs = Machine.Offsets.PIVOTFRESAT1 end + if Machine.Offsets.PIVOTLAMAT1 then SawOffs = Machine.Offsets.PIVOTLAMAT1 end + if Machine.Offsets.OFFSETBLAMA then SawBOffs = Machine.Offsets.OFFSETBLAMA end + if Machine.Offsets.OFFSETALAMA then SawAOffs = Machine.Offsets.OFFSETALAMA end + if Machine.Offsets.PIVOTFRESAT2 then Mill2Offs = -Machine.Offsets.PIVOTFRESAT2 end + if Machine.Offsets.PIVOTLAMAT2 then Saw2Offs = -Machine.Offsets.PIVOTLAMAT2 end + if Machine.Offsets.CNTRRLL_T1_Z1 then RallaOffsY = -Machine.Offsets.CNTRRLL_T1_Z1 - MillOffs end + if Machine.Offsets.CNTRRLL_T1_X1 then RallaOffsZ = -Machine.Offsets.CNTRRLL_T1_X1 end + if Machine.Offsets.OFFSETXT1 then DeltaTabY = RallaOffsY - RallaOffsZ - Machine.Offsets.OFFSETXT1 end + if Machine.Offsets.OFFSETZT1 then DeltaTabZ = RallaOffsY + RallaOffsZ + Machine.Offsets.OFFSETZT1 end + if Machine.Offsets.CNTRRLL_T2_Z2 then Ralla2OffsY = Machine.Offsets.CNTRRLL_T2_Z2 - Mill2Offs end + if Machine.Offsets.CNTRRLL_T2_X2 then Ralla2OffsZ = Machine.Offsets.CNTRRLL_T2_X2 end + if Machine.Offsets.OFFSETXT2 then Delta2TabY = -Ralla2OffsY - Ralla2OffsZ - Machine.Offsets.OFFSETXT2 end + if Machine.Offsets.OFFSETZT2 then Delta2TabZ = -Ralla2OffsY + Ralla2OffsZ + Machine.Offsets.OFFSETZT2 end + if Machine.Offsets.NOULOAD then MaxUnloadLen = Machine.Offsets.NOULOAD end + ParkX1 = EgtClamp( ParkX1, MinX1, MaxX1) + ParkZ1 = EgtClamp( ParkZ1, MinZ1, MaxZ1) + ParkA1 = EgtClamp( ParkA1, MinA1, MaxA1) + Head2Y = DeltaTabY - Delta2TabY + Head2Z = DeltaTabZ - Delta2TabZ + end + end +end + +EmtGeneral { + File='Essetre-TURN.nge', + Offset = Vector3d( 0, 723.0, -709.0), + AxisMaxAdjust = 30, + AxisMaxRotAdj = 0.5, + ExitMaxAdjust = 30, + ExitMaxRotAdj = 0.5, + AngDeltaMinForHome = 165, + Special = 'Essetre-TURN.mlse', + Processor = 'Essetre-TURN.mlpe'} +local BaseId = EmtBase { + Name = 'Base', + Geo='BASE/GEO', + Aux={'BASE/SOLID', 'BASE/TC', 'BASE/SIDE', 'BASE/COLLISION'}} +-- Ralla +local BId = EmtAxis { + Name = 'B', + Parent = 'Base', + Type = MCH_AT.ROTARY, + Dir = X_AX(), + Pos = Point3d( -483.5, RallaOffsY, RallaOffsZ), + Stroke = {MinB-90, MaxB-90}, + Home = -90, + Offset = 90, + Geo = 'B_AXIS/GEO', + Aux = {'B_AXIS/SOLID', 'B_AXIS/COLLISION'}} +-- Prima Testa +local X1Id = EmtAxis { + Name = 'X1', + Parent = 'B', + Token = 'X', + Invert = true, + Type = MCH_AT.LINEAR, + Dir = Z_AX(), + Pos = Point3d( -324.5, 681.0, 313.0), + Stroke = {MinX1, MaxX1}, + Home = ParkX1, + Geo = 'X1_AXIS/GEO', + Aux = {'X1_AXIS/SOLID', 'X1_AXIS/COLLISION'}} +EmtAxis { + Name = 'Z1', + Parent = 'X1', + Token = 'Z', + Invert = true, + Type = MCH_AT.LINEAR, + Dir = Y_AX(), + Pos = Point3d( 156.0, 602.0, 177.0), + Stroke = {MinZ1, MaxZ1}, + Home = ParkZ1, + Geo = 'Z1_AXIS/GEO', + Aux = {'Z1_AXIS/SOLID', 'Z1_AXIS/COLLISION'}} +EmtAxis { + Name = 'A1', + Parent = 'Z1', + Token = 'A', + Type = MCH_AT.ROTARY, + Dir = -Z_AX(), + Pos = Point3d( 0, -MillOffs, 125), + Stroke = {MinA1, MaxA1}, + Home = ParkA1, + Geo = 'A1_AXIS/GEO', + Aux = {'A1_AXIS/SOLID', 'A1_AXIS/COLLISION'}} +-- Frese +local H11Id = EmtHead { + Name = 'H11', + Parent = 'A1', + HSet = 'H11', + Type = MCH_HT.STD, + Pos = Point3d( 0, 0, 0), + TDir = -Y_AX(), + ADir = Z_AX(), + Rot1W = 10, + MaxDeltaR2OnFirst = false, + OthColl = {'H12', 'A1/SOLID', 'Z1/SOLID'}, + Geo = 'H11_HEAD/GEO'} +EgtSetInfo( H11Id, 'ZMAXONROT', '1,60') +-- Lama +local H12Id = EmtHead { + Name = 'H12', + Parent = 'A1', + HSet = 'H12', + Type = MCH_HT.STD, + Pos = Point3d( 0, (-MillOffs+SawOffs), 0), + TDir = Y_AX(), + ADir = Z_AX(), + Rot1W = 10, + MaxDeltaR2OnFirst = false, + OthColl = {'H11', 'A1/SOLID', 'Z1/SOLID'}, + Geo = 'H12_HEAD/GEO'} +EgtSetInfo( H12Id, 'ZMAXONROT', '1,5') +-- Sega a catena +EmtAxis { + Name = 'Q', + Parent = 'A1', + Token = '**', + Type = MCH_AT.ROTARY, + Dir = -Y_AX(), + Pos = Point3d( 0, 0, 0), + Stroke = { -91, 0}, + Home = 0, + Geo = 'Q_AXIS/GEO'} +local H13Id = EmtHead { + Name = 'H13', + Parent = 'Q', + HSet = 'H11', + Type = MCH_HT.STD, + Pos = Point3d( 0, ChSawLen, 0), + TDir = -X_AX(), + ADir = -Y_AX(), + Rot1W = 0.2, + MaxDeltaR2OnFirst = true, + SolCh = MCH_SCC.ADIR_NEAR, + OthColl = {'H12', 'A1/SOLID', 'Z1/SOLID'}, + Geo = 'H13_HEAD/GEO'} +EgtSetInfo( H13Id, 'ZMAXONROT', '1,5') +-- Dummy +EmtHead { + Name = 'H14', + Parent = 'A1', + HSet = 'H14', + Type = MCH_HT.STD, + Pos = Point3d( 0, 0, 0), + TDir = -Y_AX(), + ADir = X_AX(), + Rot1W = 10, + Geo = 'H14_HEAD/GEO'} +-- Seconda Testa +local X2Id = EmtAxis { + Name = 'X2', + Parent = 'B', + Token = 'U', + Invert = true, + Type = MCH_AT.LINEAR, + Dir = -Z_AX(), + Pos = Point3d( -324.5, 681.0, 313.0), + Stroke = {MinX2, MaxX2}, + Home = ParkX2, + Geo = 'X2_AXIS/GEO', + Aux = {'X2_AXIS/SOLID', 'X2_AXIS/COLLISION'}} +local Z2Id = EmtAxis { + Name = 'Z2', + Parent = 'X2', + Token = 'W', + Invert = true, + Type = MCH_AT.LINEAR, + Dir = -Y_AX(), + Pos = Point3d( 156.0, 602.0, 177.0), + Stroke = {MinZ2, MaxZ2}, + Home = ParkZ2, + Geo = 'Z2_AXIS/GEO', + Aux = {'Z2_AXIS/SOLID', 'Z2_AXIS/COLLISION'}} +local A2Id = EmtAxis { + Name = 'A2', + Parent = 'Z2', + Token = 'C', + Type = MCH_AT.ROTARY, + Dir = Z_AX(), + Pos = Point3d( Head2X, Head2Y-Mill2Offs, Head2Z-125), + Stroke = {MinA2, MaxA2}, + Home = ParkA2, + Geo = 'A2_AXIS/GEO', + Aux = {'A2_AXIS/SOLID', 'A2_AXIS/COLLISION'}} +local vtMoveX2 = Vector3d( Head2X - 0, 0, Head2Z + 1418) +EgtMove( EgtGetFirstNameInGroup( X2Id, 'SOLID'), vtMoveX2, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( X2Id, 'COLLISION'), vtMoveX2, GDB_RT.GLOB) +local vtMoveA2 = Vector3d( Head2X - 0, Head2Y - 1436, Head2Z + 1418) +EgtMove( EgtGetFirstNameInGroup( Z2Id, 'SOLID'), vtMoveA2, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( Z2Id, 'COLLISION'), vtMoveA2, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( A2Id, 'SOLID'), vtMoveA2, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( A2Id, 'COLLISION'), vtMoveA2, GDB_RT.GLOB) +-- Frese 2 +local H21Id = EmtHead { + Name = 'H21', + Parent = 'A2', + HSet = 'H21', + Type = MCH_HT.STD, + Pos = Point3d( Head2X, Head2Y, Head2Z), + TDir = Y_AX(), + ADir = -Z_AX(), + Rot1W = 10, + MaxDeltaR2OnFirst = false, + OthColl = {'H22', 'A2/SOLID', 'Z2/SOLID'}, + Geo = 'H21_HEAD/GEO'} +EgtSetInfo( H21Id, 'ZMAXONROT', '1,60') +-- Lama 2 +local H22Id = EmtHead { + Name = 'H22', + Parent = 'A2', + HSet = 'H22', + Type = MCH_HT.STD, + Pos = Point3d( Head2X, Head2Y + (-Mill2Offs+Saw2Offs), Head2Z), + TDir = -Y_AX(), + ADir = -Z_AX(), + Rot1W = 10, + MaxDeltaR2OnFirst = false, + OthColl = {'H21', 'A2/SOLID', 'Z2/SOLID'}, + Geo = 'H22_HEAD/GEO'} +EgtSetInfo( H22Id, 'ZMAXONROT', '1,5') +-- Morse +local YId = EmtAxis { + Name = 'Y', + Parent = 'Base', + Type = MCH_AT.LINEAR, + Dir = -X_AX(), + Pos = Point3d( -953.0, 111.75, 1450.0), + Stroke = { MinY, MaxY}, + Home = ParkY, + Geo = 'Y_AXIS/GEO', + Aux = {'Y_AXIS/SOLID', 'Y_AXIS/COLLISION'}} +local PYId = EmtAxis { + Name = 'PY', + Parent = 'Y', + Type = MCH_AT.LINEAR, + Dir = -Y_AX(), + Pos = Point3d( -904.0, -276.5, 1449.0), + Stroke = { 0, MaxOpen}, + Home = MaxOpen, + Geo = 'PY_AXIS/GEO', + Aux = {'PY_AXIS/SOLID', 'PY_AXIS/COLLISION'}} +local VId = EmtAxis { + Name = 'V', + Parent = 'Base', + Type = MCH_AT.LINEAR, + Dir = -X_AX(), + Pos = Point3d( 953.0, 111.75, 1450.0), + Stroke = { MinV, MaxV}, + Home = ParkV, + Geo = 'V_AXIS/GEO', + Aux = {'V_AXIS/SOLID', 'V_AXIS/COLLISION'}} +local PVId = EmtAxis { + Name = 'PV', + Parent = 'V', + Type = MCH_AT.LINEAR, + Dir = -Y_AX(), + Pos = Point3d( 904.0, -276.5, 1449.0), + Stroke = { 0, MaxOpen}, + Home = MaxOpen, + Geo = 'PV_AXIS/GEO', + Aux = {'PV_AXIS/SOLID', 'PV_AXIS/COLLISION'}} +-- Tavola +EmtAxis { + Name = 'T', + Parent = 'Base', + --Token = '**', + Type = MCH_AT.LINEAR, + Dir = - X_AX(), + Pos = Point3d( 0, 613.16, -830.037), + Stroke = { -40000, 40000}, + Home = LoadT, + Geo = 'T_AXIS/GEO'} +local TabId = EmtTable { + Name = 'Tab', + Parent = 'T', + Type = MCH_TT.FLAT, + Ref1 = Point3d( -DimTabX, DeltaTabY - DimTabY, DeltaTabZ), + Scale = { DimTabX / 34000, DimTabY / 800, 1}, + Geo = 'TABLE/GEO', + Aux = 'TABLE/SOLID'} +EgtSetInfo( TabId, 'TiltingLike', 1) +---- ToolChanger +-- Per testa 1 +local ptTc1 = Point3d( -1042, -9 + ( DeltaTabY + 382), 362 + ( DeltaTabZ + 923)) +EmtTcPos { + Name = 'T1', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 0), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 0), + Geo = 'BASE/T1'} +EmtTcPos { + Name = 'T2', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 30), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 30), + Geo = 'BASE/T2'} +EmtTcPos { + Name = 'T3', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 60), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 60), + Geo = 'BASE/T3'} +EmtTcPos { + Name = 'T4', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 90), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 90), + Geo = 'BASE/T4'} +EmtTcPos { + Name = 'T5', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 120), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 120), + Geo = 'BASE/T5'} +EmtTcPos { + Name = 'T6', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 150), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 150), + Geo = 'BASE/T6'} +EmtTcPos { + Name = 'T7', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 180), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 180), + Geo = 'BASE/T7'} +EmtTcPos { + Name = 'T8', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 210), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 210), + Geo = 'BASE/T8'} +EmtTcPos { + Name = 'T9', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 240), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 240), + Geo = 'BASE/T9'} +EmtTcPos { + Name = 'T10', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 270), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 270), + Geo = 'BASE/T10'} +EmtTcPos { + Name = 'T11', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 300), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 300), + Geo = 'BASE/T11'} +EmtTcPos { + Name = 'T12', + Parent = 'Base', + Pos = ptTc1 + VectorFromPolar( 300, 330), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 330), + Geo = 'BASE/T12'} +-- Per testa 2 +local ptTc2 = Vector3d( -1042, -1409 + ( DeltaTabY + 382), 362 + ( DeltaTabZ + 923)) +EmtTcPos { + Name = 'T13', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 0), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 0), + Geo = 'BASE/T13'} +EmtTcPos { + Name = 'T14', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 30), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 30), + Geo = 'BASE/T14'} +EmtTcPos { + Name = 'T15', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 60), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 60), + Geo = 'BASE/T15'} +EmtTcPos { + Name = 'T16', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 90), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 90), + Geo = 'BASE/T16'} +EmtTcPos { + Name = 'T17', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 120), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 120), + Geo = 'BASE/T17'} +EmtTcPos { + Name = 'T18', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 150), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 150), + Geo = 'BASE/T18'} +EmtTcPos { + Name = 'T19', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 180), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 180), + Geo = 'BASE/T19'} +EmtTcPos { + Name = 'T20', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 210), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 210), + Geo = 'BASE/T20'} +EmtTcPos { + Name = 'T21', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 240), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 240), + Geo = 'BASE/T21'} +EmtTcPos { + Name = 'T22', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 270), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 270), + Geo = 'BASE/T22'} +EmtTcPos { + Name = 'T23', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 300), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 300), + Geo = 'BASE/T23'} +EmtTcPos { + Name = 'T24', + Parent = 'Base', + Pos = ptTc2 + VectorFromPolar( 300, 330), + TDir = -Z_AX(), + ADir = VectorFromPolar( 1, 330), + Geo = 'BASE/T24'} +-- Per sega a catena +local ptTcs = Point3d( 533.5 + ChSawLen, -654.824 + ( DeltaTabY + 382), -1403.0 + ( DeltaTabZ + 923)) +EmtTcPos { + Name = 'T101', + Parent = 'Base', + Pos = ptTcs, + TDir = -Z_AX(), + ADir = -X_AX(), + Geo = 'BASE/T101'} + +-- Aggiusto posizioni geometriche +local vtMove = Vector3d( 0, ( DeltaTabY - 1050), ( DeltaTabZ + 909)) +EgtMove( EgtGetFirstNameInGroup( BaseId, 'SOLID'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( BaseId, 'TC'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( BaseId, 'SIDE'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( BaseId, 'COLLISION'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( YId, 'SOLID'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( YId, 'COLLISION'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( PYId, 'SOLID'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( PYId, 'COLLISION'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( VId, 'SOLID'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( VId, 'COLLISION'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( PVId, 'SOLID'), vtMove, GDB_RT.GLOB) +EgtMove( EgtGetFirstNameInGroup( PVId, 'COLLISION'), vtMove, GDB_RT.GLOB) + +-- Assegno identificativi alle spie delle morse +PYLightId = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( YId, 'SOLID') or GDB_ID.NULL, 'Light') +PVLightId = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( VId, 'SOLID') or GDB_ID.NULL, 'Light') + +--------------------------------------------------------------------- +-- Funzioni richiamate per modificare i dati macchina in casi particolari +--function OnSetTable() +--end + +--------------------------------------------------------------------- +function OnSetHead() + -- se testa 1 fresa + if EMC.HEAD == 'H11' then + -- se con utensile lungo limito la corsa + if EMC.TOTLEN > LONG_TOOL_MINLEN then + EmtModifyAxisStroke( 'A1', { max( MinA1, ParkH11_A1 - 30), min( MaxA1, ParkH11_A1 + 30)}) + else + EmtModifyAxisStroke( 'A1', { MinA1, MaxA1}) + end + -- in ogni caso posizione home vicina ad angolo di CU + EmtModifyAxisHome( 'A1', ParkH11_A1) + -- se testa 1 lama + elseif EMC.HEAD == 'H12' then + EmtModifyAxisStroke( 'A1', { MinA1, MaxA1}) + EmtModifyAxisHome( 'A1', ParkA1) + -- se testa sega a catena + elseif EMC.HEAD == 'H13' then + if EMC.DIST and abs( EMC.DIST) > 1 then + EmtModifyExitPosition( EMC.HEAD, EMC.EXIT, Point3d( 0, EMC.DIST, 0)) + local vtMove = Point3d( 0, EMC.DIST, 0) - Point3d( EMC.EXITPOS) + local ExitId = EgtGetFirstNameInGroup( EgtGetHeadId( EMC.HEAD), 'T'..tostring( EMC.EXIT)) + EgtMove( ExitId, vtMove) + end + EmtModifyAxisStroke( 'A1', { MinA1, MaxA1}) + EmtModifyAxisHome( 'A1', ParkA1) + -- se testa 2 fresa + elseif EMC.HEAD == 'H21' then + -- se con utensile lungo limito la corsa + if EMC.TOTLEN > LONG_TOOL_MINLEN then + EmtModifyAxisStroke( 'A2', { max( MinA2, ParkH21_A2 - 30), min( MaxA2, ParkH21_A2 + 30)}) + else + EmtModifyAxisStroke( 'A2', { MinA2, MaxA2}) + end + -- in ogni caso posizione home vicina ad angolo di CU + EmtModifyAxisHome( 'A2', ParkH21_A2) + -- se testa 2 fresa-lama + elseif EMC.HEAD == 'H22' then + EmtModifyAxisStroke( 'A2', { MinA2, MaxA2}) + EmtModifyAxisHome( 'A2', ParkA2) + end +end + +--------------------------------------------------------------------- +function GetHeadSet( sHead) + if sHead == 'H11' or sHead == 'H12' or sHead == 'H13' then + return 1 + elseif sHead == 'H21' or sHead == 'H22' then + return 2 + else + return 0 + end +end + +--------------------------------------------------------------------- +-- Funzione per impostare spia stato morsa carrello Y +function SetPYLight( bClosed) + if not PYLightId then return end + EgtSetColor( PYLightId, EgtIf( bClosed, 'RED', 'LIME')) + if bClosed then + EgtSetInfo( PYLightId, 'On', '1') + else + EgtRemoveInfo( PYLightId, 'On') + end +end + +--------------------------------------------------------------------- +-- Funzione per leggere lo stato della morsa carrello Y +function GetPYLight() + if not PYLightId then return false end + return ( EgtGetInfo( PYLightId, 'On') == '1') +end + +--------------------------------------------------------------------- +-- Funzione per impostare spia stato morsa carrello V +function SetPVLight( bClosed) + if not PVLightId then return end + EgtSetColor( PVLightId, EgtIf( bClosed, 'RED', 'LIME')) + if bClosed then + EgtSetInfo( PVLightId, 'On', '1') + else + EgtRemoveInfo( PVLightId, 'On') + end +end + +--------------------------------------------------------------------- +-- Funzione per leggere lo stato della morsa carrello V +function GetPVLight() + if not PVLightId then return false end + return ( EgtGetInfo( PVLightId, 'On') == '1') +end + +--------------------------------------------------------------------- +-- Funzione per resettare tutte le attivazioni della macchina +function OnResetMachine() + EmtUnlinkAllRawPartsFromGroups() + EmtUnlinkAllFixturesFromGroups() + SetPYLight( false) + SetPVLight( false) + -- nascondo Vmill + local nRawId = EgtGetFirstRawPart() + while nRawId do + local nVmId = EgtGetFirstNameInGroup( nRawId, 'VMill') + local nId = EgtGetFirstInGroup( nRawId) + while nId do + EgtSetStatus( nId, EgtIf( nId ~= nVmId, GDB_ST.ON, GDB_ST.OFF)) + nId = EgtGetNext( nId) + end + nRawId = EgtGetNextRawPart( nRawId) + end + EgtSetStatus( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'VMill') or GDB_ID.NULL, GDB_ST.OFF) +end diff --git a/Essetre-TURN.mlpe b/Essetre-TURN.mlpe new file mode 100644 index 0000000..054a557 --- /dev/null +++ b/Essetre-TURN.mlpe @@ -0,0 +1,1564 @@ +-- Processore macchina Essetre-TURN by EgalTech s.r.l. 2022/11/28 +-- Funzioni generiche indipendenti dal controllo + +-- Intestazioni +require( 'EmtGenerator') +EgtEnableDebug( false) + +--------------------------------------------------------------------- +-- *** GENERATION *** +--------------------------------------------------------------------- +local sBaseDir = EgtGetSourceDir() +if NumericalControl == 'NUM' then + dofile( sBaseDir .. 'Essetre-TURN.NUM.mlpe') +elseif NumericalControl == 'TPA' then + error( 'Numerical Control error : TPA not yet managed') +else + error( 'Numerical Control error : unkwnown type') +end + +--------------------------------------------------------------------- +-- *** SIMULATION *** +--------------------------------------------------------------------- +local COLL_SAFE_DIST = 2.5 + +--------------------------------------------------------------------- +function OnSimulStart() + -- Carico gli utensili sulle barre portautensili + local vTcPos = EgtGetAllTcPosNames() + if vTcPos then + for i = 1, #vTcPos do + local vTools = EgtGetToolsInCurrSetupPos( vTcPos[i]) + if vTools and vTools[1] then + EgtLoadTool( vTcPos[i], 1, vTools[1]) + ShowToolInTcPos( vTcPos[i], true) + end + end + end + -- Se reset o home, esco + if EMT.SIM1ST then return end + -- Creo o svuoto gruppo per copia finale degli oggetti virtual milling + local nVmGrpId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'VMill') + if nVmGrpId then + EgtSetStatus( nVmGrpId, GDB_ST.ON) + EgtEmptyGroup( nVmGrpId) + else + nVmGrpId = EgtGroup( GDB_ID.ROOT) + EgtSetName( nVmGrpId, 'VMill') + EgtSetLevel( nVmGrpId, GDB_LV.TEMP) + end + -- Preparo lista oggetti da verificare per collisioni + EMT.COLLOBJ = {} + AddToCollisionCheck( 'A1', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'Z1', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'X1', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'A2', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'Z2', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'X2', 'COLLISION', EMT.COLLOBJ) + AddToCollisionCheck( 'B', 'COLLISION', EMT.COLLOBJ) + AddToolToCollisionCheck( 'H12', 1, EMT.COLLOBJ) + AddToolToCollisionCheck( 'H22', 1, EMT.COLLOBJ) + DumpCollisionCheck( EMT.COLLOBJ, 'Collision Objects :', 4) + -- Preparo lista solidi macchina con cui possono collidere gli oggetti sopra riportati (in aggiunta a VMill) + local function GetMCoDet( AbId, sGrpName, sSolName) + local GrpId = EgtGetFirstNameInGroup( AbId, sGrpName) + if not GrpId then return GDB_ID.NULL end + return EgtGetFirstNameInGroup( GrpId, sSolName) or GDB_ID.NULL + end + local function VerifyMCoDet( vMCD, sName) + for i = #vMCD, 1, -1 do + if not vMCD[i] or vMCD[i] == GDB_ID.NULL then + table.remove( vMCD, i) + EgtOutLog( ' Warning : '..sName..'[' .. tostring( i) .. '] is null') + elseif EgtGetDebugLevel() >= 4 then + EgtOutLog( ' '..sName..'[' .. tostring( i) .. ']='..tostring(vMCD[i])) + end + end + end + EMT.MCODET = {} + EMT.MCODET[1] = GetMCoDet( EgtGetAxisId( 'Y'), 'COLLISION', 'SOL1') + EMT.MCODET[2] = GetMCoDet( EgtGetAxisId( 'Y'), 'COLLISION', 'SOL2') + EMT.MCODET[3] = GetMCoDet( EgtGetAxisId( 'PY'), 'COLLISION', 'SOL1') + EMT.MCODET[4] = GetMCoDet( EgtGetAxisId( 'V'), 'COLLISION', 'SOL1') + EMT.MCODET[5] = GetMCoDet( EgtGetAxisId( 'V'), 'COLLISION', 'SOL2') + EMT.MCODET[6] = GetMCoDet( EgtGetAxisId( 'PV'), 'COLLISION', 'SOL1') + EMT.MCODET[7] = GetMCoDet( EgtGetAxisId( 'B'), 'COLLISION', 'RACK1') + EMT.MCODET[8] = GetMCoDet( EgtGetAxisId( 'B'), 'COLLISION', 'RACK2') + EMT.MCODET[9] = GetMCoDet( EgtGetAxisId( 'B'), 'COLLISION', 'RALLA') + EMT.MCODET[10] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL1') + EMT.MCODET[11] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL2') + EMT.MCODET[12] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL3') + EMT.MCODET[13] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL4') + EMT.MCODET[14] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL5') + EMT.MCODET[15] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL6') + EMT.MCODET[16] = GetMCoDet( EgtGetBaseId( 'Base'), 'COLLISION', 'SOL7') + EMT.MCODET_H1 = {} + EMT.MCODET_H1[1] = GetMCoDet( EgtGetAxisId( 'A1'), 'COLLISION', 'SOL1') + EMT.MCODET_H1[2] = GetMCoDet( EgtGetAxisId( 'A1'), 'COLLISION', 'SOL2') + EMT.MCODET_H1[3] = GetMCoDet( EgtGetAxisId( 'A1'), 'COLLISION', 'SOL3') + EMT.MCODET_H2 = {} + EMT.MCODET_H2[1] = GetMCoDet( EgtGetAxisId( 'A2'), 'COLLISION', 'SOL1') + EMT.MCODET_H2[2] = GetMCoDet( EgtGetAxisId( 'A2'), 'COLLISION', 'SOL2') + EMT.MCODET_H2[3] = GetMCoDet( EgtGetAxisId( 'A2'), 'COLLISION', 'SOL3') + VerifyMCoDet( EMT.MCODET, 'MCODET') + VerifyMCoDet( EMT.MCODET_H1, 'MCODET_H1') + VerifyMCoDet( EMT.MCODET_H2, 'MCODET_H2') + -- Preparo lista collisioni vuota + EMT.COLLIDE = {} +end + +--------------------------------------------------------------------- +--function OnSimulEnd() +--end + +--------------------------------------------------------------------- +function OnSimulDispositionStarting() + EmtUnlinkAllRawPartsFromGroups() + if EMT.PHASE > 1 then + if IsStartOrRestPhase( EMT.PHASE) then + EgtSetAxisPos( 'T', LoadT) + end + end +end + +--------------------------------------------------------------------- +function OnSimulDispositionStart() + EMT.OPEISDISP = true + + -- Se prima disposizione + if EMT.PHASE == 1 then + -- Determino dimensioni del grezzo + local nSolId = EgtGetFirstNameInGroup( EgtGetFirstRawPart() or GDB_ID.NULL, 'RawSolid') or GDB_ID.NULL + local b3Sol = EgtGetBBoxGlob( nSolId, GDB_BB.STANDARD) + EMT.LB = 0 + EMT.SB = 0 + EMT.HB = 0 + if b3Sol then + EMT.LB = b3Sol:getDimX() + EMT.SB = b3Sol:getDimY() + EMT.HB = b3Sol:getDimZ() + end + -- Carico primo utensile sulla testa 1 + local sTool1, nTlen1 = FindFirstToolOnHead( 'H11') + if sTool1 and nTlen1 < LONG_TOOL_MINLEN then + EMT.TOOL_1 = sTool1 + else + EMT.TOOL_1 = GetDefaultToolName( 1) + end + EgtLoadTool( 'H11', 1, EMT.TOOL_1) + EMT.TCPOS_1 = GetToolTcPos( EMT.TOOL_1) + ShowToolInTcPos( EMT.TCPOS_1, false) + -- Carico primo utensile sulla testa 2 + local sTool2, nTlen2 = FindFirstToolOnHead( 'H21') + if sTool2 then + EMT.TOOL_2 = sTool2 + else + EMT.TOOL_2 = GetDefaultToolName( 2) + end + EgtLoadTool( 'H21', 1, EMT.TOOL_2) + EMT.TCPOS_2 = GetToolTcPos( EMT.TOOL_2) + ShowToolInTcPos( EMT.TCPOS_2, false) + -- Dichiaro in carico + EMT.LOAD = true + -- Se vero inizio e abilitato creo gli Zmap + EMT.VMILL = {} + if not EMT.SIM1ST and EgtGetInfo( EgtGetCurrMachGroup(), 'Vm', 'b') then + local nLastOrd = GetPhaseOrd( EgtGetPhaseCount()) + local nPartRawId = EgtGetFirstRawPart() + while nPartRawId do + -- se è lo scarto finale tagliato a pezzi, esco + local nRawOrd = EgtGetInfo( nPartRawId, 'ORD', 'i') + if nRawOrd == nLastOrd + 1 then break end + -- elimino eventuale vecchio Zmap + EgtErase( EgtGetFirstNameInGroup( nPartRawId, 'VMill') or GDB_ID.NULL) + -- recupero il solido + local nSolId = EgtGetFirstNameInGroup( nPartRawId, 'RawSolid') + local b3Raw = EgtGetBBoxGlob( nSolId, GDB_BB.STANDARD) + -- aggiungo eventuale scrap successivo + if nRawOrd == nLastOrd then + local nScrapId = EgtGetNextRawPart( nPartRawId) + if nScrapId then + local nScrapSolId = EgtGetFirstNameInGroup( nScrapId, 'RawSolid') + local b3ScrapRaw = EgtGetBBoxGlob( nScrapSolId, GDB_BB.STANDARD) + if b3ScrapRaw then + b3Raw:Add( b3ScrapRaw) + end + end + end + -- determino la risoluzione dello Zmap + local dArea = b3Raw:getDimX() * b3Raw:getDimY() + b3Raw:getDimX() * b3Raw:getDimZ() + b3Raw:getDimY() * b3Raw:getDimZ() + local dTol = 4.71 + if dArea < CoeffVM * 0.15e6 then + dTol = 0.71 + elseif dArea < CoeffVM * 0.3e6 then + dTol = 1.01 + elseif dArea < CoeffVM * 0.6e6 then + dTol = 1.51 + elseif dArea < CoeffVM * 1.2e6 then + dTol = 1.97 + elseif dArea < CoeffVM * 2.4e6 then + dTol = 2.81 + elseif dArea < CoeffVM * 4.8e6 then + dTol = 3.77 + end + -- creo lo Zmap + local VMillId = EgtVolZmapBox( nPartRawId, b3Raw:getMin(), b3Raw:getDimX(), b3Raw:getDimY(), b3Raw:getDimZ(), dTol, true, GDB_RT.GLOB) + if VMillId then + EgtSetName( VMillId, 'VMill') + EgtSetLevel( VMillId, GDB_LV.TEMP) + EgtSetColor( VMillId, EgtGetColor( nSolId), false) + -- nascondo le altre geometrie + local nId = EgtGetFirstInGroup( nPartRawId) + while nId do + if nId ~= VMillId then + EgtSetStatus( nId, GDB_ST.OFF) + end + nId = EgtGetNext( nId) + end + table.insert( EMT.VMILL, VMillId) + end + nPartRawId = EgtGetNextRawPart( nPartRawId) + end + -- imposto eventuale utensile corrente + SetToolForVmill( EMT.TOOL, EMT.HEAD, EMT.EXIT, EMT.VMILL) + end + -- fasi successive + else + EMT.LOAD = false + end + + -- Nascondo tutte le lavorazioni + local nMchId = EgtGetFirstOperation() + while nMchId do + if EgtGetOperationType( nMchId) ~= MCH_OY.DISP then + EgtSetOperationStatus( nMchId, false) + end + nMchId = EgtGetNextOperation( nMchId) + end + + -- Se fase inizio o rimanenza, aggancio grezzi della fase alla tavola + if IsStartOrRestPhase( EMT.PHASE) then + -- indice primo grezzo della fase + local nOrd = GetPhaseOrd( EMT.PHASE) + local nScrapOrd = GetPhaseOrd( EgtGetPhaseCount()) + 1 + local b3Raw = BBox3d() + local nPartRawId, nScrapRawId + local nRawId = EgtGetFirstRawPart() + while nRawId do + local nNextRawId = EgtGetNextRawPart( nRawId) + if EgtVerifyRawPartPhase( nRawId, EMT.PHASE) then + EmtLinkRawPartToGroup( nRawId, 'Tab') + local nRawOrd = EgtGetInfo( nRawId, 'ORD', 'i') + if nRawOrd == nOrd then + b3Raw = EgtGetRawPartBBox( nRawId) + nPartRawId = nRawId + elseif nRawOrd == nOrd + 1 and nRawOrd == nScrapOrd then + local b3Tmp = EgtGetRawPartBBox( nRawId) or BBox3d() + b3Raw:Add( b3Tmp) + nScrapRawId = nRawId + end + end + nRawId = nNextRawId + end + -- gestione eventuale scarto affettato successivo + if EMT.VMILL and #EMT.VMILL > 0 then + EMT.SCRAP = nScrapRawId + EgtSetStatus( EMT.SCRAP or GDB_ID.NULL, GDB_ST.OFF) + else + EMT.SCRAP = nil + end + -- 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 + -- se vero inizio, assegno solidi per verifica collisione + if not EMT.SIM1ST then + EMT.CODET = {} + for i = 1, #( EMT.MCODET or {}) do + EMT.CODET[i] = EMT.MCODET[i] + end + for i = 1, #( EMT.VMILL or {}) do + table.insert( EMT.CODET, EMT.VMILL[i]) + end + end + -- se altrimenti fase intermedia, aggancio grezzi della fase alla tavola + elseif IsMidPhase( EMT.PHASE) then + -- eseguo aggancio + local nRawId = EgtGetFirstRawPart() + while nRawId do + local nNextRawId = EgtGetNextRawPart( nRawId) + if EgtVerifyRawPartPhase( nRawId, EMT.PHASE) then + EmtLinkRawPartToGroup( nRawId, 'Tab') + end + nRawId = nNextRawId + end + -- se Vmill, nascondo eventuale scrap + if EMT.VMILL then + EgtSetStatus( EMT.SCRAP or GDB_ID.NULL, GDB_ST.OFF) + end + -- se altrimenti fasi intermedia o finale speciali, aggancio primo grezzo alla tavola e gli altri in posizione pre-carico + elseif IsMid2Phase( EMT.PHASE) or IsEnd2Phase( EMT.PHASE) then + -- indice primo grezzo della fase + local nOrd = GetPhaseOrd( EMT.PHASE) + -- ricerco vettore movimento per i successivi + local vtMove = Vector3d() + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtGetInfo( nRawId, 'ORD', 'i') == nOrd + 1 then + vtMove = Vector3d( - LoadT - EgtGetRawPartBBox( nRawId):getMax():getX(), 0, 0) + break + end + nRawId = EgtGetNextRawPart( nRawId) + end + -- eseguo + 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') + else + EgtMove( nRawId, vtMove, GDB_RT.GLOB) + EgtSetStatus( nRawId, GDB_ST.OFF) + end + end + nRawId = nNextRawId + end + -- altrimenti fase finale, aggancio primo grezzo alla tavola e gli altri in posizione carico al carro Y + else + -- indice primo grezzo della fase + local nOrd = GetPhaseOrd( EMT.PHASE) + -- ricerco vettore movimento per i successivi + local vtMove = Vector3d() + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtGetInfo( nRawId, 'ORD', 'i') == nOrd + 1 then + vtMove = Vector3d( - LoadT - EgtGetRawPartBBox( nRawId):getMax():getX(), 0, 0) + break + end + nRawId = EgtGetNextRawPart( nRawId) + end + -- eseguo + 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') + else + EgtMove( nRawId, vtMove, GDB_RT.GLOB) + EmtLinkRawPartToGroup( nRawId, 'Y') + end + end + nRawId = nNextRawId + end + end +end + +--------------------------------------------------------------------- +function OnSimulDispositionEnd() + if EMT.UNLOADING or EMT.FALL then + ExecUnloading() + EMT.UNLOADING = false + EMT.FALL = false + end + EMT.OPEISDISP = false +end + +--------------------------------------------------------------------- +function OnSimulToolSelect( dPosQ) + -- se utensile non definito, è disposizione ed esco + if EMT.TOOL == '' then return end + -- recupero dati utensile + EMT.TOOLTYPE = EgtTdbGetCurrToolParam( MCH_TP.TYPE) + EMT.TOTLEN = EgtTdbGetCurrToolParam( MCH_TP.TOTLEN) + EMT.TOTDIAM = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) + local nHSet = GetHeadSet( EMT.HEAD) + -- se non è chiamato da altro script (non c'è parametro) + if not dPosQ then + -- se attivo Vmill + SetToolForVmill( EMT.TOOL, EMT.HEAD, EMT.EXIT, EMT.VMILL) + -- se attivo Collision Check + EMT.SAFEDIST = COLL_SAFE_DIST + if EMT.COLLOBJ then + for i, Coll in ipairs( EMT.COLLOBJ) do + EmtAddCollisionObjEx( i, Coll.Fr, Coll.Ty, Coll.Mv, Coll.P1, Coll.P2, Coll.P3) + end + if EMT.HEAD == 'H12' then + AddToolToCollisionObj( nil, 'H11', 1, 1001) + AddToolHolderToCollisionObj( nil, 'H11', 1, 1002) + elseif EMT.HEAD == 'H22' then + AddToolToCollisionObj( nil, 'H21', 1, 1001) + AddToolHolderToCollisionObj( nil, 'H21', 1, 1002) + else + AddToolToCollisionObj( EMT.TOOL, EMT.HEAD, EMT.EXIT, 1001) + AddToolHolderToCollisionObj( EMT.TOOL, EMT.HEAD, EMT.EXIT, 1002) + end + for i = #EMT.CODET, #( EMT.MCODET or {}) + #( EMT.VMILL or {}) + 1, -1 do + table.remove( EMT.CODET, i) + end + if nHSet == 1 then + for i = 1, #EMT.MCODET_H2 do + table.insert( EMT.CODET, EMT.MCODET_H2[i]) + end + else + for i = 1, #EMT.MCODET_H1 do + table.insert( EMT.CODET, EMT.MCODET_H1[i]) + end + end + end + -- dichiaro assi ausiliari da visualizzare + EMT.AuxAxes = 2 + EMT.A1n = 'Y' + EMT.A2n = 'V' + end + -- carico utensile se non lama o fresone su sua testa o dummy + if EMT.HEAD ~= 'H12' and EMT.HEAD ~= 'H22' and EMT.HEAD ~= 'H14' then + -- se sega a catena, imposto subito angolo scelto per asse virtuale A + if EMT.HEAD == 'H13' then + if not dPosQ then + -- recupero la lavorazione successiva + local NextMchId + if EMT.MCHID then + NextMchId = EgtGetNextActiveOperation( EMT.MCHID) + else + NextMchId = EgtGetFirstActiveOperation() + end + while NextMchId and EgtGetOperationType( NextMchId) == MCH_OY.DISP do + NextMchId = EgtGetNextActiveOperation( NextMchId) + end + EgtSetCurrMachining( NextMchId) + -- recupero il valore dell'asse virtuale bloccato Q + local sVal = EgtGetMachiningParam( MCH_MP.BLOCKEDAXIS) + dPosQ = tonumber( sVal:sub( 3)) + end + -- imposto il valore di Q + EgtSetAxisPos( 'Q', dPosQ) + if abs( dPosQ) < 0.1 then + EgtSetAxisPos( 'B', 0) + end + EgtSetAxisPos( 'A1', 90) + end + -- breve pausa + EgtPause( 100) + EgtOutText( '') + if nHSet == 1 then + EMT.TOOL_1 = EMT.TOOL + EMT.TCPOS_1 = EMT.TCPOS + else + EMT.TOOL_2 = EMT.TOOL + EMT.TCPOS_2 = EMT.TCPOS + end + -- lo nascondo sul portautensili + ShowToolInTcPos( EMT.TCPOS, false) + end +end + +--------------------------------------------------------------------- +function OnSimulToolDeselect() + -- se prossimo utensile non definito, è disposizione ed esco + if EMT.NEXTTOOL == '' then return end + -- se utensile corrente è sega a catena o punta lunga o fresa di grosso diametro su testa 1, devo cambiare + if EMT.HEAD == 'H13' or ( EMT.HEAD == 'H11' and ( EMT.TOTLEN > LONG_TOOL_MINLEN or EMT.TOTDIAM > BIG_TOOL_DIAM)) then + EgtOutText( 'Tool change in progress...') + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + local CollSimRotStep = min( RapSimRotStep, 5) + -- movimento scarico sega a catena + if EMT.HEAD == 'H13' then + SimulMoveAxis( 'Z1', MinZ1, RapSimStep) + local dPosQ = EgtGetAxisPos( 'Q') + if abs( dPosQ) < 0.1 then + SimulMoveAxes( 'A1', 90, CollSimRotStep, 'B', -90, CollSimRotStep) + else + SimulMoveAxes( 'A1', 90, CollSimRotStep, 'B', -180, CollSimRotStep) + end + -- movimento scarico utensile lungo o di grosso diametro + else + SimulMoveAxis( 'Z1', MinZ1, RapSimStep) + SimulMoveAxes( 'A1', ParkH11_A1, CollSimRotStep, 'B', -90, CollSimRotStep) + end + -- breve pausa + EgtPause( 100) + -- nascondo utensile su testa e lo visualizzo su TcPos + EgtSetStatus( EgtGetHeadId( EMT.HEAD), GDB_ST.OFF) + ShowToolInTcPos( EMT.TCPOS_1, true) + -- movimento per carico utensile + if EMT.NEXTHEAD ~= 'H13' then + SimulMoveAxes( 'A1', 180, RapSimRotStep, 'B', -90, RapSimRotStep) + else + SimulMoveAxes( 'A1', 0, RapSimRotStep, 'B', -180, RapSimRotStep) + end + -- se utensile successivo non va su testa 1 uscita 1, carico utensile di default + if EMT.NEXTHEAD ~= 'H11' then + local sDefTool = GetDefaultToolName( 1) + EgtLoadTool( 'H11', 1, sDefTool) + EMT.TOOL_1 = sDefTool + EMT.TCPOS_1 = GetToolTcPos( EMT.TOOL_1) + -- lo nascondo sul portautensili + ShowToolInTcPos( EMT.TCPOS_1, false) + end + EgtOutText( '') + -- se utensile corrente è punta lunga o fresa di grosso diametro su testa 2, devo cambiare + elseif EMT.HEAD == 'H21' and ( EMT.TOTLEN > LONG_TOOL_MINLEN or EMT.TOTDIAM > BIG_TOOL_DIAM) then + EgtOutText( 'Tool change in progress...') + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + local CollSimRotStep = min( RapSimRotStep, 5) + -- movimento scarico utensile lungo o di grosso diametro + SimulMoveAxis( 'Z2', MaxZ2, RapSimStep) + SimulMoveAxes( 'A2', ParkH21_A2, CollSimRotStep, 'B', 0, CollSimRotStep) + -- breve pausa + EgtPause( 100) + -- nascondo utensile su testa e lo visualizzo su TcPos + EgtSetStatus( EgtGetHeadId( EMT.HEAD), GDB_ST.OFF) + ShowToolInTcPos( EMT.TCPOS_2, true) + -- movimento per carico utensile + SimulMoveAxes( 'A2', 0, RapSimRotStep, 'B', -90, RapSimRotStep) + -- se utensile successivo non va su testa 2 uscita 1, carico utensile di default + if EMT.NEXTHEAD ~= 'H21' then + local sDefTool = GetDefaultToolName( 2) + EgtLoadTool( 'H21', 1, sDefTool) + EMT.TOOL_2 = sDefTool + EMT.TCPOS_2 = GetToolTcPos( EMT.TOOL_2) + -- lo nascondo sul portautensili + ShowToolInTcPos( EMT.TCPOS_2, false) + end + EgtOutText( '') + end + -- recupero testa del prossimo utensile + local nHSet = GetHeadSet( EMT.NEXTHEAD) + -- se prossima è testa 1 + if nHSet == 1 then + -- deposito utensile se prossimo non lama su sua testa + if EMT.NEXTHEAD ~= 'H12' then + if EMT.NEXTTOOL ~= EMT.TOOL_1 then + EgtOutText( 'Tool change in progress...') + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + local CollSimRotStep = min( RapSimRotStep, 10) + -- simulo movimento + SimulMoveAxis( 'Z1', MinZ1, RapSimStep) + SimulMoveAxes( 'A1', 180, CollSimRotStep, 'B', -90, CollSimRotStep) + -- breve pausa + EgtPause( 100) + ShowToolInTcPos( EMT.TCPOS_1, true) + -- se segue sega a catena + if EMT.NEXTHEAD == 'H13' then + -- se non lama, nascondo l'utensile corrente + if EMT.HEAD ~= 'H12' then + EgtSetStatus( EgtGetHeadId( EMT.HEAD), GDB_ST.OFF) + end + -- eseguo movimento opportuno + SimulMoveAxes( 'A1', 90, RapSimRotStep, 'B', -180, RapSimRotStep) + end + else + EMT.TOOL_1 = nil + EMT.TCPOS_1 = nil + end + end + -- altrimenti prossima è testa 2 + else + -- deposito utensile se prossimo non grosso truciolatore su sua testa + if EMT.NEXTHEAD ~= 'H22' then + if EMT.NEXTTOOL ~= EMT.TOOL_2 then + EgtOutText( 'Tool change in progress...') + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + local CollSimRotStep = min( RapSimRotStep, 10) + -- simulo movimento + SimulMoveAxis( 'Z2', MaxZ2, RapSimStep) + SimulMoveAxes( 'A2', 0, CollSimRotStep, 'B', -90, CollSimRotStep) + -- breve pausa + EgtPause( 100) + ShowToolInTcPos( EMT.TCPOS_2, true) + else + EMT.TOOL_2 = nil + EMT.TCPOS_2 = nil + end + end + end +end + +--------------------------------------------------------------------- +function OnSimulMachiningStart() + -- se lavorazione attuale e precedente con sega a catena con angolo A diverso, devo scaricare e ricaricare + if EMT.HEAD == 'H13' and EMT.HEAD == EMT.PREVHEAD then + local dPrevQ = EgtGetAxisPos( 'Q') + local sVal = EgtGetMachiningParam( MCH_MP.BLOCKEDAXIS) + local dPosQ = tonumber( sVal:sub( 3)) + if abs( dPosQ - dPrevQ) > 1 then + OnSimulToolDeselect() + EgtSetStatus( EgtGetHeadId( EMT.HEAD), GDB_ST.ON) + OnSimulToolSelect( dPosQ) + end + end + -- recupero alcuni dati della lavorazione + EMT.MCHNAME = EgtGetOperationName( EMT.MCHID) + EMT.MCHTYPE = EgtGetMachiningParam( MCH_MP.TYPE) + local sNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) + EMT.VMRS = ( EMT.MCHTYPE ~= MCH_MY.DRILLING and not ( sNotes and sNotes:find( 'VMRS=0;', 1, true))) + -- recupero TASKID della feature lavorata + local vId = EgtGetMachiningGeometry() + if vId and #vId > 0 and #vId[1] > 0 then + EMT.TASKID = EgtGetInfo( vId[1][1], 'TASKID', 'i') or 0 ; + else + EMT.TASKID = 0 + end + -- non ancora iniziata la lavorazione + EMT.MCHFIRST = true +end + +--------------------------------------------------------------------- +function OnSimulMachiningEnd() + if EMT.LOAD then + EMT.LOAD = false + elseif EMT.UNLOADING or EMT.FALL then + ExecUnloading() + EMT.UNLOADING = false + EMT.FALL = false + end + EMT.PREVHEAD = EMT.HEAD + EMT.PREVEXIT = EMT.EXIT +end + +--------------------------------------------------------------------- +--function OnSimulPathStart() +--end + +--------------------------------------------------------------------- +function OnSimulPathEnd() + -- se attivo VMILL, lavorazione ed è richiesto di eliminare gli sfridi + if EMT.VMILL and #EMT.VMILL > 0 and not EMT.OPEISDISP and EMT.VMRS then + EgtOutLog( 'OnSimulPathEnd', 5) + local vMillId = EMT.VMILL[1] + local nPart = EgtVolZmapPartCount( vMillId) + if nPart > 1 then + -- ricerca del pezzo con massimo volume + local nPartMax = 0 + local dVolMax = 0 + for i = 1, nPart do + local dVol = EgtVolZmapPartVolume( vMillId, i - 1) + if dVol > dVolMax then + dVolMax = dVol + nPartMax = i + end + end + -- eliminazione di tutti i pezzi piccoli + for i = nPart, 1, -1 do + if i ~= nPartMax then + local b3Vmill = EgtVolZmapGetPartBBoxGlob( vMillId, i - 1, GDB_BB.STANDARD) + if b3Vmill:getDimX() < 1200 then + EgtRemoveVolZmapPart( vMillId, i - 1) + end + end + end + -- aggiorno visualizzazione + EgtDraw() + end + end +end + +--------------------------------------------------------------------- +function OnSimulPathStartAux() + --EgtOutLog( 'OnSimulPathStartAux - ' .. EgtNumToString( EMT.AUXIND, 0) .. ' - ' .. EMT.AUX) + EgtOutLog( 'OnSimulPathStartAux', 5) + -- eseguo il comando + ExecAuxCmd( EMT.AUX) +end + +--------------------------------------------------------------------- +function OnSimulPathEndAux() + --EgtOutLog( 'OnSimulPathEndAux - ' .. EgtNumToString( EMT.AUXIND, 0) .. ' - ' .. EMT.AUX) + EgtOutLog( 'OnSimulPathEndAux', 5) + -- eseguo il comando + ExecAuxCmd( EMT.AUX) +end + +--------------------------------------------------------------------- +function OnSimulMoveStart() + if EMT.MCHFIRST then EgtOutText( '') end + -- Recupero la posizione corrente dei carrelli + local Yp = EgtGetAxisPos( 'Y') + local Vp = EgtGetAxisPos( 'V') + -- Imposto movimento carrelli insieme con la tavola : + -- entrambe le pinze + if EMT.YDELTA and EMT.VDELTA then + EMT.AuxAxes = 2 + EMT.A1n = 'Y' + EMT.A1m = 'T' + EMT.A1 = EMT.L1 + EMT.YDELTA + EMT.A2n = 'V' + EMT.A2m = 'T' + EMT.A2 = EMT.L1 + EMT.VDELTA + -- solo pinza Y + elseif EMT.YDELTA then + EMT.AuxAxes = 2 + EMT.A1n = 'Y' + EMT.A1m = 'T' + EMT.A1 = EMT.L1 + EMT.YDELTA + EMT.A2n = 'V' + EMT.A2m = nil + EMT.A2 = ParkV + -- solo pinza V + elseif EMT.VDELTA then + EMT.AuxAxes = 2 + EMT.A1n = 'Y' + EMT.A1m = nil + EMT.A1 = EgtIf( EMT.YSPEC, Yp, ParkY) + EMT.A2n = 'V' + EMT.A2m = 'T' + EMT.A2 = EMT.L1 + EMT.VDELTA + end + -- Controllo scorrimento pinze chiuse Y e V + if EMT.YDELTA then + local dYDeltaP = Yp - EMT.L1p + if abs( EMT.YDELTA - dYDeltaP) > 0.1 then + EMT.ERR = 2 + local sErr = 'Y slide : ' .. EmtLenToString( dYDeltaP, 3) .. ' -> ' .. EmtLenToString( EMT.YDELTA, 3) + EmtSetLastError( 1202, sErr) + end + end + if EMT.VDELTA then + local dVDeltaP = Vp - EMT.L1p + if abs( EMT.VDELTA - dVDeltaP) > 0.1 then + EMT.ERR = 2 + local sErr = 'V slide : ' .. EgtNumToString( dVDeltaP, 3) .. ' -> ' .. EgtNumToString( EMT.VDELTA, 3) + EmtSetLastError( 1202, sErr) + end + end + -- Controllo corse assi Y e V + VerifyYStroke( EMT.A1) + VerifyVStroke( EMT.A2) + -- step di simulazione + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + local CollSimRotStep = min( RapSimRotStep, 5) + -- se primo movimento in rapido + if EMT.MOVE == 0 and EMT.MCHFIRST then + -- se movimento iniziale da Zmax con lama o fresa + if EMT.ZMAX or ( EMT.FLAG == 2 and EMT.FLAG2 == 1) then + local nHSet = GetHeadSet( EMT.HEAD) + local BPos = EgtGetAxisPos( 'B') + if abs( EMT.R1 - BPos) > 30 then + if nHSet == 1 then + SimulMoveAxis( 'Z1', ParkZ1, RapSimStep) + else + SimulMoveAxis( 'Z2', ParkZ2, RapSimStep) + end + end + SimulMoveAxis( 'B', EMT.R1, CollSimRotStep) + if nHSet == 1 then + SimulMoveAxis( 'A1', EMT.R2, RapSimRotStep) + else + SimulMoveAxis( 'A2', EMT.R2, RapSimRotStep) + end + EMT.ZX_AT_END = true + EMT.MASK = EMT.MASK & ( ~ ( 2 | 4)) + end + EMT.ZMAX = nil + else + EMT.MCHFIRST = false + end +end + +--------------------------------------------------------------------- +function OnSimulMoveEnd() + -- completo movimento teste lasciato in sospeso + if EMT.ZX_AT_END then + local RapSimStep = 4 * EMT.SIMSTEP + local nHSet = GetHeadSet( EMT.HEAD) + if nHSet == 1 then + SimulMoveAxis( 'Z1', EMT.L2, RapSimStep) + SimulMoveAxis( 'X1', EMT.L3, RapSimStep) + else + SimulMoveAxis( 'Z2', EMT.L2, RapSimStep) + SimulMoveAxis( 'X2', EMT.L3, RapSimStep) + end + EMT.ZX_AT_END = nil + end + -- se movimento finale a Zmax + if EMT.FLAG == 3 then + -- se cambia utensile vado in home + local sNextTool = GetNextTool( EMT.MCHID) + if ( sNextTool ~= EMT.TOOL) then + ExecMoveZmax() + end + end +end + +--------------------------------------------------------------------- +function OnSimulCollision() + -- se prima collisione della lavorazione, la segnalo + if EMT.MCHNAME ~= EMT.LAST_MCHNAME_COLLIDE then + local Class = '' + if EMT.SIMCOBIND == 1001 then + Class = 'T_H1' + elseif EMT.SIMCOBIND == 1002 then + Class = 'TH_H1' + else + Class = EMT.COLLOBJ[EMT.SIMCOBIND].Cl + end + table.insert( EMT.COLLIDE, { Mc = EMT.MCHNAME, Cl = Class, Vm = EMT.SIMVMID}) + EMT.LAST_MCHNAME_COLLIDE = EMT.MCHNAME + EMT.ERR = 1 + local sErr = 'CUTID='..tostring( EMT.CUTID)..'; TASKID='..tostring( EMT.TASKID)..'; Mach='..EMT.MCHNAME..'; Class='..Class..'; VMill='..EMT.SIMVMID + EmtSetLastError( 1221, sErr, true) + EgtOutLog( 'Collision : ' .. sErr, 1) + end +end + +--------------------------------------------------------------------- +function ExecAuxCmd( sCmd) + local RapSimStep = 4 * EMT.SIMSTEP + local Cmd = EgtSplitString( sCmd) + if Cmd[1] == '0' then + if Cmd[2] == 'Unloading' then + EMT.UNLOADING = true + elseif Cmd[2] == 'Fall' then + EMT.FALL = true + end + EgtOutText( EgtIf( Cmd[3], Cmd[3], Cmd[2])) + elseif Cmd[1] == '1' then + if Cmd[2] == 'Z' then + ExecMoveZmax() + else + if not SimulMoveAxis( Cmd[2], tonumber( Cmd[3]), RapSimStep) then + if VerifyYVStroke( Cmd[2], tonumber( Cmd[3])) == nil then + EgtOutLog( 'Error on ExecAuxCmd : ' .. sCmd) + end + end + end + elseif Cmd[1] == '2' then + -- Verifico movimento carrello con trave agganciata + VerifyOneChariotSlide( Cmd[2], Cmd[3], Cmd[4], Cmd[5]) + -- Eseguo il movimento + local _, bOk, bOk2 = SimulMoveAxes( Cmd[2], tonumber( Cmd[3]), RapSimStep, + Cmd[4], tonumber( Cmd[5]), RapSimStep) + if not ( bOk and bOk2) then + local nI = EgtIf( not bOk, 2, 4) + if VerifyYVStroke( Cmd[nI], tonumber( Cmd[nI+1])) == nil then + EgtOutLog( 'Error on ExecAuxCmd : ' .. sCmd) + end + end + elseif Cmd[1] == '3' then + -- Verifico movimento carrelli con trave agganciata + VerifyTwoChariotsSlide( Cmd[2], Cmd[3], Cmd[4], Cmd[5], Cmd[6], Cmd[7]) + -- Eseguo il movimento + local _, bOk, bOk2, bOk3 = SimulMoveAxes( Cmd[2], tonumber( Cmd[3]), RapSimStep, + Cmd[4], tonumber( Cmd[5]), RapSimStep, + Cmd[6], tonumber( Cmd[7]), RapSimStep) + if not ( bOk and bOk2 and bOk3) then + local nI = EgtIf( not bOk, 2, EgtIf( not bOk2, 4, 6)) + if VerifyYVStroke( Cmd[nI], tonumber( Cmd[nI+1])) == nil then + EgtOutLog( 'Error on ExecAuxCmd : ' .. sCmd) + end + end + elseif Cmd[1] == '4' then + ExecMoveZmax() + elseif Cmd[1] == '11' then + local dPY = MaxOpen + if Cmd[2] ~= '0' then + dPY = EMT.SB + end + SimulMoveAxis( 'PY', dPY, RapSimStep) + SetPYLight( Cmd[2] ~= '0') + elseif Cmd[1] == '12' then + local dPV = MaxOpen + if Cmd[2] ~= '0' then + dPV = EMT.SB + end + SimulMoveAxis( 'PV', dPV, RapSimStep) + SetPVLight( Cmd[2] ~= '0') + elseif Cmd[1] == '21' then + local nYDelta = tonumber( Cmd[2]) + local nVDelta = tonumber( Cmd[3]) + if nYDelta > 0.01 and nVDelta > 0.01 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nVDelta + elseif nYDelta > 0.01 then + EMT.YDELTA = nYDelta + EMT.VDELTA = nil + elseif nVDelta > 0.01 then + EMT.YDELTA = nil + EMT.VDELTA = nVDelta + end + elseif Cmd[1] == '31' then + local nRawId = tonumber( Cmd[2]) + EmtUnlinkRawPartFromGroup( nRawId) + EmtLinkRawPartToGroup( nRawId, Cmd[3]) + EMT.YSPEC = true + end +end + +--------------------------------------------------------------------- +function ExecMoveZmax() + local RapSimStep = 4 * EMT.SIMSTEP + local RapSimRotStep = RapSimStep / 10 + SimulMoveAxis( 'X1', EgtGetAxisHomePos( 'X1'), RapSimStep) + SimulMoveAxes( 'Z1', EgtGetAxisHomePos( 'Z1'), RapSimStep, 'A1', EgtGetAxisHomePos( 'A1'), RapSimRotStep) + SimulMoveAxis( 'X2', EgtGetAxisHomePos( 'X2'), RapSimStep) + SimulMoveAxes( 'Z2', EgtGetAxisHomePos( 'Z2'), RapSimStep, 'A2', EgtGetAxisHomePos( 'A2'), RapSimRotStep) + EMT.ZMAX = true +end +--------------------------------------------------------------------- +function ExecUnloading() + if EMT.VMILL and #EMT.VMILL > 0 then + local vMillId = EMT.VMILL[1] + -- gruppo dei Vmill + local nVmGrpId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'VMill') + -- li sposto per lasciare spazio al nuovo pezzo + local nId = EgtGetFirstInGroup( nVmGrpId) + while nId do + EgtMove( nId, Vector3d( 0, -( EMT.SB + 50.0), 0), GDB_RT.GLOB) + nId = EgtGetNext( nId) + end + -- creo un nuovo layer e vi inserisco il nuovo pezzo + local nLayId = EgtGroup( nVmGrpId, EgtGetGlobFrame( vMillId)) + EgtRelocate( vMillId, nLayId) + local vtMove = Vector3d( 0, -1000, 0) + if EMT.FALL then vtMove = Vector3d( -500, 0, -750) end + EgtMove( nLayId, vtMove, GDB_RT.GLOB) + EgtSetLevel( vMillId, GDB_LV.USER) + -- aggiungo gli spigoli + local nFirstId, nCount = EgtVolZmapGetEdges( vMillId, nLayId) + if nFirstId then + for nId = nFirstId, nFirstId + nCount - 1 do + EgtSetColor( nId, Color3d( 96, 96, 96)) + end + end + -- rilascio Vmill + table.remove( EMT.VMILL, 1) + -- aggiorno la visualizzazione + EgtDraw() + -- se finito + if EMT.PHASE == EgtGetPhaseCount() then + -- se impostato di salvare i Vmill, lo faccio + local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini' + if EgtGetStringFromIni( 'VMill', 'Save', '', sMachIni) == '1' then + local sFile = EgtGetCurrFilePath() + if sFile then + local sDir, sName, sExt = EgtSplitPath( sFile) + if sExt and sExt:lower() == ".nge" then + sName = sName .. '_VM_' .. EgtGetMachGroupName( EgtGetCurrMachGroup()) + EgtSetLevel( nVmGrpId, GDB_LV.USER) + EgtSaveObjToFile( nVmGrpId, sDir .. sName .. '.Nge') + EgtSetLevel( nVmGrpId, GDB_LV.TEMP) + end + end + end + end + end +end + +--------------------------------------------------------------------- +function VerifyYSlide( sName1, dVal1, sName2, dVal2) + -- Se movimento trave agganciata con carrello Y + if sName1 == 'T' and sName2 == 'Y' and GetPYLight() then + local dYDeltaP = EgtGetAxisPos( 'T') - EgtGetAxisPos( 'Y') + local dYDeltaA = tonumber( dVal1) - tonumber( dVal2) + EgtOutLog( string.format( 'YDeltaP=%.3f YDeltaA=%.3f', dYDeltaP, dYDeltaA), 5) + if abs( dYDeltaA - dYDeltaP) > 0.5 then + EMT.ERR = 2 + local sErr = 'Y slide : ' .. EmtLenToString( dYDeltaP, 3) .. ' -> ' .. EmtLenToString( dYDeltaA, 3) + EmtSetLastError( 1202, sErr) + end + end + -- Tutto bene + return true +end + +--------------------------------------------------------------------- +function VerifyVSlide( sName1, dVal1, sName2, dVal2) + -- Se movimento trave agganciata con carrello V + if sName1 == 'T' and sName2 == 'V' and GetPVLight() then + local dVDeltaP = EgtGetAxisPos( 'T') - EgtGetAxisPos( 'V') + local dVDeltaA = tonumber( dVal1) - tonumber( dVal2) + EgtOutLog( string.format( 'VDeltaP=%.3f VDeltaA=%.3f', dVDeltaP, dVDeltaA), 5) + if abs( dVDeltaA - dVDeltaP) > 0.5 then + EMT.ERR = 2 + local sErr = 'V slide : ' .. EmtLenToString( dVDeltaP, 3) .. ' -> ' .. EmtLenToString( dVDeltaA, 3) + EmtSetLastError( 1202, sErr) + end + end + return true +end + +--------------------------------------------------------------------- +function VerifyOneChariotSlide( sName1, dVal1, sName2, dVal2) + -- Metto in prima posizione la trave + if sName2 == 'T' then + sName1, sName2 = sName2, sName1 + dVal1, dVal2 = dVal2, dVal1 + end + -- Eseguo verifica + if sName2 == 'Y' then + return VerifyYSlide( sName1, dVal1, sName2, dVal2) + elseif sName2 == 'V' then + return VerifyVSlide( sName1, dVal1, sName2, dVal2) + end + return true +end + +--------------------------------------------------------------------- +function VerifyTwoChariotsSlide( sName1, dVal1, sName2, dVal2, sName3, dVal3) + -- Metto in prima posizione la trave + if sName2 == 'T' then + sName1, sName2 = sName2, sName1 + dVal1, dVal2 = dVal2, dVal1 + elseif sName3 == 'T' then + sName1, sName3 = sName3, sName1 + dVal1, dVal3 = dVal3, dVal1 + end + -- Eseguo verifica + if sName2 == 'Y' then + return VerifyYSlide( sName1, dVal1, sName2, dVal2) and VerifyVSlide( sName1, dVal1, sName3, dVal3) + elseif sName2 == 'V' then + return VerifyVSlide( sName1, dVal1, sName2, dVal2) and VerifyYSlide( sName1, dVal1, sName3, dVal3) + end + return true +end + +--------------------------------------------------------------------- +function VerifyYStroke( dY) + if dY < MinY then + EmtSetOutstrokeInfo( 'Y', 'Y', true, dY - MinY, ' (L1-)') + EMT.ERR = 1 + local sErr = 'Y axis outstroke ' .. EgtNumToString( dY - MinY, 3) + EgtOutLog( sErr) + return false + elseif dY > MaxY then + EmtSetOutstrokeInfo( 'Y', 'Y', true, dY - MaxY, ' (L1+)') + EMT.ERR = 1 + local sErr = 'Y axis outstroke ' .. EgtNumToString( dY - MaxY, 3) + EgtOutLog( sErr) + return false + end + return true +end + +--------------------------------------------------------------------- +function VerifyVStroke( dV) + if dV > MaxV then + EmtSetOutstrokeInfo( 'V', 'V', true, dV - MaxV, ' (L1+)') + EMT.ERR = 1 + local sErr = 'V axis outstroke ' .. EgtNumToString( dV - MaxV, 3) + EgtOutLog( sErr) + return false + elseif dV < MinV then + EmtSetOutstrokeInfo( 'V', 'V', true, dV - MinV, ' (L1-)') + EMT.ERR = 1 + local sErr = 'V axis outstroke ' .. EgtNumToString( dV - MinV, 3) + EgtOutLog( sErr) + return false + end + return true +end + +--------------------------------------------------------------------- +function VerifyYVStroke( sName, dVal) + if sName == 'Y' then + return VerifyYStroke( dVal) + elseif sName == 'V' then + return VerifyVStroke( dVal) + else + return nil + end +end + +--------------------------------------------------------------------- +function ShowToolInTcPos( sTcPos, bShow) + -- recupero il gruppo dell'utensile + local TcExitId = EgtGetFirstNameInGroup( EgtGetTcPosId( sTcPos or '') or GDB_ID.NULL, 'T1') + if not TcExitId then return end + -- imposto lo stato di visualizzazione + EgtSetStatus( TcExitId, EgtIf( bShow, GDB_ST.ON, GDB_ST.OFF)) +end + +--------------------------------------------------------------------- +function GetToolTcPos( sTool) + -- salvo stato iniziale + local CurrTool = EgtTdbGetCurrToolParam( MCH_TP.NAME) + -- recupero la posizione di cambio utensile dell'utensile indicato + local sTcPos + if EgtTdbSetCurrTool( sTool) then + sTcPos = EgtTdbGetCurrToolParam( MCH_TP.TCPOS) + end + -- ripristino stato iniziale + if CurrTool then + EgtTdbSetCurrTool( CurrTool) + else + EgtTdbSetCurrTool( '') + end + -- restituisco risultato + return sTcPos +end + + +--------------------------------------------------------------------- +-- *** ESTIMATION T&L *** +--------------------------------------------------------------------- +local RAPID_X_FEED = 75000 -- mm/min +local RAPID_Y_FEED = 100000 -- mm/min +local RAPID_Z_FEED = 50000 -- mm/min +local RAPID_C_FEED = 15000 -- deg/min +local RAPID_B_FEED = 15000 -- deg/min +local RAPID_MIN_T = 0.1 -- s +local LOAD_T = 2 -- s +local CHAR_ONE_MOVE_T = 1 -- s +local ROTATION_T = 40 -- s +local SPLIT_T = 6 -- s +local UNLOAD_T = 4 -- s +local FALL_T = 2 -- s + +--------------------------------------------------------------------- +function OnEstimStart() + EMT.INCHES = not EgtUiUnitsAreMM() -- unità di misura mm/inches +end + +--------------------------------------------------------------------- +function OnEstimEnd() +end + +--------------------------------------------------------------------- +function OnEstimProgramStart() + -- imposto inizio movimenti da Home + EMT.L1 = EgtGetAxisHomePos( 'T') + EMT.L2 = EgtGetAxisHomePos( 'X1') + EMT.L3 = EgtGetAxisHomePos( 'Z1') + EMT.R1 = EgtGetAxisHomePos( 'B') + EMT.R2 = EgtGetAxisHomePos( 'A1') + -- aggiorno valori come precedenti + EmtUpdatePrev() + -- totalizzatori tempi e lunghezze + EMT.TOTCUTLEN = 0 + EMT.TOTCUTTIME = 0 + EMT.TOTEXTLEN = 0 + EMT.TOTEXTTIME = 0 + -- variabile per lunghezza taglio utensili + EMT.TOOLCUTLEN = {} + -- intestazioni + EmtTleStart( EMT.INFO) +end + +--------------------------------------------------------------------- +function OnEstimProgramEnd() + -- stampa dei totali delle lavorazioni + EmtTleAddTotal( EmtSecToHMS( EMT.TOTCUTTIME + EMT.TOTEXTTIME), EmtLenToMF( EMT.TOTCUTLEN)) + -- stampa dei totali degli utensili + for i = 1, #EMT.TOOLCUTLEN do + local TCL = EMT.TOOLCUTLEN[i] + EmtTleAddTool( TCL.Name, EmtLenToMF( TCL.Len)) + end + -- completo il file + local _, _, sExt = EgtSplitPath( EMT.FILE) + EmtTleEnd( sExt:sub( 2)) + -- salvo i dati principali nel progetto + EgtSetInfo( EgtGetCurrMachGroup(), 'Ttot', EgtNumToString( EMT.TOTCUTTIME + EMT.TOTEXTTIME, 0)) + EgtSetInfo( EgtGetCurrMachGroup(), 'Ltot', EgtNumToString( EMT.TOTCUTLEN, 0)) +end + +--------------------------------------------------------------------- +function OnEstimDispositionStart() + -- inizio disposizione + EMT.OPEISDISP = true + -- sulla prima fase dichiaro carico barra + if EMT.PHASE == 1 then + EMT.LOAD = true + else + EMT.LOAD = false + end +end + +--------------------------------------------------------------------- +function OnEstimDispositionEnd() + -- Se disposizione inizio o rimanenza + if IsStartOrRestPhase( EMT.PHASE) then + ; + -- se altrimenti disposizione intermedia o finale dopo separazione e rotazione, eventuale rotazione + elseif IsMidPhase( EMT.PHASE) or IsMid2Phase( EMT.PHASE) or IsEnd2Phase( EMT.PHASE) then + -- recupero le rotazioni delle fasi corrente e precedente + local nRot = GetPhaseRot( EMT.PHASE) + local nPrevRot = GetPhaseRot( EMT.PHASE - 1) + -- verifico se sono diverse + if nRot ~= nPrevRot then + -- imposto stato post-rotazione + EMT.POSTROT = true + end + -- altrimenti disposizione finale, eventuale scarico pezzo lavorato se non ci sono lavorazioni + else + ; + end + -- emetto dati in sospeso + if EMT.TLE_NAME then + EmtTleAddMachining( EMT.TLE_NAME, EmtSecToHMS( EMT.TLE_TIME), ' - ', ' - ') + EMT.TLE_NAME = nil + EMT.TLE_TIME = nil + end + -- termine disposizione + EMT.OPEISDISP = false +end + +--------------------------------------------------------------------- +function OnEstimToolSelect() + -- reset indice utensile in tabella lunghezze + EMT.TCLIND = 0 + -- verifico che l'utensile sia definito + if #EMT.TOOL == 0 then return end + -- cerco l'utensile nella tabella + for i = 1, #EMT.TOOLCUTLEN do + if EMT.TOOLCUTLEN[i].Name == EMT.TOOL then + EMT.TCLIND = i + break + end + end + -- se non trovato, lo aggiungo + if EMT.TCLIND == 0 then + table.insert( EMT.TOOLCUTLEN, { Name = EMT.TOOL, Len = 0}) + EMT.TCLIND = #EMT.TOOLCUTLEN + end +end + +--------------------------------------------------------------------- +function OnEstimToolDeselect() +end + +--------------------------------------------------------------------- +function OnEstimMachiningStart() + EMT.MCHNAME = EgtGetOperationName( EMT.MCHID) + EMT.MCHTYPE = EgtGetMachiningParam( MCH_MP.TYPE) + EgtOutLog( 'Mach : ' .. EMT.MCHNAME, 5) + -- reset contatori di lavorazione + EMT.MCHCUTLEN = 0 + EMT.MCHCUTTIME = 0 + EMT.MCHEXTLEN = 0 + EMT.MCHEXTTIME = 0 +end + +--------------------------------------------------------------------- +function OnEstimMachiningEnd() + -- nel caso di foratura devo dimezzare la lunghezza di taglio perchè comprende anche l'uscita + if EMT.MCHTYPE == MCH_MY.DRILLING then + EMT.MCHCUTLEN = EMT.MCHCUTLEN / 2 + end + local sName = EgtGetName( EMT.MCHID) + EmtTleAddMachining( sName, EmtSecToHMS( EMT.MCHCUTTIME + EMT.MCHEXTTIME), EmtLenToMF( EMT.MCHCUTLEN), EMT.TOOL) + -- aggiorno totali e utensili + EMT.TOTCUTLEN = EMT.TOTCUTLEN + EMT.MCHCUTLEN + EMT.TOTCUTTIME = EMT.TOTCUTTIME + EMT.MCHCUTTIME + EMT.TOTEXTLEN = EMT.TOTEXTLEN + EMT.MCHEXTLEN + EMT.TOTEXTTIME = EMT.TOTEXTTIME + EMT.MCHEXTTIME + EMT.TOOLCUTLEN[EMT.TCLIND].Len = EMT.TOOLCUTLEN[EMT.TCLIND].Len + EMT.MCHCUTLEN + -- emetto dati in sospeso + if EMT.TLE_NAME then + EmtTleAddMachining( EMT.TLE_NAME, EmtSecToHMS( EMT.TLE_TIME), ' - ', ' - ') + EMT.TLE_NAME = nil + EMT.TLE_TIME = nil + end +end + +--------------------------------------------------------------------- +function OnEstimPathStart() + EMT.AUXTYPE = nil + EMT.MCHMOVEFIRST = true +end + +--------------------------------------------------------------------- +function OnEstimPathEnd() + EMT.AUXTYPE = nil +end + +--------------------------------------------------------------------- +function OnEstimPathStartAux() + -- se richiesto, preparo il carico barra + if EMT.LOAD then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = LOAD_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EmtTleAddMachining( 'Loading', EmtSecToHMS( dTime), ' - ', ' - ') + EMT.LOAD = false + end + -- se altrimenti carico dopo rotazione + elseif EMT.POSTROT then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = ROTATION_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EmtTleAddMachining( 'Rotation', EmtSecToHMS( dTime), ' - ', ' - ') + EMT.POSTROT = false + end + -- altrimenti, spostamento carrelli + else + if EMT.AUXTOT > 2 and EMT.AUXIND == EMT.AUXTOT then + local dTime = ( EMT.AUXTOT - 2) * CHAR_ONE_MOVE_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EmtTleAddMachining( 'Charriots move', EmtSecToHMS( dTime), ' - ', ' - ') + end + end +end + +--------------------------------------------------------------------- +function OnEstimPathEndAux() + -- verifico tipo di emissione + if EMT.OPEISDISP then + if not EMT.AUXTYPE then + local Cmd = EgtSplitString( EMT.AUX) + if Cmd[1] == '0' and Cmd[2] == 'Unloading' then + EMT.AUXTYPE = 'U' + else + EMT.AUXTYPE = 'R' + end + end + else + if not EMT.AUXTYPE then + local Cmd = EgtSplitString( EMT.AUX) + if Cmd[1] == '0' and Cmd[2] == 'Split' then + EMT.AUXTYPE = 'S' + elseif Cmd[1] == '0' and Cmd[2] == 'Unloading' then + EMT.AUXTYPE = 'U' + elseif Cmd[1] == '0' and Cmd[2] == 'Fall' then + EMT.AUXTYPE = 'F' + else + EMT.AUXTYPE = 'P' + end + end + end + -- per lo scarico della rimanenza + if EMT.AUXTYPE == 'R' then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = LOAD_T + UNLOAD_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EMT.TLE_NAME = 'Remnant unloading' + EMT.TLE_TIME = dTime + end + -- per lo split + elseif EMT.AUXTYPE == 'S' then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = SPLIT_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EMT.TLE_NAME = 'Splitting' + EMT.TLE_TIME = dTime + end + -- per lo scarico + elseif EMT.AUXTYPE == 'U' then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = UNLOAD_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EMT.TLE_NAME = 'Unloading' + EMT.TLE_TIME = dTime + end + -- per lo scarico a caduta + elseif EMT.AUXTYPE == 'F' then + if EMT.AUXIND == EMT.AUXTOT then + local dTime = FALL_T + EMT.TOTEXTTIME = EMT.TOTEXTTIME + dTime + EMT.TLE_NAME = 'Fall' + EMT.TLE_TIME = dTime + end + -- per la pre-rotazione + elseif EMT.AUXTYPE == 'P' then + ; -- calcolato come parte della rotazione + end +end + +--------------------------------------------------------------------- +function OnEstimRapid() + -- dati movimento + local dL1 = EMT.L1 - EMT.L1p + local dL2 = EMT.L2 - EMT.L2p + local dL3 = EMT.L3 - EMT.L3p + local dR1 = 0 + if EMT.R1 and EMT.R1p then dR1 = EMT.R1 - EMT.R1p end + local dR2 = 0 + if EMT.R2 and EMT.R2p then dR2 = EMT.R2 - EMT.R2p end + -- se primo posizionamento della lavorazione il movimento di L1 è già conteggiato in quello dei carrelli + if EMT.MCHMOVEFIRST then + EMT.MCHMOVEFIRST = false + dL1 = 0 + end + -- calcolo lunghezza + local dLen = sqrt( dL1 * dL1 + dL2 * dL2 + dL3 * dL3) + EMT.MCHEXTLEN = EMT.MCHEXTLEN + dLen + -- calcolo tempo + local dTime = RAPID_MIN_T + local dT1 = abs( dL1) / RAPID_X_FEED * 60 + if dT1 > dTime then dTime = dT1 end + local dT2 = abs( dL2) / RAPID_Y_FEED * 60 + if dT2 > dTime then dTime = dT2 end + local dT3 = abs( dL3) / RAPID_Z_FEED * 60 + if dT3 > dTime then dTime = dT3 end + local dT4 = abs( dR1) / RAPID_C_FEED * 60 + if dT4 > dTime then dTime = dT4 end + local dT5 = abs( dR2) / RAPID_B_FEED * 60 + if dT5 > dTime then dTime = dT5 end + EMT.MCHEXTTIME = EMT.MCHEXTTIME + dTime + EgtOutLog( string.format( ' G0 Len=%.0f Rot=%.0f° Time=%.2f', dLen, abs( dR1) + abs( dR2), dTime), 5) + -- aggiorno valori come precedenti + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +function OnEstimLinear() + -- dati movimento + local dL1 = EMT.L1 - EMT.L1p + local dL2 = EMT.L2 - EMT.L2p + local dL3 = EMT.L3 - EMT.L3p + -- calcolo lunghezza + local dLen = sqrt( dL1 * dL1 + dL2 * dL2 + dL3 * dL3) + EMT.MCHCUTLEN = EMT.MCHCUTLEN + dLen + -- calcolo tempo + local dTime = dLen / EMT.F * 60 + EMT.MCHCUTTIME = EMT.MCHCUTTIME + dTime + EgtOutLog( string.format( ' G1 Len=%.0f Time=%.2f', dLen, dTime), 5) + -- aggiorno valori come precedenti + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +function OnEstimArc() + -- dati movimento + local dLxy = EMT.RR * abs( EMT.AC) * pi / 180 + local dLz = abs( ( Point3d( EMT.L1, EMT.L2, EMT.L3) - Point3d( EMT.L1p, EMT.L2p, EMT.L3p)) * Vector3d( EMT.EXTR)) + -- calcolo lunghezza + local dLen = sqrt( dLxy * dLxy + dLz * dLz) + EMT.MCHCUTLEN = EMT.MCHCUTLEN + dLen + -- calcolo tempo + local dTime = dLen / EMT.F * 60 + EMT.MCHCUTTIME = EMT.MCHCUTTIME + dTime + EgtOutLog( string.format( ' G2 Len=%.0f Time=%.2f', dLen, dTime), 5) + -- aggiorno valori come precedenti + EmtUpdatePrev() +end + +--------------------------------------------------------------------- +-- *** GENERAL *** +--------------------------------------------------------------------- +function FindFirstToolOnHead( sH1) + -- salvo stato iniziale + local CurrMachId = EgtGetCurrMachining() + local CurrTool = EgtTdbGetCurrToolParam( MCH_TP.NAME) + -- cerco lavorazione con utensile su testa indicata + local sTool, nTlen + local OpId = EgtGetFirstActiveOperation() + while OpId do + local nType = EgtGetOperationType( OpId) + if nType ~= MCH_OY.NONE and nType ~= MCH_OY.DISP then + if EgtSetCurrMachining( OpId) then + local sTest = EgtGetMachiningParam( MCH_MP.TOOL) + if EgtTdbSetCurrTool( sTest) then + local sHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + if sHead and ( sHead == sH1) then + sTool = sTest + nTlen = EgtTdbGetCurrToolParam( MCH_TP.TOTLEN) + break + end + end + end + end + OpId = EgtGetNextActiveOperation( OpId) + end + -- ripristino stato iniziale + if CurrMachId then + EgtSetCurrMachining( CurrMachId) + else + EgtResetCurrMachining() + end + if CurrTool then + EgtTdbSetCurrTool( CurrTool) + else + EgtTdbSetCurrTool( '') + end + -- restituisco risultato + return sTool, nTlen +end + +--------------------------------------------------------------------- +function GetDefaultToolName( nHead) + local DefTcPos = EgtIf( nHead == 2, DefTc2Pos, DefTc1Pos) + local vTools = EgtGetToolsInCurrSetupPos( DefTcPos) + if vTools and vTools[1] and #vTools[1] > 0 then + return vTools[1] + else + local sErr = 'Missing tool in Default Position ' .. DefTcPos + EgtOutLog( 'Error : ' .. sErr) + if EMT.VER and EMT.VER >= '2.3a2' and EMT.SIM1ST then + EgtOutBox( sErr, 'ERROR', 'ERROR') + end + return '' + end +end + +--------------------------------------------------------------------- +function GetNextTool( nMchId) + -- inizializzo prossimo utensile + local sNextTool + -- recupero lavorazione successiva + local nNextMchId = EgtGetNextActiveOperation( nMchId) + while nNextMchId do + if EgtGetOperationType( nNextMchId) ~= MCH_OY.DISP then + break + end + nNextMchId = EgtGetNextActiveOperation( nNextMchId) + end + -- se trovata + if nNextMchId and EgtSetCurrMachining( nNextMchId) then + sNextTool = EgtGetMachiningParam( MCH_MP.TOOL) + end + -- ripristino stato corrente + EgtSetCurrMachining( EMT.MCHID) + EgtTdbSetCurrTool( EMT.TOOL) + return sNextTool +end + +--------------------------------------------------------------------- +function IsStartPhase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'START') +end + +--------------------------------------------------------------------- +function IsRestPhase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'REST') +end + +--------------------------------------------------------------------- +function IsStartOrRestPhase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'START' or sVal == 'REST') +end + +--------------------------------------------------------------------- +function IsMidPhase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'MID') +end + +--------------------------------------------------------------------- +function IsMid2Phase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'MID2') +end + +--------------------------------------------------------------------- +function IsEnd2Phase( nPhase) + local sVal = GetPhaseType( nPhase) + return ( sVal == 'END2') +end + +--------------------------------------------------------------------- +function GetPhaseType( nPhase) + return ( EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') or '') +end + +--------------------------------------------------------------------- +function GetPhaseOrd( nPhase) + return ( EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'ORD', 'i') or 0) +end + +--------------------------------------------------------------------- +function GetPhaseRot( nPhase) + return ( EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'ROT', 'i') or 0) +end + +--------------------------------------------------------------------- +-- *** END GENERAL *** +--------------------------------------------------------------------- diff --git a/Essetre-TURN.mlse b/Essetre-TURN.mlse new file mode 100644 index 0000000..1e0ed0f --- /dev/null +++ b/Essetre-TURN.mlse @@ -0,0 +1,3775 @@ +-- Special Operations macchina Essetre-TURN by EgalTech s.r.l. 2022/11/30 +-- 2022/04/04 DS ver 2.4d1 Prima versione. + +-- Intestazioni +require( 'EmtGenerator') +EgtEnableDebug( false) + +-- Carico i dati globali +local sBaseDir = EgtGetSourceDir() +local BD = dofile( sBaseDir .. 'Beam\\BeamData.lua') + +EgtOutLog ( '** Essetre-TURN '..PP_VER..' **', 1) + + +---------------------- OnSpecialGetMaxZ ----------------------------- +--------------------------------------------------------------------- +function OnSpecialGetMaxZ() + -- Inizializzazioni + EMC.ERR = 0 + local nHSet = GetHeadSet( EMC.HEAD) + if nHSet == 1 then + EMC.MAXZ = MaxX1 - 0.5 + elseif nHSet == 2 then + EMC.MAXZ = MaxX2 - 0.5 + else + EMC.ERR = 1 + end +end + +---------- OnSpecialApplyDisposition & OnPostApplyMachining --------- +----------------------- Costanti ------------------------------------ +local DELTA_TOL_V = 110 +local DELTA_TOL_S = 210 +local DELTA_TOL_L = 410 +local DELTA_TOL_FIXED = 50 +local DeltaTol = DELTA_TOL_S +local DELTA_SIC = 1 +local AGG_LOAD = 50 +local AGG_B_SPLIT = 0 +local MIN_JOIN_VV = 75 +local MIN_JOIN_SS = 100 +local MIN_JOIN_LS = 100 +local MIN_JOIN_SL = 290 +local MIN_JOIN_LL = 400 +local MinJoin = MIN_JOIN_SS +local MinOther = abs( MinY) + abs( MaxV) + MinJoin + +----------------------- Variabili ----------------------------------- +local Test = false + +--------------------------------------------------------------------- +local function PrepareClGroup( nParentId) + + local nClId = EgtGetFirstNameInGroup( nParentId, 'CL') + -- se non c'è, lo aggiunge + if not nClId then + nClId = EgtGroup( EMC.DISPID) + if not nClId then + return nil + end + EgtSetName( nClId, 'CL') + -- altrimenti lo svuoto + else + EgtEmptyGroup( nClId) + end + + return nClId +end + +--------------------------------------------------------------------- +local function IsStartOrRestPhase( nPhase) + local sVal = EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') + return ( sVal == 'START' or sVal == 'REST') +end + +--------------------------------------------------------------------- +local function IsMidPhase( nPhase) + local sVal = EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') + return ( sVal == 'MID') +end + +--------------------------------------------------------------------- +local function IsEndPhase( nPhase) + local sVal = EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') + return ( sVal == 'END') +end + +--------------------------------------------------------------------- +local function IsMid2Phase( nPhase) + local sVal = EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') + return ( sVal == 'MID2') +end + +--------------------------------------------------------------------- +local function IsEnd2Phase( nPhase) + local sVal = EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'TYPE') + return ( sVal == 'END2') +end + +--------------------------------------------------------------------- +local function GetNextStartOrRestPhase( nPhase) + local nNextPhase = nPhase + 1 + while nNextPhase <= EgtGetPhaseCount() do + if IsStartOrRestPhase( nNextPhase) then + break ; + end + nNextPhase = nNextPhase + 1 + end + return nNextPhase +end + +--------------------------------------------------------------------- +local function GetPhaseRot( nPhase) + return ( EgtGetInfo( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL, 'ROT', 'i') or 0) +end + +--------------------------------------------------------------------- +local function IsLastOperationBeforeRotation( nOperId) + -- se ultima fase o ultima fase del pezzo, ritorno risultato negativo + if EMC.PHASE == EgtGetPhaseCount() or IsEndPhase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE) then + return false + end + -- recupero la successiva operazione attiva + local nNextOperId = EgtGetNextActiveOperation( nOperId) + -- se non esiste o non è una disposizione, ritorno risultato negativo + if not nNextOperId or EgtGetOperationType( nNextOperId) ~= MCH_OY.DISP then + return false + end + -- recupero le rotazioni della fase corrente e della prossima fase + local nRot = GetPhaseRot( EMC.PHASE) + local nNextRot = GetPhaseRot( EMC.PHASE + 1) + -- ritorno se sono diverse + return ( nRot ~= nNextRot) +end + +--------------------------------------------------------------------- +local function IsFirstMachiningAfterRotation( nMchId) + -- se prima fase o prima fase del pezzo, ritorno risultato negativo + if EMC.PHASE == 1 or IsStartOrRestPhase( EMC.PHASE) then + return false + end + -- recupero la precedente operazione attiva + local nPrevOperId = EgtGetPrevActiveOperation( nMchId) + -- se non esiste o non è una disposizione, ritorno risultato negativo + if not nPrevOperId or EgtGetOperationType( nPrevOperId) ~= MCH_OY.DISP then + return false + end + -- recupero le rotazioni della fase corrente e della fase precedente + local nRot = GetPhaseRot( EMC.PHASE) + local nPrevRot = GetPhaseRot( EMC.PHASE - 1) + -- ritorno se sono diverse + return ( nRot ~= nPrevRot) +end + +--------------------------------------------------------------------- +local function UpdateMinJoinDeltaTol() + local L_SMALL = 800 + local H_V = 90 + local H_S = 150 + local H_L = 250 + local W_V = 90 + local W_S = 200 + local W_L = 400 + if EMC.SB <= W_V and EMC.HB <= H_V then + MinJoin = MIN_JOIN_VV + DeltaTol = DELTA_TOL_V + elseif EMC.LB <= L_SMALL then + MinJoin = MIN_JOIN_SS + DeltaTol = DELTA_TOL_S + else + local dMinJoinS + local dMinJoinL + if EMC.SB <= W_S then + dMinJoinS = MIN_JOIN_SS + dMinJoinL = MIN_JOIN_LS + elseif EMC.SB <= W_L then + local Coeff = ( EMC.SB - W_S) / ( W_L - W_S) + dMinJoinS = ( 1 - Coeff) * MIN_JOIN_SS + Coeff * MIN_JOIN_SL + dMinJoinL = ( 1 - Coeff) * MIN_JOIN_LS + Coeff * MIN_JOIN_LL + else + dMinJoinS = MIN_JOIN_SL + dMinJoinL = MIN_JOIN_LL + end + if EMC.HB <= H_S then + MinJoin = dMinJoinS + DeltaTol = DELTA_TOL_S + elseif EMC.HB <= H_L then + local Coeff = ( EMC.HB - H_S) / ( H_L - H_S) + MinJoin = ( 1 - Coeff) * dMinJoinS + Coeff * dMinJoinL + DeltaTol = ( 1 - Coeff) * DELTA_TOL_S + Coeff * DELTA_TOL_L + else + MinJoin = dMinJoinL + DeltaTol = DELTA_TOL_L + end + if EMC.SB < W_V then + DeltaTol = DELTA_TOL_V + end + end + MinOther = abs( MinY) + abs( MaxV) + MinJoin +end + +--------------------------------------------------------------------- +local function GetCUTID() + -- recupero CUTID del pezzo in lavoro + local nOrd = GetPhaseOrd( EMC.PHASE) + local nPartRawId + local nRawId = EgtGetFirstRawPart() + while nRawId do + local nRawOrd = EgtGetInfo( nRawId, 'ORD', 'i') + if nRawOrd == nOrd then + nPartRawId = nRawId + break + end + nRawId = EgtGetNextRawPart( nRawId) + end + local CutID = EgtGetInfo( EgtGetFirstPartInRawPart( nPartRawId or GDB_ID.NULL) or GDB_ID.NULL, 'CUTID', 'i') or 0 + return CutID +end + +--------------------------------------------------------------------- +local function EnsureZmax( bZmaxOk, vCmd) + if not bZmaxOk then table.insert( vCmd, { 1, 'Z', 0}) end + return true +end + +--------------------------------------------------------------------- +local function EmitComment( vCmd, sOut) + EgtOutLog( ' ' .. sOut, 1) + if Test then + table.insert( vCmd, { 0, sOut}) + end +end + +--------------------------------------------------------------------- +function OnSpecialApplyDisposition() + + EgtOutLog( ' *** Fase : ' .. EgtNumToString( EMC.PHASE, 0) .. ' ***', 1) + + -- Inizializzo codice di errore + EMC.ERR = 0 + + -- Campi obbligatori ma non usati + EMC.HEAD = "H14" + EMC.EXIT = 1 + EMC.TCPOS = "" + EMC.SHIFTS = 0 + EMC.SBH = false + + -- Se disposizione da saltare non devo fare alcunché + if EgtExistsInfo( EMC.DISPID, 'SKIP') then return end + + -- Assegno flag di pezzo separato dal resto del grezzo + local bSplit = IsEndPhase( EMC.PHASE) or IsMid2Phase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE) + + -- Recupero il tipo dell'operazione successiva + local nNextOpeType = EgtGetOperationType( EgtGetNextActiveOperation( EMC.DISPID) or GDB_ID.NULL) + + -- Se unica operazione o ci sono lavorazioni successive non devo fare alcunché + if ( EMC.PHASE == 1 and nNextOpeType == MCH_OY.NONE) or ( nNextOpeType ~= MCH_OY.NONE and nNextOpeType ~= MCH_OY.DISP) then return end + + -- Imposto gruppo e path di movimento + local nClId = PrepareClGroup( EMC.DISPID) + if not nClId then + EMC.ERR = 3 + return + end + local nPathId = EgtGroup( nClId) + if not nPathId then + EMC.ERR = 6 + return + end + EgtSetName( nPathId, 'Empty') + EMC.PATHID = nPathId + EMC.SHIFTS = -1 + + -- Se l'operazione successiva è una disposizione con rotazione, devo preparare il pezzo alla rotazione + if IsLastOperationBeforeRotation( EMC.DISPID) then + -- aggiornamento posizioni + if IsStartPhase( EMC.PHASE) then + -- carico le posizioni + local dPosT = EgtGetInfo( EMC.DISPID, 'TPOS', 'd') + local dPosY = EgtGetInfo( EMC.DISPID, 'YPOS', 'd') + EMC.TPOS = dPosT + EMC.YDELTA = dPosY - dPosT + EMC.VDELTA = nil + EMC.CNT = 1 + else + local nPrevOpeId = EgtGetPrevActiveOperation( EMC.DISPID) + local nLastPathId = EgtGetLastInGroup( EgtGetFirstNameInGroup( nPrevOpeId, 'CL') or GDB_ID.NULL) + local nLastEntId = EgtGetLastInGroup( nLastPathId) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + EMC.YDELTA = EgtGetInfo( nLastPathId, 'YDELTA', 'd') + EMC.VDELTA = EgtGetInfo( nLastPathId, 'VDELTA', 'd') + EMC.CNT = EgtGetInfo( nLastPathId, 'CNT', 'i') + end + -- Determinazione delle dimensioni del grezzo in lavoro + local b3Raw = BBox3d() + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtVerifyRawPartPhase( nRawId, EMC.PHASE) then + b3Raw = EgtGetRawPartBBox( nRawId) + break + end + nRawId = EgtGetNextRawPart( nRawId) + end + EMC.LB = b3Raw:getDimX() + 10 * GEO.EPS_SMALL + -- Assegno sovramateriale di testa e ingombro tagli di testa e di coda + EMC.HOVM = EgtGetInfo( nRawId, 'HOVM', 'd') or 0 + EMC.HCING = 0 + EMC.TCING = EgtGetInfo( nRawId, 'TCING', 'd') or 0 + -- Eseguo preparazione alla rotazione + local vCmd = SpecCalcPreRot() + SpecOutputCmds( vCmd, true) + return + end + + -- Se l'operazione successiva è ancora una disposizione, devo scaricare il pezzo + if nNextOpeType == MCH_OY.DISP and bSplit and not IsEnd2Phase( EMC.PHASE) then + -- aggiornamento posizioni + local nPrevOpeId = EgtGetPrevActiveOperation( EMC.DISPID) + local nLastPathId = EgtGetLastInGroup( EgtGetFirstNameInGroup( nPrevOpeId, 'CL') or GDB_ID.NULL) + local nLastEntId = EgtGetLastInGroup( nLastPathId) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + EMC.YDELTA = EgtGetInfo( nLastPathId, 'YDELTA', 'd') + EMC.VDELTA = EgtGetInfo( nLastPathId, 'VDELTA', 'd') + EMC.CNT = EgtGetInfo( nLastPathId, 'CNT', 'i') + -- Determinazione delle dimensioni del grezzo in lavoro + local b3Raw = BBox3d() + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtVerifyRawPartPhase( nRawId, EMC.PHASE) and not EgtVerifyRawPartPhase( nRawId, EMC.PHASE + 1) then + b3Raw = EgtGetRawPartBBox( nRawId) + break + end + nRawId = EgtGetNextRawPart( nRawId) + end + EMC.LB = b3Raw:getDimX() + 10 * GEO.EPS_SMALL + EMC.HOVM = EgtGetInfo( nRawId or GDB_ID.NULL, 'HOVM', 'd') or 0 + -- Eseguo scarico + local vCmd = SpecCalcUnload() + SpecOutputCmds( vCmd, true) + return + end + + -- Verifico ci sia un solo grezzo nella fase corrente + local nRawCount = 0 + local nCurrRawId = GDB_ID.NULL + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtVerifyRawPartPhase( nRawId, EMC.PHASE) then + nRawCount = nRawCount + 1 + nCurrRawId = nRawId + end + nRawId = EgtGetNextRawPart( nRawId) + end + + -- Determinazione delle sue dimensioni + local b3Raw = EgtGetRawPartBBox( nCurrRawId) + if b3Raw:isEmpty() then + EMC.ERR = 11 + return + end + EMC.LB = b3Raw:getDimX() + 10 * GEO.EPS_SMALL + EMC.SB = b3Raw:getDimY() + EMC.HB = b3Raw:getDimZ() + EMC.ZMIN = b3Raw:getMin():getZ() + + -- Aggiorno limiti di presa e tolleranza + UpdateMinJoinDeltaTol() + + -- Assegno sovramateriale di testa e ingombro tagli di testa e di coda + EMC.HOVM = 0 + EMC.HCING = 0 + EMC.TCING = 0 + + -- Devo scaricare il grezzo rimasto (deve essere unico) + -- Posizione trave + local dPosT + + -- Se fase 1 o dopo rotazione eseguo carico con carrello Y + local vCmd = {} + if EMC.PHASE == 1 or IsEnd2Phase( EMC.PHASE) then + dPosT = LoadT + if IsEnd2Phase( EMC.PHASE) then dPosT = dPosT + TurnerOffs end + vCmd = SpecCalcLoad( dPosT, 0, min( EMC.LB - MinOther - AGG_LOAD, MaxY - dPosT)) + -- se altrimenti fase successiva alla prima di tipo inizio o rimanenza + elseif IsStartOrRestPhase( EMC.PHASE) then + -- recupero posizione trave e quota di aggancio carrello + dPosT = EgtGetInfo( EMC.DISPID, 'TPOS', 'd') + local dPosY = EgtGetInfo( EMC.DISPID, 'YPOS', 'd') + -- se carrello agganciato + if dPosY then + -- confermo i nuovi parametri di aggancio + table.insert( vCmd, { 21, dPosY - dPosT, 0}) + -- recupero CNT + local nPrevOpeId = EgtGetPrevActiveOperation( EMC.DISPID) + if EgtGetOperationType( nPrevOpeId) == MCH_OY.DISP and EgtExistsInfo( nPrevOpeId, 'SKIP') then + nPrevOpeId = EgtGetPrevActiveOperation( nPrevOpeId) + end + local nLastPathId = EgtGetLastInGroup( EgtGetFirstNameInGroup( nPrevOpeId, 'CL') or GDB_ID.NULL) + EMC.CNT = EgtGetInfo( nLastPathId, 'CNT', 'i') + -- altrimenti è grezzo scaricato al carico e devo ricaricarlo + else + vCmd = SpecCalcLoad( dPosT, 0, min( EMC.LB - MinOther - AGG_LOAD, MaxY - dPosT)) + end + -- altrimenti fase successiva pari + else + local dPosV = EgtGetInfo( EMC.DISPID, 'VPOS', 'd') + EMC.VDELTA = dPosV + end + -- Se fase inizio o rimanenza, eseguo scambio per avere solo pinza V + local vCmd2 = {} + if IsStartOrRestPhase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE) then + EMC.TPOS = dPosT + SpecSetCarrPosFromCmds( vCmd) + local dDistFront = EgtIf( EMC.LB < abs( MinV - UnloadT), MinJoin, EMC.LB - abs( MinV - UnloadT) + MinJoin + DeltaTol) + vCmd2 = SpecCalcCarriages( dDistFront, 0) + if vCmd and #vCmd > 1 and vCmd2 and #vCmd2 > 1 then + table.insert( vCmd, { 0, 'CARR_MOVE'}) + end + end + -- eseguo scarico + SpecSetCarrPosFromCmds( vCmd2) + local vCmd3 = SpecCalcUnload() + -- unisco ed emetto i comandi + vCmd = EgtJoinTables( vCmd, vCmd2) + vCmd = EgtJoinTables( vCmd, vCmd3) + SpecOutputCmds( vCmd, true) +end + +--------------------------------------------------------------------- +function OnPostApplyMachining() + + EgtOutLog( ' Lavorazione : ' .. EgtGetName( EMC.MCHID), 1) + + -- Inizializzo codice di errore + EMC.ERR = 0 + + -- Recupero la posizione della trave e dei carrelli al termine della precedente operazione + local nPrevOpeId = EgtGetPrevActiveOperation( EMC.MCHID) + -- se precedente operazione non esiste, errore + if not nPrevOpeId then + EMC.ERR = 1 + return + -- se precedente operazione è disposizione + elseif EgtGetOperationType( nPrevOpeId) == MCH_OY.DISP then + if EMC.PHASE == 1 or IsFirstMachiningAfterRotation( EMC.MCHID) then + -- posizioni home + EMC.TPOS = nil + EMC.YDELTA = nil + EMC.VDELTA = nil + EMC.HCING_IGNORE = true + elseif IsStartOrRestPhase( EMC.PHASE) then + -- carico le posizioni + local dPosT = EgtGetInfo( nPrevOpeId, 'TPOS', 'd') + local dPosY = EgtGetInfo( nPrevOpeId, 'YPOS', 'd') + -- se carrello agganciato + if dPosY then + EMC.TPOS = dPosT + EMC.YDELTA = dPosY - dPosT + EMC.VDELTA = nil + -- altrimenti è grezzo scaricato al carico e devo ricaricarlo + else + EMC.TPOS = nil + EMC.YDELTA = nil + EMC.VDELTA = nil + end + EMC.HCING_IGNORE = true + else + -- aggiornamento posizioni (da lavorazione precedente a disposizione) + local nPrev2OpeId = EgtGetPrevActiveOperation( nPrevOpeId) + if not nPrev2OpeId then + EMC.ERR = 1 + return + end + local nLastPathId = EgtGetLastInGroup( EgtGetFirstNameInGroup( nPrev2OpeId, 'CL') or GDB_ID.NULL) + local nLastEntId = EgtGetLastInGroup( nLastPathId) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + EMC.YDELTA = EgtGetInfo( nLastPathId, 'YDELTA', 'd') + EMC.VDELTA = EgtGetInfo( nLastPathId, 'VDELTA', 'd') + end + EMC.CNT = nil + -- altrimenti precedente operazione è lavorazione + else + -- aggiornamento posizioni + local nLastPathId = EgtGetLastInGroup( EgtGetFirstNameInGroup( nPrevOpeId, 'CL') or GDB_ID.NULL) + local nLastEntId = EgtGetLastInGroup( nLastPathId) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + EMC.YDELTA = EgtGetInfo( nLastPathId, 'YDELTA', 'd') + EMC.VDELTA = EgtGetInfo( nLastPathId, 'VDELTA', 'd') + EMC.CNT = EgtGetInfo( nLastPathId, 'CNT', 'i') + end + + -- Verifico se ultima lavorazione della fase + local nNextOpeId = EgtGetNextActiveOperation( EMC.MCHID) + local bMchLast = ( not nNextOpeId or EgtGetOperationPhase( nNextOpeId) ~= EMC.PHASE) + + -- Verifico se ultima lavorazione prima di una rotazione + local bPreRotMch = IsLastOperationBeforeRotation( EMC.MCHID) + + -- Verifico flag di separazione e fase di scarico + local sNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) + local bPreSplit = ( sNotes:find( 'Presplit') ~= nil) + local bSplitting = ( sNotes:find( 'Split') ~= nil) + local bPreCut = ( sNotes:find( 'Precut') ~= nil) + local bCutting = ( sNotes:find( 'Cut') ~= nil) + local bUnload = IsEndPhase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE) + if bPreSplit or bPreCut then + EgtSetInfo( EMC.MCHID, 'IS_PRE', '1') + else + EgtRemoveInfo( EMC.MCHID, 'IS_PRE') + end + + -- Agisco sui diversi percorsi della lavorazione + local nPathId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( EMC.MCHID, 'CL') or GDB_ID.NULL) + while nPathId do + -- assegno id percorso da elaborare + EMC.PATHID = nPathId + -- recupero id del successivo + nPathId = EgtGetNext( nPathId) + -- verifico se ultimo percorso di ultima lavorazione della fase + local bLast = ( bMchLast and ( not nPathId)) + -- se ultimo, elimino ritorno in home + if bLast then EgtRemoveOperationHome( EMC.MCHID) end + -- salvo lo stato di trave e carrelli + local OriTPos = EMC.TPOS + local OriYDelta = EMC.YDELTA + local OriVDelta = EMC.VDELTA + local OriCnt = EMC.CNT + -- eseguo le elaborazioni + SpecApplyPath( bPreSplit, bSplitting, bPreCut, bCutting, bLast and bUnload, bLast and bPreRotMch) + -- se separazione, verifico il risultato + if bSplitting then + -- recupero CUTID del pezzo in lavoro + local CutID = GetCUTID() + -- in caso di errore mancato pinzaggio uscita riprovo dopo aver disabilitato le lavorazioni finali + if EMC.ERR == 18 then + -- segnalazione warning + EMC.ERR = -101 + EMC.MSG = 'Warning : skipped final processes (WRN=101,CUTID='..tostring( CutID)..')' + -- ripristino lo stato originale di trave e carrelli + EMC.TPOS = OriTPos + EMC.YDELTA = OriYDelta + EMC.VDELTA = OriVDelta + EMC.CNT = OriCnt + -- eseguo le elaborazioni + SpecApplyPath( bPreSplit, bSplitting, bPreCut, bCutting, bLast and bUnload, bLast and bPreRotMch) + -- pinzaggio ancora impossibile, pezzo a caduta + if EMC.ERR == 18 then + -- segnalazione warning + EMC.ERR = -102 + EMC.MSG = 'Warning : skipped final processes and unload by fall (WRN=102,CUTID='..tostring( CutID)..')' + end + -- scarico standard + elseif EMC.ERR == 0 then + -- segnalazione warning + EMC.ERR = -100 + EMC.MSG = 'Warning : standard unload (WRN=100,CUTID='..tostring( CutID)..')' + end + -- se taglio del residuo finale, scarico standard + elseif bCutting then + -- recupero CUTID del pezzo in lavoro + local CutID = GetCUTID() + -- se non ci sono errori, segnalazione warning + if EMC.ERR == 0 then + EMC.ERR = -100 + EMC.MSG = 'Warning : standard unload (WRN=100,CUTID='..tostring( CutID)..')' + end + end + if EMC.ERR > 0 then return end + -- determino la posizione finale della trave + local nLastEntId = EgtGetLastInGroup( EMC.PATHID) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + end + +end + +--------------------------------------------------------------------- +function SpecApplyPath( bPreSplit, bSplitting, bPreCut, bCutting, bUnload, bPreRotMch) + + -- Assegno flag di pezzo separato dal resto del grezzo + local bSplit = IsEndPhase( EMC.PHASE) or IsMid2Phase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE) + + -- Assegno flag di pezzo in separazione + local bFixedDelta = ( bPreSplit or bSplitting or bPreCut or bCutting) + + -- Se separazione o taglio del grezzo finale, verifico se precedente era una preparazione + local bFixedPos = false + if bPreSplit or bSplitting or bPreCut or bCutting then + local nPrevOpeId = EgtGetPrevActiveOperation( EMC.MCHID) + bFixedPos = EgtExistsInfo( nPrevOpeId or GDB_ID.NULL, 'IS_PRE') + end + + -- Determinazione delle dimensioni totali dei grezzi e del grezzo in lavoro + local b3Tot = BBox3d() + local b3Raw = BBox3d() + local nNextOddPhase = GetNextStartOrRestPhase( EMC.PHASE) + local nRawId = EgtGetFirstRawPart() + local nCurrRawId = GDB_ID.NULL + while nRawId do + if EgtVerifyRawPartPhase( nRawId, EMC.PHASE) then + local b3Tmp = EgtGetRawPartBBox( nRawId) + b3Tot:Add( b3Tmp) + if EgtGetPartInRawPartCount( nRawId) > 0 and not EgtVerifyRawPartPhase( nRawId, nNextOddPhase) then + b3Raw = b3Tmp + nCurrRawId = nRawId + end + end + nRawId = EgtGetNextRawPart( nRawId) + end + if b3Tot:isEmpty() then + EMC.ERR = 11 + return + end + EMC.LB = EgtIf( bSplit, b3Raw:getDimX(), b3Tot:getDimX()) + 10 * GEO.EPS_SMALL + EMC.SB = b3Tot:getDimY() + EMC.HB = b3Tot:getDimZ() + EMC.LR = b3Raw:getDimX() + 10 * GEO.EPS_SMALL + EMC.YMIN = b3Raw:getMin():getY() + EMC.ZMIN = b3Raw:getMin():getZ() + + -- Aggiorno limiti di presa e tolleranza + UpdateMinJoinDeltaTol() + + -- Recupero sovramateriale di testa e ingombro tagli di testa e di coda + EMC.HOVM = EgtGetInfo( nCurrRawId, 'HOVM', 'd') or 0 + EMC.HCING = EgtGetInfo( nCurrRawId, 'HCING', 'd') or 0 + EMC.TCING = EgtGetInfo( nCurrRawId, 'TCING', 'd') or 0 + + -- Calcolo dell'ingombro della lavorazione + local dDistFront, dDistBack = SpecialCalcMachiningEncumbrance( EMC.MCHID, bPreCut) + if not dDistFront or not dDistBack then return end + if bPreSplit or bSplitting then + local dDistF = SpecialCalcPhaseEncumbrance( EMC.PHASE + 1) + dDistFront = min( dDistFront, dDistF) + local dNextHOVM = EgtGetInfo( EgtGetNextRawPart( nCurrRawId) or GDB_ID.NULL, 'HOVM', 'd') or 0 + dDistBack = dDistBack - AGG_B_SPLIT - max( dNextHOVM - 300, 0) + elseif bPreCut or bCutting then + local dDistF = SpecialCalcPhaseEncumbrance( EMC.PHASE + 1) + dDistFront = min( dDistFront, dDistF) + dDistBack = 0.0 + end + + -- Verifico lunghezza pezzo + if not bSplit and not VerifyPartLength() then + return + end + + -- Se inizio o appena dopo rotazione, eseguo il carico + if not EMC.TPOS then + local dPosT = LoadT + if IsFirstMachiningAfterRotation( EMC.MCHID) then dPosT = dPosT + TurnerOffs end + local vCmd = SpecCalcLoad( dPosT, dDistFront, max( dDistBack, MinJoin)) + local vCmd2 = SpecCalcCarriages( dDistFront, dDistBack, bFixedDelta, bFixedPos) + if vCmd2 and #vCmd2 > 1 then + table.insert( vCmd, { 0, 'CARR_MOVE'}) + end + EgtJoinTables( vCmd, vCmd2) + SpecOutputCmds( vCmd) + + -- Se altrimenti carri entrambi diponibili, eseguo calcoli per carrelli + elseif not IsEndPhase( EMC.PHASE) then + local vCmd = SpecCalcCarriages( dDistFront, dDistBack, bFixedDelta, bFixedPos) + -- Se non ci sono spostamenti, confermo i parametri di aggancio + if SpecTestOnlyRemarkInCmds( vCmd) then + table.insert( vCmd, { 21, EgtIf( EMC.YDELTA, EMC.YDELTA, 0), EgtIf( EMC.VDELTA, EMC.VDELTA, 0)}) + end + SpecOutputCmds( vCmd) + + -- Altrimenti, non muovo i carrelli rispetto alla trave + else + local vCmd = {} + SpecOutputCmds( vCmd) + end + EMC.HCING_IGNORE = nil + + -- Se taglio di separazione + local vCmd = {} + if bSplitting then + -- rimuovo eventuale vecchia info di Skip + local NextDispId = EgtGetPhaseDisposition( EMC.PHASE + 1) or GDB_ID.NULL + EgtRemoveInfo( NextDispId, 'SKIP') + -- verifico se separazione con caduta + if not EMC.VDELTA then + EgtOutLog( ' Warning SPLITTING -> separazione con caduta pezzo') + if IsEndPhase( EMC.PHASE + 1) then + EgtSetInfo( NextDispId, 'SKIP', '1') + local NextOpeId = EgtGetNextOperation( NextDispId) + while NextOpeId and EgtGetOperationPhase( NextOpeId) == EMC.PHASE + 1 do + EgtSetOperationMode( NextOpeId, false) + NextOpeId = EgtGetNextOperation( NextOpeId) + end + end + EMC.ERR = 18 + -- verifico che la barra sia agganciata ad entrambi i carrelli + elseif not EMC.YDELTA or not EMC.VDELTA then + EMC.ERR = 19 + EMC.MSG = ' Error SPLIT : Y or V not clamped' + return false + end + -- eseguo la separazione ( standard o di pezzo ruotato) + if not IsMid2Phase( EMC.PHASE + 1) then + vCmd = SpecCalcSplit( b3Raw:getDimX()) + else + vCmd = SpecCalcSplitRot( b3Raw:getDimX()) + end + end + -- Se taglio finale di grezzo a perdere + if bCutting then + -- salvo distanza carrello V da inizio grezzo rimasto nella disposizione della prossima fase + local NextDispId = EgtGetPhaseDisposition( EMC.PHASE + 1) + if NextDispId then + EgtSetInfo( NextDispId, 'VPOS', EMC.VDELTA) + end + end + + -- Se previsto scarico, lo eseguo + if bUnload then + EMC.LB = b3Raw:getDimX() + 10 * GEO.EPS_SMALL + local vCmdTmp = SpecCalcUnload() + vCmd = EgtJoinTables( vCmd, vCmdTmp) + end + + -- Se ritorno al carico per rotazione + if bPreRotMch then + -- determino posizione testa trave + local nLastEntId = EgtGetLastInGroup( EMC.PATHID) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + -- eseguo movimento prima di rotazione + local vCmdTmp = SpecCalcPreRot() + vCmd = EgtJoinTables( vCmd, vCmdTmp) + end + + -- Emetto eventuali comandi di separazione e/o scarico + if #vCmd > 0 then + SpecOutputCmds( vCmd, true) + end + +end --SpecApplyPath( bLast) + +--------------------------------------------------------------------- +function SpecialCalcMachiningEncumbrance( nMchId, bPreCut) + -- gruppi della lavorazione + local nClId = EgtGetFirstNameInGroup( nMchId, 'CL') + local nPathId = EgtGetFirstInGroup( nClId or GDB_ID.NULL) + if not nPathId then + EMC.ERR = 12 + return + end + -- recupero ptMin ptMax della lavorazione + local ptMin = EgtGetInfo( nClId, 'MMIN', 'p') + local ptMax = EgtGetInfo( nClId, 'MMAX', 'p') + if not ptMin or not ptMax then + EMC.ERR = 13 + return + end + -- se pre-taglio, aggiorno ptMax con quello del taglio finale + if bPreCut then + local ptFinMax = GetFinalCutPmax( nMchId) + if ptFinMax then + ptMax = ptFinMax + end + end + -- Recupero del vettore estrusione (coincide con il vettore utensile) + local vtTool = EgtGetInfo( nPathId, 'EXTR', 'v') + if not vtTool then + EMC.ERR = 14 + return + end + -- Recupero testa + local sHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + -- Calcolo del vettore ausiliario + local vAxes = EmtGetAxesPos( EgtGetFirstInGroup( nPathId)) + if not vAxes or #vAxes < 5 or ( sHead == 'H3' and #vAxes < 6) then + EMC.ERR = 15 + return + end + local vtAux = EgtGetCalcAuxDirFromAngles( vAxes[4], vAxes[5], vAxes[6]) + if not vtAux then + EMC.ERR = 16 + return + end + -- Recupero dei dati dell'utensile + local nToolType = EgtTdbGetCurrToolParam( MCH_TP.TYPE) + local bSaw = ( nToolType == MCH_TY.SAW_STD or nToolType == MCH_TY.SAW_FLAT) + local bChain = ( nToolType == MCH_TY.MORTISE_STD) + local dTLen = EgtTdbGetCurrToolParam( MCH_TP.LEN) + local dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + -- Calcolo limiti derivanti dalla lavorazione + local dDistFront, dDistBack = SpecCalcEncumbrance( vtTool, vtAux, ptMin, ptMax, bSaw, bChain, dTLen, dTDiam) + return dDistFront, dDistBack +end + +--------------------------------------------------------------------- +function SpecialCalcPhaseEncumbrance( nPhase) + -- Deve essere la fase finale di lavorazione di un pezzo (già staccato dal resto della trave) + local dDistFront = EMC.LB + local dDistBack = EMC.LB + -- Salvo lavorazione e utensile correnti, per ripristinarli alla fine + local nOrigMchId = EgtGetCurrMachining() + local sOrigTool = EgtTdbGetCurrToolParam( MCH_TP.NAME) + local sOrigHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + local nOrigExit = EgtTdbGetCurrToolParam( MCH_TP.EXIT) + -- Ciclo sulle lavorazioni + local nMchId = EgtGetNextActiveOperation( EgtGetPhaseDisposition( nPhase) or GDB_ID.NULL) + while nMchId and EgtGetOperationPhase( nMchId) == nPhase do + -- imposto lavorazione e utensile correnti + EgtSetCurrMachining( nMchId) + local sTool = EgtGetMachiningParam( MCH_MP.TOOL) + if not EgtTdbSetCurrTool( sTool) then + local sTuuid = EgtGetMachiningParam( MCH_MP.TUUID) + sTool = EgtTdbGetToolFromUUID( sTuuid) + EgtTdbSetCurrTool( sTool) + end + local sHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + local nExit = EgtTdbGetCurrToolParam( MCH_TP.EXIT) + if sTool and sHead and nExit then EgtSetCalcTool( sTool, sHead, nExit) end + -- calcolo ingombri + local dDistF, dDistB = SpecialCalcMachiningEncumbrance( nMchId) + if dDistF and dDistB then + dDistFront = min( dDistFront, dDistF) + dDistBack = min( dDistBack, dDistB) + end + nMchId = EgtGetNextActiveOperation( nMchId) + end + -- Ripristino lavorazione e utensile correnti + if nOrigMchId then EgtSetCurrMachining( nOrigMchId) end + if sOrigTool then EgtTdbSetCurrTool( sOrigTool) end + if sOrigTool and sOrigHead and nOrigExit then EgtSetCalcTool( sOrigTool, sOrigHead, nOrigExit) end + -- Restituisco gli ingombri trovati + return dDistFront, dDistBack +end + +--------------------------------------------------------------------- +function GetFinalCutPmax( nMchId) + local nFinalCutId + local nId = EgtGetNextActiveOperation( nMchId) + while nId and EgtGetOperationPhase( nId) == EMC.PHASE do + nFinalCutId = nId + nId = EgtGetNextActiveOperation( nId) + end + if not nFinalCutId then return end + local nCLId = EgtGetFirstNameInGroup( nFinalCutId, 'CL') + if not nCLId then return end + return EgtGetInfo( nCLId, 'MMAX', 'p') +end + +--------------------------------------------------------------------- +function SpecCalcEncumbrance( vtTool, vtArm, ptMin, ptMax, bSaw, bChain, dTLen, dTDiam) + -- Quota in Z dal punto di inclinazione dei carrelli + local dCompZ = sqrt( 1 - vtTool:getZ() * vtTool:getZ()) + local dZup = ptMin:getZ() - 0.5 * dCompZ * dTDiam - ( EMC.ZMIN + 130) + -- Ingombro a sinistra + local dDistBack = EMC.LB + ptMin:getX() + LoadT + local dHeadBack = 350 + if bSaw then + if vtTool:getX() > 0 and abs( vtTool:getY()) < 0.088 and abs( vtTool:getZ()) < 0.088 then + dHeadBack = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif abs( vtTool:getZ()) < 0.26 and abs( vtTool:getX()) < 0.35 then + dHeadBack = 350 + elseif abs( vtTool:getZ()) < 0.26 and abs( vtTool:getX()) < 0.71 then + dHeadBack = EgtIf( vtTool:getX() > 0, 50, 90) + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif ( vtTool:getX() > 0.7 and abs( vtTool:getY()) < 0.2 and ptMax:getZ() > EMC.ZMIN + 0.9 * EMC.HB) then + if vtTool:getZ() > 0 then + dHeadBack = max( 50, 90 - 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX())) + else + dHeadBack = max( 50, 40 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX())) + end + if ptMax:getZ() < EMC.ZMIN + BD.VICE_MINH then + dHeadBack = dHeadBack + BD.VICE_MINH + end + elseif ( vtTool:getX() > 0.2 and abs( vtTool:getZ()) < 0.5) then + dHeadBack = max( 90, 40 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX())) + elseif abs( vtTool:getZ()) < 0.93 then + if vtTool:getX() > 0 and abs( vtTool:getY()) < 0.2 and ptMax:getZ() > EMC.ZMIN + BD.VICE_MINH then + dHeadBack = 180 + elseif vtTool:getX() > -0.05 then + dHeadBack = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif vtTool:getX() > -0.3 then + dHeadBack = 250 + elseif vtTool:getX() > -0.707 then + dHeadBack = 350 + elseif vtTool:getX() > -0.8667 then + dHeadBack = 450 + else + dHeadBack = 650 + end + else + dHeadBack = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + end + else + if vtTool:getX() > 0.5 then + dHeadBack = max( 50, dTDiam / 2 * abs( vtTool:getZ()) + 20) + elseif vtTool:getX() > -0.1 then + dHeadBack = max( 180, dTDiam / 2 + 20) + elseif vtTool:getX() < -0.8 then + dHeadBack = 675 + elseif vtTool:getX() < -0.75 then + dHeadBack = 650 + elseif vtTool:getX() < -0.5 then + dHeadBack = 450 + end + if vtTool:getX() < -0.25 then + dHeadBack = dHeadBack + max( dTLen - 130, 0) * abs( vtTool:getX()) + elseif vtTool:getX() < 0 then + dHeadBack = dHeadBack + ( dTLen + 180) * abs( vtTool:getX()) + end + if vtTool:getX() > 0.866 then + dHeadBack = 50 + elseif vtTool:getX() >= 0 and dZup > 0 then + dHeadBack = max( EgtIf( EMC.CNT == 1, 180, 130), dHeadBack - dZup) + end + if abs( vtTool:getX()) < 0.5 and abs( vtTool:getZ()) > 0.259 and dZup < 0 then + dHeadBack = 260 + end + -- per evitare collisione asse X pinza Y rinforzo posteriore + if EMC.SB > 300 then + dHeadBack = max( dHeadBack, 500) + end + end + -- Ingombro a destra + local dDistFront = - ptMax:getX() - LoadT + local dHeadFront = 350 + if bSaw then + if vtTool:getX() < 0 and abs( vtTool:getY()) < 0.088 and abs( vtTool:getZ()) < 0.088 then + dHeadFront = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif abs( vtTool:getZ()) < 0.26 and abs( vtTool:getX()) < 0.35 then + dHeadFront = 350 + elseif abs( vtTool:getZ()) < 0.26 and abs( vtTool:getX()) < 0.71 then + dHeadFront = EgtIf( vtTool:getX() < 0, 50, 90) + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif ( vtTool:getX() < - 0.7 and abs( vtTool:getY()) < 0.2 and ptMax:getZ() > EMC.ZMIN + 0.9 * EMC.HB) then + if vtTool:getZ() > 0 then + dHeadFront = max( 50, 90 - 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX())) + else + dHeadFront = max( 50, 40 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX())) + end + if ptMax:getZ() < EMC.ZMIN + BD.VICE_MINH then + dHeadFront = dHeadFront + BD.VICE_MINH + end + elseif ( vtTool:getX() < -0.2 and abs( vtTool:getZ()) < 0.5) then + dHeadFront = max( 90, 40 + 0.5 * dTDiam * sqrt( vtTool:getY() * vtTool:getY() + vtTool:getZ() * vtTool:getZ())) + elseif abs( vtTool:getZ()) < 0.93 then + if vtTool:getX() < 0 and abs( vtTool:getY()) < 0.2 and ptMax:getZ() > EMC.ZMIN + BD.VICE_MINH then + dHeadFront = 180 + elseif vtTool:getX() < 0.05 then + dHeadFront = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + elseif vtTool:getX() < 0.3 then + dHeadFront = 250 + elseif vtTool:getX() < 0.707 then + dHeadFront = 350 + elseif vtTool:getX() < 0.8667 then + dHeadFront = 450 + else + dHeadFront = 650 + end + else + dHeadFront = 50 + 0.5 * dTDiam * sqrt( 1 - vtTool:getX() * vtTool:getX()) + end + else + if vtTool:getX() < -0.5 then + dHeadFront = max( 50, dTDiam / 2 * abs( vtTool:getZ()) + 20) + elseif vtTool:getX() < 0.1 then + dHeadFront = max( 180, dTDiam / 2 + 20) + elseif vtTool:getX() > 0.8 then + dHeadFront = 675 + elseif vtTool:getX() > 0.75 then + dHeadFront = 650 + elseif vtTool:getX() > 0.5 then + dHeadFront = 450 + end + if vtTool:getX() > 0.25 then + dHeadFront = dHeadFront + max( dTLen - 130, 0) * vtTool:getX() + elseif vtTool:getX() > 0 then + dHeadFront = dHeadFront + ( dTLen + 180) * vtTool:getX() + end + if vtTool:getX() < -0.866 then + dHeadFront = 50 + elseif vtTool:getX() <= 0 and dZup > 0 then + dHeadFront = max( 130, dHeadFront - dZup) + end + if abs( vtTool:getX()) < 0.5 and abs( vtTool:getZ()) > 0.259 and dZup < 0 then + dHeadFront = 260 + end + end + -- Stampe debug + EgtOutLog( ' Tdir=' .. tostring( vtTool) .. ' Adir=' .. tostring( vtArm) .. ' Zup=' .. EgtNumToString( dZup), 3) + EgtOutLog( ' DistFront=' .. EgtNumToString( dDistFront) .. ' DistBack=' .. EgtNumToString( dDistBack) .. + ' HeadFront=' .. EgtNumToString( dHeadFront) .. ' HeadBack=' .. EgtNumToString( dHeadBack), 3) + -- Restituisco ingombri effettivi + return ( dDistFront - dHeadFront), ( dDistBack - dHeadBack) +end + +--------------------------------------------------------------------- +function VerifyPartLength() + + -- Verifico lunghezza pezzo + if EMC.LB < MinJoin + MinOther + AGG_LOAD + EMC.HCING + EMC.HOVM then + EgtOutLog( ' Error CLAMP -> pezzo troppo corto') + EMC.ERR = 17 + return false + end + + return true +end + +--------------------------------------------------------------------- +function SpecCalcLoad( dPosT, dDistFront, dDistBack) + --[L] + local dMinDistBack= max( dDistBack, MinJoin + EgtIf( IsMid2Phase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE), EMC.TCING, 0)) + local dNewYDelta = max( EMC.LB - dMinDistBack, MinOther + AGG_LOAD + EMC.HCING + EMC.HOVM) + local dNewVDelta = nil + local dNewY = dPosT + TurnerOffs + dNewYDelta + local vCmd = {} + EgtOutLog( ' *[L]', 1) + -- [L-1] + if dNewY - MaxY > 0 then + dNewYDelta = min( EMC.LB - MinJoin + AGG_LOAD, MaxY - dPosT - TurnerOffs) + EgtOutLog( ' *[L1]', 1) + end --[L-2] + if EMC.LB - dNewYDelta < MinJoin then + dNewYDelta = min( EMC.LB - MinJoin + AGG_LOAD, MaxY - dPosT - TurnerOffs) + EgtOutLog( ' *[L2]', 1) + end + -- Commento + table.insert( vCmd, { 0, 'Loading'}) + -- risalita testa a Zmax + local bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- Apro entrambe le morse + table.insert( vCmd, { 11, 0}) + table.insert( vCmd, { 12, 0}) + -- Sposto il carrello Y per il carico + table.insert( vCmd, { 2, 'Y', dPosT + dNewYDelta, 'V', ParkV}) + -- Chiudo morsa Y + table.insert( vCmd, { 11, EgtIf( EMC.LB - dNewYDelta < LenToPress, 1, 2)}) + -- confermo i nuovi parametri di aggancio + table.insert( vCmd, { 21, dNewYDelta, 0}) + -- Inizializzo contatore globale + EMC.CNT = 1 + SpecOutputCNT() + -- Assegno stato corrente + EMC.TPOS = dPosT + EMC.YDELTA = dNewYDelta + EMC.VDELTA = nil + -- Restituisco i comandi + return vCmd +end -- SpecAdjustLoad [L] + +--------------------------------------------------------------------- +function SpecCalcCarriages( dDistFront, dDistBack, bFixedDelta, bFixedPos) + + local MinFrontJoin = MinJoin + EMC.HCING + EMC.HOVM + local MinBackJoin = MinJoin + EgtIf( IsMid2Phase( EMC.PHASE) or IsEnd2Phase( EMC.PHASE), EMC.TCING, 0) + local MyMinOther = MinOther + EgtIf( EMC.CNT == 1, AGG_LOAD, 0) + + local dDistFrontEff = min( dDistFront, EMC.LB - MyMinOther - EMC.TCING) + if bFixedDelta and IsMid2Phase( EMC.PHASE + 1) then + dDistFrontEff = min( dDistFrontEff, EMC.LR - MinOther - EMC.TCING) + end + local dDistBackEff = min( dDistBack, EMC.LB - MyMinOther - EMC.HCING - EMC.HOVM) + + EgtOutLog( ' Dist/Min : Back=' .. EgtNumToString( dDistBackEff, 1) .. '/' .. EgtNumToString( MinBackJoin, 1) .. + ' Front=' .. EgtNumToString( dDistFrontEff, 1) .. '/' .. EgtNumToString( MinFrontJoin, 1) .. + ' Fixed : Delta=' .. EgtIf( bFixedDelta, 'T', 'F') .. ' Pos=' .. EgtIf( bFixedPos, 'T', 'F'), 3) + + -- [A] se posso mettere solo carrello Y + if dDistFrontEff < MinFrontJoin and dDistBackEff > MinBackJoin - GEO.EPS_SMALL then + + local dPosT = EMC.TPOS + local dYDelta = EMC.YDELTA + local dVDelta = EMC.VDELTA + + local dNewPosT = nil + local dNewYDelta = EMC.LB - dDistBackEff + local dNewVDelta = nil + + return SpecAdjustCarriages( dPosT, dYDelta, dVDelta, dNewPosT, dNewYDelta, dNewVDelta, bFixedDelta, bFixedPos) + + -- [B] se altrimenti posso mettere entrambi i carrelli Y e V + elseif dDistBackEff > MinBackJoin - GEO.EPS_SMALL and + dDistFrontEff > MinFrontJoin - GEO.EPS_SMALL then + + local dPosT = EMC.TPOS + local dYDelta = EMC.YDELTA + local dVDelta = EMC.VDELTA + + local dNewPosT = nil + local dNewYDelta = EMC.LB - dDistBackEff + local dNewVDelta = dDistFrontEff + + return SpecAdjustCarriages( dPosT, dYDelta, dVDelta, dNewPosT, dNewYDelta, dNewVDelta, bFixedDelta, bFixedPos) + + -- [C] se altrimenti posso mettere solo carrello V + elseif dDistBackEff < MinBackJoin and dDistFrontEff > MinFrontJoin - GEO.EPS_SMALL then + + local dPosT = EMC.TPOS + local dYDelta = EMC.YDELTA + local dVDelta = EMC.VDELTA + + local dNewPosT = nil + local dNewYDelta = nil + local dNewVDelta = dDistFrontEff + + return SpecAdjustCarriages( dPosT, dYDelta, dVDelta, dNewPosT, dNewYDelta, dNewVDelta, bFixedDelta, bFixedPos) + + -- altrimenti errore + else + if EgtGetDebugLevel() < 3 then + EgtOutLog( ' Dist/Min : Back=' .. EgtNumToString( dDistBackEff, 1) .. '/' .. EgtNumToString( MinBackJoin, 1) .. + ' Front=' .. EgtNumToString( dDistFrontEff, 1) .. '/' .. EgtNumToString( MinFrontJoin, 1)) + end + EgtOutLog( ' Error CLAMP impossible') + EMC.ERR = 18 + return {} + end + +end + +--------------------------------------------------------------------- +function SpecCalcSplit( dLenRaw) + local vCmd = {} + EgtOutLog( ' *[S]', 1) + table.insert( vCmd, { 0, EgtIf( EMC.VDELTA, 'Split', 'Fall')}) + -- determino i grezzi da agganciare al carrello Y (sono quelli presenti nella fase successiva dispari) + local nNextOddPhase = GetNextStartOrRestPhase( EMC.PHASE) + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtVerifyRawPartPhase( nRawId, nNextOddPhase) then + table.insert( vCmd, { 31, nRawId, 'Y'}) + end + nRawId = EgtGetNextRawPart( nRawId) + end + -- riporto il carrello Y al carico con il resto della trave + local dLDelta = EMC.YDELTA - dLenRaw + table.insert( vCmd, { 1, 'Y', LoadT + dLDelta}) + table.insert( vCmd, { 21, 0, EMC.VDELTA or 0}) + -- imposto subito Y non più attaccato al trave in lavoro + EMC.YDELTA = nil + -- salvo posizione carrello Y in disposizione del pezzo dopo split + local PostDispId = EgtGetPhaseDisposition( EMC.PHASE + 1) + if PostDispId then + EgtSetInfo( PostDispId, 'YPOS', LoadT + dLDelta) + end + -- salvo posizione grezzo rimasto e posizione carrello Y nella disposizione iniziale del pezzo succ (prossima fase dispari) + local NextDispId = EgtGetPhaseDisposition( nNextOddPhase) + if NextDispId then + EgtSetInfo( NextDispId, 'TPOS', LoadT) + EgtSetInfo( NextDispId, 'YPOS', LoadT + dLDelta) + end + return vCmd +end + +--------------------------------------------------------------------- +function SpecCalcSplitRot( dLenRaw) + local vCmd = {} + EgtOutLog( ' *[SR]', 1) + table.insert( vCmd, { 0, 'SplitRot'}) + -- determino i grezzi da agganciare al carrello Y (sono quelli presenti nella fase successiva dispari) + local vRaw = {} + local nNextOddPhase = GetNextStartOrRestPhase( EMC.PHASE) + local nRawId = EgtGetFirstRawPart() + while nRawId do + if EgtVerifyRawPartPhase( nRawId, nNextOddPhase) then + table.insert( vRaw, nRawId) + end + nRawId = EgtGetNextRawPart( nRawId) + end + for _, nId in ipairs( vRaw) do + table.insert( vCmd, { 31, nId, 'Y'}) + end + -- riporto il carrello Y al carico con il resto della trave + local dLDelta = EMC.YDELTA - dLenRaw + table.insert( vCmd, { 1, 'Y', LoadT + TurnerOffs + dLDelta}) + table.insert( vCmd, { 21, 0, EMC.VDELTA}) + -- imposto subito Y non più attaccato alla trave in lavoro + EMC.YDELTA = nil + -- apro il carrello Y + table.insert( vCmd, { 11, 0}) + -- sgancio i grezzi dal carrello Y + for _, nId in ipairs( vRaw) do + table.insert( vCmd, { 31, nId, ''}) + end + -- lo porto in parcheggio + table.insert( vCmd, { 1, 'Y', ParkY}) + -- salvo posizione grezzo rimasto nella disposizione iniziale del pezzo succ (prossima fase dispari) + local NextDispId = EgtGetPhaseDisposition( nNextOddPhase) + if NextDispId then + EgtSetInfo( NextDispId, 'TPOS', LoadT) + end + return vCmd +end + +--------------------------------------------------------------------- +function SpecCalcUnload() + local vCmdPre = {} + EgtOutLog( ' *[U]', 1) + -- Se pinza Y chiusa , devo effettuare uno scambio + if EMC.YDELTA then + -- determino posizione testa trave + local nLastEntId = EgtGetLastInGroup( EMC.PATHID) + local vAxes = EmtGetAxesPos( nLastEntId) + if #vAxes > 0 then EMC.TPOS = vAxes[1] end + -- imposto quote aggancio per avere solo pinza V + local dDistFront = EMC.LB - MinOther - EMC.TCING - 10 * GEO.EPS_SMALL + local dDistBack = 0 + -- effettuo scambio + vCmdPre = SpecCalcCarriages( dDistFront, dDistBack) + if EMC.ERR ~= 0 then + return {} + end + -- recupero nuova posizione carrelli + SpecSetCarrPosFromCmds( vCmdPre) + EgtOutLog( ' *[U1]', 1) + end + local vCmd = {} + -- Tipo di scarico + local bStdUl = ( MaxUnloadLen < 1 or EMC.LB - EMC.HOVM < MaxUnloadLen + 1) + -- Commento + table.insert( vCmd, { 0, 'Unloading', EgtIf( bStdUl, 'Unloading', 'Manual Unloading')}) + -- risalita testa a Zmax + local bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- Se pinza Y chiusa, la apro + if EMC.YDELTA then + table.insert( vCmd, { 11, 0}) + end + -- Se non supero la lunghezza massima di scarico, sposto il pezzo in posizione di scarico + if bStdUl then + local dFinT = UnloadT - EMC.LB + local dFinV = dFinT + EMC.VDELTA + table.insert( vCmd, { 2, 'T', dFinT, 'V', dFinV}) + else + table.insert( vCmd, { 1, 'V', MaxV}) + end + -- apro la morsa + table.insert( vCmd, { 12, 0}) + -- riporto il carrello in home + table.insert( vCmd, { 1, 'V', ParkV}) + + -- eventuale unione tabelle + if #vCmdPre > 0 then + vCmd = EgtJoinTables( vCmdPre, vCmd) + end + + return vCmd +end + +--------------------------------------------------------------------- +function SpecCalcPreRot() + local vCmdPre = {} + EgtOutLog( ' *[PR]', 1) + -- Se pinza V chiusa , devo effettuare uno scambio + if EMC.VDELTA then + -- imposto quote aggancio per avere solo pinza Y + local dDistFront = 0 + local dDistBack = EMC.LB - MinOther - EMC.HOVM + 10 * GEO.EPS_SMALL + -- effettuo scambio + vCmdPre = SpecCalcCarriages( dDistFront, dDistBack) + -- recupero nuova posizione carrelli + SpecSetCarrPosFromCmds( vCmdPre) + EgtOutLog( ' *[PR1]', 1) + end + -- porto il pezzo alla zona di rotazione con il carro Y + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Pre-Rotation'}) + -- risalita testa a Zmax + local bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- Se pinza V chiusa, la apro + if EMC.VDELTA then + table.insert( vCmd, { 12, 0}) + end + -- riporto la trave al carico + local RotT = LoadT + TurnerOffs + table.insert( vCmd, { 2, 'Y', RotT + EMC.YDELTA, 'T', RotT}) + -- apro la morsa + table.insert( vCmd, { 11, 0}) + -- riporto il carrello in home + table.insert( vCmd, { 1, 'Y', ParkY}) + + -- eventuale unione tabelle + if #vCmdPre > 0 then + vCmd = EgtJoinTables( vCmdPre, vCmd) + end + + return vCmd +end + +--------------------------------------------------------------------- +function SpecAdjustCarriages( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta, bFixedPos) + + -- [A] richiesto solo carrello Y + if dYDeltaF and ( not dVDeltaF) then + -- [A1] rimango sul carrello Y + if dYDeltaI and ( not dVDeltaI) then + return SpecAdjustCarrA1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + -- [A2] torno da entrambi + elseif dYDeltaI and dVDeltaI then + return SpecAdjustCarrA2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + -- [A3] torno da carrello V + elseif dVDeltaI and (not dYDeltaI) then + return SpecAdjustCarrA3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + else + EgtOutLog( ' Error CLAMP NULL-> Y impossibile') + error( 'Error CLAMP NULL-> Y impossibile') + end + + -- (B) richiesti entrambi i carrelli + elseif dYDeltaF and dVDeltaF then + -- [B1] passo da carrello Y a entrambi + if dYDeltaI and ( not dVDeltaI) then + return SpecAdjustCarrB1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + -- [B2] continuo con entrambi i carrelli + elseif dYDeltaI and dVDeltaI then + return SpecAdjustCarrB2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + -- [B3] passo da carrello V a entrambi + elseif dVDeltaI and (not dYDeltaI) then + return SpecAdjustCarrB3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + else + EgtOutLog( ' Error CLAMP NULL-> Y+V impossibile') + error( 'Error CLAMP NULL-> Y+V impossibile') + end + + -- [C] richiesto solo carrello V + elseif ( not dYDeltaF) and dVDeltaF then + -- [C1] provengo da solo carrello Y + if dYDeltaI and ( not dVDeltaI) then + return SpecAdjustCarrC1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + -- [C2] provengo da carrelli Y e V + elseif dYDeltaI and dVDeltaI then + return SpecAdjustCarrC2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + -- [C3] rimango sul carrello V + elseif ( not dYDeltaI) and dVDeltaI then + return SpecAdjustCarrC3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta, bFixedPos) + else + EgtOutLog( ' Error CLAMP NULL-> V impossibile') + error( 'Error CLAMP NULL-> V impossibile') + end + + end + +end + +--------------------------------------------------------------------- +local function CalcCharStatus( sType, dDelta) + -- se per carrello Y + if sType == 'Y' then + return EgtIf( EMC.LB - dDelta < LenToPress, 1, 2) + -- altrimenti per carrello V + else + return EgtIf( dDelta < LenToPress, 1, 2) + end +end + +--------------------------------------------------------------------- +local function GetDeltaTol( dLenPresa, TCING, HCING, HOVM, Carr, bFixedDelta) + local dDeltaTolEff = DELTA_SIC + if Carr == 'Y' then + local dLenPreEff = dLenPresa - TCING + if dLenPreEff < MinJoin + DeltaTol then + dDeltaTolEff = max( DELTA_SIC, dLenPreEff - MinJoin + 10 * GEO.EPS_SMALL) + else + if BD.GO_FAST and BD.GO_FAST ~= 0 then + if bFixedDelta == false then + dDeltaTolEff = min( EMC.LB + 700, dLenPreEff, 3200) + else + dDeltaTolEff = 900 + end + else + dDeltaTolEff = DeltaTol + end + end + elseif Carr == 'V' then + local dLenPreEff = dLenPresa - HCING - HOVM + if dLenPreEff < MinJoin + DeltaTol then + dDeltaTolEff = max( DELTA_SIC, dLenPreEff - MinJoin + 10 * GEO.EPS_SMALL) + else + dDeltaTolEff = DeltaTol + end + end + return EgtIf( bFixedDelta, min( dDeltaTolEff, DELTA_TOL_FIXED), dDeltaTolEff) +end + +--------------------------------------------------------------------- +local function GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistN, sSide) + local dRecTotn = min( dDistN, dCorsaYfc+ dCorsaVfc) -- recupero possibile al netto di dCorsa..TrA) + local dCorsaYd, dCorsaYTd, dCorsaVd, dCorsaVTd + if sSide == 'Fr' then + if dRecTotn / 2 <= dCorsaYfc then + if dRecTotn / 2 <= dCorsaVfc then + dCorsaYTd = dRecTotn / 2 + dCorsaVd = dRecTotn / 2 + else + dCorsaVd = dCorsaVfc + dCorsaYTd = min( dCorsaYfc, dRecTotn - dCorsaVd) + end + else + dCorsaYTd = dCorsaYfc + dCorsaVd = min( dCorsaVfc, dRecTotn - dCorsaYTd) + end + dCorsaY = dCorsaYTd + dCorsaV = dCorsaVd + else + if dRecTotn / 2 <= dCorsaVfc then + if dRecTotn / 2 <= dCorsaYfc then + dCorsaVTd = dRecTotn / 2 + dCorsaYd = dRecTotn / 2 + else + dCorsaYd = dCorsaYfc + dCorsaVTd = min( dCorsaVfc, dRecTotn - dCorsaYd) + end + else + dCorsaVTd = dCorsaVfc + dCorsaYd = min( dCorsaYfc, dRecTotn - dCorsaVTd) + end + dCorsaY = dCorsaYd + dCorsaV = dCorsaVTd + end + return dCorsaY, dCorsaV +end + +--------------------------------------------------------------------- +local function PosxExtraYV( dYPosA, dVPosA, dTPosA, dMinY, dMaxV, sYV) + -- svolge la predisposizione iniziale di trave e carrelli in caso di situazione iniziale con un solo carrello chiuso + -- con un solo carrello chiuso per l'aggancio del carrello aperto + local dYPos, dVPos, dTPos + -- per aggancio del carrello V + if sYV == 'V' then + dTPos = min( dTPosA, dVPosA - MinJoin - EgtIf( EMC.HCING_IGNORE, 0, EMC.HCING) - EMC.HOVM) + dYPos = dYPosA + ( dTPos - dTPosA) + if dYPos < dMinY then + dVPos = dVPosA + ( dMinY - dYPos) + if dVPos > dMaxV + GEO.EPS_SMALL then + EmitComment( vCmd, ' Error CLAMP V') + error( 'Error CLAMP V') + return + elseif dVPos > dMaxV - GEO.EPS_SMALL then + dVPos = dMaxV + end + dYPos = dMinY + dTPos = dTPosA + ( dYPos - dYPosA) + else + --dYPos = dMinY + --dYPos = dYPos! + --dTPos = dTPosA + ( dYPos - dYPosA) + --dTPos = dTPos! + dVPos = dVPosA + end + end + -- per aggancio del carrello Y + if sYV == 'Y' then + dTPos = max( dTPosA, dYPosA + MinJoin + EMC.TCING - EMC.LB) + dVPos = dVPosA + ( dTPos - dTPosA) + if dVPos > dMaxV then + dYPos = dYPosA - ( dVPos - dMaxV) + if dYPos < dMinY - GEO.EPS_SMALL then + EmitComment( vCmd, ' Error CLAMP Y') + error( 'Error CLAMP Y') + return + elseif dYPos < dMinY + GEO.EPS_SMALL then + dYPos = dMinY + end + dVPos = dMaxV + dTPos = dTPosA + ( dVPos - dVPosA) + else + -- ++++++++++++++++++++++++++++++++ + --dVPos = dMaxV + --dVPos = dVPos! + --dTPos = dTPosA + ( dVPos - dVPosA) + --dTpos = dTPos!! + dYPos = dYPosA + end + end + return dYPos, dVPos, dTPos +end + +--------------------------------------------------------------------- +local function PosXs2Enl (dYa, dVa, dTa, dExtraC, dCorsaTra, dCorsaYd, dCorsaVd, sYV) + -- svolge la fase di allontanamento dei carrelli per il recupero di 'ExtraV'/'ExtraY' + -- richiesto alle posizioni [--.xs2] delle funzioni SpecAdjustCarr.. + if sYV == 'V' then -- caso di ExtraV (ed eventuale ulteriore allontanamento di Y) + local dCorsaYTrA = dCorsaTra + local dExtraVn = dExtraC - dCorsaYTrA + -- eseguo allontanamento di Y e (V+T) + if dExtraVn / 2 <= dCorsaYd then + if dExtraVn / 2 <= dCorsaVd then + dYa = dYa + dExtraVn / 2 + dVa = dVa - dExtraVn / 2 + dTa = dTa - dExtraVn / 2 + else + dVa = dVa - dCorsaVd + dTa = dTa - dCorsaVd + dYa = dYa + min( dExtraVn - dCorsaVd, dCorsaYd) + end + else + dYa = dYa + dCorsaYd + dVa = dVa - min( dExtraVn - dCorsaYd, dCorsaVd) + dTa = dTa - min( dExtraVn - dCorsaYd, dCorsaVd) + end + end + + if sYV == 'Y' then -- caso di ExtraY (ed eventuale ulteriore allontanamento di V) + local dCorsaVTrA = dCorsaTra + local dExtraYn = -dExtraC - dCorsaVTrA + -- eseguo allontanamento di (Y+T) e V + if dExtraYn / 2 <= dCorsaVd then + if dExtraYn / 2 <= dCorsaYd then + dVa = dVa - dExtraYn / 2 + dYa = dYa + dExtraYn / 2 + dTa = dTa + dExtraYn / 2 + else + dYa = dYa + dCorsaYd + dTa = dTa + dCorsaYd + dVa = dVa - min( dExtraYn - dCorsaYd, dCorsaVd) + end + else + dVa = dVa - dCorsaVd + dYa = dYa + min( dExtraYn - dCorsaVd, dCorsaYd) + dTa = dTa + min( dExtraYn - dCorsaVd, dCorsaYd) + end + end + return dYa, dVa, dTa +end + +--------------------------------------------------------------------- +-- *** [A1] da carrello Y a Y : Y -> Y *** +--------------------------------------------------------------------- +function +SpecAdjustCarrA1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + EgtOutLog( ' *[A1] = Y -> Y', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y -> Y'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + -- recupero le posizioni correnti dei carrelli + local dYPosA = dTPosI + dYDeltaI + local dVPosA = ParkV + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVPosA - dTPosA + local dNewYDelta -- = dYDeltaF + local dCorsaYfc = MaxY - dYPosA + local dCorsaYd = min( dCorsaYfc, EMC.LB - dYDeltaI - MinJoin) + + -- tolleranza + local dYDeltaTol = GetDeltaTol( EMC.LB - dYDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y') + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol/2 + else + dNewYDelta = dYDeltaA + end + EgtOutLog( ' YDeltaI=' .. EgtNumToString( dYDeltaI) .. ' TPosI=' .. EgtNumToString( dTPosI), 1) + EgtOutLog( ' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' NewYDelta=' .. EgtNumToString( dNewYDelta), 1) + -- flag per risalita resta a Zmax + local bZmaxOk = false + + -- **[A1Ys]** |pos. di Y cambia in modo significativo| + if bYDeltaS then + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- definisco 'ExtraY' con (Y+T) e V accentrati q.b. per la presa con V + local dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'V') + local dNewY = dTPos + dNewYDelta + local dExtraY = dNewY - MyMinY + -- effettuo spostamenti di (Y+T) e V per predisporre all'aggancio di T con V + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dVDeltaA = dVPosA - dTPosA + + -- **[A1Ys-x]** posizione di |Y non raggiungibile| (oltre MyMinY) + if dExtraY < 0 then + -- **[A1Ys-xs]** posizione di Y non raggiungibile, |con ExtraY 'significativo'| + if -dExtraY > dYDeltaTol /2 then + --EmitComment( vCmd, '[A1Ys-xs]') + -- calcolo le **corse disponibili dei carrelli a partire da Y e V c.s.** per allontanare q.p. (Y+T) e V + local dCorsaYfc = MaxY - dYPos + local dCorsaVfc = dVPos - MinV + local dDistFrN = (dVPos-dTPos) - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + local dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto **le corse di 'recupero'** dai due carrelli possibili riaccentrando Y e (V+T) + local dCorsaVTr = dCorsaVd + (MaxV - dVPos) + local dCorsaYr = dCorsaYTd + -- **[A1Ys-xsw]** posizione finale dNewV non raggiungibile, con |dEXtraY > CorsaVr + CorsaYr| + if -dExtraY > ( dCorsaVTr + dCorsaYr) and bYDeltaS then + EmitComment( vCmd, '[A1Ys-xsw]' .. 'CASO NON GESTITO') + return + end + + local dCorsaVTrA = MaxV - dVPos -- !! att.ne: non dVPosA !! + -- **[A1Ys-xs1]** se posso recuperare ExtraY semplicem' accentrando Y e (V+T) + -- (dalle posizione impostate sopra per l'aggancio di V) + if dCorsaVTrA >= -dExtraY then + EmitComment( vCmd, '[A1Ys-xs1]') + -- chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: accentro** Y e (V+T) + dYPosA = MyMinY -- (pos. finale) + dVPosA = dVPosA + (-dExtraY) + dTPosA = dTPosA + (-dExtraY) + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dYDeltaA = dYPosA - dTPosA + + else -- **[A1Ys-xs2]** + -- ci sarebbe un doppio movimento di Y ? => caso impossibile ? + EmitComment( vCmd, '[A1Ys-xs2]') + -- **1:** posiziono (ulteriormente!) (Y+T) e V + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraY, dCorsaVTrA, dCorsaYTd, dCorsaVd, 'Y') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dVDeltaA = dVPosA - dTPosA + -- chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2: accentro** Y e (V+T) + dYPosA = MyMinY -- (pos. finale) + dVPosA = MaxV + dTPosA = dVPosA - dVDeltaA + --dVDeltaA = dVPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [A1Ys-xs1/-xs2] + + -- **[A1Ys-xn]** |dExtraY ancora < 0 ma non 'significativo')| + else --if -dExtraY < DeltaToll/2 + EmitComment( vCmd, '[A1Ys-xn]') + -- chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1:** accentro Y + dExtraY = 0 + dYPosA = MyMinY -- (pos. finale) + table.insert( vCmd, { 1, 'Y', dYPosA}) + -- dYDeltaA = dYPosA - dTPosA + end --[A1Ys-xs/xn] + + -- **[A1Ys-r]** |posizione di Y raggiungibile| (ExtraY >=0) + -- (si esclude la possibilità di extra corsa oltre maxY) + else + EmitComment( vCmd, '[A1Ys-r]') + -- chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1:** posiziono Y alla posizione richiesta + dYPosA = dNewY + table.insert( vCmd, { 1, 'Y', dYPosA}) + end -- [A1Ys] + + -- calcolo il nuovo parametro di aggancio + dYDeltaA = dYPosA - dTPosA + -- chiudo Y e apro V + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, 0}) + -- sposto il carrello V in parcheggio + table.insert( vCmd, { 1, 'V', ParkV}) + -- imposto il nuovo parametro di aggancio + table.insert( vCmd, { 21, dYDeltaA, 0}) + + -- reset contatore + EMC.CNT = nil + + else -- **[A1Yns]** |spostamento| finale richiesto (ev' residuo) di |Y non 'significativo'| + EmitComment( vCmd, '[A1Yns]') + end --[A1Ys/ns] + + EgtOutLog(' YDeltaA =' .. EgtNumToString( dYDeltaA), 1) + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrA1 + +--------------------------------------------------------------------- +-- *** [A2] da entrambi a carrello Y : Y+V -> Y *** +--------------------------------------------------------------------- +function SpecAdjustCarrA2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + EgtOutLog( ' *[A2] = Y+V -> Y ', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y+V -> Y'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + local dCorsaY = MaxY - MyMinY + local dCorsaV = MaxV - MinV + -- recupero le posizioni correnti dei carrelli + local dYPosA = dTPosI + dYDeltaI + local dVPosA = dTPosI + dVDeltaI + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVDeltaI + local dNewYDelta -- = dYDeltaF + -- tolleranze + local dYDeltaTol = GetDeltaTol( EMC.LB - dYDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y') + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol/2 + else + dNewYDelta = dYDeltaA + end + -- definisco 'ExtraY' + local dNewY = dTPosA + dNewYDelta + local dExtraY = dNewY - MyMinY -- < 0 = nuova pos. di Y 'non raggiungibile' (= oltre MyMinY) + -- definisco 'ExtraY significativo' + local bYxs = -dExtraY > dYDeltaTol/2 + + EgtOutLog( ' YDeltaI=' .. EgtNumToString( dYDeltaI) .. ' TPosI=' .. EgtNumToString( dTPosI) .. + ' VDeltaI=' .. EgtNumToString( dVDeltaI), 1) + EgtOutLog( ' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' NewYDelta=' .. EgtNumToString( dNewYDelta), 1) + -- flag per risalita resta a Zmax + local bZmaxOk = false + -- risalita testa a Zmax (da effettuare comunque, per il parcheggio di V) + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- calcoli preliminari in caso di spostamento richiesto per Y significativo + local dCorsaYfc, dCorsaVfc, dDistFrN, dCorsaYTd, dCorsaVd, dCorsaVTr, dCorsaYr, bXsw + if bYDeltaS then + if bYxs then + -- calcolo le **corse disponibili** dei carrelli **a partire dalle posizioni attuali** (=iniziali) + -- per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto **le corse di 'recupero'** dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + (MaxV - dVPosA) + dCorsaYr = dCorsaYTd + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaYr + dCorsaVTr + end + end + + -- **[A2Ys-xsw]** posizione NewY non raggiungibile (oltre MyMinY), con ||dEXtraY | > CorsaYr + CorsaVTr| + while bXsw do + EmitComment( vCmd, '[A2Ys-xsw]') + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- chiudo eventualmente il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** allontano q.p. (Y+T) e V + dYPosA = dYPosA + dCorsaYTd + dTPosA = dTPosA + dCorsaYTd + dVPosA = dVPosA - dCorsaVd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2:** accentro Y e (V+T) + dYPosA = MyMinY + dVPosA = dVPosA + dCorsaVTr + dTPosA = dTPosA + dCorsaVTr + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + -- valuto Delta attuali + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + -- aggiorno l'extra corsa residua per Y + dExtraY = dExtraY + dCorsaYr + dCorsaVTr + bYxs = -dExtraY > dYDeltaTol/2 + -- **aggiorno la valutazione delle corse disponibili** + -- a partire da Y e V c.s. per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + dCorsaYr = dCorsaYTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end -- [A2Ys-xw] + + -- **[A2Ys]** se lo |spostamento| richiesto (ev' residuo) per |Y| è |'significativo'| + if bYDeltaS then + -- **[A2Ys-x]** se la |posizione per Y non è 'raggiungibile'| + if dExtraY < 0 then + -- **[A2Ys-xs]** se |ExtraY 'significativo'| + if bYxs then + local dCorsaVTrA = MaxV - dVPosA + -- **[A2Ys-xs1]** se posso recuperare ExtraY solo accentrando (V+T) e Y + if dCorsaVTrA >= -dExtraY then + EmitComment( vCmd, '[A2Ys-xs1]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1:** accentro (V+T) q.b. e Y + dVPosA = dVPosA + (-dExtraY) + dTPosA = dTPosA + (-dExtraY) + dYPosA = MyMinY -- (pos. finale) + --dYDeltaA = dYPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + else -- **[A2Ys-xs2]** + EmitComment( vCmd, '[A2Ys-xs2]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** allontano (Y+T) e V + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraY, dCorsaVTrA, dCorsaYTd, dCorsaVd, 'Y') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dVDeltaA = dVPosA - dTPosA + -- chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2:** accentro Y e (V+T) q.b. per recupero di dExtraY + dYPosA = MyMinY + dVPosA = MaxV + dTPosA = dVPosA - dVDeltaA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end --[A2Ys-xs1/-xs2] + + -- [A2Ys-xn] |ExtraY ancora <= 0, ma 'non significativo'| + else --if dExtraY <= 0 then + EmitComment( vCmd, '[A2Ys-xn]') + dExtraY = 0 + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- 1: accentro Y + dYPosA = MyMinY -- (pos. finale) + table.insert( vCmd, { 1, 'Y', dYPosA}) + end -- [A2Ys-xs/xn] + + --[A2Ys-r] dExtrav > 0 ( |pos. Y'raggiungibile|) + else + EmitComment( vCmd, '[A2Ys-r]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- posizione Y + dYPosA = dTPosA + dNewYDelta -- (pos. finale) + table.insert( vCmd, { 1, 'Y', dYPosA}) + end -- [A2Ys-x/r] + + else -- [A2Yns] |spostamento Y| (ev' residuo) |non significativo| + EmitComment( vCmd, '[A2Yns]') + end -- [A2Ys/ns] + + -- calcolo i nuovi parametri di aggancio + dYDeltaA = dYPosA - dTPosA + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, 0}) + -- sposto il carrello V in parcheggio + table.insert( vCmd, { 1, 'V', ParkV}) + -- imposto i nuovi parametri di aggancio + table.insert( vCmd, { 21, dYDeltaA, 0}) + + EgtOutLog( ' YDeltaA =' .. EgtNumToString( dYDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrA2 + +--------------------------------------------------------------------- +-- *** [A3] da carrello V a Y : V -> Y *** +--------------------------------------------------------------------- +function SpecAdjustCarrA3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF) + EgtOutLog( ' *[A3] = V -> Y', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'V -> Y'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + -- recupero le posizioni correnti + local dYPosA = ParkY + local dTPosA = dTPosI + local dVPosA = dTPosI + dVDeltaI + local dYDeltaA = dYPosA - dTPosA + local dVDeltaA = dVDeltaI + local dNewYDelta -- = dVDeltaF + -- tolleranza + local dYDeltaTol = GetDeltaTol( EMC.LB - dYDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y') + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + -- reimposto i delta finali in caso di spostamenti richiesti significativi, tenuto conto delle tolleranze + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol/2 + else + dNewYDelta = dYDeltaA + end + -- + EgtOutLog(' VDeltaI=' .. EgtNumToString( dVDeltaA) .. ' YDeltaI(Park)='.. EgtNumToString( dYDeltaA).. + ' TPosI=' .. EgtNumToString( dTPosI) , 1) + EgtOutLog(' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' NewYDelta=' .. EgtNumToString( dNewYDelta) , 1) + local bZmaxOk = false + -- risalita testa a Zmax (da effettuare comunque, dato lo scambio di carrelli) + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- calcoli preliminari in caso di spostamento richiesto per Y significativo + local dYPos, dVPos, dTPos + local dNewY, dExtraY, bYxs + local dCorsaYfc, dCorsaVfc, dDistFrN, dCorsaYTd, dCorsaVd, dCorsaVTr, dCorsaYr, bXsw + if bYDeltaS then + -- definisco 'ExtraY' con Y e (V+T) accentrati q.b. per la presa con Y + dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'Y') + dNewY = dTPos + dNewYDelta + dExtraY = dNewY - MyMinY --( <0 <=> pos. 'non raggiungibile') + bYxs = -dExtraY > dYDeltaTol/2 + if bYxs then + -- calcolo le **corse disponibili dei carrelli a partire da Y e V c.s.** per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPos + dCorsaVfc = dVPos - MinV + --local dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dDistFrN = (dVPos-dTPos) - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto **le corse di 'recupero'** dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + (MaxV - dVPos) + dCorsaYr = dCorsaYTd + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end + -- inizializzo + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + end + + -- **[A3Ys-xsw]** posizione finale dNewY non raggiungibile, con |dEXtraY > CorsaVr + CorsaYr| + while bXsw do + EmitComment( vCmd, '[A3Ys-xsw]') + -- |1:| posiziono (V+T) e Y come calcolato sopra + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo ev' il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- |2:| allontano (Y+T) e V quanto possibile + dYPosA = dYPosA + dCorsaYTd + dTPosA = dTPosA + dCorsaYTd + dVPosA = dVPosA - dCorsaVd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |3:| accentro (V+T) e Y + dVPosA = dVPosA + dCorsaVTr + dTPosA = dTPosA + dCorsaVTr + dYPosA = MyMinY + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto i Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + -- aggiorno ExtraY + dExtraY = dExtraY + dCorsaYr + dCorsaVTr + -- **aggiorno la valutazione delle corse disponibili** + -- a partire da Y e V c.s. per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + dCorsaYr = dCorsaYTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end --[A3Ys-xw] + + -- **[A3Ys]** |spostamento| richiesto (ev' residuo) |di Y| |'significativo'| + if bYDeltaS then + EmitComment( vCmd, '[A3Ys]') + -- **[A3Ys-x]** posizione di |Y non raggiungibile| + if dExtraY < 0 then + + -- **[A3Ys-xs]** |pos. NewY non raggiungibile, con ExtraY 'significativo'| + -- ( -dExtraY <= (CorsaYr+CorsaVr) da ciclo precedente ) + if bYxs then + local dCorsaVTrA = MaxV - dVPosA + -- **[A3Ys-xs1]** se posso recuperare ExtraY semplicem' accentrando Y e (V+T) + -- ulteriormente rispetto a YPos e Vpos definiti c.s. + if dCorsaVTrA >= -dExtraY then + EmitComment( vCmd, '[A3Ys-xs1]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: accentro** Y e (V+T) + dYPosA = MyMinY -- (pos. finale) + dVPosA = dVPosA + dExtraY + dTPosA = dTPosA + dExtraY + dYDeltaA = dYPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[A3Ys-xs2]** + EmitComment( vCmd, '[A3Ys-xs2]') + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: accentro** ev' Y e (V+T) alle posizioni impostate + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dYDeltaA = dYPosA - dTPosA + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2: allontano** (Y+T) e V + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraY, dCorsaVTrA, dCorsaYTd, dCorsaVd, 'Y') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dVDeltaA = dVPosA - dTPosA + + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **3: accentro** Y e (V+T) + dYPosA = MyMinY -- (pos. finale) + dVPosA = MaxV + dTPosA = dVPosA - dVDeltaA + --dYDeltaA = dYPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [A3Ys-xs1/-xs2] + + -- **[A3Ys-xn]** |dExtraY ancora < 0 ma non 'significativo')| + else --if -dExtraY < DeltaToll/2 + EmitComment( vCmd, '[A3Ys-xn]') + -- ev' chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1:** accentro Y e porto (V+T) alla posizione impostata + dExtraY = 0 + dYPosA = MyMinY -- (pos. finale) + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end --[A3Ys-xs/xn] + + -- **[A3Ys-r]** |posizione di Y raggiungibile (ExtraY >=0)| + else + EmitComment( vCmd, '[A3Ys-r]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- posizione Y in posizione finale ed ev' (V+T) come impostato sopra + dYPosA = dTPosA + dNewYDelta + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [A3Ys] + + else -- **[A3Yns]** |spostamento| finale richiesto (ev' residuo) di |Y non 'significativo'| + EmitComment( vCmd, '[A3Yns]') + end --[A3Ys/ns] + + -- calcolo il nuovo parametro di aggancio + dYDeltaA = dYPosA - dTPosA + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, 0}) + -- sposto il carrello V in parcheggio + table.insert( vCmd, { 1, 'V', ParkV}) + -- imposto il nuovo parametro di aggancio + table.insert( vCmd, { 21, dYDeltaA, 0}) + + EgtOutLog( ' YDeltaA =' .. EgtNumToString( dYDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrA3 + +--------------------------------------------------------------------- +local function AdjustPositionsForB( dNewYDelta, dNewVDelta, TCING, HCING, HOVM, bFixedDelta) + local REF_DIST = 1400 + local dYDelta = 0 + local dVDelta = 0 + -- incremento se possibile la distanza tra le due posizioni + if not bFixedDelta and ( dNewYDelta - dNewVDelta) < REF_DIST then + local dEffAddDist = ( REF_DIST - ( dNewYDelta - dNewVDelta)) / 2 + dYDelta = max( min( dEffAddDist, EMC.LB - dNewYDelta - MinJoin - TCING), 0) + dVDelta = max( min( dEffAddDist, dNewVDelta - MinJoin - HOVM - HCING), 0) + end + return dYDelta, dVDelta +end + +--------------------------------------------------------------------- +-- *** [B1] da carrello Y a entrambi : Y -> Y+V *** +--------------------------------------------------------------------- +function SpecAdjustCarrB1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + EgtOutLog( ' *[B1] = Y -> Y+V', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y -> Y+V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + local dCorsaY = MaxY - MyMinY + local dCorsaV = MaxV - MinV + -- recupero le posizioni correnti + local dYPosA = dTPosI + dYDeltaI + local dVPosA = ParkV + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVPosA - dTPosA + local dNewYDelta + local dNewVDelta + -- incremento la distanza tra le due posizioni ( se abilitato e possibile) + local dYDeltaAgg, dVDeltaAgg = AdjustPositionsForB( dYDeltaF, dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, bFixedDelta) + -- tolleranze + local dYDeltaTol = dYDeltaAgg + GetDeltaTol( EMC.LB - dYDeltaF - dYDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y', bFixedDelta) + local dVDeltaTol = dVDeltaAgg + GetDeltaTol( dVDeltaF - dVDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + -- definisco criteri per movimenti 'significativi' in base alle 'nuove' tolleranze + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + local bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- reimposto i delta finali in caso di spostamenti richiesti significativi, tenuto conto delle tolleranze + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol / 2 + else + dNewYDelta = dYDeltaA + end + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol / 2 + else + dNewVDelta = dVDeltaA + end + + EgtOutLog(' YDeltaI=' .. EgtNumToString( dYDeltaA) .. ' VDeltaI(Park)='.. EgtNumToString( dVDeltaA) .. + ' TPosI='.. EgtNumToString( dTPosI), 1) + EgtOutLog(' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' VDeltaF=' .. EgtNumToString( dVDeltaF), 1) + EgtOutLog(' NewYDelta=' .. EgtNumToString( dNewYDelta) .. ' NewVDelta=' .. EgtNumToString( dNewVDelta), 1) + + -- risalita testa a Zmax + local bZmaxOk = false + + -- calcoli preliminari in caso di spostamento richiesto per V significativo + local dYPos, dVpos, dTPos + local dNewV, dExtraV, bVxs + local dCorsaYfc, dCorsaVfc, dDistBkN, dCorsaYd, dCorsaVTd, dCorsaYTr, dCorsaVr, bXsw + if bVDeltaS then + -- definisco 'ExtraV' con (Y+T) e V accentrati q.b. per la presa di V + dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'V') + dNewV = dTPos + dNewVDelta + dExtraV = dNewV - MaxV -- se > 0 pos. V non direttamente 'raggiungibile' + bVxs = dExtraV > dVDeltaTol/2 -- ExtraV 'significativo' + if bVxs then + -- calcolo le **corse disponibili** dei carrelli a partire da Y e V c.s.| + -- per allontanare q.p. Y e (V+T) + dCorsaYfc = MaxY - dYPos + dCorsaVfc = dVPos - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- valuto le **corse di 'recupero'** dai due carrelli possibili riaccentrando (Y+T) e V + dCorsaYTr = dCorsaYd + (dYPos - MyMinY) + dCorsaVr = dCorsaVTd + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaVr + dCorsaYTr + end + -- inizializzo + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + end + + -- **[B1Vs-xsw]** posizione finale dNewV non raggiungibile, con |dEXtraV > CorsaVr + CorsaYr| + while bXsw do + EmitComment( vCmd, '[B1Vs-xsw]') + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- |1:| imposto (Y+T) e V come calcolato sopra + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |2:| allontano Y e (V+T) quanto possibile + dYPosA = dYPosA + dCorsaYd + dVPosA = dVPosA - dCorsaVTd + dTPosA = dTPosA - dCorsaVTd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- |3:| accentro (Y+T) e V + dYPosA = dYPosA - dCorsaYTr + dTPosA = dTPosA - dCorsaYTr + dVPosA = MaxV + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto i Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- aggiorno l'extra corsa residuo per V + dExtraV = dExtraV - dCorsaYTr - dCorsaVr + + -- **aggiorno la valutazione delle corse disponibili** + -- a partire da Y e V c.s. per allontanare q.p. Y e (V+T) + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- aggiorno i prossimi recuperi disponibili + dCorsaYTr = dCorsaYd + dCorsaVr = dCorsaVTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaVr + dCorsaYTr + end --[B1Vs-xw] + + -- **[B1Vs]** se lo |spostamento| finale richiesto (ev' residuo) di |V| è |'significativo'| + if bVDeltaS then + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- **[B1Vs-x]** posizione di |V non raggiungibile| + if dExtraV > 0 then + -- **[B1Vs-xs]** |ExtraV 'signfificativo'| + -- (ExtraV <= (CorsaYr+CorsaVr) da ciclo precedente ) + if bVxs then + local dCorsaYTrA = dYPosA - MyMinY + local dCorsaVra = MaxV - dVPosA + -- **[B1Vs-xs1]** se posso recuperare ExtraV semplicem' accentrando V e (Y+T) + -- ulteriormente rispetto a YPos e Vpos definiti c.s. + if dCorsaYTrA >= dExtraV then + EmitComment( vCmd, '[B1Vs-xs1]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: accentro** (Y+T) e V + dYPosA = dYPosA - dExtraV + dTPosA = dTPosA - dExtraV + dVPosA = MaxV -- (pos. finale) + dVDeltaA = dVPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[B1Vs-xs2]** + EmitComment( vCmd, '[B1Vs-xs2]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: accentro** ev' (Y+T) e V alle posizioni impostate + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dVDeltaA = dVPosA - dTPosA + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2: allontano** (V+T) e Y + -- tenendo conto di dover 'recuperare' ExtraV.... + local dYPos1, dVPos1, dTPos1 = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraV, dCorsaYTrA, dCorsaYd, dCorsaVTd, 'V') + local dYDispl1 = dYPos1 - dYPosA + local dVDispl1 = dVPos1 - dVPosA + --local dTDispl1 = dTPos1 - dTPosA + local dYDeltaDiff = dNewYDelta - (dYPos1 - dTPos1) + -- ...e anche di posizionare possibilmente Y alla posizione finale + if dYDeltaDiff > 0 then + dCorsaYfc = MaxY - dYPos1 + dCorsaVfc = dVPos1 - MinV + dDistBkN = EMC.LB - (dYPos1-dTPos1) - MinJoin - EMC.TCING -- DistBack1 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPos1, dVPos1, dTPos1, dYDeltaDiff, 0, dCorsaYd, dCorsaVTd, 'V') + else + dYPosA = dYPos1; dVPosA = dVPos1; dTPosA = dTPos1 + end + + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **3: accentro** (Y+T) e V + dYPosA = dYPosA - dYDispl1 - dCorsaYTrA -- POS. FINALE + dTPosA = dTPosA - dYDispl1 - dCorsaYTrA + dVPosA = dVPosA - dVDispl1 + dCorsaVra -- POS. FINALE + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B1Vs-xs1/-xs2] + + -- **[B1Vs-xn]** |dExtraV ancora > 0 ma non 'significativo')| + else --if dExtraV < DeltaToll/2 + EmitComment( vCmd, '[B1Vs-xn]') + -- ev' chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- 1: accentro (Y+T) alla posizione impostate e V al max + dExtraV = 0 + dVPosA = MaxV -- (pos. finale) + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B1s-xs/xn] + + -- **[B1Vs-r]** |dExtraV < 0 (pos. V raggiungibile)| + else + EmitComment( vCmd, '[B1Vs-r]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- posiziono ev' (Y+T) come impostato sopra e V in posizione finale + dVPosA = dTPosA + dNewVDelta + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B1Vs] + + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + + else -- **[B1Vns]** |spostamento| finale richiesto (ev' residuo) di |V non 'significativo'| + EmitComment( vCmd, '[B1Vns]') + if SpecTestOnlyRemarkInCmds( vCmd) then + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- emetto posizione di V + table.insert( vCmd, { 1, 'V', dVPosA}) + end + end -- [B1-s/ns] + + -- aggiorno la verifica di movimento 'significativo' per Y + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + -- **[B1Ys]** Se vi è uno |spostamento residuo di Y significativo'| + if bYDeltaS then + EmitComment( vCmd, '[B1Ys]') + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + local dNewY = dTPosA + dNewYDelta + local dExtraY = dNewY - MyMinY + -- **[B1Ys-r]** se pos. NewY è raggiungibile direttamente + if dExtraY >= 0 then --dNewY > MyMinY then + EmitComment( vCmd, '[B1Ys-r]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- sposto il carrello Y + dYPosA = dTPosA + dNewYDelta + table.insert( vCmd, { 1, 'Y', dYPosA}) + + -- **[B1Ys-xn]** se pos. NewY non è raggiungibile direttamente, ma ExtraY non è 'significativo' + elseif -dExtraY <= dYDeltaTol / 2 then + EmitComment( vCmd, '[B1Ys-xn]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- accentro Y + dYPosA = MyMinY + table.insert( vCmd, { 1, 'Y', dYPosA}) + -- [B1sY-nr.xs] ma ExtraY 'significativo' + + else -- **[B1Ys-xs]** + EmitComment( vCmd, '[B1Ys-xs]') + EgtOutLog( ' CLAMP : caso [B1Ys-xs] non gestito') + error( ' CLAMP : caso [B1Ys-xs] non gestito') + + end --[B1Ys-r/-nr] + else -- [B1Yns] spostamento residuo di Y non significativo + EmitComment( vCmd, '[B1Yns]') + end -- [B1Ys/ns] + + -- calcolo i nuovi parametri di aggancio + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- se non emessi movimenti, imposto posizione V + if not bZmaxOk then + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + table.insert( vCmd, { 1, 'V', dVPosA}) + end + -- imposto stato carrelli, per eventuale uso pressori (sempre eseguita risalita Z) + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + -- imposto i nuovi parametri di aggancio + table.insert( vCmd, { 21, dYDeltaA, dVDeltaA}) + + EgtOutLog( ' YDeltaA =' .. EgtNumToString( dYDeltaA) .. ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end -- SpecAdjustCarrB1 + +--------------------------------------------------------------------- +-- *** [B2] da entrambi a entrambi i carrelli : Y+V -> Y+V *** +--------------------------------------------------------------------- +function SpecAdjustCarrB2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + EgtOutLog( ' *[B2] = Y+V -> Y+V', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y+V -> Y+V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + -- recupero le posizioni correnti + local dYPosA = dTPosI + dYDeltaI + local dVPosA = dTPosI + dVDeltaI + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVDeltaI + local dNewYDelta + local dNewVDelta + -- incremento la distanza tra le due posizioni ( se abilitato e possibile) + local dYDeltaAgg, dVDeltaAgg = AdjustPositionsForB( dYDeltaF, dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, bFixedDelta) + -- tolleranze + local dYDeltaTol = dYDeltaAgg + GetDeltaTol( EMC.LB - dYDeltaF - dYDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y', bFixedDelta) + local dVDeltaTol = dVDeltaAgg + GetDeltaTol( dVDeltaF - dVDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + -- definisco criteri per movimenti 'significativi' in base alle 'nuove' tolleranze + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + local bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- reimposto i delta finali in caso di spostamenti richiesti significativi, tenuto conto delle tolleranze + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol / 2 + else + dNewYDelta = dYDeltaA + end + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol / 2 + else + dNewVDelta = dVDeltaA + end + -- definisco 'ExtraY' e ExtraV' + local dNewY = dTPosA + dNewYDelta + local dNewV = dTPosA + dNewVDelta + local dExtraY = dNewY - MyMinY -- < 0 => nuova pos. di Y 'non raggiungibile' + local dExtraV = dNewV - MaxV -- > 0 => nuova pos. di V 'non raggiungibile' + local bYxs = -dExtraY > dYDeltaTol/2 + local bVxs = dExtraV > dVDeltaTol/2 + + EgtOutLog( ' YDeltaI=' .. EgtNumToString( dYDeltaI) .. ' VDeltaI=' .. EgtNumToString( dVDeltaI) .. + ' TPosI='.. EgtNumToString( dTPosI), 1) + EgtOutLog( ' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' VDeltaF=' .. EgtNumToString( dVDeltaF), 1) + EgtOutLog( ' NewYDelta=' .. EgtNumToString( dNewYDelta) .. ' NewVDelta=' .. EgtNumToString( dNewVDelta), 1) + -- flag risalita a Zmax + local bZmaxOk = false + + -- **[B2V]** |accentramento di V| + if dVDeltaF > dVDeltaI then + EmitComment( vCmd, '[B2V]') + + -- calcoli preliminari in caso di spostamento richiesto per V significativo + local dCorsaYfc, dCorsaVfc, dDistBkN, dCorsaYd, dCorsaVTd, dCorsaYTr, dCorsaVr, bXsw + if bVDeltaS then + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + if bVxs then + -- calcolo le corse disponibili dei carrelli **dalle posizioni iniziali** + -- per allontanare Y e (V+T) + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- calcolo le corse di 'recupero' accentrando (Y+T) e V dopo l'allontanamento + dCorsaYTr = dCorsaYd + (dYPosA - MyMinY) + dCorsaVr = dCorsaVTd -- ((MaxV-dNewV) non fa parte del recupero in quanto già disponibile!) + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaYTr + dCorsaVr + end + end + + -- **[B2V-xsw]** posizione NewV non raggiungibile, con |dEXtraV > CorsaVr + CorsaYTr| + -- e spostamento richiesto di V significativo; + while bXsw do + EmitComment( vCmd, '[B2V-xsw]') + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1**: allontano Y e V(+T) quanto possibile + dYPosA = dYPosA + dCorsaYd + dVPosA = dVPosA - dCorsaVTd + dTPosA = dTPosA - dCorsaVTd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2:** accentro (Y+T) e V + dYPosA = dYPosA - dCorsaYTr -- = MyMinY + dTPosA = dTPosA - dCorsaYTr + dVPosA = MaxV + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- aggiorno ExtraV residuo + dExtraV = dExtraV - dCorsaYTr - dCorsaVr + -- **aggiorno i recuperi disponibili** riallontanando Y e (V+T) e riaccentrando (Y+T) e V + dCorsaYfc = dCorsaY -- MaxY - dNewY + dCorsaVfc = dCorsaV -- dNewV - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + dCorsaYTr = dCorsaYd + dCorsaVr = dCorsaVTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaYTr + dCorsaVr + end -- [B2V-xsw] + + + --[B2Vs] |accentramento| (ev' residuo) |di V 'significativo'| + if bVDeltaS then + --[B2Vs-x] accentramento di V 'significativo' |con pos. NewV 'non raggiungibile'|(= oltre MaxV) + if dExtraV > 0 then + -- (ExtraV <= (CorsaYTr+CorsaVr) da ciclo precedente) + --[B2Vs-xs] accentramento di V con |ExtraV 'significativo'| + if bVxs then + local dCorsaYTrA = dYPosA - MyMinY + local dCorsaVra = MaxV - dVPosA + -- **[B2Vs-xs1]** se posso recuperare ExtraV solo accentrando V e (Y+T) + if dCorsaYTrA >= dExtraV then + EmitComment( vCmd, '[B2Vs-xs1]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** accentro (Y+T) q.b. e V + dYPosA = dYPosA - dExtraV + dTPosA = dTPosA - dExtraV + dVPosA = MaxV -- (pos. finale) + dExtraV = 0 + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[B2Vs-xs2]** + EmitComment( vCmd, '[B2Vs-xs2]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: allontano** (V+T) e Y + -- tenendo conto di dover 'recuperare' ExtraV... + local dYPos1, dVPos1, dTPos1 = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraV, dCorsaYTrA, dCorsaYd, dCorsaVTd, 'V') + local dYDispl1 = dYPos1 - dYPosA + local dVDispl1 = dVPos1 - dVPosA + --local dTDispl1 = dTPos1 - dTPosA + local dYDeltaDiff = dNewYDelta - (dYPos1 - dTPos1) + -- ...e anche possibilmente di posizionare Y alla posizione finale + if dYDeltaDiff > 0 then + dCorsaYfc = MaxY - dYPos1 + dCorsaVfc = dVPos1 - MinV + dDistBkN = EMC.LB - (dYPos1-dTPos1) - MinJoin - EMC.TCING -- DistBack1 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + --dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPos1, dVPos1, dTPos1, dYDeltaDiff, 0, dCorsaYd-dYDispl1, dCorsaVTd+dVDispl1, 'V') + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPos1, dVPos1, dTPos1, dYDeltaDiff, 0, dCorsaYd, dCorsaVTd, 'V') + else + dYPosA = dYPos1; dVPosA = dVPos1; dTPosA = dTPos1 + end + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2: accentro** (Y+T) e V + dYPosA = dYPosA - dYDispl1 - dCorsaYTrA -- POS. FINALE + dTPosA = dTPosA - dYDispl1 - dCorsaYTrA + dVPosA = dVPosA - dVDispl1 + dCorsaVra -- POS. FINALE + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B2Vs-xs1/xs2] + + -- **[B2Vs-xn]** |dExtraV non 'significativo'| + else + EmitComment( vCmd, '[B2Vs-xn]') + dExtraV = 0 + -- ev' chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- 1: posiziono V assumendo maxV come pos. finale + dVPosA = MaxV -- (pos finale) + table.insert( vCmd, { 1, 'V', dVPosA}) + end -- [B2Vs-xs/xn] + + -- **[B2Vs-r]** accentramento di |V| 'significativo' con pos.|'raggiungibile'| (= non oltre MaxV) + else + EmitComment( vCmd, '[B2Vs-r]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- 1: posiziono V -- (pos finale) + dVPosA = dTPosA + dNewVDelta + dExtraV = 0 + table.insert( vCmd, { 1, 'V', dVPosA}) + end --[B2Vs] + + -- **[B2Vns]** accentramento di V non 'significativo'| + else + EmitComment( vCmd, '[B2Vns]') + dExtraV = 0 + end --[B2Vs/ns] + end --[B2V] ( accentramento di V) + + -- --------------------------------------------------------------------------- + -- **[B2Y]** |accentramento di Y| + if dYDeltaF < dYDeltaI then + EmitComment( vCmd, '[B2Y]') + + -- calcoli preliminari in caso di spostamento richiesto per Y significativo + local dCorsaYfc, dCorsaVfc, dDistFrN, dCorsaYTd, dCorsaVd, dCorsaVTr, dCorsaYr + if bYDeltaS then + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + if bYxs then + -- calcolo le **corse disponibili** dei carrelli dalle posizioni iniziali + -- per allontanare (Y+T) e V + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + (MaxV - dVPosA) + dCorsaYr = dCorsaYTd + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end + end + + -- **[B2Ys-xsw]** |-dEXtraY > dCorsaYr + dCorsaVTr| + while bXsw do + EmitComment( vCmd, '[B2Y-xsw]') + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- |1:| allontano (Y+T) e V quanto possibile + dYPosA = dYPosA + dCorsaYTd + dTPosA = dTPosA + dCorsaYTd + dVPosA = dVPosA - dCorsaVd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + + -- |2:| accentro Y e (V+T) + dYPosA = MyMinY -- = dYPosA - dCorsaYr + dVPosA = dVPosA + dCorsaVTr -- = MaxV + dTPosA = dTPosA + dCorsaVTr + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto Delta 'attuali' + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- aggiorno ExtraY residuo + dExtraY = dExtraY + dCorsaYr + dCorsaVTr + -- aggiorno i recuperi disponibili riallontanando (Y+T) V e riaccentrando succ' Y e (V+T) + dCorsaYfc = dCorsaY -- MaxY - dNewY + dCorsaVfc = dCorsaV -- dNewV - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + dCorsaYr = dCorsaYTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end -- [B2Ys-xsw] + + -- **[B2Ys]** |accentramento di Y 'significativo'| + if bYDeltaS then + -- **[B2Ys-x]** accentramento di Y 'significativo' |con pos. NewY 'non raggiungibile'|(= oltre MyMinY) + if dExtraY < 0 then + -- (-ExtraY <= (dCorsaYr + dCorsaVTr ) a ciclo precedente + -- **[B2Ys-xs]** accentramento di Y con |'ExtraY 'significativo'| + if bYxs then + local dCorsaVTrA = MaxV - dVPosA + local dCorsaYra = dYPosA - MyMinY + -- **[B2Ys-xs1]** se posso recuperare ExtraY solo accentrando Y e (V+T) + if dCorsaVTrA >= -dExtraY then + EmitComment( vCmd, '[B2Ys-xs1]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- accentro Y e (V+T) q.b. + dYPosA = MyMinY -- (pos. finale) + dVPosA = dVPosA - dExtraY -- = +(-dEXtraY) + dTPosA = dTPosA - dExtraY -- = +(-dEXtraY) + dExtraY = 0 + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[B2Ys-xs2]** + EmitComment( vCmd, '[B2Ys-xs2]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: allontano** (Y+T) e V + -- tenendo conto di dover 'recuperare' ExtraY... + dYPos1, dVPos1, dTPos1 = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraY, dCorsaVTrA, dCorsaYTd, dCorsaVd, 'Y') + local dYDispl1 = dYPos1 - dYPosA + local dVDispl1 = dVPos1 - dVPosA + local dVDeltaDiff = dNewVDelta - (dVPos1 - dTPos1) + -- ...e anche possibilmente di posizionare V alla posizione finale + if dVDeltaDiff < 0 then + dCorsaYfc = MaxY - dYPos1 + dCorsaVfc = dVPos1 - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront1 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPos1, dVPos1, dTPos1, dVDeltaDiff, 0, dCorsaYTd, dCorsaVd, 'Y') + else + dYPosA = dYPos1; dVPosA = dVPos1; dTPosA = dTPos1 + end + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + --dVDeltaA = dVPosA - dTPosA + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |2:| accentro Y e (V+T) + dYPosA = dYPosA - dYDispl1 - dCorsaYra -- POS. FINALE + dVPosA = dVPosA - dVDispl1 + dCorsaVTrA -- POS. FINALE + dTPosA = dTPosA - dVDispl1 + dCorsaVTrA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B2Ys-xs1/xs2] + + -- **[B2Ys-xn]** |dExtraY non 'significativo'| + else + EmitComment( vCmd, '[B2Ys-xn]') + dExtraY = 0 + -- ev' chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- 1: posiziono Y assumendo MyMinY come pos. finale + dYPosA = MyMinY -- (pos finale) + table.insert( vCmd, { 1, 'Y', dYPosA}) + end -- [B2Ys-xs/xn] + + --[B2Ys-r] accentramento di |Y| 'significativo' con pos.|'raggiungibile'| (non oltre MyMinY) + else + EmitComment( vCmd, '[B2Ys-r]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |1:| posiziono Y -- (pos finale) + dYPosA = dTPosA + dNewYDelta + dExtraV = 0 + table.insert( vCmd, { 1, 'Y', dYPosA}) + end --[B2Ys] + + -- [B2Yns] accentramento di V non 'significativo'| + else + EmitComment( vCmd, '[B2Yns]') + dExtraV = 0 + end --[B2Ys/ns] + end --[B2Y] ( accentramento di V) + + -- ricalcolo gli 'spostamenti significativi' + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + + -- ------------------------------------------------------------------------------------------ + -- **[B2C]** |Spostamenti| di Y e/o V (ev' |residui| da cicli precedenti) + -- ++ possono essere solo allontanamenti ? +++++++++++++++++++++ + EmitComment( vCmd, '[B2C]') + -- **[B2Cs]** se c'è uno |spostamento (ev' residuo) significativo| + if bYDeltaS or bVDeltaS then + -- **[B2CYs]** se lo |spostamento (ev' residuo) di Y è 'significativo'| + if bYDeltaS then + EmitComment( vCmd, '[B2CYs]') + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + local dNewY = dTPosA + dNewYDelta + local dExtraY = dNewY - MyMinY + + -- **[B2CYs-r]** se posizione di |Y raggiungibile| + if dExtraY >= 0 and dNewY <= MaxY then + EmitComment( vCmd, '[B2CYs-r]') + -- chiudo eventualmente V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- sposto il carrello Y + dYPosA = dNewY + table.insert( vCmd, { 1, 'Y', dYPosA}) + -- **[B2CYs-nr]** + else + EmitComment( vCmd, '[B2CYs-nr]') + EgtOutLog( ' CLAMP : posizione Y non raggiungibile' .. '- caso [B2Ys-nr] non gestito') + error( 'CLAMP : posizione Y non raggiungibile') + end + end -- [B2CYs] + + -- **[B2CVs]** se lo |spostamento (ev' residuo) di V è 'significativo'| + if bVDeltaS then + EmitComment( vCmd, '[B2CVs]') + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + local dNewV = dTPosA + dNewVDelta + local dExtraV = dNewV - MaxV + + -- **[B2CVs-r]** se posizione NewV raggiungibile + if dExtraV <= 0 and dNewV >= MinV then + EmitComment( vCmd, '[B2CVs-r]') + -- chiudo eventualmente Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- sposto il carrello V + dVPosA = dNewV + table.insert( vCmd, { 1, 'V', dVPosA}) + -- **[B2CVs-nr]** + else -- se ExtraV > 0 anche se non significativo + EmitComment( vCmd, '[B2CVs-nr]') + EgtOutLog( ' CLAMP : posizione V non raggiungibile' .. '- caso [B2cVs-nr] non gestito') + error( 'CLAMP : posizione V non raggiungibile') + end + end --[B2CsV] + + -- **[B2Cn]** |nessuno spostamento (ev' residuo significativo)| + else + EmitComment( vCmd, '[B2Cn]') + end -- [B2C] + + -- calcolo i nuovi parametri di aggancio + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- imposto stato carrelli, per eventuale uso pressori + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + -- imposto i nuovi parametri di aggancio + table.insert( vCmd, { 21, dYDeltaA, dVDeltaA}) + + EgtOutLog( ' YDeltaA =' .. EgtNumToString( dYDeltaA) .. ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrB2 + +--------------------------------------------------------------------------------------------------------- +-- *** [B3] da carrello V a entrambi i carrelli : V -> Y+V *** +--------------------------------------------------------------------------------------------------------- +function SpecAdjustCarrB3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + EgtOutLog( ' *[B3] = V -> Y+V', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'V -> Y+V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + local dCorsaY = MaxY - MyMinY + local dCorsaV = MaxV - MinV + -- recupero le posizioni correnti + local dVPosA = dTPosI + dVDeltaI + local dYPosA = ParkY + local dTPosA = dTPosI + local dVDeltaA = dVDeltaI + local dYDeltaA = dYPosA - dTPosA + local dNewYDelta + local dNewVDelta + -- incremento la distanza tra le due posizioni ( se abilitato e possibile) + local dYDeltaAgg, dVDeltaAgg = AdjustPositionsForB( dYDeltaF, dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, bFixedDelta) + -- tolleranze + local dYDeltaTol = dYDeltaAgg + GetDeltaTol( EMC.LB - dYDeltaF - dYDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'Y', bFixedDelta) + local dVDeltaTol = dVDeltaAgg + GetDeltaTol( dVDeltaF - dVDeltaAgg, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + -- definisco criteri per movimenti 'significativi' in base alle 'nuove' tolleranze + local bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + local bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- reimposto i delta finali in caso di spostamenti richiesti significativi, tenuto conto delle tolleranze + if bYDeltaS then + dNewYDelta = dYDeltaF + dYDeltaTol / 2 + else + dNewYDelta = dYDeltaA + end + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol / 2 + else + dNewVDelta = dVDeltaA + end + + EgtOutLog( ' YDeltaI(Park)='.. EgtNumToString( dYDeltaA)..' VDeltaI=' .. EgtNumToString( dVDeltaA) .. + ' TPosI='.. EgtNumToString( dTPosI), 1) + EgtOutLog( ' YDeltaF=' .. EgtNumToString( dYDeltaF) .. ' VDeltaF=' .. EgtNumToString( dVDeltaF), 1) + EgtOutLog( ' NewYDelta=' .. EgtNumToString( dNewYDelta) .. ' NewVDelta=' .. EgtNumToString( dNewVDelta), 1) + -- risalita testa a Zmax + local bZmaxOk = false + + -- calcoli preliminari in caso di spostamento richiesto per Y significativo + local dYPos, dVPos, dTPos + local dNewY, dExtraY, bYxs + local dCorsaYfc, dCorsaVfc, dDistFrN, dCorsaYTd, dCorsaVd, dCorsaVTr, dCorsaYr, bXsw + if bYDeltaS then + -- definisco 'ExtraY' con (V+T) e Y accentrati q.b. per la presa di Y + dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'Y') + dNewY = dTPos + dNewYDelta + dExtraY = dNewY - MyMinY -- se < 0 pos. Y non direttamente 'raggiungibile' + bYxs = -dExtraY > dYDeltaTol/2 -- ExtraY 'significativo' + if bYxs then + -- calcolo le **corse disponibili dei carrelli a partire da Y e V c.s.** per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPos + dCorsaVfc = dVPos - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto **le corse di 'recupero'** dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + (MaxV - dVPos) + dCorsaYr = dCorsaYTd + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end + -- inizializzo + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + end + + -- **[B3Ys-xsw]** posizione finale dNewV non raggiungibile, con |dEXtraY > CorsaVr + CorsaYr| + while bXsw do + EmitComment( vCmd, '[B3Ys-xsw]') + + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- |1:| posiziono (V+T) e Y come calcolato sopra + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- |2:| allontano (Y+T) e V quanto possibile + dYPosA = dYPosA + dCorsaYTd + dTPosA = dTPosA + dCorsaYTd + dVPosA = dVPosA - dCorsaVd + table.insert( vCmd, { 3, 'Y', dTPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |3:| accentro (V+T) e Y + dVPosA = dVPosA + dCorsaVTr + dTPosA = dTPosA + dCorsaVTr + dYPosA = MyMinY + table.insert( vCmd, { 3, 'Y', dTPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto i Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bYDeltaS = ( dYDeltaF < dYDeltaA - dYDeltaTol or dYDeltaF > dYDeltaA + DELTA_SIC) + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- aggiorno ExtraY + dExtraY = dExtraY + dCorsaYr + dCorsaVTr + + -- **aggiorno la valutazione delle corse disponibili** + -- a partire da Y e V c.s. per allontanare q.p. (Y+T) e V + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando Y e (V+T) + dCorsaVTr = dCorsaVd + dCorsaYr = dCorsaYTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bYDeltaS and bYxs and -dExtraY > dCorsaVTr + dCorsaYr + end --[B3Ys-xsw] + + -- **[B3Ys]** |spostamento| finale richiesto (ev' residuo) di |Y| |'significativo'| + if bYDeltaS then + EmitComment( vCmd, '[B3Ys]') + + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- **[B3Ys-x]** posizione di |Y non raggiungibile| + -- ( -dExtraY <= (CorsaYr+CorsaVr) da ciclo precedente ) + if dExtraY < 0 then + --EmitComment( vCmd, '[B3Ys-x]') + + -- **[B3Ys-xs]** |ExtraY 'significativo'| + if bYxs then + --EmitComment( vCmd, '[B3Ys-xs]') + + local dCorsaVTrA = MaxV - dVPosA + local dCorsaYra = dYPosA - MyMinY + -- **[B3Ys-xs1]** se posso recuperare ExtraY semplicem' accentrando Y e (V+T) + -- ulteriormente rispetto a YPos e Vpos definiti c.s. + if dCorsaVTrA >= -dExtraY then + EmitComment( vCmd, '[B3Ys-xs1]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: accentro** Y e (V+T) + dYPosA = MyMinY -- (pos. finale) + dVPosA = dVPosA - dExtraY + dTPosA = dTPosA - dExtraY + dYDeltaA = dYPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[B3Ys-xs2]** + EmitComment( vCmd, '[B3Ys-xs2]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: accentro** ev' Y e (V+T) alle posizioni impostate + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dYDeltaA = dYPosA - dTPosA + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2: allontano** (Y+T) e V + -- tenendo conto di dover 'recuperare' ExtraY... + dYPos1, dVPos1, dTPos1 = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraY, dCorsaVTrA, dCorsaYTd, dCorsaVd, 'Y') + local dYDispl1 = dYPos1 - dYPosA + local dVDispl1 = dVPos1 - dVPosA + local dVDeltaDiff = dNewVDelta - (dVPos1 - dTPos1) + -- ...e anche di posizionare possibilmente V alla posizione finale + if dVDeltaDiff < 0 then + CorsaYfc = MaxY - dYPos1 + dCorsaVfc = dVPos1 - MinV + dDistFrN = dVDeltaA - MinJoin - EMC.HCING - EMC.HOVM -- DistFront1 'netta' + dCorsaYTd, dCorsaVd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistFrN, 'Fr') + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPos1, dVPos1, dTPos1, dVDeltaDiff, 0, dCorsaYTd, dCorsaVd, 'Y') + else + dYPosA = dYPos1; dVPosA = dVPos1; dTPosA = dTPos1 + end + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + + -- chiudo il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **3: accentro** Y e (V+T) + dYPosA = dYPosA - dYDispl1 - dCorsaYra -- POS. FINALE + dVPosA = dVPosA - dVDispl1 + dCorsaVTrA -- POS. FINALE + dTPosA = dTPosA - dVDispl1 + dCorsaVTrA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B3Ys-xs1/-xs2] + + -- **[B3Ys-xn]** |dExtraY ancora < 0 ma non 'significativo')| + else --if -dExtraY < DeltaToll/2 + EmitComment( vCmd, '[B3Ys-xn]') + -- ev' chiudo V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- 1: accentro Y e porto (V+T) alla posizione impostata + dExtraY = 0 + dYPosA = MyMinY -- (pos. finale) + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end --[B3Ys-xs/xn] + + -- **[B3Ys-r]** |dExtraY > 0 (pos. Y raggiungibile)| + else + EmitComment( vCmd, '[B3Ys-r]') + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- posizione ev' (V+T) come impostato sopra e Y in posizione finale + dYPosA = dTPosA + dNewYDelta + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [B3Ys] + -- + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + + else -- [B3Yns] |spostamento| finale richiesto (ev' residuo) di |Y non 'significativo'| + EmitComment( vCmd, '[B3Yns]') + end --[B3Ys/ns] + + -- aggiorno la verifica di movimento 'significativo' per V + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- **[B3Vs]** Se vi è uno |spostamento residuo di V significativo'| + if bVDeltaS then + EmitComment( vCmd, '[B3Vs]') + + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + local dNewV = dTPosA + dNewVDelta + local dExtraV = dNewV - MaxV + + -- **[B3Vs-x]** se pos. |NewV non è raggiungibile direttamente| (oltre MaxV) + if dExtraV > 0 then --dNewV <= MaxV then + -- **[B3Vs-xs]** |ExtraV 'significativo'| + if dExtraV > dVDeltaTol /2 then + EmitComment( vCmd, '[B3Vs-xs]') + EgtOutLog( ' CLAMP : caso [B3Vs-xs] non gestito') + error( ' CLAMP : caso [B3Vs-xs] non gestito') + + -- **[B3Vs-xn]** |ExtraV non 'significativo'| + else + EmitComment( vCmd, '[B3Vs-xn]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- accentro V q.p. + dVPosA = MaxV + table.insert( vCmd, { 1, 'V', dVPosA}) + end -- [B3Vs-xs/xn] + + else -- **[B3Vs-r]** pos. |NewV raggiungibile direttamente| (non oltre MaxV) + EmitComment( vCmd, '[B3Vs-r]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- sposto il carrello V + dVPosA = dNewV + table.insert( vCmd, { 1, 'V', dVPosA}) + end --[B3Vs-x/-r] + + else -- [B3Vns] spostamento residuo di V non significativo + EmitComment( vCmd, '[B3Vns]') + end -- [B3Vs/ns] + + -- calcolo i nuovi parametri di aggancio + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- se non emessi movimenti, imposto posizione Y + if not bZmaxOk then + -- risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + table.insert( vCmd, { 1, 'Y', dYPosA}) + end + -- imposto stato carrelli, per eventuale uso pressori (sempre effettuato movimento) + table.insert( vCmd, { 11, CalcCharStatus( 'Y', dYDeltaA)}) + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + -- imposto i nuovi parametri di aggancio + table.insert( vCmd, { 21, dYDeltaA, dVDeltaA}) + + EgtOutLog( ' YDeltaA =' .. EgtNumToString( dYDeltaA) .. ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end -- SpecAdjustCarrB3 + +--------------------------------------------------------------------- +-- *** [C1] da carrello Y a V : Y -> V *** +--------------------------------------------------------------------- +function SpecAdjustCarrC1( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + EgtOutLog( ' *[C1] = Y -> V ', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y -> V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + -- recupero le posizioni correnti + --local dCorsaY = MaxY - MyMinY + --local dCorsaV = MaxV - MinV + local dYPosA = dTPosI + dYDeltaI + local dVPosA = ParkV + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVPosA - dTPosA + local dNewVDelta -- = dVDeltaF + -- tolleranza + local dVDeltaTol = GetDeltaTol( dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + local bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- reimposto i delta finali in caso di spostamenti richiesti significativi, tenuto conto delle tolleranze + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol/2 + else + dNewVDelta = dVDeltaA + end + EgtOutLog(' YDeltaI=' .. EgtNumToString( dYDeltaA) .. ' VDeltaI(Park)='.. EgtNumToString( dVDeltaA).. + ' TPosI=' .. EgtNumToString( dTPosI) , 1) + EgtOutLog(' VDeltaF=' .. EgtNumToString( dVDeltaF) .. ' NewVDelta=' .. EgtNumToString( dNewVDelta) , 1) + + -- risalita testa a Zmax (da effettuare comunque, dato lo scambio di carrelli) + local bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- calcoli preliminari in caso di spostamento richiesto per V significativo + local dYPos, dVPos, dTPos + local dNewV, dExtraV, bVxs + local dCorsaYfc, dCorsaVfc, dDistFrN, dCorsaYTd, dCorsaVd, dCorsaVTr, dCorsaYr, bXsw + if bVDeltaS then + -- definisco 'ExtraV' con (Y+T) e V accentrati q.b. per la presa di V + dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'V') + dNewV = dTPos + dNewVDelta + dExtraV = dNewV - MaxV + bVxs = dExtraV > dVDeltaTol/2 -- ExtraV 'significativo' + if bVxs then + -- calcolo le **corse disponibili dei carrelli a partire da Y e V c.s.** per allontanare q.p. Y e (V+T) + dCorsaYfc = MaxY - dYPos + dCorsaVfc = dVPos - MinV + --local dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dDistBkN = EMC.LB - (dYPos-dTPos) - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando (Y+T) e V + dCorsaYTr = dCorsaYd + (dYPos -MyMinY) + dCorsaVr = dCorsaVTd + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaVr + dCorsaYTr + end + -- inizializzo + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + end + + -- **[C1Vs-xsw]** posizione finale di V non raggiungibile, con |dEXtraV > CorsaVr + CorsaYr| + -- con spostamento richiesto significativo e ExtraV significativo + while bXsw do + EmitComment( vCmd, '[C1Vs-xsw]') + -- **1:** posiziono (Y+T) e V come calcolato sopra + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2:** allontano Y e (V+T) quanto possibile + dYPosA = dYPosA + dCorsaYd + dVPosA = dVPosA - dCorsaVTd + dTPosA = dTPosA - dCorsaVTd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **3:** accentro (Y+T) e V + dYPosA = dYPosA - dCorsaYTr -- = MyMinY + dTPosA = dTPosA - dCorsaYTr + dVPosA = MaxV + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto i Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- **aggiorno ExtraV** + dExtraV = dExtraV - dCorsaYTr - dCorsaVr + -- **aggiorno la valutazione di ulteriori corse disponibili** + -- a partire da Y e V c.s. per allontanare q.p. Y e (V+T) + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- aggiorno i prossimi recuperi disponibili + dCorsaYTr = dCorsaYd + dCorsaVr = dCorsaVTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaVr + dCorsaYTr + end --[C1Vs-xw] + + -- **[C1Vs]** |spostamento| richiesto (ev' residuo) |di V| |'significativo'| + if bVDeltaS then + -- **[C1Vs-x]** posizione di |V non raggiungibile| + if dExtraV > 0 then + -- (dExtraV <= (CorsaYr+CorsaVr) da ciclo precedente) + -- **[C1Vs-xs]** posizione di V non raggiungibile, |con ExtraV 'significativo'| + if bVxs then + local dCorsaYTrA = dYPosA - MyMinY + -- **[C1Vs-xs1]** se posso recuperare dExtraV solo accentrando V e (Y+T) + if dCorsaYTrA >= dExtraV then + EmitComment( vCmd, '[C1Vs-xs1]') + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** accentro (Y+T) q.b. e V + dYPosA = dYPosA - dExtraV + dTPosA = dTPosA - dExtraV + dVPosA = MaxV -- (pos. finale) + dVDeltaA = dVPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + -- **[C1Vs-xs2]** dCorsaYTrA < dExtraV + else + EmitComment( vCmd, '[C1Vs-xs2]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: accentro** ev' (Y+T) e V alle posizioni impostate + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + dVDeltaA = dVPosA - dTPosA + -- chiudo (ev') il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **2:allontano** (V+T) q.b./q.p. e Y per preparare il recupero di ExtraV + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraV, dCorsaYTrA, dCorsaYd, dCorsaVTd, 'V') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dYDeltaA = dYPosA - dTPosA + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **3: accentro**(Y+T) e V (pos. finale) + dYPosA = MyMinY + dTPosA = dYPosA - dYDeltaA + dVPosA = MaxV + dVDeltaA = dVPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + end -- [C1Vs-xs1/xs2] + + -- **[C1Vs-xn]** |ExtraV ancora > 0 , ma non 'significativo'| (<= DeltaTol/2) + else + EmitComment( vCmd, '[C1Vs-xn]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- 1: porto ev' (Y+T) alla posizione impostata sopra e accentro V + dExtraV = 0 + dVPosA = MaxV -- pos. finale + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + -- chiudo V (?) + table.insert( vCmd, { 12, 1}) + end -- [C1Vs-xs/xn] + + -- **[C1Vs-r]** posizione di V 'raggiungibile' (ExtraV <= 0) + else + EmitComment( vCmd, '[C1Vs-r]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- posizione ev' (Y+T) come impostato sopra e V in posizione finale + dVPosA = dTPosA + dNewVDelta + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [C1V-s] + + -- **[C1Vns]** |spostamento| richIesto per V |non 'significativo'| + else + EmitComment( vCmd, '[C1Vns]') + end + + -- calcolo i nuovi parametri di aggancio + dVDeltaA = dVPosA - dTPosA + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + table.insert( vCmd, { 11, 0}) + -- sposto il carrello Y in parcheggio + table.insert( vCmd, { 1, 'Y', ParkY}) + -- imposto i nuovi parametri di aggancio + table.insert( vCmd, { 21, 0, dVDeltaA}) + + EgtOutLog( ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrC1 + +--------------------------------------------------------------------- +-- *** [C2] da entrambi i carrelli a V : Y+V -> V *** +--------------------------------------------------------------------- +function SpecAdjustCarrC2( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta) + EgtOutLog( ' *[C2] = Y+V -> V', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'Y+V -> V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + local dCorsaY = MaxY - MyMinY + local dCorsaV = MaxV - MinV + -- recupero le posizioni correnti dei carrelli + local dYPosA = dTPosI + dYDeltaI + local dVPosA = dTPosI + dVDeltaI + local dTPosA = dTPosI + local dYDeltaA = dYDeltaI + local dVDeltaA = dVDeltaI + local dNewVDelta -- = dVDeltaF + -- tolleranze + local dVDeltaTol = GetDeltaTol( dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + -- definisco spostamento 'significativo' in base alle tolleranze + local bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- reimposto ev' il delta finale + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol/2 + else + dNewVDelta = dVDeltaA + end + -- definisco 'ExtraV' + local dNewV = dTPosI + dNewVDelta + local dExtraV = dNewV - MaxV -- > 0 se nuova pos. di V 'non raggiungibile' (= oltre MaxV) + local bVxs = dExtraV > dVDeltaTol/2 -- 'ExtraV significativo' + + EgtOutLog( ' YDeltaI=' .. EgtNumToString( dYDeltaI) .. ' VDeltaI=' .. EgtNumToString( dVDeltaI) .. + ' VDeltaF=' .. EgtNumToString( dVDeltaF) ,1) + EgtOutLog( ' NewVDelta=' .. EgtNumToString( dNewVDelta), 1) + + -- risalita testa a Zmax (da effettuare comunque, per il parcheggio di Y) + local bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + + -- calcoli preliminari in caso di spostamento richiesto per YV significativo + local dCorsaYfc, dCorsaVfc, dDistBkN, dCorsaYd, dCorsaVd, dCorsaVTd, dCorsaYTr, dCorsaVr, bXsw + if bVDeltaS then + if bVxs then + -- calcolo le corse disponibili dei carrelli dalle posizioni attuali (=iniziali) + -- per allontanare Y e (V+T) q.p. + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- valuto le corse di 'recupero' dai due carrelli possibili riaccentrando (Y+T) e V + dCorsaYTr = dCorsaYd + (dYPosA - MyMinY) + dCorsaVr = dCorsaVTd + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaYTr + dCorsaVr + end + end + + -- **[C2Vs-xsw]** posizione finale di V non raggiungibile, |con dEXtraV > CorsaYTr + CorsaVr| + while bXsw do + EmitComment( vCmd, '[C2Vs-xsw]') + + -- chiudo eventualmente il carrello V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- |1:| allontano Y e (V+T) quanto possibile + dYPosA = dYPosA + dCorsaYd + dVPosA = dVPosA - dCorsaVTd + dTPosA = dTPosA - dCorsaVTd + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- |3:| accentro (Y+T) e V + dYPosA = dYPosA - dCorsaYTr + dTPosA = dTPosA - dCorsaYTr + dVPosA = MaxV + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + + -- valuto i Delta ottenuti + dYDeltaA = dYPosA - dTPosA + dVDeltaA = dVPosA - dTPosA + -- aggiorno la verifica di spostamento significativo + bVDeltaS = ( dVDeltaF > dVDeltaA + dVDeltaTol or dVDeltaF < dVDeltaA - DELTA_SIC) + -- **aggiorno ExtraV** + dExtraV = dExtraV - dCorsaYTr - dCorsaVr + -- **aggiorno la valutazione di ulteriori corse disponibili** + dCorsaYfc = MaxY - dYPosA + dCorsaVfc = dVPosA - MinV + dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- aggiorno i prossimi recuperi disponibili + dCorsaYTr = dCorsaYd + (dYPosA - MyMinY) + dCorsaVr = dCorsaVTd + -- aggiorno verifica per ripetizione del ciclo + bXsw = bVDeltaS and bVxs and dExtraV > dCorsaYTr + dCorsaVr + end -- [C2V-xsw] + + -- **[C2Vs]** se lo |spostamento richiesto per V è significativo| + if bVDeltaS then + -- **[C2Vs-x]** posizione di |V non raggiungibile| (oltre MaxV) + if dExtraV > 0 then + -- **[C2Vs-xs]** |ExtraV 'significativo'| + if bVxs then + local dCorsaYTrA = dYPosA - MyMinY + -- **[C2Vs-xs1]** se posso recuperare ExtraV semplicem' accentrando V e (Y+T) + if dCorsaYTrA >= dExtraV then + EmitComment( vCmd, '[C2Vs-xs1]') + + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: accentro** (Y+T) e V + dYPosA = dYPosA - dExtraV + dTPosA = dTPosA - dExtraV + dVPosA = MaxV -- (pos. finale) + dVDeltaA = dVPosA - dTPosA + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + + else -- **[C2Vs-xs2]** + EmitComment( vCmd, '[C2Vs-xs2]') + + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, 1}) + table.insert( vCmd, { 11, 0}) + -- **1: allontano** (V+T) e Y + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraV, dCorsaYTrA, dCorsaYd, dCorsaVTd, 'V') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dYDeltaA = dYPosA - dTPosA + + -- chiudo il carrello Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2: accentro** (Y+T) e V + dYPosA = MyMinY + dTPosA = dYPosA - dYDeltaA + dVPosA = MaxV -- (pos. finale) + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [C2Vs-xs1/-xs2] + + -- **[C2Vs-xn]** |dExtraV ancora > 0 ma non 'significativo')| + else --if dExtraV < DeltaToll/2 + EmitComment( vCmd, '[B1Vs-xn]') + -- ev' chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** accentro V + dExtraV = 0 + dVPosA = MaxV -- (pos. finale) + table.insert( vCmd, { 1, 'V', dVPosA}) + end -- [C2s-xs/xn] + + -- **[C2Vs-r]** |dExtraV < 0 (pos. V raggiungibile)| + else + EmitComment( vCmd, '[C2Vs-r]') + -- chiudo ev' Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- porto V in posizione finale + dVPosA = dTPosA + dNewVDelta + table.insert( vCmd, { 1, 'V', dVPosA}) + end --[C2Vs] + + -- **[C2Vns]** = |spostamento di V non significativo| + else + EmitComment( vCmd, '[C2Vns]') + end --[C2Vs/n] + + -- calcolo il nuovo parametro di aggancio + dVDeltaA = dVPosA - dTPosA + -- chiudo eventualmente il carrello V e apro Y + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + table.insert( vCmd, { 11, 0}) + -- sposto il carrello Y in parcheggio + table.insert( vCmd, { 1, 'Y', ParkY}) + -- imposto il nuovo parametro di aggancio + table.insert( vCmd, { 21, 0, dVDeltaA}) + + EgtOutLog( ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + -- reset contatore + EMC.CNT = nil + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrC2 + +--------------------------------------------------------------------- +-- *** [C3] da carrello V a V : V -> V *** +--------------------------------------------------------------------- +function SpecAdjustCarrC3( dTPosI, dYDeltaI, dVDeltaI, dTPosF, dYDeltaF, dVDeltaF, bFixedDelta, bFixedPos) + EgtOutLog( ' *[C3] = V -> V', 1) + -- elenco comandi + local vCmd = {} + -- Commento + table.insert( vCmd, { 0, 'V -> V'}) + -- se primo scambio + local MyMinY = EgtIf( EMC.CNT == 1, MinY + AGG_LOAD, MinY) + -- recupero le posizioni correnti dei carrelli + local dVPosA = dTPosI + dVDeltaI + local dYPosA = ParkY + local dTPosA = dTPosI + local dVDeltaA = dVDeltaI + local dYDeltaA = dYPosA - dTPosA + local dNewVDelta + -- tolleranza + local dVDeltaTol = GetDeltaTol( dVDeltaF, EMC.TCING, EMC.HCING, EMC.HOVM, 'V', bFixedDelta) + local bVDeltaS = (( dVDeltaF > dVDeltaA + dVDeltaTol and not bFixedPos) or dVDeltaF < dVDeltaA - DELTA_SIC) + if bVDeltaS then + dNewVDelta = dVDeltaF - dVDeltaTol / 2 + else + dNewVDelta = dVDeltaA + end + EgtOutLog( ' VDeltaI=' .. EgtNumToString( dVDeltaI) .. ' TPosI=' .. EgtNumToString( dTPosI), 1) + EgtOutLog( ' VDeltaF=' .. EgtNumToString( dVDeltaF) .. ' NewVDelta=' .. EgtNumToString( dNewVDelta), 1) + -- flag per risalita testa a Zmax + local bZmaxOk = false + + -- **[C3Vs]** |pos. di V cambia in modo significativo| + if bVDeltaS then + EmitComment( vCmd, '[C3Vs]') + -- eventuale risalita testa a Zmax + bZmaxOk = EnsureZmax( bZmaxOk, vCmd) + -- definisco 'ExtraV' con (V+T) e Y accentrati q.b. per la presa con Y + local dYPos, dVPos, dTPos = PosxExtraYV( dYPosA, dVPosA, dTPosA, MyMinY, MaxV, 'Y') + local dNewV = dTPos + dNewVDelta + local dExtraV = dNewV - MaxV + -- effettuo spostamenti per predisporre all'aggancio di T con Y + dYPosA = dYPos + dVPosA = dVPos + dTPosA = dTPos + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dYDeltaA = dYPosA - dTPosA + + -- **[C3Vs-x]** posizione di |V non raggiungibile| (oltre MaxV) + if dExtraV > 0 then + -- **[C3Vs-xs]** posizione di V non raggiungibile, |con ExtraV 'significativo'| + if dExtraV > dVDeltaTol /2 then + -- calcolo le **corse disponibili dei carrelli a partire da Y e V c.s.** per allontanare q.p. (V+T) e Y + local dCorsaYfc = MaxY - dYPos + local dCorsaVfc = dVPos - MinV + local dDistBkN = EMC.LB - dYDeltaA - MinJoin - EMC.TCING -- DistBack 'netta' + local dCorsaYd, dCorsaVTd = GetCorseDisp( dCorsaYfc, dCorsaVfc, dDistBkN, 'Bk') + -- valuto **le corse di 'recupero'** dai due carrelli possibili riaccentrando (Y+T) e V + local dCorsaYTr = dCorsaYd + (dYPos - MyMinY) + local dCorsaVr = dCorsaVTd + + -- **[C3Vs-xsw]** posizione finale dNewV non raggiungibile, con |dEXtraV > CorsaVr + CorsaYr| + if dExtraV > ( dCorsaYTr + dCorsaVr) and bVDeltaS then + EmitComment( vCmd, '[C3Vs-xsw]' .. 'CASO NON GESTITO') + return + end + + local dCorsaYTrA = dYPos - MyMinY -- !! att.ne: non dYPosA !! + -- **[C3Vs-xs1]** se posso recuperare ExtraV semplicem' accentrando (Y+T) e V + -- (dalle posizione impostate sopra per l'aggancio di Y) + if dCorsaYTrA >= dExtraV then + EmitComment( vCmd, '[C3Vs-xs1]') + -- chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1: accentro** (Y+T) e V + dYPosA = dYPosA - dExtraV + dTPosA = dTPosA - dExtraV + dVPosA = MaxV -- (pos. finale) + table.insert( vCmd, { 3, 'Y', dYPosA , 'T', dTPosA, 'V', dVPosA}) + dVDeltaA = dVPosA - dTPosA + + else -- **[C3Vs-xs2]** + -- ci sarebbe un doppio movimento di V ? => caso impossibile ? + EmitComment( vCmd, '[C3Vs-xs2]') + -- **1:** posiziono (ulteriormente!) Y e (V+T) + dYPosA, dVPosA, dTPosA = PosXs2Enl( dYPosA, dVPosA, dTPosA, dExtraV, dCorsaYTrA, dCorsaYd, dCorsaVTd, 'V') + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA }) + dYDeltaA = dYPosA - dTPosA + -- chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2: accentro** (Y+T) e V + dYPosA = MyMinY + dVPosA = MaxV -- (pos. finale) + dTPosA = dYPosA - dYDeltaA + table.insert( vCmd, { 3, 'Y', dYPosA, 'T', dTPosA, 'V', dVPosA}) + end -- [C3Vs-xs1/-xs2] + + -- **[C3Vs-xn]** |dExtraV > 0 ma 'non significativo')| + else --if dExtraV < DeltaToll/2 + EmitComment( vCmd, '[C3Vs-xn]') + -- chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **1:** accentro V + dExtraV = 0 + dVPosA = MaxV -- (pos. finale) + table.insert( vCmd, { 1, 'V', dVPosA}) + end --[C3Vs-xs/xn] + + -- **[C3Vs-r]** |posizione di Y raggiungibile| (ExtraY >=0) + -- (si esclude la possibilità di extra corsa oltre maxY) + else + EmitComment( vCmd, '[C3Vs-r]') + -- chiudo Y e apro V + table.insert( vCmd, { 11, 1}) + table.insert( vCmd, { 12, 0}) + -- **2:** posiziono V alla posizione richiesta + dVPosA = dNewV + table.insert( vCmd, { 1, 'V', dVPosA}) + end -- [C3Vs] + + -- calcolo il nuovo parametro di aggancio + dVDeltaA = dVPosA - dTPosA + -- chiudo ev' V e apro Y + table.insert( vCmd, { 12, CalcCharStatus( 'V', dVDeltaA)}) + table.insert( vCmd, { 11, 0}) + -- sposto il carrello Y in parcheggio + table.insert( vCmd, { 1, 'Y', ParkY}) + -- imposto il nuovo parametro di aggancio + table.insert( vCmd, { 21, 0, dVDeltaA}) + + -- reset contatore + EMC.CNT = nil + + else -- **[C3Vns]** |spostamento| finale richiesto (ev' residuo) di |V non 'significativo'| + EmitComment( vCmd, '[C3Vns]') + end --[C3Vs/ns] + + EgtOutLog( ' VDeltaA =' .. EgtNumToString( dVDeltaA), 1) + + SpecOutputCNT() + return vCmd +end --SpecAdjustCarrC3 + +--------------------------------------------------------------------- +function SpecOutputCNT() + if EMC.CNT == 1 then + EgtSetInfo( EMC.PATHID, 'CNT', 1) + else + EgtRemoveInfo( EMC.PATHID, 'CNT') + end +end + +--------------------------------------------------------------------- +function SpecOutputCmds( vCmd, bEnd) + + local sRoot = EgtIf( not bEnd, 'AS', 'AE') + + -- Registro il numero di comandi + if #vCmd > 0 then + EgtSetInfo( EMC.PATHID, sRoot..'#', #vCmd) + else + EgtRemoveInfo( EMC.PATHID, sRoot..'#') + end + -- Registro i comandi + for i = 1, #vCmd do + local Cmd = vCmd[i] + local sKey = sRoot..tostring( i) + -- commento + if Cmd[1] == 0 then + local sInfo = '0,'..Cmd[2] + if Cmd[3] then sInfo = sInfo..','..Cmd[3] end + EgtSetInfo( EMC.PATHID, sKey, sInfo) + -- movimento di 1 asse + elseif Cmd[1] == 1 then + local sInfo = '1,'..Cmd[2]..','..EgtNumToString( Cmd[3],3) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + -- movimento di 2 assi + elseif Cmd[1] == 2 then + local sInfo = '2,'..Cmd[2]..','..EgtNumToString( Cmd[3],3)..','..Cmd[4]..','..EgtNumToString( Cmd[5],3) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + -- movimento di 3 assi + elseif Cmd[1] == 3 then + local sInfo = '3,'..Cmd[2]..','..EgtNumToString( Cmd[3],3)..','..Cmd[4]..','..EgtNumToString( Cmd[5],3)..','.. + Cmd[6]..','..EgtNumToString( Cmd[7],3) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + -- apertura/chiusura morsa Y + elseif Cmd[1] == 11 then + local sInfo = '11,'..EgtNumToString( Cmd[2],0) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + if Cmd[2] == 0 then EMC.YDELTA = nil end + -- apertura/chiusura morsa V + elseif Cmd[1] == 12 then + local sInfo = '12,'..EgtNumToString( Cmd[2],0) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + if Cmd[2] == 0 then EMC.VDELTA = nil end + -- impostazione nuovo stato dei carrelli + elseif Cmd[1] == 21 then + local sInfo = '21,'..EgtNumToString( Cmd[2],3)..','..EgtNumToString( Cmd[3],3) + EgtSetInfo( EMC.PATHID, sKey, sInfo) + if Cmd[2] > 0 and Cmd[3] > 0 then + EMC.YDELTA = Cmd[2] + EMC.VDELTA = Cmd[3] + elseif Cmd[2] > 0 then + EMC.YDELTA = Cmd[2] + EMC.VDELTA = nil + elseif Cmd[3] > 0 then + EMC.YDELTA = nil + EMC.VDELTA = Cmd[3] + end + -- aggancio grezzo a carrello + elseif Cmd[1] == 31 then + local sInfo = '31,'..EgtNumToString( Cmd[2],0)..','..Cmd[3] + EgtSetInfo( EMC.PATHID, sKey, sInfo) + end + end + + -- Salvo i nuovi delta dei carrelli + if EMC.YDELTA then + EgtSetInfo( EMC.PATHID, 'YDELTA', EMC.YDELTA) + else + EgtRemoveInfo( EMC.PATHID, 'YDELTA') + end + if EMC.VDELTA then + EgtSetInfo( EMC.PATHID, 'VDELTA', EMC.VDELTA) + else + EgtRemoveInfo( EMC.PATHID, 'VDELTA') + end + +end + +--------------------------------------------------------------------- +function SpecSetCarrPosFromCmds( vCmd) + -- recupero nuova posizione carrelli + for i = 1, #vCmd do + local Cmd = vCmd[i] + if Cmd[1] == 21 then + if Cmd[2] > 0 and Cmd[3] > 0 then + EMC.YDELTA = Cmd[2] + EMC.VDELTA = Cmd[3] + elseif Cmd[2] > 0 then + EMC.YDELTA = Cmd[2] + EMC.VDELTA = nil + elseif Cmd[3] > 0 then + EMC.YDELTA = nil + EMC.VDELTA = Cmd[3] + end + end + end +end + +--------------------------------------------------------------------- +function SpecTestOnlyRemarkInCmds( vCmd) + if not vCmd then return true end + -- verifico se nella lista dei comandi ci sono solo commenti + for i = 1, #vCmd do + if vCmd[i][1] ~= 0 then + return false + end + end + return true +end diff --git a/Essetre-TURN.nge b/Essetre-TURN.nge new file mode 100644 index 0000000..6a5321e Binary files /dev/null and b/Essetre-TURN.nge differ diff --git a/Messages/Eng.txt b/Messages/Eng.txt new file mode 100644 index 0000000..758cf28 --- /dev/null +++ b/Messages/Eng.txt @@ -0,0 +1,255 @@ +// English machine message file 2022/01/17 + +[MDI] +1=Take tool n° 1 +2=Take tool n° 2 +3=Take tool n° 3 +4=Take tool n° 4 +5=Take tool n° 5 +6=Take tool n° 6 +7=Take tool n° 7 +8=Take tool n° 8 +9=Take tool n° 9 +10=Take tool n° 10 +11=Take tool n° 11 +12=Take tool n° 12 +13=Take tool n° 13 +14=Take tool n° 14 +15=Take tool n° 15 +16=Take tool n° 16 +17=Take tool n° 17 +18=Take tool n° 18 +19=Head whitout tool +20=Take the Chainsaw +21=Activate tool magazine +22=Tool tool loader n°1 Forwards +23=Tool tool loader n°1 Backwards +24=Tool tool loader n°2 Forwards +25=Tool tool loader n°2 Backwards +26=Tool tool loader Chainsaw Forwards +27=Tool tool loader Chainsaw Backwards +28=Front zero reference ascent +29=Front zero reference descent +30=Lateral zero roller ascent +31=Lateral zero roller descent +32=Ability clockwise rotation right driller motor +33=Ability counterclockwise rotation right driller motor +34=Ability clockwise rotation left driller motor +35=Ability counterclockwise rotation left driller motor +36=Stop rotation of drilling spindles +37=Manual tool number assignment in the 5-axis head (E80001=1; E80001=2; E80001=3;ETC...) + +[PLC] +1=Macchina spenta +2=Assi in extracorsa +3=Attesa carico trave +4=Attesa chiusura Pinza 1 +5=Attesa apertura Pinza 1 +6=Attesa chiusura Pinza 4 +7=Attesa apertura Pinza 4 +8=Verificare olio lubrificazione aggregati catena +9=Termici motori +10=Trasferimento programma in corso +11=Modulo Adam 1 non Ok verificare V7624.L +12=Minimo livello grasso +13=Difetto impianto lubrificazione assi verificare livello grasso +14=Manca aria compressa +15=Sovratemperatura armadio elettrico Cn +16=Modulo Adam 2 non Ok verificare V7634.L +17=Refrigratore mandrini +18=Sovratemperatura armadio elettrico Drive +19=Verificare collegamento Marcatore +20=Attesa marcatore libero +21=Barriere intervenute !!! +22=Attesa conferma per chiusura Pinza 1 o 4 +23=Malfunzionamento azion. asse X Slave +24=Malfunzionamento asse X Testa 1 +25=Malfunzionamento asse Y +26=Malfunzionamento asse Z Testa 1 +27=Malfunzionamento asse A Testa 1 +28=Malfunzionamento asse B +29=Malfunzionamento asse V +30=Malfunzionamento asse Cu Testa 1 +31=Malfunzionamento asse Cu Testa 2 +32=Asse A bloccato +33=Bypass segnali assi digitali attivo +34=Attesa chiusura Pinza 2 +35=Attesa apertura Pinza 2 +36=Attesa chiusura Pinza 3 +37=Attesa apertura Pinza 3 +38= +39=Sensore controllo giri Lama guasto +40=Fuori giri Lama +41=Attesa ribaltamento 90 gradi trave (Girare chiave in modo manuale) +42=Attesa ribaltamento 180 gradi trave (Girare chiave in modo manuale) +43=Attesa ribaltamento 270 gradi trave (Girare chiave in modo manuale) +44=Attesa scarico spezzone in entrata (Girare chiave in modo manuale) +45=Attesa conferma scarico trave +46=Rotazione T1 proibita senza utensili: verificare +47=Rotazione T2 proibita senza utensili: verificare +48= +49= +50=Malfunzionamento asse X Testa 2 +51=Malfunzionamento asse Z Testa 2 +52=Malfunzionamento asse A Testa 2 +53=Malfunzionamento asse B2 Movimento Cu +54=Riferimento di zero entrata non basso +55=Riferimento di scarico non a riposo +56= +57= +58= +59=*** MANUTENZIONE CE *** +60=Attesa scarico utensile manuale +61=Attesa carico utensile manuale +62= +63=Attesa apertura totale pinza 3 +64=Attesa conferma carico trave +65=Attesa conferma scarico spezzone corto non tenuto da pinza 1 +66=Attesa conferma scarico spezzone su rulliera entrata +67=Attesa stampa etichetta pezzo precedente +68=Attesa carico trave M75 in corso +69=Traslatore scarico pieno +70=Testa nuovo trave non trovata +71=Corsa arretramento spezzone troppo grande +72=Ft lettura testa trave occupata +73=Attesa Start dopo carico trave con muletto +74=Pezzo scaricato su nastro !!!!! +75=Scaricare trave con muletto e resettare allarme +76=Pinza 1 chiusa senza trave aprirla con M111 +77=Pinza 4 chiusa senza trave aprirla con M171 +78=Micro controllo chiusura pinza 1 non Ok +79=Attesa conferma lavoro con pinza 4 dentro macchina VERIFICARE !!! +80=Pezzo incompleto alcune lavorazioni non eseguite !!! +81=Micro controllo chiusura pinza 4 non Ok +82=Attesa Ft pinza 1 lettura coda trave a zero +83=Cambi utensile non indietro !!! +84=Testa avanti programmare M90 e poi M199 +85=Cambio T201-T202 non possibile con pinza 1 impegnata +86=Attesa protezione cambio utensile aperta +87=Asse A fuori posizione +88=Avanti magazzino utensili non Ok +89=Indietro magazzino utensili non Ok +90= +91= +92= +93= +94= +95=Messa a punto inserita permessi solo movimenti manuali +96= +97= +98=Avanti testa per cambio utensile non Ok +99=Indietro testa per cambio utensile non Ok +100= +101=Motore T1 non in rotazione (Fcinv0=1) +102=Motore T2 non in rotazione (Fcinv0=1) +103= +104= +105=Larghezza trave EX non Ok !!! +106=Altezza trave EZ non Ok !!! +107= +108=Attendere inserzioni di potenza +109=Premere reset su CNC +110= +111=Malfunzionamento inverter 1 +112=Malfunzionamento inverter 2 +113= +114= +115= +116= +117= +118=Flussostato Testa 1 non Ok +119=Flussostato Testa 2 non Ok +120= +121=Sovratemperatura resistenze di frenatura inverter 1 +122=Sovratemperatura resistenze di frenatura inverter 2 +123= +124= +125= +126= +127= +128= +129= +130= +131=Sovratemperatura motore testa 1 +132=Sovratemperatura motore testa 2 +133= +134= +135= +136= +137= +138= +139= +140= +141=Sovracorrente inverter 1 +142=Sovracorrente inverter 2 +143= +144= +145= +146= +147= +148=Cambi utensili non avanti +149=Posizione cambio utensile 1 impegnata per scarico +150=Posizione cambio utensile 2 impegnata per scarico +151=Difetto bloccaggio utensile testa 1 +152=Difetto bloccaggio utensile testa 2 +153=Utensile presente su testa 1 con E80001=0 +154=Utensile presente su testa 2 con E80002=0 +155=Difetto sbloccaggio utensile testa 1 +156=Difetto sbloccaggio utensile testa 2 +157=Cono utensile testa 1 sporco +158=Cono utensile testa 2 sporco +159=Pistone sbloccaggio cono testa 1 non a riposo +160=Pistone sbloccaggio cono testa 2 non a riposo +161=Asse X1 non a zero per cambio utensile +162=Asse X2 non a zero per cambio utensile +163= +164= +165= +166= +167= +168= +169= + + +[CNC] +900=INVALID TOOL NUMBER M6T +901=TOOL NUMBER LOADED NOT OK +902=INVALID MOTOR TOOL NUMBER E80001 +903=SENSOR SETPOINT B MILLING NOT OK +904=SENSOR SETPOINT C MILLING NOT OK +905=SENSOR SETPOINT B SAW BLADE NOT OK +906=SENSOR SETPOINT C SAW BLADE NOT OK +907=UNLOAD CHAINSAW MANUALLY +908=WORK WITH 2 BLADES NOT POSSIBLE B<>90 OR C<>0 OR 180 +909=DEFINE TOOL NUMBER ENGINE SAW BLADE EU +910=G124 X REQUIRED +911=G124 Y REQUIRED +912=G124 B REQUIRED +913=G124 C REQUIRED +914=libero +915=libero +916=DEFINE SPINDLE NUMBER ET.. (1=BLADE 2=MILL 3=RIGHT DRILLER 4=LEFT DRILLER) +917=UNLOADING MOTOR TOOL +918=G104X.. REQUIRED +919=G104Y.. REQUIRED +920=G104Z.. REQUIRED +921=G104ET.. NOT OK (MANDATORY SCREWDRIVER NUMBER ET0-ET1-ET2-ET3) +922=G104EF.. NOT OK (REQUIRED LAYER NUMBER) +923=SETPOINT V SENSOR NOT OK +924=OFFSET X SAW BLADE NOT ALIGNED WITH CADCAM +925=OFFSET Y SAW BLADE NOT ALIGNED WITH CADCAM +926=OFFSET Z SAW BLADE NOT ALIGNED WITH CADCAM +927=PIVOT Z SAW BLADE NOT ALIGNED WITH CADCAM +928=PIVOT C SAW BLADE NOT ALIGNED WITH CADCAM +929=OFFSET X MILL NOT ALIGNED WITH CADCAM +930=OFFSET Y MILL NOT ALIGNED WITH CADCAM +931=OFFSET Z MILL NOT ALIGNED WITH CADCAM +932=PIVOT Z MILL NOT ALIGNED WITH CADCAM +933=MANDATORY X-U-W-Z PROGRAMMING WITH G102EH.. NON-ZERO +934=OFFSET X RIGHT DRILLER NOT ALIGNED WITH CADCAM +935=OFFSET Y RIGHT DRILLER NOT ALIGNED WITH CADCAM +936=OFFSET Z RIGHT DRILLER NOT ALIGNED WITH CADCAM +937=OFFSET X LEFT DRILLER NOT ALIGNED WITH CADCAM +938=OFFSET Y LEFT DRILLER NOT ALIGNED WITH CADCAM +939=OFFSET Z LEFT DRILLER NOT ALIGNED WITH CADCAM + diff --git a/Messages/FromMachine_Ita.txt b/Messages/FromMachine_Ita.txt new file mode 100644 index 0000000..827bc71 --- /dev/null +++ b/Messages/FromMachine_Ita.txt @@ -0,0 +1,170 @@ +% 9999.9 +N1 $01:Macchina spenta +N2 $02:Assi in extracorsa +N3 $03:Attesa carico trave +N4 $04:Attesa chiusura Pinza 1 +N5 $05:Attesa apertura Pinza 1 +N6 $06:Attesa chiusura Pinza 4 +N7 $07:Attesa apertura Pinza 4 +N8 $08:Verificare olio lubrificazione aggregati catena +N9 $09:Termici motori +N10 $10:Trasferimento programma in corso +N11 $11:Modulo Adam 1 non Ok verificare V7624.L +N12 $12:Minimo livello grasso +N13 $13:Difetto impianto lubrificazione assi verificare livello grasso +N14 $14:Manca aria compressa +N15 $15:Sovratemperatura armadio elettrico Cn +N16 $16:Modulo Adam 2 non Ok verificare V7634.L +N17 $17:Refrigratore mandrini +N18 $18:Sovratemperatura armadio elettrico Drive +N19 $19:Verificare collegamento Marcatore +N20 $20:Attesa marcatore libero +N21 $21:Barriere intervenute !!! +N22 $22:Attesa conferma per chiusura Pinza 1 o 4 +N23 $23:Malfunzionamento azion. asse X Slave +N24 $24:Malfunzionamento asse X Testa 1 +N25 $25:Malfunzionamento asse Y +N26 $26:Malfunzionamento asse Z Testa 1 +N27 $27:Malfunzionamento asse A Testa 1 +N28 $28:Malfunzionamento asse B +N29 $29:Malfunzionamento asse V +N30 $30:Malfunzionamento asse Cu Testa 1 +N31 $31:Malfunzionamento asse Cu Testa 2 +N32 $32:Asse A bloccato +N33 $33:Bypass segnali assi digitali attivo +N34 $34:Attesa chiusura Pinza 2 +N35 $35:Attesa apertura Pinza 2 +N36 $36:Attesa chiusura Pinza 3 +N37 $37:Attesa apertura Pinza 3 +N38 $38: +N39 $39:Sensore controllo giri Lama guasto +N40 $40:Fuori giri Lama +N41 $41:Attesa ribaltamento 90 gradi trave (Girare chiave in modo manuale) +N42 $42:Attesa ribaltamento 180 gradi trave (Girare chiave in modo manuale) +N43 $43:Attesa ribaltamento 270 gradi trave (Girare chiave in modo manuale) +N44 $44:Attesa scarico spezzone in entrata (Girare chiave in modo manuale) +N45 $45:Attesa conferma scarico trave +N46 $46:Rotazione T1 proibita senza utensili: verificare +N47 $47:Rotazione T2 proibita senza utensili: verificare +N48 $48: +N49 $49: +N50 $50:Malfunzionamento asse X Testa 2 +N51 $51:Malfunzionamento asse Z Testa 2 +N52 $52:Malfunzionamento asse A Testa 2 +N53 $53:Malfunzionamento asse B2 Movimento Cu +N54 $54:Riferimento di zero entrata non basso +N55 $55:Riferimento di scarico non a riposo +N56 $56: +N57 $57: +N58 $58: +N59 $59:*** MANUTENZIONE CE *** +N60 $60:Attesa scarico utensile manuale +N61 $61:Attesa carico utensile manuale +N62 $62: +N63 $63:Attesa apertura totale pinza 3 +N64 $64:Attesa conferma carico trave +N65 $65:Attesa conferma scarico spezzone corto non tenuto da pinza 1 +N66 $66:Attesa conferma scarico spezzone su rulliera entrata +N67 $67:Attesa stampa etichetta pezzo precedente +N68 $68:Attesa carico trave M75 in corso +N69 $69:Traslatore scarico pieno +N70 $70:Testa nuovo trave non trovata +N71 $71:Corsa arretramento spezzone troppo grande +N72 $72:Ft lettura testa trave occupata +N73 $73:Attesa Start dopo carico trave con muletto +N74 $74:Pezzo scaricato su nastro !!!!! +N75 $75:Scaricare trave con muletto e resettare allarme +N76 $76:Pinza 1 chiusa senza trave aprirla con M111 +N77 $77:Pinza 4 chiusa senza trave aprirla con M171 +N78 $78:Micro controllo chiusura pinza 1 non Ok +N79 $79:Attesa conferma lavoro con pinza 4 dentro macchina VERIFICARE !!! +N80 $80:Pezzo incompleto alcune lavorazioni non eseguite !!! +N81 $81:Micro controllo chiusura pinza 4 non Ok +N82 $82:Attesa Ft pinza 1 lettura coda trave a zero +N83 $83:Cambi utensile non indietro !!! +N84 $84:Testa avanti programmare M90 e poi M199 +N85 $85:Cambio T201-T202 non possibile con pinza 1 impegnata +N86 $86:Attesa protezione cambio utensile aperta +N87 $87:Asse A fuori posizione +N88 $88:Avanti magazzino utensili non Ok +N89 $89:Indietro magazzino utensili non Ok +N90 $90: +N91 $91: +N92 $92: +N93 $93: +N94 $94: +N95 $95:Messa a punto inserita permessi solo movimenti manuali +N96 $96: +N97 $97: +N98 $98:Avanti testa per cambio utensile non Ok +N99 $99:Indietro testa per cambio utensile non Ok +N100 $100: +N101 $101:Motore T1 non in rotazione (Fcinv0=1) +N102 $102:Motore T2 non in rotazione (Fcinv0=1) +N103 $103: +N104 $104: +N105 $105:Larghezza trave EX non Ok !!! +N106 $106:Altezza trave EZ non Ok !!! +N107 $107: +N108 $108:Attendere inserzioni di potenza +N109 $109:Premere reset su CNC +N110 $110: +N111 $111:Malfunzionamento inverter 1 +N112 $112:Malfunzionamento inverter 2 +N113 $113: +N114 $114: +N115 $115: +N116 $116: +N117 $117: +N118 $118:Flussostato Testa 1 non Ok +N119 $119:Flussostato Testa 2 non Ok +N120 $120: +N121 $121:Sovratemperatura resistenze di frenatura inverter 1 +N122 $122:Sovratemperatura resistenze di frenatura inverter 2 +N123 $123: +N124 $124: +N125 $125: +N126 $126: +N127 $127: +N128 $128: +N129 $129: +N130 $130: +N131 $131:Sovratemperatura motore testa 1 +N132 $132:Sovratemperatura motore testa 2 +N133 $133: +N134 $134: +N135 $135: +N136 $136: +N137 $137: +N138 $138: +N139 $139: +N140 $140: +N141 $141:Sovracorrente inverter 1 +N142 $142:Sovracorrente inverter 2 +N143 $143: +N144 $144: +N145 $145: +N146 $146: +N147 $147: +N148 $148:Cambi utensili non avanti +N149 $149:Posizione cambio utensile 1 impegnata per scarico +N150 $150:Posizione cambio utensile 2 impegnata per scarico +N151 $151:Difetto bloccaggio utensile testa 1 +N152 $152:Difetto bloccaggio utensile testa 2 +N153 $153:Utensile presente su testa 1 con E80001=0 +N154 $154:Utensile presente su testa 2 con E80002=0 +N155 $155:Difetto sbloccaggio utensile testa 1 +N156 $156:Difetto sbloccaggio utensile testa 2 +N157 $157:Cono utensile testa 1 sporco +N158 $158:Cono utensile testa 2 sporco +N159 $159:Pistone sbloccaggio cono testa 1 non a riposo +N160 $160:Pistone sbloccaggio cono testa 2 non a riposo +N161 $161:Asse X1 non a zero per cambio utensile +N162 $162:Asse X2 non a zero per cambio utensile +N163 $163: +N164 $164: +N165 $165: +N166 $166: +N167 $167: +N168 $168: +N169 $169: diff --git a/Messages/Ita.txt b/Messages/Ita.txt new file mode 100644 index 0000000..15fb099 --- /dev/null +++ b/Messages/Ita.txt @@ -0,0 +1,43 @@ +// File dei messaggi macchina Italiano 2022/01/17 +[MDI] +1=Prendi utensile n° 1 +2=Prendi utensile n° 2 +3=Prendi utensile n° 3 +4=Prendi utensile n° 4 +5=Prendi utensile n° 5 +6=Prendi utensile n° 6 +7=Prendi utensile n° 7 +8=Prendi utensile n° 8 +9=Prendi utensile n° 9 +10=Prendi utensile n° 10 +11=Prendi utensile n° 11 +12=Prendi utensile n° 12 +13=Prendi utensile n° 13 +14=Prendi utensile n° 14 +15=Prendi utensile n° 15 +16=Prendi utensile n° 16 +17=Prendi utensile n° 17 +18=Prendi utensile n° 18 +19=Scarica utensili +20=Prendi Elettrosega +21=Attiva magazzino utensili +22=Magazzino utensili n°1 avanti +23=Magazzino utensili n°1 indietro +24=Magazzino utensili n°2 avanti +25=Magazzino utensili n°2 indietro +26=Magazzino utensili Elettrosega avanti +27=Magazzino utensili Elettrosega indietro +28=Salita rulli zero frontale +29=Discesa rulli zero frontale +30=Salita rulli zero laterale +31=Discesa rulli zero laterale +32=Abilita rotazione oraria motore foratore destro +33=Abilita rotazione antioraria motore foratore destro +34=Abilita rotazione oraria motore foratore sinistro +35=Abilita rotazione antioraria motore foratore sinistro +36=Stop rotazione mandrini foratori +37=Assegnazione manuale numero utensile nella testa a 5 assi (E80001=1; E80001=2;E80001=3;ETC...) + +[PLC] + +[CNC] diff --git a/Scripts/ExitMach.lua b/Scripts/ExitMach.lua new file mode 100644 index 0000000..beff4d2 --- /dev/null +++ b/Scripts/ExitMach.lua @@ -0,0 +1,36 @@ +-- 2018/11/21 17:30:00 +-- Machining Exit for Essetre-TURN2T machine + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +-------------------------------------------------------------------------------- +-- *** Uscita da Lavorazioni *** + +-- Nascondo il pezzo così marcato e le geometrie aggiunte, visualizzo il Box +local function ProcessPart( PartId) + -- visualizzo il Box + EgtSetStatus( EgtGetFirstNameInGroup( PartId, 'Box') or GDB_ID.NULL, GDB_ST.ON) +end + +-- Disabilito segnalazione modifica progetto +local bEnMod = EgtGetEnableModified() +EgtDisableModified() + +-- Processo i pezzi nella radice (già chiusi tutti i gruppi di lavoro) +local PartId = EgtGetFirstPart() +while PartId do + ProcessPart( PartId) + PartId = EgtGetNextPart( PartId) +end + +EgtZoom( SCE_ZM.ALL, false) + +-- Ripristino segnalazione modifica progetto +if bEnMod then + EgtEnableModified() +end + +MACH.ERR = 0 diff --git a/Scripts/InitMach.lua b/Scripts/InitMach.lua new file mode 100644 index 0000000..2e50f8d --- /dev/null +++ b/Scripts/InitMach.lua @@ -0,0 +1,44 @@ +-- 2018/11/21 16:30:00 +-- Machining Init for Essetre-TURN2T machine + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +-------------------------------------------------------------------------------- +-- *** Ingresso in Lavorazioni *** + +-- Rendo visibile il pezzo e le geometrie aggiunte, nascondo il Box +local function ProcessPart( PartId) + -- nascondo il Box + EgtSetStatus( EgtGetFirstNameInGroup( PartId, 'Box') or GDB_ID.NULL, GDB_ST.OFF) +end + +-- Disabilito segnalazione modifica progetto +local bEnMod = EgtGetEnableModified() +EgtDisableModified() + +-- Processo i pezzi nella radice +local PartId = EgtGetFirstPart() +while PartId do + ProcessPart( PartId) + PartId = EgtGetNextPart( PartId) +end + +-- Processo i pezzi già nei gruppi di lavoro (quando appena lanciata Process) +local GhostId = EgtGetFirstGhostPart() +while GhostId do + local PartId = EgtGetInfo( GhostId, GDB_SI.SOURCE, 'i') + if PartId then + ProcessPart( PartId) + end + GhostId = EgtGetNextGhostPart( GhostId) +end + +-- Ripristino segnalazione modifica progetto +if bEnMod then + EgtEnableModified() +end + +MACH.ERR = 0 diff --git a/Scripts/SetUp.lua b/Scripts/SetUp.lua new file mode 100644 index 0000000..f8ad944 --- /dev/null +++ b/Scripts/SetUp.lua @@ -0,0 +1,214 @@ +-- Gestione attrezzaggio per Essetre-TURN2T - 2022/09/20 + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +-- Tavola di passaggio valori +local STU = {} +STU.TUUID = "" +STU.TCPOS = "" +STU.HEAD = "" +STU.GROUP = "" +STU.POS = "" +STU.EXIT = 0 +STU.INDEX = 0 +STU.HEAD1 = "" +STU.HEAD2 = "" +STU.ISVALID = false +STU.ERR = 0 +_G.STU = STU + +local INVALIDPOS = "" +local POS = "Pos" + +-- Geom Set +local GS = {} + +-- Configurazione posizioni +local PositionTable={{Pos = "Pos1", TcPos = "T1", Head = "H11", Group = "G1"}, + {Pos = "Pos2", TcPos = "T2", Head = "H11", Group = "G1"}, + {Pos = "Pos3", TcPos = "T3", Head = "H11", Group = "G1"}, + {Pos = "Pos4", TcPos = "T4", Head = "H11", Group = "G1"}, + {Pos = "Pos5", TcPos = "T5", Head = "H11", Group = "G1"}, + {Pos = "Pos6", TcPos = "T6", Head = "H11", Group = "G1"}, + {Pos = "Pos7", TcPos = "T7", Head = "H11", Group = "G1"}, + {Pos = "Pos8", TcPos = "T8", Head = "H11", Group = "G1"}, + {Pos = "Pos9", TcPos = "T9", Head = "H11", Group = "G1"}, + {Pos = "Pos10", TcPos = "T10", Head = "H11", Group = "G1"}, + {Pos = "Pos11", TcPos = "T11", Head = "H11", Group = "G1"}, + {Pos = "Pos12", TcPos = "T12", Head = "H11", Group = "G1"}, + {Pos = "Pos13", TcPos = "T42", Head = "H12", Group = "G1"}, + {Pos = "Pos14", TcPos = "T13", Head = "H21", Group = "G2"}, + {Pos = "Pos15", TcPos = "T14", Head = "H21", Group = "G2"}, + {Pos = "Pos16", TcPos = "T15", Head = "H21", Group = "G2"}, + {Pos = "Pos17", TcPos = "T16", Head = "H21", Group = "G2"}, + {Pos = "Pos18", TcPos = "T17", Head = "H21", Group = "G2"}, + {Pos = "Pos19", TcPos = "T18", Head = "H21", Group = "G2"}, + {Pos = "Pos20", TcPos = "T19", Head = "H21", Group = "G2"}, + {Pos = "Pos21", TcPos = "T20", Head = "H21", Group = "G2"}, + {Pos = "Pos22", TcPos = "T21", Head = "H21", Group = "G2"}, + {Pos = "Pos23", TcPos = "T22", Head = "H21", Group = "G2"}, + {Pos = "Pos24", TcPos = "T23", Head = "H21", Group = "G2"}, + {Pos = "Pos25", TcPos = "T24", Head = "H21", Group = "G2"}, + {Pos = "Pos26", TcPos = "T43", Head = "H22", Group = "G2"}, + {Pos = "Pos27", TcPos = "T101", Head = "H13", Group = "G3"}} + +local UsePositionHead = true + +local function IsInGeomSet( ToolHead, PosHead) + for GsIndex = 1, #GS do + local bToolHead = false + local bPosHead = false + for HIndex = 1, #GS[GsIndex] do + if GS[GsIndex][HIndex] == ToolHead then + bToolHead = true + elseif GS[GsIndex][HIndex] == PosHead then + bPosHead = true + end + if bToolHead and bPosHead then + return true + end + end + if bToolHead and bPosHead then + return true + end + end + return false +end + +function STU.IsCompatibleHeads() + STU.ISVALID = false + if IsInGeomSet(STU.HEAD1, STU.HEAD2) then + STU.ISVALID = true + else + STU.ISVALID = false + end +end + +function STU.GetValidHeadExitForPos() + -- se TUUID non valido restituisco errore + local ToolName = EgtTdbGetToolFromUUID( STU.TUUID) + if ToolName == nill then + STU.ERR = 1 + return + end + EgtTdbSetCurrTool( ToolName) + local CurrToolHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + STU.EXIT = EgtTdbGetCurrToolParam( MCH_TP.EXIT) + -- recupero testa predefinita per la posizione corrente + local CurrPosHead + for i = 1, #PositionTable do + if PositionTable[i].TcPos == STU.TCPOS then + CurrPosHead = PositionTable[i].Head + break + end + end + -- verifico se la testa è quella della posizione predefinita + if CurrPosHead == CurrToolHead then + STU.HEAD = CurrToolHead + STU.ERR = 0 + return + -- verifico se la testa è compatibile con quella della posizione predefinita + elseif IsInGeomSet( CurrToolHead, CurrPosHead) then + if UsePositionHead then + STU.HEAD = CurrPosHead + STU.ERR = 0 + return + else + STU.HEAD = CurrToolHead + STU.ERR = 0 + return + end + -- la testa non è compatibile con quella della posizione predefinita + else + STU.HEAD = INVALIDPOS + STU.ERR = 0 + return + end +end + +function STU.IsValidTcPosFromHead() + STU.ISVALID = false + for i = 1, #PositionTable do + if PositionTable[i].TcPos == STU.TCPOS then + if PositionTable[i].Head == STU.HEAD then + STU.ISVALID = true + STU.ERR = 0 + return + elseif IsInGeomSet(PositionTable[i].Head, STU.HEAD) then + STU.ISVALID = true + STU.ERR = 0 + return + end + STU.ISVALID = false + STU.ERR = 0 + return + end + end +end + +function STU.GetTcPosHeadGroupFromPos() + for i = 1, #PositionTable do + if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then + STU.TCPOS = PositionTable[i].TcPos + STU.HEAD = PositionTable[i].Head + STU.GROUP = PositionTable[i].Group + STU.ERR = 0 + return + end + end + STU.TCPOS = INVALIDPOS + STU.HEAD = INVALIDPOS + STU.GROUP = INVALIDPOS + STU.ERR = 1 +end + +function STU.GetPosFromTcPos() + for i = 1, #PositionTable do + if PositionTable[i].TcPos == STU.TCPOS then + STU.POS = PositionTable[i].Pos + STU.ERR = 0 + return + end + end + STU.POS = INVALIDPOS + STU.ERR = 1 +end + +function STU.GetGroupFromTcPos() + for i = 1, #PositionTable do + if PositionTable[i].TcPos == STU.TCPOS then + STU.GROUP = PositionTable[i].Group + STU.ERR = 0 + return + end + end + STU.GROUP = INVALIDPOS + STU.ERR = 1 +end + +function STU.GetHeadFromPos() + for i = 1, #PositionTable do + if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then + STU.HEAD = PositionTable[i].Head + STU.ERR = 0 + return + end + end + STU.HEAD = INVALIDPOS + STU.ERR = 1 +end + +function STU.GetTcPosFromPos() + for i = 1, #PositionTable do + if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then + STU.TCPOS = PositionTable[i].TcPos + STU.ERR = 0 + return + end + end + STU.TCPOS = INVALIDPOS + STU.ERR = 1 +end diff --git a/THolders/AngTransm.nge b/THolders/AngTransm.nge new file mode 100644 index 0000000..d2541c4 Binary files /dev/null and b/THolders/AngTransm.nge differ diff --git a/THolders/BH.nge b/THolders/BH.nge new file mode 100644 index 0000000..daf8cd8 Binary files /dev/null and b/THolders/BH.nge differ diff --git a/THolders/ChainSaw.nge b/THolders/ChainSaw.nge new file mode 100644 index 0000000..d29af27 Binary files /dev/null and b/THolders/ChainSaw.nge differ diff --git a/THolders/MillNoTip.nge b/THolders/MillNoTip.nge new file mode 100644 index 0000000..414ea8e Binary files /dev/null and b/THolders/MillNoTip.nge differ diff --git a/THolders/Saw.nge b/THolders/Saw.nge new file mode 100644 index 0000000..fa0aa7c Binary files /dev/null and b/THolders/Saw.nge differ diff --git a/THolders/Standard.nge b/THolders/Standard.nge new file mode 100644 index 0000000..23ee6c6 Binary files /dev/null and b/THolders/Standard.nge differ diff --git a/THolders/Standard_78.nge b/THolders/Standard_78.nge new file mode 100644 index 0000000..bb1e695 Binary files /dev/null and b/THolders/Standard_78.nge differ diff --git a/THolders/Standard_LC.nge b/THolders/Standard_LC.nge new file mode 100644 index 0000000..7d2b4c3 Binary files /dev/null and b/THolders/Standard_LC.nge differ diff --git a/THolders/TcSaw.nge b/THolders/TcSaw.nge new file mode 100644 index 0000000..e8de2ef Binary files /dev/null and b/THolders/TcSaw.nge differ