From 46d433296b7c775b268d67b1faa78c7fc6b1fa71 Mon Sep 17 00:00:00 2001 From: DarioS Date: Tue, 28 Dec 2021 08:39:00 +0100 Subject: [PATCH] EgtMachKernel 2.3l2 : - in simulazione aggiunta gestione assi linkati ad altri assi. --- EgtMachKernel.rc | Bin 11782 -> 11782 bytes MachMgrDBTools.cpp | 2 +- OutputConst.h | 1 + Simulator.cpp | 113 ++++++++++++++++++++++++++++++++++++--------- Simulator.h | 1 + ToolsMgr.cpp | 8 ++-- 6 files changed, 99 insertions(+), 26 deletions(-) diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index d2ae8a20a1f840b688e08a2b1e578dcd3a61ff4c..dc9365c339d04207612e8705ed7dd3ca9b166476 100644 GIT binary patch delta 252 zcmZpRX^Yvgj#=B4A&()QA%`K8p_n0qL4iSoArvT*$xyH zADB6q8I3moWU~cQlh1RAZw?TOVcfim+Xo_ik!kV?!2-C{3KndNrLihj3L(`w2Pezv m&YP^IF2W0PxF^`DISiE`hfe;$oVEFix(+j{)Mi2LuS@{V8bfCQ delta 252 zcmZpRX^Yvgj#=H4A&()QA%`KAp%{o27&I7y8A=!ufjAS$3kAw%g4mMeHApr8Wy{e`NvyW_m$s diff --git a/MachMgrDBTools.cpp b/MachMgrDBTools.cpp index e0ed411..839ace7 100644 --- a/MachMgrDBTools.cpp +++ b/MachMgrDBTools.cpp @@ -855,7 +855,7 @@ MachMgr::TdbExport( const STRVECTOR& vsToolsNames, const string& sOutFile) const if ( vsToolsNames.empty()) return true ; - // recupero il gestore di utensili della macchina corrente + // recupero il gestore di utensili della macchina corrente ToolsMgr* pTsMgr = GetCurrToolsMgr() ; if ( pTsMgr == nullptr) return false ; diff --git a/OutputConst.h b/OutputConst.h index 59d18fe..7bc0eaf 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -150,6 +150,7 @@ static const std::string GVAR_SHOWAXES = ".ShowAxes" ; // (bool) flag visu static const std::string GVAR_AUXAXES = ".AuxAxes" ; // (int) numero assi ausiliari per simulazione static const std::string GVAR_AN = ".AN" ; // (num) valore del N-esimo asse ausiliario per simulazione static const std::string GVAR_ANN = ".ANn" ; // (string) nome del N-esimo asse ausiliario per simulazione +static const std::string GVAR_ANM = ".ANm" ; // (string) asse master del N-esimo asse ausiliario per simulazione static const std::string GVAR_VMILL = ".VMILL" ; // (int/s) identificativi Zmap attivi per Virtual Milling static const std::string GVAR_CODET = ".CODET" ; // (int/s) identificativi Zmap attivi per Collision Detection static const std::string GVAR_SIM1ST = ".SIM1ST" ; // (bool) flag inizio simulazione diff --git a/Simulator.cpp b/Simulator.cpp index e0adcf7..1fabbac 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -604,6 +604,7 @@ Simulator::ResetAuxAxes( void) m_AuxAxesLinear.clear() ; m_AuxAxesVal.clear() ; m_AuxAxesEnd.clear() ; + m_AuxAxesLink.clear() ; // abilito assi principali m_bEnabAxes = true ; m_bShowAxes = true ; @@ -1010,14 +1011,28 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove) } for ( int i = 1 ; i <= nStep ; ++ i) { double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ; + DBLVECTOR vDeltaVal( m_AxesName.size()) ; // assegno posizioni finali for ( int j = 0 ; j < int( m_AxesName.size()) ; ++ j) { + double dPrevVal ; + m_pMachine->GetAxisPos( m_AxesName[j], dPrevVal) ; double dVal = m_AxesVal[j] * ( 1 - dCurrCoeff) + AxesEnd[j] * dCurrCoeff ; m_pMachine->SetAxisPos( m_AxesName[j], dVal) ; + vDeltaVal[j] = dVal - dPrevVal ; } // 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 ; + double dVal = 0 ; + if ( m_AuxAxesLink[j] == 0) { + dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ; + } + else { + m_pMachine->GetAxisPos( m_AuxAxesName[j], dVal) ; + if ( m_AuxAxesLink[j] > 0) + dVal += vDeltaVal[m_AuxAxesLink[j] - 1] ; + else + dVal -= vDeltaVal[-m_AuxAxesLink[j] - 1] ; + } m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ; } // eseguo eventuale collision check @@ -1058,19 +1073,42 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove) } for ( int i = 1 ; i <= nStep ; ++ i) { double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ; + DBLVECTOR vDeltaVal( m_AxesName.size()) ; // assi lineari vtRot.Rotate( vtN, dDiffAng / nStep) ; - m_pMachine->SetAxisPos( m_AxesName[0], ptCen.x + vtRot.x + dCurrCoeff * dDeltaN * vtN.x) ; - m_pMachine->SetAxisPos( m_AxesName[1], ptCen.y + vtRot.y + dCurrCoeff * dDeltaN * vtN.y) ; - m_pMachine->SetAxisPos( m_AxesName[2], ptCen.z + vtRot.z + dCurrCoeff * dDeltaN * vtN.z) ; + double dPrevVal, dVal ; + m_pMachine->GetAxisPos( m_AxesName[0], dPrevVal) ; + dVal = ptCen.x + vtRot.x + dCurrCoeff * dDeltaN * vtN.x ; + m_pMachine->SetAxisPos( m_AxesName[0], dVal) ; + vDeltaVal[0] = dVal - dPrevVal ; + m_pMachine->GetAxisPos( m_AxesName[1], dPrevVal) ; + dVal = ptCen.y + vtRot.y + dCurrCoeff * dDeltaN * vtN.y ; + m_pMachine->SetAxisPos( m_AxesName[1], dVal) ; + vDeltaVal[1] = dVal - dPrevVal ; + m_pMachine->GetAxisPos( m_AxesName[2], dPrevVal) ; + dVal = ptCen.z + vtRot.z + dCurrCoeff * dDeltaN * vtN.z ; + m_pMachine->SetAxisPos( m_AxesName[2], dVal) ; + vDeltaVal[2] = dVal - dPrevVal ; // assi rotanti for ( int j = 3 ; j < int( m_AxesName.size()) ; ++ j) { + double dPrevVal ; m_pMachine->GetAxisPos( m_AxesName[j], dPrevVal) ; double dVal = m_AxesVal[j] * ( 1 - dCurrCoeff) + AxesEnd[j] * dCurrCoeff ; m_pMachine->SetAxisPos( m_AxesName[j], dVal) ; + vDeltaVal[j] = dVal - dPrevVal ; } // eventuali assi ausiliari for ( int j = 0 ; j < int( m_AuxAxesName.size()) ; ++ j) { - double dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ; + double dVal = 0 ; + if ( m_AuxAxesLink[j] == 0) { + dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ; + } + else { + m_pMachine->GetAxisPos( m_AuxAxesName[j], dVal) ; + if ( m_AuxAxesLink[j] > 0) + dVal += vDeltaVal[m_AuxAxesLink[j] - 1] ; + else + dVal -= vDeltaVal[-m_AuxAxesLink[j] - 1] ; + } m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ; } // eseguo eventuale Vmill @@ -1123,8 +1161,13 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove) 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) ; + if ( m_AuxAxesLink[j] == 0) { + double dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ; + m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ; + } + else { + + } } // eseguo eventuale collision check bCollCheck = bCollCheck && ExecCollisionCheck( nCdInd, nObjInd, nMoveType) ; @@ -1487,6 +1530,7 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co m_AuxAxesLinear.push_back( bLinear) ; m_AuxAxesVal.emplace_back( dVal) ; m_AuxAxesEnd.emplace_back( dVal) ; + m_AuxAxesLink.emplace_back( 0) ; } } else @@ -1734,28 +1778,55 @@ Simulator::OnMoveStart( const CamData* pCamData, int& nErr) 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 ; double dEnd ; + string sName ; string sToken ; bool bInvert ; bool bLinear ; double dVal ; double dEnd ; string sLink ; string sAuxAxVal = GLOB_VAR + GVAR_AN ; ReplaceString( sAuxAxVal, "N", ToString( i)) ; string sAuxAxName = GLOB_VAR + GVAR_ANN ; ReplaceString( sAuxAxName, "N", ToString( i)) ; + string sAuxAxMaster = GLOB_VAR + GVAR_ANM ; ReplaceString( sAuxAxMaster, "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_pMachine->LuaGetGlobVar( sAuxAxVal, dEnd)) { - // se assi principali disabilitati o non è tra questi, lo aggiungo - if ( ! m_bEnabAxes || find( m_AxesName.begin(), m_AxesName.end(), sName) == m_AxesName.end()) { - 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( dEnd) ; - if ( ! m_pMachine->VerifyOutstroke( sName, dEnd)) { - nErr = 1 ; - bOk = false ; + m_pMachine->GetAxisPos( sName, dVal)) { + // se da agganciare ad asse principale + if ( m_pMachine->LuaGetGlobVar( sAuxAxMaster, sLink)) { + bool bNeg = ( sLink.find( '-') != string::npos) ; + string sMainAxis = sLink ; ReplaceString( sMainAxis, "-", "") ; + int nInd = 0 ; + for ( int i = 0 ; nInd == 0 && i < int( m_AxesName.size()) ; ++ i) { + if ( m_AxesName[i] == sMainAxis) + nInd = i + 1 ; + } + // se assi principali abilitati e trovato asse principale di riferimento + if ( m_bEnabAxes && nInd > 0) { + m_AuxAxesName.emplace_back( sName) ; + m_AuxAxesToken.emplace_back( sToken) ; + m_AuxAxesInvert.push_back( bInvert) ; + m_AuxAxesLinear.push_back( bLinear) ; + m_AuxAxesVal.emplace_back( 0) ; + m_AuxAxesEnd.emplace_back( 0) ; + m_AuxAxesLink.emplace_back( ( bNeg ? -nInd : nInd)) ; } } + // se altrimenti specificato valore finale del movimento + else if ( m_pMachine->LuaGetGlobVar( sAuxAxVal, dEnd)) { + // se assi principali disabilitati o non è tra questi, lo aggiungo + if ( ! m_bEnabAxes || find( m_AxesName.begin(), m_AxesName.end(), sName) == m_AxesName.end()) { + 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( dEnd) ; + m_AuxAxesLink.emplace_back( 0) ; + if ( ! m_pMachine->VerifyOutstroke( sName, dEnd)) { + nErr = 1 ; + bOk = false ; + } + } + } + // altrimenti errore + else + bOk = false ; } else bOk = false ; diff --git a/Simulator.h b/Simulator.h index 7ac3a9d..f871537 100644 --- a/Simulator.h +++ b/Simulator.h @@ -145,4 +145,5 @@ class Simulator BOOLVECTOR m_AuxAxesLinear ; // flag di lineare degli assi macchina ausiliari abilitati DBLVECTOR m_AuxAxesVal ; // valori degli assi macchina ausiliari all'inizio del movimento corrente DBLVECTOR m_AuxAxesEnd ; // valori degli assi macchina ausiliari alla fine del movimento corrente + INTVECTOR m_AuxAxesLink ; // indice + 1 asse principale di aggancio (negativo valore opposto, 0 nessuno) } ; diff --git a/ToolsMgr.cpp b/ToolsMgr.cpp index a8fe347..c65f1fb 100644 --- a/ToolsMgr.cpp +++ b/ToolsMgr.cpp @@ -857,7 +857,7 @@ bool ToolsMgr::ExportOneTool( const string& sToolName, Writer& TheWriter, int nCounter, const string& sOutDir) const { // se il tool non esiste nel DB lo ignoro - if ( m_suData.find( sToolName) == m_suData.end()){ + if ( m_suData.find( sToolName) == m_suData.end()) { string sOut = "Warning Export Tool : " + sToolName + " not found. Tool is ignored" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; return true ; @@ -865,7 +865,7 @@ ToolsMgr::ExportOneTool( const string& sToolName, Writer& TheWriter, int nCounte const ToolData * tData = GetTool( sToolName) ; string sOut ; - if ( tData == nullptr){ + if ( tData == nullptr) { sOut = "Export Tools : Error exporting " + sToolName ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; return false ; @@ -885,7 +885,7 @@ ToolsMgr::ExportOneTool( const string& sToolName, Writer& TheWriter, int nCounte bOk = ! sOut.empty() && TheWriter.OutText( sOut) ; } - if ( ! bOk){ + if ( ! bOk) { sOut = "Export Tools : Error exporting " + sToolName ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; // visto che non ho salvato correttamente il tool elimino il suo disegno @@ -1155,7 +1155,7 @@ ToolsMgr::CopyToolDraw( const string& sDraw, const string& sOutDraw, const strin LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; bOk = false ; } - if ( bOk && ! ExeTdbCurrToolDraw( nGenCtx, nToolCtx)) { + if ( bOk && ExeTdbCurrToolDraw( nGenCtx, nToolCtx) != 0) { string sOut = " Error : " + sToolName + " CurrToolDraw" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; bOk = false ;