From 50bbbe202bc5b81b177ef8947a295ae25288e843 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 24 Dec 2019 08:40:28 +0000 Subject: [PATCH] EgtMachKernel : - aggiunte funzioni EmtModifyAxisPosition e EmtModifyAxisDirection per variare dati assi secondo testa corrente. --- Axis.cpp | 35 +++++++++++++++++++++++++++++++++++ Axis.h | 4 +++- Machine.cpp | 36 +++++++++++++++++++++++++++++++++++- Machine.h | 4 ++++ MachineLua.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/Axis.cpp b/Axis.cpp index f03318b..8236d4f 100644 --- a/Axis.cpp +++ b/Axis.cpp @@ -13,6 +13,7 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" +#include "DllMain.h" #include "Axis.h" #include "MachConst.h" #include "/EgtDev/Include/EGkGdbConst.h" @@ -130,6 +131,40 @@ Axis::Set( const string& sName, const string& sToken, bool bInvert, int nType, return m_vtDir.Normalize() ; } +//---------------------------------------------------------------------------- +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 ; + if ( vtDeltaPerp.Len() > dAxisMaxAdjust) { + string sOut = " Modify Axis " + m_sName + " Position (" + ToString( ptPos) + ") failed" ; + LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + return false ; + } + // Assegno la nuova posizione + m_ptPos = ptPos ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Axis::Modify( const Vector3d& vtDir, double dAxisMaxRotAdj) +{ + // Verifico che la rotazione non superi il massimo ammesso + Vector3d vtDirN = vtDir ; + double dAngRot ; + if ( ! vtDirN.Normalize() || ! m_vtDir.GetAngle( vtDirN, dAngRot) || abs( dAngRot) > dAxisMaxRotAdj) { + string sOut = " Modify Axis " + m_sName + " Direction (" + ToString( vtDir) + ") failed" ; + LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + return false ; + } + // Assegno la nuova direzione + m_vtDir = vtDirN ; + return true ; +} + //---------------------------------------------------------------------------- bool Axis::Modify( const STROKE& Stroke) diff --git a/Axis.h b/Axis.h index 55aee10..6ada655 100644 --- a/Axis.h +++ b/Axis.h @@ -32,6 +32,8 @@ class Axis : public IUserObj Axis( void) ; bool Set( const std::string& sName, const std::string& sToken, bool bInvert, int nType, const Point3d& ptPos, const Vector3d& vtDir, const STROKE& Stroke, double dHome) ; + bool Modify( const Point3d& ptPos, double dAxisMaxAdjust) ; + bool Modify( const Vector3d& vtDir, double dAxisMaxRotAdj) ; bool Modify( const STROKE& Stroke) ; bool Modify( double dHome) ; bool SetCurrVal( double dVal) @@ -42,7 +44,7 @@ class Axis : public IUserObj { return m_sToken ; } bool GetInvert( void) const { return m_bInvert ; } - int GetType( void) const + int GetType( void) const { return m_nType ; } const Point3d& GetPos( void) const { return m_ptPos ; } diff --git a/Machine.cpp b/Machine.cpp index 413bab4..ffc285f 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -380,7 +380,7 @@ Machine::AdjustAxis( int nLay, const string& sPart, const string& sName, Vector3d vtDirN = vtDir ; if ( ! vtDirN.Normalize() || ! AreSameVectorEpsilon( vtAxis, vtDirN, 10 * SIN_EPS_ANG_SMALL)) { double dAngRot ; - if ( ! vtAxis.GetAngle( vtDirN, dAngRot) || abs( dAngRot) > m_dExitMaxRotAdj) { + if ( ! vtAxis.GetAngle( vtDirN, dAngRot) || abs( dAngRot) > m_dAxisMaxRotAdj) { string sOut = " Wrong Axis Vector or Dir " + sPart ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; return false ; @@ -420,6 +420,40 @@ Machine::AdjustAxis( int nLay, const string& sPart, const string& sName, return true ; } +//---------------------------------------------------------------------------- +bool +Machine::ModifyMachineAxisPosition( const string& sName, const Point3d& ptPos) +{ + // controllo GeomDB + if ( m_pGeomDB == nullptr) + return false ; + // recupero il gruppo dell'asse + int nAxGrp = GetGroup( sName) ; + // recupero il relativo gestore + Axis* pAx = GetAxis( nAxGrp) ; + if ( pAx == nullptr) + return false ; + // eseguo la modifica + return pAx->Modify( ptPos, m_dAxisMaxAdjust) ; +} + +//---------------------------------------------------------------------------- +bool +Machine::ModifyMachineAxisDirection( const string& sName, const Vector3d& vtDir) +{ + // controllo GeomDB + if ( m_pGeomDB == nullptr) + return false ; + // recupero il gruppo dell'asse + int nAxGrp = GetGroup( sName) ; + // recupero il relativo gestore + Axis* pAx = GetAxis( nAxGrp) ; + if ( pAx == nullptr) + return false ; + // eseguo la modifica + return pAx->Modify( vtDir, m_dAxisMaxRotAdj) ; +} + //---------------------------------------------------------------------------- bool Machine::ModifyMachineAxisStroke( const string& sName, const STROKE& Stroke) diff --git a/Machine.h b/Machine.h index e16c807..c7fc067 100644 --- a/Machine.h +++ b/Machine.h @@ -177,6 +177,8 @@ class Machine double dHome, bool bAdjustAux, const std::string& sGeo, const STRVECTOR& vsAux) ; bool AdjustAxis( int nLay, const std::string& sPart, const std::string& sName, int nType, const Point3d& ptPos, const Vector3d& vtDir, bool bAdjustAux) ; + bool ModifyMachineAxisPosition( const std::string& sName, const Point3d& ptPos) ; + bool ModifyMachineAxisDirection( const std::string& sName, const Vector3d& vtDir) ; bool ModifyMachineAxisStroke( const std::string& sName, const STROKE& Stroke) ; bool ModifyMachineAxisHome( const std::string& sName, double dHome) ; bool LoadMachineStdHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, @@ -285,6 +287,8 @@ class Machine static int LuaEmtStdHead( lua_State* L) ; static int LuaEmtMultiHead( lua_State* L) ; static int LuaEmtSpecialHead( lua_State* L) ; + static int LuaEmtModifyAxisPosition( lua_State* L) ; + static int LuaEmtModifyAxisDirection( lua_State* L) ; static int LuaEmtModifyAxisStroke( lua_State* L) ; static int LuaEmtModifyAxisHome( lua_State* L) ; static int LuaEmtAddRapidStart( lua_State* L) ; diff --git a/MachineLua.cpp b/MachineLua.cpp index ad227e0..611715d 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -88,6 +88,8 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtAxis", Machine::LuaEmtAxis) ; m_LuaMgr.RegisterFunction( "EmtHead", Machine::LuaEmtHead) ; // registro le funzioni di modifica macchina per lua + m_LuaMgr.RegisterFunction( "EmtModifyAxisPosition", Machine::LuaEmtModifyAxisPosition) ; + m_LuaMgr.RegisterFunction( "EmtModifyAxisDirection", Machine::LuaEmtModifyAxisDirection) ; m_LuaMgr.RegisterFunction( "EmtModifyAxisStroke", Machine::LuaEmtModifyAxisStroke) ; m_LuaMgr.RegisterFunction( "EmtModifyAxisHome", Machine::LuaEmtModifyAxisHome) ; m_LuaMgr.RegisterFunction( "EmtLinkRawPartToGroup", Machine::LuaEmtLinkRawPartToGroup) ; @@ -465,7 +467,7 @@ Machine::LuaEmtAxis( lua_State* L) // lettura eventuale campo 'Home' dalla tabella (default 0) double dHome = 0 ; LuaGetTabFieldParam( L, 1, FLD_HOME, dHome) ; - // lettura eventuale campo 'AdjustAux' dalla tabella (defualt false) + // lettura eventuale campo 'AdjustAux' dalla tabella (default false) bool bAdjustAux = false ; LuaGetTabFieldParam( L, 1, FLD_ADJUSTAUX, bAdjustAux) ; // lettura campo 'Geo' dalla tabella @@ -734,6 +736,46 @@ Machine::LuaEmtSpecialHead( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtModifyAxisPosition( lua_State* L) +{ + // 2 parametri : sAxisName, ptPos + string sAxisName ; + LuaCheckParam( L, 1, sAxisName) + Point3d ptPos ; + LuaCheckParam( L, 2, ptPos) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // modifico la posizione dell'asse + bool bOk = m_pMchLua->ModifyMachineAxisPosition( sAxisName, ptPos) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtModifyAxisDirection( lua_State* L) +{ + // 2 parametri : sAxisName, vtDir + string sAxisName ; + LuaCheckParam( L, 1, sAxisName) + Vector3d vtDir ; + LuaCheckParam( L, 2, vtDir) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // modifico la direzione dell'asse + bool bOk = m_pMchLua->ModifyMachineAxisDirection( sAxisName, vtDir) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtModifyAxisStroke( lua_State* L)