From f448eac9a402c7d3b8e98c989a02fd713bb1c3fc Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Sat, 7 Jan 2017 09:31:15 +0000 Subject: [PATCH] EgtMachKernel : - migliorie alla simulazione per azioni ausiliarie prima e dopo i percorsi di lavoro. --- Simulator.cpp | 168 +++++++++++++++++++++++++++++++------------------- Simulator.h | 10 ++- 2 files changed, 110 insertions(+), 68 deletions(-) diff --git a/Simulator.cpp b/Simulator.cpp index 65d97f6..cc46534 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -39,6 +39,10 @@ Simulator::Simulator( void) m_nEntId = GDB_ID_NULL ; m_nEntInd = 0 ; m_dCoeff = 0 ; + m_nAuxSTot = 0 ; + m_nAuxSInd = 0 ; + m_nAuxETot = 0 ; + m_nAuxEInd = 0 ; m_AxesName.reserve( 8) ; m_AxesToken.reserve( 8) ; m_AxesLinear.reserve( 8) ; @@ -112,11 +116,15 @@ Simulator::Move( int& nStatus) m_dCoeff = 0 ; } - // Se arrivato alla fine di un percorso di lavoro - if ( m_nEntId == GDB_ID_NULL) { + // Se appena arrivato alla fine di un percorso di lavoro + if ( m_nEntId == GDB_ID_NULL && m_nAuxEInd == 0) { // gestione fine percorso di lavoro if ( ! ManagePathEnd( nStatus)) return false ; + } + + // Se alla fine del percorso dopo esecuzione azioni ausiliarie + if ( m_nEntId == GDB_ID_NULL && m_nAuxEInd >= m_nAuxETot) { // ricerca e gestione inizio percorso di lavoro if ( ! FindAndManagePathStart( nStatus)) return false ; @@ -140,6 +148,14 @@ Simulator::Move( int& nStatus) return false ; } + // Se sto eseguendo i movimenti ausiliari di inizio percorso + if ( m_nAuxSInd < m_nAuxSTot) + return ManagePathStartAux( nStatus) ; + + // Se sto eseguendo i movimenti ausiliari di fine percorso + if ( m_nAuxEInd < m_nAuxETot) + return ManagePathEndAux( nStatus) ; + // Gestione movimento assi return ManageMove( nStatus) ; } @@ -256,13 +272,9 @@ Simulator::GoHome( void) bool Simulator::Stop( void) { - // controllo validità stato - if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr || m_pMachine == nullptr) + // porto in home + if ( ! GoHome()) return false ; - // porto la macchina in home - m_pMchMgr->ResetAllAxesPos() ; - // reset stato macchina - OnResetMachine() ; // rimuovo tavola variabili globali m_pMachine->LuaResetGlobVar( GLOB_VAR) ; // reset dello stato @@ -270,6 +282,10 @@ Simulator::Stop( void) m_nCLPathId = GDB_ID_NULL ; m_nEntId = GDB_ID_NULL ; m_dCoeff = 0 ; + m_nAuxSTot = 0 ; + m_nAuxSInd = 0 ; + m_nAuxETot = 0 ; + m_nAuxEInd = 0 ; return true ; } @@ -555,17 +571,18 @@ Simulator::FindAndManagePathStart( int& nStatus) Point3d ptMin, ptMax ; m_pGeomDB->GetInfo( m_nCLPathId, KEY_PMIN, ptMin) ; m_pGeomDB->GetInfo( m_nCLPathId, KEY_PMAX, ptMax) ; - // recupero il numero di eventi ausiliari - int nAS = 0 ; - m_pGeomDB->GetInfo( m_nCLPathId, KEY_AS_TOT, nAS) ; + // recupero il numero di eventi ausiliari di inizio + if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AS_TOT, m_nAuxSTot)) + m_nAuxSTot = 0 ; + m_nAuxSInd = 0 ; + // reset numero eventi ausiliari di fine + m_nAuxEInd = 0 ; + m_nAuxETot = 0 ; // richiamo gestione evento inizio percorso di lavoro - if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd, nAS, ptStart, vtExtr, ptMin, ptMax)) { + if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd, m_nAuxSTot, ptStart, vtExtr, ptMin, ptMax)) { nStatus = MCH_SIM_ERR ; return false ; } - // gestione eventuali eventi ausiliari prima di percorso - if ( ! ManagePathStartAuxes( nStatus)) - return false ; } return true ; @@ -575,69 +592,57 @@ Simulator::FindAndManagePathStart( int& nStatus) bool Simulator::ManagePathEnd( int& nStatus) { - // recupero il numero di eventi ausiliari - int nAE ; - m_pGeomDB->GetInfo( m_nCLPathId, KEY_AE_TOT, nAE) ; + // recupero il numero di eventi ausiliari di fine + if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AE_TOT, m_nAuxETot)) + m_nAuxETot = 0 ; + m_nAuxEInd = 0 ; // richiamo gestione evento fine percorso di lavoro - if ( ! OnPathEnd( nAE)) { + if ( ! OnPathEnd( m_nAuxETot)) { nStatus = MCH_SIM_ERR ; return false ; } - // gestione eventuali eventi ausiliari dopo percorso - if ( ! ManagePathEndAuxes( nStatus)) + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::ManagePathStartAux( int& nStatus) +{ + // aggiorno indice corrente + ++ m_nAuxSInd ; + // recupero i dati per l'evento corrente + string sAS ; + if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AS + ToString( m_nAuxSInd), sAS)) { + nStatus = MCH_SIM_ERR ; return false ; + } + // richiamo gestione evento ausiliario prima di inizio percorso di lavoro + if ( ! OnPathStartAux( m_nAuxSInd, sAS)) { + nStatus = MCH_SIM_ERR ; + return false ; + } + nStatus = MCH_SIM_END_STEP ; return true ; } //---------------------------------------------------------------------------- bool -Simulator::ManagePathStartAuxes( int& nStatus) +Simulator::ManagePathEndAux( int& nStatus) { - // recupero il numero di eventi ausiliari - int nAS ; - if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AS_TOT, nAS) || nAS == 0) - return true ; - // processo gli eventi - for ( int i = 1 ; i <= nAS ; ++ i) { - // recupero i dati per l'evento - string sAS ; - if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AS + ToString( i), sAS)) { - nStatus = MCH_SIM_ERR ; - return false ; - } - // richiamo gestione evento ausiliario prima di inizio percorso di lavoro - if ( ! OnPathStartAux( i, sAS)) { - nStatus = MCH_SIM_ERR ; - return false ; - } + // aggiorno indice corrente + ++ m_nAuxEInd ; + // recupero i dati per l'evento corrente + string sAE ; + if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AE + ToString( m_nAuxEInd), sAE)) { + nStatus = MCH_SIM_ERR ; + return false ; } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -Simulator::ManagePathEndAuxes( int& nStatus) -{ - // recupero il numero di eventi ausiliari - int nAE ; - if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AE_TOT, nAE) || nAE == 0) - return true ; - // processo gli eventi - for ( int i = 1 ; i <= nAE ; ++ i) { - // recupero i dati per l'evento - string sAE ; - if ( ! m_pGeomDB->GetInfo( m_nCLPathId, KEY_AE + ToString( i), sAE)) { - nStatus = MCH_SIM_ERR ; - return false ; - } - // richiamo gestione evento ausiliario dopo fine percorso di lavoro - if ( ! OnPathEndAux( i, sAE)) { - nStatus = MCH_SIM_ERR ; - return false ; - } + // richiamo gestione evento ausiliario dopo fine percorso di lavoro + if ( ! OnPathEndAux( m_nAuxEInd, sAE)) { + nStatus = MCH_SIM_ERR ; + return false ; } - + nStatus = MCH_SIM_END_STEP ; return true ; } @@ -742,6 +747,7 @@ Simulator::ManageMove( int& nStatus) // Altrimenti sto muovendomi all'interno dello step else nStatus = MCH_SIM_OK ; + return true ; } @@ -839,6 +845,38 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_SELECT) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; + + // reset assi ausiliari + ResetAuxAxes() ; + // recupero i dati di ritorno + int nNumAuxAxes = 0 ; + if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0) + return true ; + m_AuxAxesName.reserve( nNumAuxAxes) ; + m_AuxAxesToken.reserve( nNumAuxAxes) ; + m_AuxAxesInvert.reserve( nNumAuxAxes) ; + m_AuxAxesLinear.reserve( nNumAuxAxes) ; + m_AuxAxesVal.reserve( nNumAuxAxes) ; + m_AuxAxesEnd.reserve( nNumAuxAxes) ; + for ( int i = 1 ; i <= nNumAuxAxes && bOk ; ++ i) { + string sName ; string sToken ; bool bInvert ; bool bLinear ; double dVal ; + string sAuxAxName = GLOB_VAR + GVAR_ANN ; ReplaceString( sAuxAxName, "N", ToString( i)) ; + if ( m_pMachine->LuaGetGlobVar( sAuxAxName, sName) && + m_pMachine->GetAxisToken( sName, sToken) && + m_pMachine->GetAxisInvert( sName, bInvert) && + m_pMachine->GetAxisType( sName, bLinear) && + m_pMachine->GetAxisPos( sName, dVal)) { + m_AuxAxesName.emplace_back( sName) ; + m_AuxAxesToken.emplace_back( sToken) ; + m_AuxAxesInvert.push_back( bInvert) ; + m_AuxAxesLinear.push_back( bLinear) ; + m_AuxAxesVal.emplace_back( dVal) ; + m_AuxAxesEnd.emplace_back( dVal) ; + } + else + bOk = false ; + } + return bOk ; } diff --git a/Simulator.h b/Simulator.h index 524b194..8628f59 100644 --- a/Simulator.h +++ b/Simulator.h @@ -48,8 +48,8 @@ class Simulator bool ManageOperationEnd( int& nStatus) ; bool FindAndManagePathStart( int& nStatus) ; bool ManagePathEnd( int& nStatus) ; - bool ManagePathStartAuxes( int& nStatus) ; - bool ManagePathEndAuxes( int& nStatus) ; + bool ManagePathStartAux( int& nStatus) ; + bool ManagePathEndAux( int& nStatus) ; bool ManageMove( int& nStatus) ; bool OnDispositionStarting( int nOpId, int nOpInd, int nPhase, const std::string& sTable, const Point3d& ptOri1, bool bEmpty) ; @@ -80,7 +80,11 @@ class Simulator int m_nCLPathInd ; // contatore del percorso di lavoro corrente nell'operazione int m_nEntId ; // identificativo dell'entità corrente int m_nEntInd ; // contatore dell'entità corrente nel percorso di lavoro - double m_dCoeff ; // coefficiente di movimento corrente + double m_dCoeff ; // coefficiente di esecuzione del movimento corrente (0...1) + 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 + int m_nAuxEInd ; // indice del movimento ausiliario di fine percorso corrente std::string m_sTool ; // nome dell'utensile corrente STRVECTOR m_AxesName ; // nomi degli assi macchina attivi STRVECTOR m_AxesToken ; // token degli assi macchina attivi