EgtMachKernel 2.3g3 :

- gestione collisioni rilevate in OnToolDeselect e in OnToolSelect.
This commit is contained in:
DarioS
2021-07-12 16:03:50 +02:00
parent 8389a1d274
commit ddeeff8455
3 changed files with 89 additions and 36 deletions
+85 -32
View File
@@ -416,8 +416,10 @@ Simulator::GoHome( void)
//----------------------------------------------------------------------------
bool
Simulator::UpdateTool( bool bFirst)
Simulator::UpdateTool( bool bFirst, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
// Recupero l'utensile della lavorazione corrente
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch != nullptr) {
@@ -441,8 +443,12 @@ Simulator::UpdateTool( bool bFirst)
// se cambierà ed esiste il corrente, lo scarico
if ( bDiffTool && ! m_sTool.empty()) {
// eventuale lancio script per scarico utensile
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos))
return false ;
int nCurrErr ;
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != 11)
return false ;
}
}
// se prima volta, pulisco la testa
if ( bFirst)
@@ -481,10 +487,14 @@ Simulator::UpdateTool( bool bFirst)
}
// se cambiato oppure prima volta, lancio lo script di selezione
if ( bDiffTool || bFirst) {
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst))
return false ;
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != 11)
return false ;
}
}
return true ;
return ( nErr == 0) ;
}
// Provo con una disposizione
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
@@ -495,8 +505,12 @@ Simulator::UpdateTool( bool bFirst)
// se esiste utensile corrente e cambierà, lo scarico
if ( ! m_sTool.empty() && sTool != m_sTool) {
// eventuale lancio script per scarico utensile
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos))
return false ;
int nCurrErr ;
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != 11)
return false ;
}
}
// carico l'utensile
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
@@ -509,9 +523,13 @@ Simulator::UpdateTool( bool bFirst)
if ( ! UpdateAxes())
return false ;
// eventuale lancio script
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst))
return false ;
return true ;
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != 11)
return false ;
}
return ( nErr == 0) ;
}
return false ;
}
@@ -612,8 +630,11 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus)
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch != nullptr && ! pMch->IsEmpty()) {
// aggiorno utensile e assi conseguenti
if ( ! UpdateTool( bFirst)) {
nStatus = CalcStatusOnError( 0) ;
int nErr ;
if ( ! UpdateTool( bFirst, nErr)) {
string sOut = "Err=" + ToString( nErr) ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
nStatus = CalcStatusOnError( nErr) ;
return false ;
}
++ m_nOpInd ;
@@ -660,8 +681,9 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus)
// cambio fase
m_pMchMgr->SetCurrPhase( nPhase, ( nPhase == 1)) ;
// aggiorno utensile e assi conseguenti
if ( ! UpdateTool( bFirst)) {
nStatus = CalcStatusOnError( 0) ;
int nErr ;
if ( ! UpdateTool( bFirst, nErr)) {
nStatus = CalcStatusOnError( nErr) ;
return false ;
}
++ m_nOpInd ;
@@ -962,7 +984,7 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
double dDist = sqrt( dSqDist) ;
if ( dDist > EPS_SMALL) {
double dStep = min( ( nMoveType == 0 ? 2 : 1) * m_dStep, MAX_STEP) ;
int nStep = int( max( dDist / dStep, 1.)) ;
int nStep = max( int( dDist / dStep), 1) ;
m_dCoeff += 1. / nStep ;
if ( m_dCoeff > 1)
m_dCoeff = 1 ;
@@ -1082,7 +1104,8 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
double dPrevCoeff = m_dCoeff ;
double dDist = sqrt( dSqDist) ;
if ( dDist > EPS_SMALL) {
int nStep = int( max( dDist / ( ( nMoveType == 0 ? 2 : 1) * m_dStep), 1.)) ;
double dStep = min( ( nMoveType == 0 ? 2 : 1) * m_dStep, MAX_STEP) ;
int nStep = max( int( dDist / dStep), 1) ;
m_dCoeff += 1. / nStep ;
if ( m_dCoeff > 1)
m_dCoeff = 1 ;
@@ -1090,13 +1113,22 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
else
m_dCoeff = 1 ;
dMove = ( m_dCoeff - dPrevCoeff) * dDist ;
// Muovo eventuali assi ausiliari
for ( int i = 0 ; i < int( m_AuxAxesName.size()) ; ++ i) {
double dVal = m_AuxAxesVal[i] * ( 1 - m_dCoeff) + m_AuxAxesEnd[i] * m_dCoeff ;
m_pMachine->SetAxisPos( m_AuxAxesName[i], dVal) ;
// se attivo CollisionCheck approssimo movimento con più step
int nStep = 1 ;
if ( NeedCollisionCheck()) {
const double LEN_COLL_STEP = 10. ;
nStep = max( int( dMove / LEN_COLL_STEP), 1) ;
}
for ( int i = 1 ; i <= nStep ; ++ i) {
double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ;
// muovo eventuali assi ausiliari
for ( int j = 0 ; j < int( m_AuxAxesName.size()) ; ++ j) {
double dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ;
m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ;
}
// eseguo eventuale collision check
bCollCheck = bCollCheck && ExecCollisionCheck( nCdInd, nObjInd, nMoveType) ;
}
// eseguo eventuale collision check
bCollCheck = bCollCheck && ExecCollisionCheck( nCdInd, nObjInd, nMoveType) ;
}
// Se riscontrata collisione
@@ -1122,8 +1154,9 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
}
nStatus = MCH_SIM_END_STEP ;
// richiamo gestione evento fine entità
if ( ! OnMoveEnd()) {
nStatus = CalcStatusOnError( 0) ;
int nErr ;
if ( ! OnMoveEnd( nErr)) {
nStatus = CalcStatusOnError( nErr) ;
return false ;
}
}
@@ -1384,8 +1417,10 @@ Simulator::OnDispositionEnd( void)
//----------------------------------------------------------------------------
bool
Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, const string& sTcPos,
bool bFirst)
bool bFirst, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
// reset oggetti per verifica collisione con grezzo
m_CollObj.clear() ;
// assegno il nome dell'utensile, la testa e l'uscita
@@ -1411,6 +1446,9 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co
// assegno il flag di chiamata di utensile iniziale
if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIRST, bFirst))
return false ;
// reset errore
if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr))
return false ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_SELECT))
return true ;
@@ -1420,11 +1458,13 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co
UpdateAxesPos() ;
// recupero distanza di sicurezza per verifica collisione
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_SAFEDIST, m_dSafeDist) ;
// verifico codice di errore
bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
// recupero i dati di ritorno per assi ausiliari
ResetAuxAxes() ;
int nNumAuxAxes = 0 ;
if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0)
return true ;
return ( bOk && nErr == 0) ;
m_AuxAxesName.reserve( nNumAuxAxes) ;
m_AuxAxesToken.reserve( nNumAuxAxes) ;
m_AuxAxesInvert.reserve( nNumAuxAxes) ;
@@ -1453,13 +1493,15 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co
bOk = false ;
}
return bOk ;
return ( bOk && nErr == 0) ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnToolDeselect( const string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos)
Simulator::OnToolDeselect( const string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
// assegno il prossimo utensile
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTOOL, sNextTool) ;
// assegno la prossima testa
@@ -1468,6 +1510,8 @@ Simulator::OnToolDeselect( const string& sNextTool, const string& sNextHead, int
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTEXIT, nNextExit) ;
// assegno l'eventuale prossima posizione nel TC
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTCPOS, sNextTcPos) ;
// reset errore
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_DESELECT))
return bOk ;
@@ -1475,7 +1519,9 @@ Simulator::OnToolDeselect( const string& sNextTool, const string& sNextHead, int
bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_DESELECT) ;
// forzo aggiornamento posizione assi (possono essere stati mossi nello script)
UpdateAxesPos() ;
return bOk ;
// verifico codice di errore
bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
}
//----------------------------------------------------------------------------
@@ -1720,16 +1766,23 @@ Simulator::OnMoveStart( const CamData* pCamData, int& nErr)
//----------------------------------------------------------------------------
bool
Simulator::OnMoveEnd( void)
Simulator::OnMoveEnd( int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END))
return true ;
// reset errore
if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr))
return false ;
// chiamo la funzione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_END) ;
// forzo aggiornamento posizione assi (possono essere stati mossi nello script)
UpdateAxesPos() ;
return bOk ;
// verifico codice di errore
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
}
//----------------------------------------------------------------------------