EgtMachKernel 2.5a2 :
- in simulazione corretta gestione collisione rilevata durante ToolDeselect che non deve far saltare le successive operazioni - aggiunta funzione lua EmtMoveAxes per consentire movimento assi in simulazione da esterno.
This commit is contained in:
+100
-17
@@ -44,8 +44,11 @@ using namespace std ;
|
||||
static const double MIN_STEP = 1.0 ;
|
||||
static const double MAX_STEP = 100.0 ;
|
||||
static const double MID_STEP = 50.0 ;
|
||||
static const double COLL_STEP = 10. ;
|
||||
static const double COEFF_LIM = 0.999 ;
|
||||
static const double SAFEDIST_STD = 5.0 ;
|
||||
static const int ERR_OUTSTROKE = 1 ;
|
||||
static const int ERR_COLLISION = 11 ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Simulator::Simulator( void)
|
||||
@@ -450,7 +453,7 @@ Simulator::UpdateTool( bool bFirst, int& nErr)
|
||||
int nCurrErr ;
|
||||
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
|
||||
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
|
||||
if ( nCurrErr != 11)
|
||||
if ( nCurrErr != ERR_COLLISION)
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
@@ -477,7 +480,7 @@ Simulator::UpdateTool( bool bFirst, int& nErr)
|
||||
int nCurrErr ;
|
||||
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
|
||||
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
|
||||
if ( nCurrErr != 11)
|
||||
if ( nCurrErr != ERR_COLLISION)
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
@@ -495,7 +498,7 @@ Simulator::UpdateTool( bool bFirst, int& nErr)
|
||||
int nCurrErr ;
|
||||
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
|
||||
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
|
||||
if ( nCurrErr != 11)
|
||||
if ( nCurrErr != ERR_COLLISION)
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
@@ -513,7 +516,7 @@ Simulator::UpdateTool( bool bFirst, int& nErr)
|
||||
int nCurrErr ;
|
||||
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
|
||||
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
|
||||
if ( nCurrErr != 11)
|
||||
if ( nCurrErr != ERR_COLLISION)
|
||||
return false ;
|
||||
}
|
||||
return ( nErr == 0) ;
|
||||
@@ -622,13 +625,14 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus)
|
||||
// se lavorazione valida
|
||||
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
|
||||
if ( pMch != nullptr && ! pMch->IsEmpty()) {
|
||||
bool bOk = true ;
|
||||
// aggiorno utensile e assi conseguenti
|
||||
int nErr ;
|
||||
if ( ! UpdateTool( bFirst, nErr)) {
|
||||
string sOut = "Err=" + ToString( nErr) ;
|
||||
LOG_INFO( GetEMkLogger(), sOut.c_str())
|
||||
nStatus = CalcStatusOnError( nErr) ;
|
||||
return false ;
|
||||
bOk = false ;
|
||||
}
|
||||
++ m_nOpInd ;
|
||||
// imposto la lavorazione come corrente
|
||||
@@ -644,8 +648,10 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus)
|
||||
// richiamo gestione evento inizio lavorazione
|
||||
if ( ! OnMachiningStart( m_nOpId, m_nOpInd, ptMin, ptMax, vAxMin, vAxMax)) {
|
||||
nStatus = CalcStatusOnError( 0) ;
|
||||
return false ;
|
||||
bOk = false ;
|
||||
}
|
||||
if ( ! bOk)
|
||||
return false ;
|
||||
break ;
|
||||
}
|
||||
// se disposizione con cambio di fase
|
||||
@@ -1004,10 +1010,8 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
|
||||
if ( nMoveType != 2 && nMoveType != 3) {
|
||||
// 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) ;
|
||||
}
|
||||
if ( NeedCollisionCheck())
|
||||
nStep = max( int( dMove / COLL_STEP), 1) ;
|
||||
for ( int i = 1 ; i <= nStep ; ++ i) {
|
||||
double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ;
|
||||
DBLVECTOR vDeltaVal( m_AxesName.size()) ;
|
||||
@@ -1160,10 +1164,8 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
|
||||
dMove = ( m_dCoeff - dPrevCoeff) * dDist ;
|
||||
// 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) ;
|
||||
}
|
||||
if ( NeedCollisionCheck())
|
||||
nStep = max( int( dMove / COLL_STEP), 1) ;
|
||||
for ( int i = 1 ; i <= nStep ; ++ i) {
|
||||
double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ;
|
||||
// muovo eventuali assi ausiliari
|
||||
@@ -1223,9 +1225,9 @@ Simulator::CalcStatusOnError( int nErr)
|
||||
{
|
||||
if ( Stopped())
|
||||
return MCH_SIM_STOP ;
|
||||
else if ( nErr == 1)
|
||||
else if ( nErr == ERR_OUTSTROKE)
|
||||
return MCH_SIM_OUTSTROKE ;
|
||||
else if ( nErr == 11)
|
||||
else if ( nErr == ERR_COLLISION)
|
||||
return MCH_SIM_COLLISION ;
|
||||
else
|
||||
return MCH_SIM_ERR ;
|
||||
@@ -1901,7 +1903,7 @@ Simulator::OnCollision( int nCdInd, int nObjInd, int& nErr)
|
||||
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
|
||||
// l'errore standard di collisione è stato portato da 1 a 11 per non collidere con altri tipi di errori
|
||||
if ( nErr == 1) {
|
||||
nErr = 11 ;
|
||||
nErr = ERR_COLLISION ;
|
||||
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
|
||||
}
|
||||
return ( nErr == 0) ;
|
||||
@@ -2040,3 +2042,84 @@ Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit,
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
Simulator::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt)
|
||||
{
|
||||
// Salvo lo step di simulazione corrente
|
||||
double dOrigStep = m_dStep ;
|
||||
// verifico ci siano assi da muovere
|
||||
if ( vAxNaEpSt.empty())
|
||||
return SIM_AXMV_RES_ERR ;
|
||||
// numero assi da muovere
|
||||
int nAxCount = int( vAxNaEpSt.size()) ;
|
||||
// posizioni iniziali
|
||||
DBLVECTOR vPrev( nAxCount) ;
|
||||
for ( int i = 0 ; i < nAxCount ; ++ i) {
|
||||
if ( ! m_pMchMgr->GetAxisPos( vAxNaEpSt[i].sName, vPrev[i]))
|
||||
return SIM_AXMV_RES_ERR ;
|
||||
}
|
||||
// determino gli step di movimento
|
||||
int nStep = 1 ;
|
||||
for ( int i = 0 ; i < nAxCount ; ++ i) {
|
||||
double dMove = abs( vAxNaEpSt[i].dEndPos - vPrev[i]) ;
|
||||
int nAxStep = int( dMove / max( vAxNaEpSt[i].dStep, 1.)) + 1 ;
|
||||
nStep = max( nStep, nAxStep) ;
|
||||
}
|
||||
// eseguo il movimento
|
||||
for ( int j = 1 ; j <= nStep ; ++ j) {
|
||||
// muovo
|
||||
bool bMoveOk = true ;
|
||||
double dCoeff = double( j) / nStep ;
|
||||
for ( int i = 0 ; i < nAxCount ; ++ i)
|
||||
bMoveOk = m_pMchMgr->SetAxisPos( vAxNaEpSt[i].sName, ( 1 - dCoeff) * vPrev[i] + dCoeff * vAxNaEpSt[i].dEndPos) && bMoveOk ;
|
||||
ExeDraw() ;
|
||||
// verifica collisioni
|
||||
int nCdInd, nObjInd ;
|
||||
bool bCollCheck = ExecCollisionCheck( nCdInd, nObjInd, nMoveType) ;
|
||||
if ( ! bCollCheck) {
|
||||
// Richiamo funzione di convalida collisione
|
||||
int nPrevErr ;
|
||||
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nPrevErr) ;
|
||||
int nErr ;
|
||||
if ( ! OnCollision( nCdInd, nObjInd, nErr) && nErr == ERR_COLLISION) {
|
||||
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
|
||||
if ( ExeGetEnableUI()) {
|
||||
// Box di messaggio : Collisione! AVVERTIMENTO
|
||||
ExeMessageBox( ExeGetMsg( 5319), ExeGetMsg( 5315), MB_OK | MB_ICONWARNING) ;
|
||||
// Gestione Pausa
|
||||
m_nUiStatus = MCH_UISIM_PAUSE ;
|
||||
while ( m_nUiStatus == MCH_UISIM_PAUSE) {
|
||||
// -11 notifica al simulatore pausa dopo collisione
|
||||
ExeProcessEvents( -11, 2) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nPrevErr) ;
|
||||
}
|
||||
}
|
||||
if ( ! bMoveOk)
|
||||
return SIM_AXMV_RES_ERR ;
|
||||
if ( ExeGetEnableUI()) {
|
||||
// Aggiornamento interfaccia
|
||||
ExeProcessEvents( 0, 2) ;
|
||||
while ( m_nUiStatus == MCH_UISIM_PAUSE) {
|
||||
ExeProcessEvents( 0, 2) ;
|
||||
}
|
||||
// Gestione Stop
|
||||
if ( m_nUiStatus == MCH_UISIM_STOP)
|
||||
return SIM_AXMV_RES_STOP ;
|
||||
// Se cambia lo step di simulazione in modo significativo ...
|
||||
if ( abs( m_dStep - dOrigStep) > 5) {
|
||||
double dRat = m_dStep / dOrigStep ;
|
||||
for ( int i = 0 ; i < nAxCount ; ++ i)
|
||||
const_cast<double&>( vAxNaEpSt[i].dStep) *= dRat ;
|
||||
return MoveAxes( nMoveType, vAxNaEpSt) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SIM_AXMV_RES_OK ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user