diff --git a/Axis.cpp b/Axis.cpp index 350e459..baafff8 100644 --- a/Axis.cpp +++ b/Axis.cpp @@ -17,9 +17,11 @@ #include "Axis.h" #include "MachConst.h" #include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkGeoVector3d.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGkUiUnits.h" +#include "/EgtDev/Include/EgtNumUtils.h" using namespace std ; @@ -137,9 +139,8 @@ Axis::Set( const string& sName, const string& sToken, bool bInvert, double dOffs bool Axis::Modify( const Point3d& ptPos, double dAxisMaxAdjust) { - // Verifico che lo spostamento non superi il massimo ammesso - Vector3d vtDelta = ptPos - m_ptPos ; - Vector3d vtDeltaPerp = vtDelta - ( vtDelta * m_vtDir) * m_vtDir ; + // Verifico che lo spostamento perpendicolare alla sua direzione non superi il massimo ammesso + Vector3d vtDeltaPerp = OrthoCompo( ptPos - m_ptPos, m_vtDir) ; if ( vtDeltaPerp.Len() > dAxisMaxAdjust) { string sOut = " Modify Axis " + m_sName + " Position (" + ToString( ptPos) + ") failed" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; @@ -147,6 +148,11 @@ Axis::Modify( const Point3d& ptPos, double dAxisMaxAdjust) } // Assegno la nuova posizione m_ptPos = ptPos ; + // Sistemo la geometria dell'asse + int nV = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, m_sName) ; + IGeoVector3d* pGV = GetGeoVector3d( m_pGeomDB->GetGeoObj( nV)) ; + if ( pGV != nullptr) + pGV->ChangeBase( m_ptPos) ; return true ; } @@ -164,6 +170,11 @@ Axis::Modify( const Vector3d& vtDir, double dAxisMaxRotAdj) } // Assegno la nuova direzione m_vtDir = vtDirN ; + // Sistemo la geometria dell'asse + int nV = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, m_sName) ; + IGeoVector3d* pGV = GetGeoVector3d( m_pGeomDB->GetGeoObj( nV)) ; + if ( pGV != nullptr) + pGV->ChangeVector( m_vtDir) ; return true ; } @@ -172,10 +183,7 @@ bool Axis::Modify( const STROKE& Stroke) { m_Stroke = Stroke ; - if ( m_dHomeVal < m_Stroke.Min) - m_dHomeVal = m_Stroke.Min ; - else if ( m_dHomeVal > m_Stroke.Max) - m_dHomeVal = m_Stroke.Max ; + m_dHomeVal = Clamp( m_dHomeVal, m_Stroke.Min, m_Stroke.Max) ; return true ; } @@ -183,12 +191,7 @@ Axis::Modify( const STROKE& Stroke) bool Axis::Modify( double dHome) { - if ( dHome < m_Stroke.Min) - m_dHomeVal = m_Stroke.Min ; - else if ( dHome > m_Stroke.Max) - m_dHomeVal = m_Stroke.Max ; - else - m_dHomeVal = dHome ; + m_dHomeVal = Clamp( dHome, m_Stroke.Min, m_Stroke.Max) ; return true ; } diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 09b0dd0..511367b 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Exit.cpp b/Exit.cpp index 79c6cb3..f745a85 100644 --- a/Exit.cpp +++ b/Exit.cpp @@ -124,6 +124,9 @@ Exit::Modify( const Point3d& ptPos, double dExitMaxAdjust) } // Assegno la nuova posizione m_ptPos = ptPos ; + // Sistemo la geometria dell'uscita + if ( ! vtDelta.IsZero()) + m_pGeomDB->Translate( m_nOwnerId, vtDelta) ; return true ; } diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index 6b6f646..f9ac352 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -356,7 +356,7 @@ bool MachMgr::SetAxisPos( const string& sAxis, double dVal, double* pdNewVal) { Machine* pMch = GetCurrMachine() ; - return ( ( pMch != nullptr) ? pMch->SetAxisPos( sAxis, dVal, pdNewVal) : false) ; + return ( ( pMch != nullptr) ? pMch->SetAxisPos( sAxis, dVal, true, pdNewVal) : false) ; } //---------------------------------------------------------------------------- diff --git a/Machine.cpp b/Machine.cpp index b81fa02..7dc0ebb 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -441,8 +441,16 @@ Machine::ModifyMachineAxisPosition( const string& sName, const Point3d& ptPos) Axis* pAx = GetAxis( nAxGrp) ; if ( pAx == nullptr) return false ; + // se valore dell'asse non nullo, lo annullo + double dCurrVal = pAx->GetCurrVal() ; + if ( abs( dCurrVal) > EPS_ZERO) + SetAxisPos( sName, 0, false) ; // eseguo la modifica - return pAx->Modify( ptPos, m_dAxisMaxAdjust) ; + bool bOk = pAx->Modify( ptPos, m_dAxisMaxAdjust) ; + // ripristino l'asse al valore corrente + if ( abs( dCurrVal) > EPS_ZERO) + SetAxisPos( sName, dCurrVal, false) ; + return bOk ; } //---------------------------------------------------------------------------- @@ -458,8 +466,16 @@ Machine::ModifyMachineAxisDirection( const string& sName, const Vector3d& vtDir) Axis* pAx = GetAxis( nAxGrp) ; if ( pAx == nullptr) return false ; + // se valore dell'asse non nullo, lo annullo + double dCurrVal = pAx->GetCurrVal() ; + if ( abs( dCurrVal) > EPS_ZERO) + SetAxisPos( sName, 0, false) ; // eseguo la modifica - return pAx->Modify( vtDir, m_dAxisMaxRotAdj) ; + bool bOk = pAx->Modify( vtDir, m_dAxisMaxRotAdj) ; + // ripristino l'asse al valore corrente + if ( abs( dCurrVal) > EPS_ZERO) + SetAxisPos( sName, dCurrVal, false) ; + return bOk ; } //---------------------------------------------------------------------------- @@ -918,7 +934,7 @@ Machine::CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) return false ; } else { - Vector3d vtRotAx = vtTDir ^ vtDirN ; vtRotAx.Normalize() ; + Vector3d vtRotAx = vtTDir ^ vtDirN ; vtRotAx.Normalize( EPS_ZERO) ; string sOut = " Exit " + sName + " rotation = (" + ToString( dAngRot) + "/" + ToString( vtRotAx) + ")" ; LOG_DBG_INFO( GetEMkLogger(), sOut.c_str()) ; vtRotAx.ToLoc( frHead) ; @@ -976,7 +992,11 @@ Machine::ModifyMachineExitPosition( const string& sHead, int nExit, const Point3 if ( pExit == nullptr) return false ; // eseguo la modifica - return pExit->Modify( ptPos, m_dExitMaxAdjust) ; + if ( ! pExit->Modify( ptPos, m_dExitMaxAdjust)) + return false ; + // eventuale aggiornamento variabile lua EMC.EXITPOS con la nuova posizione + LuaSetGlobVar( "EMC.EXITPOS", ptPos) ; + return true ; } //---------------------------------------------------------------------------- diff --git a/Machine.h b/Machine.h index 2a19ccd..5e467b9 100644 --- a/Machine.h +++ b/Machine.h @@ -81,7 +81,7 @@ class Machine bool GetAxisInvert( const std::string& sAxis, bool& bInvert) const ; bool GetAxisOffset( const std::string& sAxis, double& dOffset) const ; bool GetAxisType( const std::string& sAxis, bool& bLinear) const ; - bool SetAxisPos( const std::string& sAxis, double dVal, double* pdNewVal = nullptr) ; + bool SetAxisPos( const std::string& sAxis, double dVal, bool bInStroke = true, double* pdNewVal = nullptr) ; bool GetAxisPos( const std::string& sAxis, double& dVal) const ; bool GetAxisMin( const std::string& sAxis, double& dMin) const ; bool GetAxisMax( const std::string& sAxis, double& dMax) const ; diff --git a/MachineAxes.cpp b/MachineAxes.cpp index 82addca..8a1fcce 100644 --- a/MachineAxes.cpp +++ b/MachineAxes.cpp @@ -19,6 +19,7 @@ #include "/EgtDev/Include/EGkGeoVector3d.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnFileUtils.h" +#include "/EgtDev/Include/EgtNumUtils.h" using namespace std ; @@ -88,7 +89,7 @@ Machine::GetAxisType( const string& sAxis, bool& bLinear) const //---------------------------------------------------------------------------- bool -Machine::SetAxisPos( const string& sAxis, double dVal, double* pdNewVal) +Machine::SetAxisPos( const string& sAxis, double dVal, bool bInStroke, double* pdNewVal) { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -114,10 +115,7 @@ Machine::SetAxisPos( const string& sAxis, double dVal, double* pdNewVal) Vector3d vtDir = pGV->GetVector() ; vtDir.Normalize() ; // limito il movimento alla corsa dell'asse - if ( dVal > Stroke.Max) - dVal = Stroke.Max ; - else if ( dVal < Stroke.Min) - dVal = Stroke.Min ; + dVal = Clamp( dVal, Stroke.Min, Stroke.Max) ; // eseguo il movimento if ( bLinear) m_pGeomDB->TranslateGroup( nAxGrp, vtDir * ( dVal - dCurrVal)) ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 8430304..ad760b7 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -24,11 +24,13 @@ #include "/EgtDev/Include/EGkGeoVector3d.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnFileUtils.h" +#include "/EgtDev/Include/EgtNumUtils.h" using namespace std ; //---------------------------------------------------------------------------- static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo +static const string EVAR_VER = ".VER" ; // (string) versione della Dll static const string EVAR_TABNAME = ".TABNAME" ; // (string) nome della tavola macchina static const string EVAR_HEAD = ".HEAD" ; // (string) nome della testa static const string EVAR_EXIT = ".EXIT" ; // (int) numero dell'uscita @@ -74,6 +76,7 @@ Machine::SetCurrTable( const string& sTable) bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bool bOk = LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_VER, GetEMkVer()) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_TABNAME, sTable) ; // chiamo funzione bOk = bOk && LuaCallFunction( ON_SET_TABLE) ; @@ -303,6 +306,7 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bool bOk = LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_VER, GetEMkVer()) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_HEAD, sHead) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_EXIT, nExit) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_TOOL, sTool) ; @@ -1481,10 +1485,7 @@ Machine::LimitAngleToStroke( int nInd, double& dAng) const if ( nInd < 0 || nInd >= int( m_vCalcRotAx.size())) return true ; // se angolo fuori corsa, lo porto all'estremo pił vicino - if ( dAng < m_vCalcRotAx[nInd].stroke.Min) - dAng = m_vCalcRotAx[nInd].stroke.Min ; - else if ( dAng > m_vCalcRotAx[nInd].stroke.Max) - dAng = m_vCalcRotAx[nInd].stroke.Max ; + dAng = Clamp( dAng, m_vCalcRotAx[nInd].stroke.Min, m_vCalcRotAx[nInd].stroke.Max) ; return true ; } @@ -1579,6 +1580,7 @@ Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bOk = bOk && LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_VER, GetEMkVer()) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_L1, dX) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_L2, dY) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_L3, dZ) ; diff --git a/Operation.cpp b/Operation.cpp index 4429703..5d362a5 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -425,7 +425,7 @@ Operation::GetElevation( int nPhase, const Point3d& ptP, const Vector3d& vtTool, } else { Vector3d vtOrtho = OrthoCompo( ptV - ptP, vtDir) ; - Vector3d vtMajAx = vtTool ^ vtDir ; vtMajAx.Normalize() ; + Vector3d vtMajAx = vtTool ^ vtDir ; vtMajAx.Normalize( EPS_ZERO) ; Vector3d vtMajOrt = ParallCompo( vtOrtho, vtMajAx) ; Vector3d vtMinOrt = ( vtOrtho - vtMajOrt) / abs( vtTool * vtDir) ; if ( vtMajOrt.SqLen() + vtMinOrt.SqLen() < dRad * dRad + EPS_ZERO)