diff --git a/MachMgr.h b/MachMgr.h index a0de374..5e8dfe5 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -475,6 +475,8 @@ class MachMgr : public IMachMgr const INTVECTOR& vVmill, bool bFirst) ; bool SimEnableToolsForVmill( bool bEnable) ; int SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ; + bool SimSaveCmd( int nType, int nPar, const std::string& sPar) ; + // Machine bool GetHeadAbove( const std::string& sHead) const ; double GetAngDeltaMinForHome( void) const ; diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index d4679d2..b434abd 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -30,9 +30,9 @@ MachMgr::SimInit( void) delete m_pSimul ; if ( GetCurrMachine() == nullptr) return false ; - //if ( GetCurrMachine()->GetMultiProcess()) - // m_pSimul = CreateSimulatorMP() ; - //else + if ( GetCurrMachine()->GetMultiProcess( 2)) + m_pSimul = CreateSimulatorMP() ; + else m_pSimul = CreateSimulatorSP() ; if ( m_pSimul == nullptr) return false ; @@ -220,3 +220,14 @@ MachMgr::SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) // lancio movimento assi return m_pSimul->MoveAxes( nMoveType, vAxNaEpSt) ; } + +//---------------------------------------------------------------------------- +bool +MachMgr::SimSaveCmd( int nType, int nPar, const string& sPar) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // salvo il comando + return m_pSimul->SaveCmd( nType, nPar, sPar) ; +} diff --git a/Machine.cpp b/Machine.cpp index c07c7dd..f1d5e45 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -41,7 +41,7 @@ Machine::Machine( void) m_dExitMaxAdjust = EPS_SMALL ; m_dExitMaxRotAdj = 10 * EPS_ANG_SMALL ; m_dAngDeltaMinForHome = INFINITO ; - m_bMultiProcess = false ; + m_nMultiProcess = 0 ; m_nCalcTabId = GDB_ID_NULL ; m_nCalcHeadId = GDB_ID_NULL ; m_nCalcExitId = GDB_ID_NULL ; diff --git a/Machine.h b/Machine.h index 32bd835..6113d47 100644 --- a/Machine.h +++ b/Machine.h @@ -71,8 +71,8 @@ class Machine int GetHeadSelectType(const std::string& sHead) const ; double GetAngDeltaMinForHome( void) const { return m_dAngDeltaMinForHome ; } - bool GetMultiProcess( void) const - { return m_bMultiProcess ; } + bool GetMultiProcess( int nOpt = 1) const + { return ( m_nMultiProcess >= nOpt) ; } bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; bool GetLoadedTool( const std::string& sHead, int nExit, std::string& sTool) const ; bool UnloadTool( const std::string& sHead, int nExit) ; @@ -293,7 +293,7 @@ class Machine double m_dExitMaxAdjust ; // massimo aggiustamento uscita da geometria a descrizione cinematica double m_dExitMaxRotAdj ; // massima rotazione di aggiustamento uscita da geometria a descrizione cinematica double m_dAngDeltaMinForHome ; // minima differenza angolare da valore precedente per scegliere di stare vicino a home - bool m_bMultiProcess ; // flag di macchina multi-processo con stima speciale prima di generazione e simulazione ad hoc + int m_nMultiProcess ; // flag di macchina multi-processo con stima speciale prima di generazione e simulazione ad hoc INTVECTOR m_vLinkedRawParts ; // elenco dei grezzi agganciati a gruppi della macchina INTVECTOR m_vLinkedFixtures ; // elenco dei bloccaggi agganciati a gruppi della macchina INTVECTOR m_vLinkedParts ; // elenco dei pezzi agganciati a gruppi della macchina @@ -380,6 +380,7 @@ class Machine static int LuaEmtAddToolForVmill( lua_State* L) ; static int LuaEmtEnableToolsForVmill( lua_State* L) ; static int LuaEmtMoveAxes( lua_State* L) ; + static int LuaEmtSaveCmd( lua_State* L) ; } ; //---------------------------------------------------------------------------- diff --git a/MachineLua.cpp b/MachineLua.cpp index 5495554..b3151a5 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -146,6 +146,8 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtEnableToolsForVmill", Machine::LuaEmtEnableToolsForVmill) ; // registro la funzione di movimento assi in simulazione m_LuaMgr.RegisterFunction( "EmtMoveAxes", Machine::LuaEmtMoveAxes) ; + // registro la funzione di salvataggio comandi in simulazione MP + m_LuaMgr.RegisterFunction( "EmtSaveCmd", Machine::LuaEmtSaveCmd) ; return true ; } @@ -345,9 +347,9 @@ Machine::LuaEmtGeneral( lua_State* L) // lettura eventuale campo 'AngDeltaForHome' dalla tabella (default INFINITO) double dAngDeltaMinForHome = INFINITO ; LuaGetTabFieldParam( L, 1, FLD_ANGDELTAMINFORHOME, dAngDeltaMinForHome) ; - // lettura eventuale campo 'MultiProcess' dalla tabella (default false) - bool bMultiProcess = false ; - LuaGetTabFieldParam( L, 1, FLD_MULTIPROCESS, bMultiProcess) ; + // lettura eventuale campo 'MultiProcess' dalla tabella (0=no, 1=si, 2=si con simulazione MP) + int nMultiProcess = 0 ; + LuaGetTabFieldParam( L, 1, FLD_MULTIPROCESS, nMultiProcess) ; LuaClearStack( L) ; // info @@ -398,7 +400,7 @@ Machine::LuaEmtGeneral( lua_State* L) m_pMchLua->m_dAngDeltaMinForHome = dAngDeltaMinForHome ; // imposto flag per macchina multiprocesso - m_pMchLua->m_bMultiProcess = bMultiProcess ; + m_pMchLua->m_nMultiProcess = nMultiProcess ; return 0 ; } @@ -1512,7 +1514,7 @@ int Machine::LuaEmtEnableToolsForVmill( lua_State* L) { // 1 parametro : bEnable - bool bEnable ; + bool bEnable = false ; LuaGetParam( L, 1, bEnable) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva @@ -1560,3 +1562,25 @@ Machine::LuaEmtMoveAxes( lua_State* L) } return 2 ; } + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtSaveCmd( lua_State* L) +{ + // parametri : nType, + int nType = 0 ; + LuaGetParam( L, 1, nType) ; + int nPar = 0 ; + LuaGetParam( L, 2, nPar) ; + string sPar ; + LuaGetParam( L, 3, sPar) ; + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // salvo il comando + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimSaveCmd( nType, nPar, sPar)) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} diff --git a/OutputConst.h b/OutputConst.h index 97ba635..1ee6854 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -184,6 +184,7 @@ static const std::string GVAR_SIMUISTAT = ".SIMUISTAT" ; // (num) stato sim static const std::string GVAR_SAFEDIST = ".SAFEDIST" ; // (num) distanza di sicurezza per verifica di collisione static const std::string GVAR_SIMVMID = ".SIMVMID" ; // (int) identificativo grezzo Vmill in collisione static const std::string GVAR_SIMCOBIND = ".SIMCOBIND" ; // (int) indice oggetto in collisione +static const std::string GVAR_MPSIM = ".MPSIM" ; // (bool) flag simulazione multiprocesso // Funzioni generazione static const std::string ON_START = "OnStart" ; static const std::string ON_END = "OnEnd" ; diff --git a/Pocketing.cpp b/Pocketing.cpp index ee2f079..0c22ab8 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -5744,7 +5744,7 @@ Pocketing::AdjustContourStart( ICurveComposite* pCompo) pCrv = pCompo->GetNextCurve() ; } // se non trovato o troppo corto, cerco il tratto generico più lungo - if ( nMax < 0 || dLenMax < 2 * m_TParams.m_dDiam) { + if ( nMax < 0 || dLenMax < 1.25 * m_TParams.m_dDiam) { i = 0 ; pCrv = pCompo->GetFirstCurve() ; while ( pCrv != nullptr) { diff --git a/Simulator.h b/Simulator.h index 854d00e..d2704e3 100644 --- a/Simulator.h +++ b/Simulator.h @@ -59,4 +59,5 @@ class __declspec( novtable) ISimulator double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) = 0 ; virtual bool EnableToolsForVmill( bool bEnable) = 0 ; virtual int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) = 0 ; + virtual bool SaveCmd( int nType, int nPar, const std::string& sPar) = 0 ; } ; diff --git a/SimulatorMP.cpp b/SimulatorMP.cpp index 5899225..6df9161 100644 --- a/SimulatorMP.cpp +++ b/SimulatorMP.cpp @@ -50,6 +50,7 @@ static const double COLL_STEP = 10. ; static const double SQ_COEFF_ROT_MOVE = 100. ; static const double COEFF_LIM = 0.999 ; static const double SAFEDIST_STD = 5.0 ; +static const int ERR_NONE = 0 ; static const int ERR_OUTSTROKE = 1 ; static const int ERR_COLLISION = 11 ; static const int ERR_TOOL_SEL = 21 ; @@ -78,6 +79,7 @@ SimulatorMP::SimulatorMP( void) m_nEntId = GDB_ID_NULL ; m_nEntInd = 0 ; m_dCoeff = 0 ; + m_bChangedTool = false ; m_nAuxSTot = 0 ; m_nAuxSInd = 0 ; m_nAuxETot = 0 ; @@ -127,6 +129,9 @@ SimulatorMP::Init( MachMgr* pMchMgr) m_pMachine = m_pMchMgr->GetCurrMachine() ; m_pPerfCnt = new PerformanceCounter ; m_nStatus = SIS_INITIALIZED ; + if ( ExeGetDebugLevel() >= 1) + LOG_INFO( GetEMkLogger(), " * SimulatorMP *") + return true ; } @@ -159,6 +164,7 @@ SimulatorMP::Start( bool bFirst) m_nExit = 0 ; m_dTDiam = 0 ; m_bCutOnTip = false ; + m_bChangedTool = false ; ResetInterpolation() ; ResetAxes() ; ResetAuxAxes() ; @@ -180,6 +186,7 @@ SimulatorMP::Start( bool bFirst) m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep) ; m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_VER, GetEMkVer()) ; m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MACHNAME, m_pMachine->GetMachineName()) ; + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MPSIM, true) ; // Se appena entrati in simulazione if ( m_nStatus == SIS_INITIALIZED) { @@ -194,7 +201,7 @@ SimulatorMP::Start( bool bFirst) // Arrivo alla preparazione per la prima lavorazione int nStatus ; - if ( ! FindAndManageOperationStart( true, bFirst, nStatus) && nStatus != MCH_SIM_STOP) + if ( ! FindAndManageOperationStart( true, bFirst, m_bChangedTool, nStatus) && nStatus != MCH_SIM_STOP) bOk = false ; // se sono ancora su disposizione if ( m_pMchMgr->GetOperationType( m_nOpId) == OPER_DISP) { @@ -312,14 +319,16 @@ SimulatorMP::Move( int& nStatus) return false ; } - // Se arrivato alla fine di una operazione - if ( m_nCLPathId == GDB_ID_NULL) { + // Se arrivato alla fine di una operazione o appena scaricato utensile + if ( m_nCLPathId == GDB_ID_NULL || m_bChangedTool) { // gestione fine operazione - if ( ! ManageOperationEnd( nStatus)) + if ( m_nCLPathId == GDB_ID_NULL && ! ManageOperationEnd( nStatus)) return false ; // ricerca e gestione nuova operazione - if ( ! FindAndManageOperationStart( false, false, nStatus)) + if ( ! FindAndManageOperationStart( false, false, m_bChangedTool, nStatus)) return false ; + if ( m_bChangedTool) + return true ; // se non ce ne sono altre, sono alla fine if ( m_nOpId == GDB_ID_NULL) { OnProgramEnd() ; @@ -489,111 +498,126 @@ SimulatorMP::GoHome( void) //---------------------------------------------------------------------------- bool -SimulatorMP::UpdateTool( bool bFirst, int& nErr) +SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr) { - // reset stato di errore da script - nErr = 0 ; - // Recupero l'utensile della lavorazione corrente + // Reset stato + nErr = ERR_NONE ; + + // Recupero la lavorazione corrente Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; - if ( pMch != nullptr) { - // recupero nome e dati nuovo utensile - string sTuuid, sTool ; - if ( ! pMch->GetParam( MPA_TUUID, sTuuid) || - ! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool)) - return false ; - string sTcPos ; string sHead ; int nExit ; - if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) { - if ( m_pMchMgr->TdbSetCurrTool( sTool)) { - m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; - m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; - m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; - } - // ripristino l'utensile corrente - m_pMchMgr->TdbSetCurrTool( m_sTool) ; + if ( pMch == nullptr) + return false ; + + // Recupero nome e dati nuovo utensile + string sTuuid, sTool ; + if ( ! pMch->GetParam( MPA_TUUID, sTuuid) || + ! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool)) + return false ; + string sTcPos ; string sHead ; int nExit ; + if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) { + if ( m_pMchMgr->TdbSetCurrTool( sTool)) { + m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; + m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; + m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; } - // verifico se cambierà - bool bDiffTool = ( sTool != m_sTool) ; - // se cambierà ed esiste il corrente, lo scarico - if ( bDiffTool && ! m_sTool.empty()) { - // eventuale lancio script per scarico utensile - int nCurrErr ; - if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) { - nErr = ( nErr != 0 ? nErr : nCurrErr) ; - if ( nCurrErr != ERR_COLLISION) - return false ; - } - } - // se prima volta, pulisco la testa - if ( bFirst) - m_pMchMgr->ResetHeadSet( sHead) ; - // recupero la lavorazione corrente e imposto la nuova - int nCurrMchId = m_pMchMgr->GetCurrMachining() ; - m_pMchMgr->SetCurrMachining( m_nOpId) ; - // carico l'utensile (e lo rendo corrente) - if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) - return false ; - m_sTool = sTool ; - m_sHead = sHead ; - m_nExit = nExit ; - m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ; - double dTipFeed = 0 ; - m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ; - m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ; - // ripristino la lavorazione corrente - m_pMchMgr->SetCurrMachining( nCurrMchId) ; - // aggiorno gli assi macchina - if ( ! UpdateAxes()) - return false ; - // se cambiato oppure prima volta, lancio lo script di selezione - if ( bDiffTool || bFirst) { - int nCurrErr ; - if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) { - nErr = ( nErr != 0 ? nErr : nCurrErr) ; - if ( nCurrErr != ERR_COLLISION) - return false ; - } - } - return ( nErr == 0) ; + // ripristino l'utensile corrente + m_pMchMgr->TdbSetCurrTool( m_sTool) ; } - // Provo con una disposizione - Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; - if ( pDisp != nullptr) { - // recupero i dati - string sTool ; string sHead ; int nExit ; string sTcPos ; - pDisp->GetToolData( sTool, sHead, nExit, sTcPos) ; - // se esiste utensile corrente e cambierà, lo scarico - if ( ! m_sTool.empty() && sTool != m_sTool) { - // eventuale lancio script per scarico utensile - int nCurrErr ; - if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) { - nErr = ( nErr != 0 ? nErr : nCurrErr) ; - if ( nCurrErr != ERR_COLLISION) - return false ; - } - } - // carico l'utensile - if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) - return false ; - m_sTool = sTool ; - m_sHead = sHead ; - m_nExit = nExit ; - m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ; - double dTipFeed = 0 ; - m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ; - m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ; - // aggiorno gli assi macchina - if ( ! UpdateAxes()) - return false ; - // eventuale lancio script + // verifico se cambierà + bool bDiffTool = ( sTool != m_sTool) ; + // se cambierà ed esiste il corrente, lo scarico + if ( bDiffTool && ! m_sTool.empty() && ! bDeselected) { + // eventuale lancio script per scarico utensile int nCurrErr ; - if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) { - nErr = ( nErr != 0 ? nErr : nCurrErr) ; + if ( OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) { + bDeselected = true ; + return true ; + } + else { + nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ; if ( nCurrErr != ERR_COLLISION) return false ; } - return ( nErr == 0) ; } - return false ; + bDeselected = false ; + // se prima volta, pulisco la testa + if ( bFirst) + m_pMchMgr->ResetHeadSet( sHead) ; + // recupero la lavorazione corrente e imposto la nuova + int nCurrMchId = m_pMchMgr->GetCurrMachining() ; + m_pMchMgr->SetCurrMachining( m_nOpId) ; + // carico l'utensile (e lo rendo corrente) + if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) + return false ; + m_sTool = sTool ; + m_sHead = sHead ; + m_nExit = nExit ; + m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ; + double dTipFeed = 0 ; + m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ; + m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ; + // ripristino la lavorazione corrente + m_pMchMgr->SetCurrMachining( nCurrMchId) ; + // aggiorno gli assi macchina + if ( ! UpdateAxes()) + return false ; + // se cambiato oppure prima volta, lancio lo script di selezione + if ( bDiffTool || bFirst) { + int nCurrErr ; + if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) { + nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ; + if ( nCurrErr != ERR_COLLISION) + return false ; + } + } + return ( nErr == ERR_NONE) ; +} + +//---------------------------------------------------------------------------- +bool +SimulatorMP::UpdateDispositionTool( bool bFirst, int& nErr) +{ + // Reset stato di errore da script + nErr = ERR_NONE ; + // Recupero la disposizione + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pDisp == nullptr) + return false ; + + // Recupero i dati + string sTool ; string sHead ; int nExit ; string sTcPos ; + pDisp->GetToolData( sTool, sHead, nExit, sTcPos) ; + // se esiste utensile corrente e cambierà, lo scarico + if ( ! m_sTool.empty() && sTool != m_sTool) { + // eventuale lancio script per scarico utensile + int nCurrErr ; + if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) { + nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ; + if ( nCurrErr != ERR_COLLISION) + return false ; + } + } + // carico l'utensile + if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) + return false ; + m_sTool = sTool ; + m_sHead = sHead ; + m_nExit = nExit ; + m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ; + double dTipFeed = 0 ; + m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ; + m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ; + // aggiorno gli assi macchina + if ( ! UpdateAxes()) + return false ; + // eventuale lancio script + int nCurrErr ; + if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) { + nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ; + if ( nCurrErr != ERR_COLLISION) + return false ; + } + return ( nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -680,18 +704,20 @@ SimulatorMP::ResetAuxAxes( void) //---------------------------------------------------------------------------- bool -SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) +SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChangedTool, int& nStatus) { // verifico parametri if ( ! bStart) bFirst = false ; // recupero la nuova operazione - if ( bStart) { - m_nOpId = m_pMchMgr->GetFirstActiveOperation() ; - m_nOpInd = 0 ; + if ( ! bChangedTool) { + if ( bStart) { + m_nOpId = m_pMchMgr->GetFirstActiveOperation() ; + m_nOpInd = 0 ; + } + else + m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; } - else - m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; // ciclo sulle successive operazioni while ( m_nOpId != GDB_ID_NULL) { // se lavorazione valida @@ -700,12 +726,14 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus bool bOk = true ; // aggiorno utensile e assi conseguenti int nErr ; - if ( ! UpdateTool( bFirst, nErr)) { + if ( ! UpdateMachiningTool( bFirst, bChangedTool, nErr)) { string sOut = "Err=" + ToString( nErr) ; LOG_INFO( GetEMkLogger(), sOut.c_str()) nStatus = CalcStatusOnError( nErr) ; - bOk = false ; + return false ; } + if ( bChangedTool) + return true ; ++ m_nOpInd ; // imposto la lavorazione come corrente m_pMchMgr->SetCurrMachining( m_nOpId) ; @@ -719,12 +747,10 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus m_pGeomDB->GetInfo( nClId, KEY_MAXMAX, vAxMax) ; // richiamo gestione evento inizio lavorazione if ( ! OnMachiningStart( m_nOpId, m_nOpInd, ptMin, ptMax, vAxMin, vAxMax)) { - nStatus = CalcStatusOnError( 0) ; - bOk = false ; - } - if ( ! bOk) + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; - break ; + } + return true ; } // se disposizione con cambio di fase Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; @@ -746,7 +772,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus if ( ! bEmpty) { // richiamo gestione evento appena prima di inizio disposizione if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) { - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; } // cambio fase @@ -754,7 +780,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus // se previsto, aggiorno utensile e assi conseguenti if ( pDisp->IsWithTool()) { int nErr ; - if ( ! UpdateTool( bFirst, nErr)) { + if ( ! UpdateDispositionTool( bFirst, nErr)) { nStatus = CalcStatusOnError( nErr) ; return false ; } @@ -762,7 +788,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus ++ m_nOpInd ; // richiamo gestione evento inizio disposizione if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) { - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; } // se ci sono movimenti manuali, aggiorno visualizzazione e breve pausa (200 ms) @@ -774,7 +800,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus else { // richiamo gestione evento appena prima di inizio disposizione if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand)) { - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; } // cambio fase @@ -783,7 +809,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus // richiamo gestione evento inizio e fine disposizione if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand) || ! OnDispositionEnd()) { - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; } // se non è inizio, aggiorno visualizzazione e breve pausa (200 ms) @@ -819,7 +845,7 @@ SimulatorMP::ManageOperationEnd( int& nStatus) } // gestione stato if ( ! bOk) - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return bOk ; } @@ -881,7 +907,7 @@ SimulatorMP::FindAndManagePathStart( int& nStatus) m_nAuxETot = 0 ; // richiamo gestione evento inizio percorso di lavoro if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd, m_nAuxSTot, ptStart, ptEnd, vtExtr, ptMin, ptMax, vAxMin, vAxMax, dElev)) { - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return false ; } } @@ -912,7 +938,7 @@ SimulatorMP::ManagePathEnd( int& nStatus) bool bOk = OnPathEnd( m_nAuxETot) ; // gestione stato if ( ! bOk) - nStatus = CalcStatusOnError( 0) ; + nStatus = CalcStatusOnError( ERR_NONE) ; return bOk ; } @@ -1381,8 +1407,8 @@ SimulatorMP::GetHeadCurrPosDirAux( const std::string& sHead, int nExit, Point3d& //---------------------------------------------------------------------------- bool SimulatorMP::ExecLineVmill( int nVmId, int nCurrTool, double dVmTdOffs, double dVmAdOffs, - const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI, - const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) + const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI, + const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) { // Recupero Zmap IVolZmap* pVZM = GetVolZmap( m_pGeomDB->GetGeoObj( nVmId)) ; @@ -1709,7 +1735,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit, bool bFirst, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // reset oggetti per verifica collisione con grezzo m_CollObj.clear() ; // assegno il nome dell'utensile, la testa e l'uscita @@ -1755,7 +1781,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit, ResetAuxAxes() ; int nNumAuxAxes = 0 ; if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0) - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; m_AuxAxesName.reserve( nNumAuxAxes) ; m_AuxAxesToken.reserve( nNumAuxAxes) ; m_AuxAxesInvert.reserve( nNumAuxAxes) ; @@ -1790,7 +1816,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit, } } - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -1798,7 +1824,7 @@ bool SimulatorMP::OnToolDeselect( const string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // assegno il prossimo utensile bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTOOL, sNextTool) ; // assegno la prossima testa @@ -1818,7 +1844,7 @@ SimulatorMP::OnToolDeselect( const string& sNextTool, const string& sNextHead, i UpdateAxesPos() ; // verifico codice di errore bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -1916,7 +1942,7 @@ bool SimulatorMP::OnPathStartAux( int nInd, const string& sAS, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START_AUX)) return true ; @@ -1930,7 +1956,7 @@ SimulatorMP::OnPathStartAux( int nInd, const string& sAS, int& nErr) UpdateAxesPos() ; // verifico codice di errore bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -1938,7 +1964,7 @@ bool SimulatorMP::OnPathEndAux( int nInd, const string& sAE, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END_AUX)) return true ; @@ -1952,7 +1978,7 @@ SimulatorMP::OnPathEndAux( int nInd, const string& sAE, int& nErr) UpdateAxesPos() ; // verifico codice di errore bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -1960,7 +1986,7 @@ bool SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // recupero e assegno i dati // dati generali e reset errore bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEID, m_nEntId) ; @@ -2025,7 +2051,7 @@ SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData, // verifico codice di errore m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - if ( nErr != 0) + if ( nErr != ERR_NONE) return false ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) @@ -2095,7 +2121,7 @@ SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData, m_AuxAxesEnd.emplace_back( dEnd) ; m_AuxAxesLink.emplace_back( 0) ; if ( ! m_pMachine->VerifyOutstroke( sName, dEnd)) { - nErr = 1 ; + nErr = ERR_OUTSTROKE ; bOk = false ; } } @@ -2116,7 +2142,7 @@ bool SimulatorMP::OnMoveEnd( int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END)) return true ; @@ -2129,7 +2155,7 @@ SimulatorMP::OnMoveEnd( int& nErr) UpdateAxesPos() ; // verifico codice di errore m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - return ( bOk && nErr == 0) ; + return ( bOk && nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -2137,7 +2163,7 @@ bool SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr) { // reset stato di errore da script - nErr = 0 ; + nErr = ERR_NONE ; // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_COLLISION)) return true ; @@ -2165,7 +2191,7 @@ SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr) ExeDraw() ; } - return ( nErr == 0) ; + return ( nErr == ERR_NONE) ; } //---------------------------------------------------------------------------- @@ -2218,7 +2244,7 @@ SimulatorMP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, c //---------------------------------------------------------------------------- bool SimulatorMP::SetToolForVmill( const string& sTool, const string& sHead, int nExit, int nFlag, double dPar1, double dPar2, - const INTVECTOR& vVmill, bool bFirst) + const INTVECTOR& vVmill, bool bFirst) { // disabilito eventuale registrazione comandi EXE (riabilitazione automatica) CmdLogOff cmdLogOff ; @@ -2332,9 +2358,9 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) if ( vAxNaEpSt.empty()) return SIM_AXMV_RES_ERR ; // Salvo i dati di movimento - m_CmdData.emplace_back( 1, nMoveType, vAxNaEpSt) ; + m_CmdData.emplace_back( nMoveType, vAxNaEpSt) ; // Log dati - if ( ExeGetDebugLevel() >= 5) { + if ( ExeGetDebugLevel() >= 4) { string sOut = "Save=SimulMoveAxes," + ToString( nMoveType) ; for ( int i = 0 ; i < int( vAxNaEpSt.size()) ; ++ i) sOut += "," + vAxNaEpSt[i].sName + @@ -2346,6 +2372,20 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) return SIM_AXMV_RES_OK ; } +//---------------------------------------------------------------------------- +bool +SimulatorMP::SaveCmd( int nType, int nPar, const string& sPar) +{ + // Salvo il comando + m_CmdData.emplace_back( nType, nPar, sPar) ; + // Log dati + if ( ExeGetDebugLevel() >= 4) { + string sOut = "Save=SimulSaveCmd," + ToString( nType) + "," + ToString( nPar) + "," + sPar ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } + return false ; +} + //---------------------------------------------------------------------------- bool SimulatorMP::ExecCmdData( int& nStatus) @@ -2354,7 +2394,7 @@ SimulatorMP::ExecCmdData( int& nStatus) auto& CmdCurr = m_CmdData[m_nCmdInd] ; // Stampe di debug - if ( ExeGetDebugLevel() >= 5) { + if ( ExeGetDebugLevel() >= 4) { if ( CmdCurr.nType == 1) { string sOut = "Cmd=SimulMoveAxes," + ToString( CmdCurr.nMoveType) ; for ( int i = 0 ; i < int( CmdCurr.vAxNaEpSt.size()) ; ++ i) @@ -2363,9 +2403,13 @@ SimulatorMP::ExecCmdData( int& nStatus) "," + ToString( CmdCurr.vAxNaEpSt[i].dStep, 3) ; LOG_INFO( GetEMkLogger(), sOut.c_str()) } + else { + string sOut = "Cmd=SimulSaveCmd," + ToString( CmdCurr.nType) + "," + ToString( CmdCurr.nPar) + "," + CmdCurr.sPar ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } } - // Eseguo + // Eseguo movimento assi if ( CmdCurr.nType == 1) { // Numero assi da muovere int nAxCount = int( CmdCurr.vAxNaEpSt.size()) ; @@ -2378,7 +2422,7 @@ SimulatorMP::ExecCmdData( int& nStatus) // Posizione e direzione attuali degli utensili e riferimenti dei pezzi (per Vmill) bool bExecVmill = (( CmdCurr.nMoveType != 0 || ! NeedCollisionCheck()) && ! m_VmTool.empty() && ! m_VmId.empty()) ; PNTVECTOR vPtNoseI ; - VCT3DVECTOR vVtDirI ; + VCT3DVECTOR vVtDirI ; VCT3DVECTOR vVtAuxI ; vector vFrVzmI ; if ( bExecVmill) { @@ -2461,14 +2505,51 @@ SimulatorMP::ExecCmdData( int& nStatus) UpdateAxesPos() ; return false ; } + UpdateAxesPos() ; + // Aggiorno dati interpolazione + if ( m_dCmdCoeff > COEFF_LIM) { + m_nCmdInd += 1 ; + m_dCmdCoeff = 0 ; + } } - UpdateAxesPos() ; - - // Aggiorno dati interpolazione - if ( m_dCmdCoeff > COEFF_LIM) { + // eseguo impostazione stato + else if ( CmdCurr.nType == 2) { + // imposto + if ( ! m_pGeomDB->SetStatus( CmdCurr.nPar, ( CmdCurr.sPar == "ON" ? GDB_ST_ON : GDB_ST_OFF))) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // Aggiorno indice comandi eseguiti m_nCmdInd += 1 ; m_dCmdCoeff = 0 ; } + // eseguo impostazione modo + else if ( CmdCurr.nType == 3) { + // imposto + if ( ! m_pGeomDB->SetMode( CmdCurr.nPar, ( CmdCurr.sPar == "STD" ? GDB_MD_STD : GDB_MD_HIDDEN))) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // Aggiorno indice comandi eseguiti + m_nCmdInd += 1 ; + m_dCmdCoeff = 0 ; + } + // eseguo chiamata funzione + else if ( CmdCurr.nType == 5) { + // chiamo la funzione + if ( ! m_pMachine->LuaCallFunction( CmdCurr.sPar)) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // Aggiorno indice comandi eseguiti + m_nCmdInd += 1 ; + m_dCmdCoeff = 0 ; + } + // altrimenti errore + else { + nStatus = MCH_SIM_ERR ; + return false ; + } return true ; } diff --git a/SimulatorMP.h b/SimulatorMP.h index 6ea5048..b768ddd 100644 --- a/SimulatorMP.h +++ b/SimulatorMP.h @@ -45,13 +45,15 @@ class SimulatorMP : public ISimulator bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) override ; bool EnableToolsForVmill( bool bEnable) override ; - int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) override ; + int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) override ; + bool SaveCmd( int nType, int nPar, const std::string& sPar) override ; public : SimulatorMP( void) ; private : - bool UpdateTool( bool bFirst, int& nErr) ; + bool UpdateMachiningTool( bool bFirst, bool& bDeselect, int& nErr) ; + bool UpdateDispositionTool( bool bFirst, int& nErr) ; bool UpdateAxes( void) ; bool UpdateAxesPos( void) ; bool ResetInterpolation( void) ; @@ -60,7 +62,7 @@ class SimulatorMP : public ISimulator private : bool VerifySetup( void) ; - bool FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) ; + bool FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChangedTool, int& nStatus) ; bool ManageOperationEnd( int& nStatus) ; bool FindAndManagePathStart( int& nStatus) ; bool ManagePathEnd( int& nStatus) ; @@ -139,12 +141,16 @@ class SimulatorMP : public ISimulator private : struct CmdData { - int nType ; - int nMoveType ; - SAMVECTOR vAxNaEpSt ; + int nType ; + int nMoveType ; + SAMVECTOR vAxNaEpSt ; + int nPar ; + std::string sPar ; CmdData( void) : nType(0) {} - CmdData( int nT, int nM, const SAMVECTOR& vAx) - : nType( nT), nMoveType( nM), vAxNaEpSt( vAx) {} + CmdData( int nM, const SAMVECTOR& vAx) + : nType( 1), nMoveType( nM), vAxNaEpSt( vAx) {} + CmdData( int nT, int nP, const std::string& sP) + : nType( nT), nPar( nP), sPar( sP) {} } ; typedef std::vector CMDVECTOR ; @@ -163,6 +169,7 @@ class SimulatorMP : public ISimulator int m_nEntId ; // identificativo dell'entità corrente int m_nEntInd ; // contatore dell'entità corrente nel percorso di lavoro double m_dCoeff ; // coefficiente di esecuzione del movimento corrente (0...1) + bool m_bChangedTool ; // flag di utensile appena scaricato int m_nAuxSTot ; // numero totale movimenti ausiliari di inizio percorso int m_nAuxSInd ; // indice del movimento ausiliario di inizio percorso corrente int m_nAuxETot ; // numero totale movimenti ausiliari di fine percorso diff --git a/SimulatorSP.h b/SimulatorSP.h index 21ce025..e67af91 100644 --- a/SimulatorSP.h +++ b/SimulatorSP.h @@ -46,6 +46,8 @@ class SimulatorSP : public ISimulator double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) override ; bool EnableToolsForVmill( bool bEnable) override ; int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) override ; + bool SaveCmd( int nType, int nPar, const std::string& sPar) override + { return false ; } public : SimulatorSP( void) ; @@ -74,9 +76,9 @@ class SimulatorSP : public ISimulator const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI, const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) ; bool NeedCollisionCheck( void) const - { return ( ! m_CollObj.empty() && ! m_CdId.empty()) ; } + { return ( ! m_CollObj.empty() && ! m_CdId.empty()) ; } bool Stopped( void) - { return ( m_nUiStatus == MCH_UISIM_STOP) ; } + { return ( m_nUiStatus == MCH_UISIM_STOP) ; } bool SetCollisionMark( int nCdInd, int nObjInd) ; bool ResetCollisionMark( void) ; bool OnInit( void) ;