From abbc7ee12b0f5c7b80d1ed53f9cfb716da25359b Mon Sep 17 00:00:00 2001 From: DarioS Date: Tue, 17 Jan 2023 11:33:37 +0100 Subject: [PATCH] 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. --- EgtMachKernel.rc | Bin 11774 -> 11774 bytes MachMgr.h | 1 + MachMgrSimulation.cpp | 15 +++++- Machine.h | 6 ++- MachineLua.cpp | 43 ++++++++++++++++ Simulator.cpp | 117 ++++++++++++++++++++++++++++++++++++------ Simulator.h | 26 +++++++--- 7 files changed, 181 insertions(+), 27 deletions(-) diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 5dda8ad021e2927a46811206c6ac89e2bc9c2902..f250b583ed2dd248a57e0e1c43c78663f9abf4a1 100644 GIT binary patch delta 97 zcmewt{V#gMFE&P_&A-`fnHh~HKa|wnoW?bQ1uSxrY4Qod0+^@}R1`^_2jk{d(jGv4 NK<#LXK~l;gTmU8!BZvS1 delta 97 zcmewt{V#gMFE&QQ&A-`fnHdcyKa|wnoW?bQ1uSxrY4Qod0+^@}R1`^_2jk{d(jGv4 NK<#LXK~l;gTmU3rBY*$^ diff --git a/MachMgr.h b/MachMgr.h index 354b596..0a8e69f 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -456,6 +456,7 @@ class MachMgr : public IMachMgr bool SimExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) ; bool SimOnCollision( int nCdInd, int nObjInd, int& nErr) ; bool SimSetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst) ; + int SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ; // Machine bool GetHeadAbove( const std::string& sHead) const ; double GetDeltaSafeZ( const std::string& sHead) const ; diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index 0124f3a..b77fc69 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2023 //---------------------------------------------------------------------------- -// File : MachMgrSimulation.cpp Data : 20.10.15 Versione : 1.6j2 +// File : MachMgrSimulation.cpp Data : 16.01.23 Versione : 2.5a2 // Contenuto : Implementazione gestione simulazione della classe MachMgr. // // @@ -191,3 +191,14 @@ MachMgr::SimSetToolForVmill( const string& sTool, const string& sHead, int nExit // imposto utensile per Vmill return m_pSimul->SetToolForVmill( sTool, sHead, nExit, vVmill, bFirst) ; } + +//---------------------------------------------------------------------------- +int +MachMgr::SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // lancio movimento assi + return m_pSimul->MoveAxes( nMoveType, vAxNaEpSt) ; +} diff --git a/Machine.h b/Machine.h index 0316a0d..1560eb0 100644 --- a/Machine.h +++ b/Machine.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2021 +// EgalTech 2015-2023 //---------------------------------------------------------------------------- -// File : Machine.h Data : 14.10.21 Versione : 2.3j5 +// File : Machine.h Data : 16.01.23 Versione : 2.5a2 // Contenuto : Dichiarazione della classe Machine. // // @@ -356,6 +356,8 @@ class Machine static int LuaEmtOnCollision( lua_State* L) ; static int LuaEmtSetToolForVmill( lua_State* L) ; static int LuaEmtAddToolForVmill( lua_State* L) ; + static int LuaEmtMoveAxes( lua_State* L) ; + } ; //---------------------------------------------------------------------------- diff --git a/MachineLua.cpp b/MachineLua.cpp index 92f44b5..512298c 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -136,6 +136,8 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtSetToolForVmill", Machine::LuaEmtSetToolForVmill) ; // registro la funzione di impostazione di utensile aggiuntivo per virtual milling in simulazione m_LuaMgr.RegisterFunction( "EmtAddToolForVmill", Machine::LuaEmtAddToolForVmill) ; + // registro la funzione di movimento assi in simulazione + m_LuaMgr.RegisterFunction( "EmtMoveAxes", Machine::LuaEmtMoveAxes) ; return true ; } @@ -1386,3 +1388,44 @@ Machine::LuaEmtAddToolForVmill( lua_State* L) LuaSetParam( L, bOk) ; return 1 ; } + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtMoveAxes( lua_State* L) +{ + // 4, ..., 16 parametri : nMoveType, sAx1, dPos1, dStep1 [, sAx2, dPos2, dStep2] [, sAx3, dPos3, dStep3] [, sAx4, dPos4, dStep4] [, sAx5, dPos5, dStep5] + int nMoveType ; + LuaCheckParam( L, 1, nMoveType) + string sAx1 ; + LuaCheckParam( L, 2, sAx1) ; + double dEnd1 ; + LuaCheckParam( L, 3, dEnd1) ; + double dStep1 ; + LuaCheckParam( L, 4, dStep1) ; + SAMVECTOR vAxNaEpSt ; + vAxNaEpSt.emplace_back( sAx1, dEnd1, dStep1) ; + for ( int i = 0 ; i < 4 ; ++ i) { + int nInd = 5 + 3 * i ; + string sAxN ; + double dEndN ; + double dStepN ; + if ( LuaGetParam( L, nInd, sAxN) && LuaGetParam( L, nInd + 1, dEndN) && LuaGetParam( L, nInd + 2, dStepN)) + vAxNaEpSt.emplace_back( sAxN, dEndN, dStepN) ; + else + break ; + } + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // eseguo movimento in simulazione + int nRes = 0 ; + if ( m_pMchLua->m_pMchMgr != nullptr) + nRes = m_pMchLua->m_pMchMgr->SimMoveAxes( nMoveType, vAxNaEpSt) ; + // assegno risultato + if ( nRes == SIM_AXMV_RES_STOP) + return luaL_error( L, "STOP") ; + else + LuaSetParam( L, ( nRes == SIM_AXMV_RES_OK)) ; + return 1 ; +} diff --git a/Simulator.cpp b/Simulator.cpp index 4f3ce87..271cdd6 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -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( vAxNaEpSt[i].dStep) *= dRat ; + return MoveAxes( nMoveType, vAxNaEpSt) ; + } + } + } + + return SIM_AXMV_RES_OK ; +} diff --git a/Simulator.h b/Simulator.h index 79ff2c0..86edcd8 100644 --- a/Simulator.h +++ b/Simulator.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2023 //---------------------------------------------------------------------------- -// File : Simulator.h Data : 19.10.15 Versione : 1.6j2 +// File : Simulator.h Data : 16.01.23 Versione : 2.5a2 // Contenuto : Dichiarazione della classe Simulator. // // @@ -21,6 +21,21 @@ class IGeomDB ; class Machine ; class PerformanceCounter ; +//------------------------ Struttura per movimento esterno assi -------------- +struct SimAxMv +{ + std::string sName ; + double dEndPos ; + double dStep ; + SimAxMv( void) : dEndPos( 0), dStep( 0) { } + SimAxMv( std::string sN, double dE, double dS) : sName( sN), dEndPos( dE), dStep( dS) {} +} ; +typedef std::vector SAMVECTOR ; + +//------------------------ Risultato movimento esterno assi ------------------- +enum SimAxMvRes { SIM_AXMV_RES_STOP = -1, + SIM_AXMV_RES_ERR = 0, + SIM_AXMV_RES_OK = 1} ; //---------------------------------------------------------------------------- class Simulator @@ -42,6 +57,7 @@ class Simulator bool ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) ; bool OnCollision( int nCdInd, int nObjInd, int& nErr) ; bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst) ; + int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ; private : bool UpdateTool( bool bFirst, int& nErr) ; @@ -105,7 +121,7 @@ class Simulator CollObj( int nI, int nF, int nT, const Vector3d& vtM, double dP1, double dP2, double dP3) : nInd( nI), nFrameId( nF), nType( nT), vtMove( vtM), dPar1( dP1), dPar2( dP2), dPar3( dP3) {} } ; - typedef std::vector< CollObj> COBVECTOR ; + typedef std::vector COBVECTOR ; struct VmTool { std::string sName ; @@ -117,7 +133,7 @@ class Simulator VmTool( std::string sN, std::string sH, int nE, double dT, double dA) : sName( sN), sHead( sH), nExit( nE), dTdOffs( dT), dAdOffs( dA) {} } ; - typedef std::vector< VmTool> VMTVECTOR ; + typedef std::vector VMTVECTOR ; private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni @@ -143,8 +159,6 @@ class Simulator double m_dTDiam ; // diametro dell'utensile corrente INTVECTOR m_VmId ; // vettore identificativi Zmap per Virtual Milling INTVECTOR m_CdId ; // vettore identificativi Zmap per Collision Detection - //double m_dVmTdOffs ; // offset utensile in direzione principale per VM - //double m_dVmAdOffs ; // offset utensile in direzione ausiliaria per VM VMTVECTOR m_VmTool ; // vettore utensili attivi per virtual milling COBVECTOR m_CollObj ; // vettore oggetti da testare per collisione con grezzo double m_dSafeDist ; // distanza di sicurezza per verifica collisioni