From 63a71db7ffd813bf4590c988b4d597bfdfeafdac Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 6 Nov 2023 08:49:27 +0100 Subject: [PATCH] EgtMachKernel : - modifiche per gestire aggregati di utensili su tool changer. --- Machine.cpp | 48 ++++++++++++++++++++++++-- Machine.h | 11 ++++-- MachineLua.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++--- SetupMgr.cpp | 14 ++++++-- 4 files changed, 153 insertions(+), 13 deletions(-) diff --git a/Machine.cpp b/Machine.cpp index 7dc0ebb..be64455 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -659,9 +659,9 @@ Machine::LoadMachineSpecialHead( const string& sName, const string& sParent, con //---------------------------------------------------------------------------- bool -Machine::LoadMachineTcPos( const string& sName, const string& sParent, - const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, - const string& sGeo, const STRVECTOR& vsAux) +Machine::LoadMachineStdTcPos( const string& sName, const string& sParent, + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + const string& sGeo, const STRVECTOR& vsAux) { // recupero pezzo e layer della geometria originale della posizione nel cambio utensile string sPart, sLay ; @@ -701,6 +701,48 @@ Machine::LoadMachineTcPos( const string& sName, const string& sParent, return m_mapGroups.emplace( sName, nLay).second ; } +//---------------------------------------------------------------------------- +bool +Machine::LoadMachineMultiTcPos( const string& sName, const string& sParent, + const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, + const string& sGeo, const STRVECTOR& vsAux) +{ + // recupero pezzo e layer della geometria originale della posizione nel cambio utensile + string sPart, sLay ; + Split( sGeo, "/", true, sPart, sLay) ; + // cerco il gruppo nella geometria originale + int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ; + int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ; + if ( nLay == GDB_ID_NULL) + return false ; + // cerco il gruppo padre per spostarvelo + int nParentId = GetGroup( sParent) ; + if ( nParentId == GDB_ID_NULL || + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) + return false ; + // sistemo lo stato di visualizzazione + m_pGeomDB->SetStatus( nLay, GDB_ST_ON) ; + // gli assegno il nome + m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; + // installo e inizializzo il gestore della posizione nel cambio utensile + TcPos* pTcPos = new(nothrow) TcPos ; + if ( pTcPos == nullptr) + return false ; + pTcPos->Set( sName, vtADir) ; + m_pGeomDB->SetUserObj( nLay, pTcPos) ; + // sistemo il riferimento dell'uscita rispetto alla direzione ausiliaria + if ( ! AdjustExitFrames( nLay, vMuExit, vtADir)) + return false ; + // trasformazione del riferimento di uscita in gruppo di uscita + if ( ! CreateExitGroups( nLay, vMuExit)) + return false ; + // lo inserisco nel dizionario dei gruppi della macchina + return m_mapGroups.emplace( sName, nLay).second ; +} + //---------------------------------------------------------------------------- int Machine::GetGroup( const string& sGroup) const diff --git a/Machine.h b/Machine.h index 5e467b9..5d4742d 100644 --- a/Machine.h +++ b/Machine.h @@ -215,9 +215,12 @@ class Machine const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, double dRot1W, bool bMaxDeltaR2On1, const STROKE& Rot2Stroke, int nSolCh, const STRVECTOR& vsOthColl, const std::string& sGeo, const STRVECTOR& vsAux) ; - bool LoadMachineTcPos( const std::string& sName, const std::string& sParent, - const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, - const std::string& sGeo, const STRVECTOR& vsAux) ; + bool LoadMachineStdTcPos( const std::string& sName, const std::string& sParent, + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + const std::string& sGeo, const STRVECTOR& vsAux) ; + bool LoadMachineMultiTcPos( const std::string& sName, const std::string& sParent, + const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, + const std::string& sGeo, const STRVECTOR& vsAux) ; int GetGroup( const std::string& sGroup) const ; bool IsBaseGroup( int nGroup) const ; Axis* GetAxis( int nGroup) const ; @@ -325,6 +328,8 @@ class Machine static int LuaEmtMultiHead( lua_State* L) ; static int LuaEmtSpecialHead( lua_State* L) ; static int LuaEmtTcPos( lua_State* L) ; + static int LuaEmtStdTcPos( lua_State* L) ; + static int LuaEmtMultiTcPos( lua_State* L) ; static int LuaEmtModifyAxisPosition( lua_State* L) ; static int LuaEmtModifyAxisDirection( lua_State* L) ; static int LuaEmtModifyAxisStroke( lua_State* L) ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 416534b..cbe8ff1 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -44,6 +44,7 @@ static const string FLD_INVERT = "Invert" ; static const string FLD_AXIS_OFFSET = "Offset" ; static const string FLD_REF1 = "Ref1" ; static const string FLD_SCALE = "Scale" ; +static const string FLD_EXIT_NBR = "ExitNbr" ; static const string FLD_POS = "Pos" ; static const string FLD_DIR = "Dir" ; static const string FLD_STROKE = "Stroke" ; @@ -661,7 +662,7 @@ Machine::LuaEmtMultiHead( lua_State* L) LuaCheckTabFieldParam( L, 1, FLD_HSET, sHSet) // lettura campo 'ExitNbr' dalla tabella int nExitNbr ; - LuaCheckTabFieldParam( L, 1, "ExitNbr", nExitNbr) + LuaCheckTabFieldParam( L, 1, FLD_EXIT_NBR, nExitNbr) // lettura campi 'PosN' e 'TDirN' per ogni uscita dalla tabella MUEXITVECTOR vMuExit ; vMuExit.reserve( nExitNbr) ; @@ -676,7 +677,7 @@ Machine::LuaEmtMultiHead( lua_State* L) // inserimento nell'array vMuExit.emplace_back( ptPos, vtTDir) ; } - // lettura campo 'ADir' dalla tabella + // lettura eventuale campo 'ADir' dalla tabella Vector3d vtADir ; LuaGetTabFieldParam( L, 1, FLD_ADIR, vtADir) ; // lettura eventuale campo 'Rot1W' dalla tabella (default 1) @@ -713,7 +714,7 @@ Machine::LuaEmtMultiHead( lua_State* L) // carico i dati della testa multipla if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, dRot1W, bMaxDeltaR2On1, Rot2Stroke, nSolCh, vsOthColl, sGeo, vsAux)) - return luaL_error( L, " Load Machine Standard Head failed") ; + return luaL_error( L, " Load Machine Multi Head failed") ; // restituisco l'indice della testa int nHeadId = m_pMchLua->GetHeadId( sName) ; @@ -797,6 +798,26 @@ Machine::LuaEmtSpecialHead( lua_State* L) //---------------------------------------------------------------------------- int Machine::LuaEmtTcPos( lua_State* L) +{ + // Il parametro 1 deve essere una tabella + if ( ! lua_istable( L, 1)) + return luaL_error( L, " Invalid Parameter, required a table") ; + // lettura campo opzionale 'ExitNbr' dalla tabella + int nExitNbr = 1 ; + LuaGetTabFieldParam( L, 1, FLD_EXIT_NBR, nExitNbr) ; + + // Procedo alla lettura a seconda del tnumero di uscite + if ( nExitNbr == 1) + return LuaEmtStdTcPos( L) ; + else if ( nExitNbr > 1) + return LuaEmtMultiTcPos( L) ; + else + return luaL_error( L, " Tc Position type unknown") ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtStdTcPos( lua_State* L) { // Il parametro 1 deve essere una tabella if ( ! lua_istable( L, 1)) @@ -833,8 +854,70 @@ Machine::LuaEmtTcPos( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della posizione cambio utensile - if ( ! m_pMchLua->LoadMachineTcPos( sName, sParent, ptPos, vtTDir, vtADir, sGeo, vsAux)) - return luaL_error( L, " Load Machine Tc Position failed") ; + if ( ! m_pMchLua->LoadMachineStdTcPos( sName, sParent, ptPos, vtTDir, vtADir, sGeo, vsAux)) + return luaL_error( L, " Load Machine Standard Tc Position failed") ; + + // restituisco l'indice della posizione cambio utensile + int nTcPosId = m_pMchLua->GetTcPosId( sName) ; + if ( nTcPosId != GDB_ID_NULL) + LuaSetParam( L, nTcPosId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtMultiTcPos( lua_State* L) +{ + // Il parametro 1 deve essere una tabella + if ( ! lua_istable( L, 1)) + return luaL_error( L, " Invalid Parameter, required a table") ; + // lettura campo 'Name' dalla tabella + string sName ; + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) + // lettura campo 'Parent' dalla tabella + string sParent ; + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) + // lettura campo 'ExitNbr' dalla tabella + int nExitNbr ; + LuaCheckTabFieldParam( L, 1, FLD_EXIT_NBR, nExitNbr) + // lettura campi 'PosN' e 'TDirN' per ogni uscita dalla tabella + MUEXITVECTOR vMuExit ; + vMuExit.reserve( nExitNbr) ; + for ( int i = 0 ; i < nExitNbr ; ++ i) { + // lettura + string sPos = FLD_POS + ToString( i + 1) ; + Point3d ptPos ; + LuaCheckTabFieldParam( L, 1, sPos.c_str(), ptPos) + string sTDir = FLD_TDIR + ToString( i + 1) ; + Vector3d vtTDir ; + LuaCheckTabFieldParam( L, 1, sTDir.c_str(), vtTDir) + // inserimento nell'array + vMuExit.emplace_back( ptPos, vtTDir) ; + } + // lettura eventuale campo 'ADir' dalla tabella + Vector3d vtADir ; + LuaGetTabFieldParam( L, 1, FLD_ADIR, vtADir) ; + // lettura campo 'Geo' dalla tabella + string sGeo ; + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; + LuaClearStack( L) ; + + // info + string sOut = "LuaEmtTcPos : " + sName ; + LOG_DBG_INFO( GetEMkLogger(), sOut.c_str()) + + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + + // carico i dati della posizione cambio utensile + if ( ! m_pMchLua->LoadMachineMultiTcPos( sName, sParent, vMuExit, vtADir, sGeo, vsAux)) + return luaL_error( L, " Load Machine Multi Tc Position failed") ; // restituisco l'indice della posizione cambio utensile int nTcPosId = m_pMchLua->GetTcPosId( sName) ; diff --git a/SetupMgr.cpp b/SetupMgr.cpp index 03c2a91..6625e9d 100644 --- a/SetupMgr.cpp +++ b/SetupMgr.cpp @@ -324,11 +324,21 @@ SetupMgr::GetToolName( const string& sHead, int nExit, string& sName) const bool SetupMgr::GetToolsInSetupPos( const string& sTcPos, STRVECTOR& vsTools) const { + // default vettore vuoto vsTools.clear() ; - // eseguo ricerca + // verifico macchina + if ( m_pMachine == nullptr) + return false ; + // eseguo ricerca (con inserimento nel vettore secondo indice dell'uscita) for ( int i = 0 ; i < int( m_vStuData.size()) ; ++ i) { if ( EqualNoCase( sTcPos, m_vStuData[i].m_sTcPos)) { - vsTools.emplace_back( m_vStuData[i].m_sName) ; + if ( vsTools.empty()) { + int nExitCnt = m_pMachine->GetHeadExitCount( m_vStuData[i].m_sHead) ; + vsTools.resize( nExitCnt) ; + } + int nExit = m_vStuData[i].m_nExit ; + if ( nExit <= int( vsTools.size())) + vsTools[nExit - 1] = m_vStuData[i].m_sName ; } } return true ;