diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 1f4c1c2..4ccd9f3 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Head.cpp b/Head.cpp index ad9fa58..c5b4938 100644 --- a/Head.cpp +++ b/Head.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "Head.h" #include "MachConst.h" +#include "/EgtDev/Include/EMkSimuGenConst.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -95,13 +96,17 @@ Head::GetGeomDB( void) const //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- Head::Head( void) - : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_nType( MCH_HT_NONE), m_dRot1W( 1) + : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_nType( MCH_HT_NONE), + m_dRot1W( 1), m_nSolCh( MCH_SCC_NONE) { + m_Rot2Stroke.Min = - INFINITO ; + m_Rot2Stroke.Max = INFINITO ; } //---------------------------------------------------------------------------- bool -Head::Set( const string& sName, int nType, const string& sHSet, const Vector3d& vtADir, double dRot1W) +Head::Set( const string& sName, int nType, const string& sHSet, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh) { m_sName = sName ; m_nType = nType ; @@ -109,6 +114,8 @@ Head::Set( const string& sName, int nType, const string& sHSet, const Vector3d& m_vsHSet.push_back( sHSet) ; m_vtADir = vtADir ; m_dRot1W = dRot1W ; + m_Rot2Stroke = Rot2Stroke ; + m_nSolCh = nSolCh ; return true ; } diff --git a/Head.h b/Head.h index 6b12bdf..ad4bf7c 100644 --- a/Head.h +++ b/Head.h @@ -30,13 +30,23 @@ class Head : public IUserObj public : Head( void) ; - bool Set( const std::string& sName, int nType, const std::string& sHSet, const Vector3d& vtADir, double dRot1W) ; + bool Set( const std::string& sName, int nType, const std::string& sHSet, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh) ; bool AddHeadToHSet( const std::string& sHead) ; - const std::string& GetName( void) { return m_sName ; } - int GetType( void) { return m_nType ; } - const STRVECTOR& GetHSet(void) { return m_vsHSet ; } - const Vector3d& GetADir( void) { return m_vtADir ; } - double GetRot1W( void) { return m_dRot1W ; } + const std::string& GetName( void) + { return m_sName ; } + int GetType( void) + { return m_nType ; } + const STRVECTOR& GetHSet(void) + { return m_vsHSet ; } + const Vector3d& GetADir( void) + { return m_vtADir ; } + double GetRot1W( void) + { return m_dRot1W ; } + const STROKE& GetRot2Stroke( void) + { return m_Rot2Stroke ; } + int GetSolCh( void) + { return m_nSolCh ; } private : int m_nOwnerId ; @@ -46,4 +56,6 @@ class Head : public IUserObj STRVECTOR m_vsHSet ; Vector3d m_vtADir ; double m_dRot1W ; + STROKE m_Rot2Stroke ; + int m_nSolCh ; } ; \ No newline at end of file diff --git a/MachMgr.h b/MachMgr.h index fe53832..c765090 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -59,6 +59,7 @@ class MachMgr : public IMachMgr virtual bool Insert( int nInsGrp) ; // Machines virtual bool SetCurrMachine( const std::string& sMachineName) ; + virtual bool GetCurrMachineName( std::string& sMachineName) const ; // MachGroups virtual int GetMachGroupCount( void) const ; virtual int GetFirstMachGroup( void) const ; diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index 4edbd6c..b0ce4ea 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -284,7 +284,7 @@ MachMgr::SetCurrMachGroup( int nId) } // verifica ed eventuale caricamento della macchina if ( ! LoadMachine( mgData.MGeoName)) - return GDB_ID_NULL ; + return false ; // se esiste gruppo corrente, lo disabilito if ( m_nCurrMGrpId != GDB_ID_NULL) { // riporto i pezzi nei grezzi precedenti nella loro posizione standard diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index 4b60775..a5654e4 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -90,6 +90,16 @@ MachMgr::SetCurrMachine( const string& sMachineName) return true ; } +//---------------------------------------------------------------------------- +bool +MachMgr::GetCurrMachineName( string& sMachineName) const +{ + if ( GetCurrMachine() == nullptr) + return false ; + sMachineName = GetCurrMachine()->GetMachineName() ; + return true ; +} + //---------------------------------------------------------------------------- int MachMgr::GetCurrMGeoId( void) const diff --git a/Machine.cpp b/Machine.cpp index efb2f44..c25a133 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -34,6 +34,12 @@ Machine::Machine( void) m_pGeomDB = nullptr ; m_nGroupId = GDB_ID_NULL ; m_nTempGroupId = GDB_ID_NULL ; + m_nCalcTabId = GDB_ID_NULL ; + m_nCalcHeadId = GDB_ID_NULL ; + m_nCalcExitId = GDB_ID_NULL ; + m_nCalcToolId = GDB_ID_NULL ; + m_dCalcRot1W = 1 ; + m_nCalcSolCh = MCH_SCC_NONE ; } //---------------------------------------------------------------------------- @@ -339,8 +345,8 @@ Machine::AdjustAxisVector( int nLay, const string& sPart, const string& sName, //---------------------------------------------------------------------------- bool Machine::LoadMachineStdHead( const string& sName, const string& sParent, const std::string& sHSet, - const Point3d& ptPos, const Vector3d& vtTDir, - const Vector3d& vtADir, double dRot1W, const string& sGeo) + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const string& sGeo) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -364,7 +370,7 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) return false ; - pHead->Set( sName, MCH_HT_STD, sHSet, vtADir, dRot1W) ; + pHead->Set( sName, MCH_HT_STD, sHSet, vtADir, dRot1W, Rot2Stroke, nSolCh) ; m_pGeomDB->SetUserObj( nLay, pHead) ; // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) @@ -381,8 +387,8 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s //---------------------------------------------------------------------------- bool Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const std::string& sHSet, - const MUEXITVECTOR& vMuExit, - const Vector3d& vtADir, double dRot1W, const string& sGeo) + const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const string& sGeo) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -406,7 +412,7 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) return false ; - pHead->Set( sName, MCH_HT_MULTI, sHSet, vtADir, dRot1W) ; + pHead->Set( sName, MCH_HT_MULTI, sHSet, vtADir, dRot1W, Rot2Stroke, nSolCh) ; m_pGeomDB->SetUserObj( nLay, pHead) ; // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) diff --git a/Machine.h b/Machine.h index f4d1fbc..e462fad 100644 --- a/Machine.h +++ b/Machine.h @@ -90,11 +90,11 @@ class Machine bool AdjustAxisVector( int nLay, const std::string& sPart, const std::string& sName, int nType, const Point3d& ptPos, const Vector3d& vtDir) ; bool LoadMachineStdHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, - const Point3d& ptPos, const Vector3d& vtTDir, - const Vector3d& vtADir, double dRot1W, const std::string& sGeo) ; + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const std::string& sGeo) ; bool LoadMachineMultiHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, - const MUEXITVECTOR& vMuExit, - const Vector3d& vtADir, double dRot1W, const std::string& sGeo) ; + const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const std::string& sGeo) ; int GetGroup( const std::string& sGroup) const ; Axis* GetAxis( int nGroup) const ; bool IsAxisGroup( int nGroup) const { return ( GetAxis( nGroup) != nullptr) ; } @@ -110,6 +110,7 @@ class Machine bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; + bool VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) ; bool AdjustAngleInStroke( int nId, double& dAng) ; bool LuaInit( const std::string& sMachineName) ; bool LuaExit( void) ; @@ -133,6 +134,7 @@ class Machine int m_nCalcExitId ; // uscita corrente per calcoli int m_nCalcToolId ; // utensile corrente per calcoli double m_dCalcRot1W ; // peso del primo asse rotante per i confronti + int m_nCalcSolCh ; // criterio di scelta della soluzione Point3d m_ptCalcPos ; // posizione utensile a riposo per calcoli Vector3d m_vtCalcDir ; // direzione utensile a riposo per calcoli Vector3d m_vtCalcADir ; // direzione ausiliaria a riposo per calcoli diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 71a508c..a09fefb 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -75,6 +75,8 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) m_nCalcHeadId = GDB_ID_NULL ; m_nCalcExitId = GDB_ID_NULL ; m_nCalcToolId = GDB_ID_NULL ; + m_dCalcRot1W = 1 ; + m_nCalcSolCh = MCH_SCC_NONE ; m_dCalcTLen = 0 ; // recupero il gruppo della testa int nHeadId = GetGroup( sHead) ; @@ -103,6 +105,7 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) m_nCalcExitId = nExitId ; m_nCalcToolId = nToolId ; m_dCalcRot1W = pHead->GetRot1W() ; + m_nCalcSolCh = pHead->GetSolCh() ; m_ptCalcPos = pExit->GetPos() ; m_vtCalcDir = pExit->GetTDir() ; m_vtCalcADir = pHead->GetADir() ; @@ -201,6 +204,14 @@ Machine::CalculateKinematicChain( void) // se entrambi di testa devo invertirne l'ordine if ( m_vCalcRotAx[0].bHead && m_vCalcRotAx[1].bHead) swap( m_vCalcRotAx[0], m_vCalcRotAx[1]) ; + // impongo limiti di corsa sul secondo asse rotante di testa + if ( m_vCalcRotAx[1].bHead) { + Head* pHead = GetHead( m_nCalcHeadId) ; + if ( pHead != nullptr) { + m_vCalcRotAx[1].stroke.Min = max( m_vCalcRotAx[1].stroke.Min, pHead->GetRot2Stroke().Min) ; + m_vCalcRotAx[1].stroke.Max = min( m_vCalcRotAx[1].stroke.Max, pHead->GetRot2Stroke().Max) ; + } + } return true ; } // altrimenti non ancora gestito, quindi errore @@ -300,7 +311,7 @@ Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, vtAx2.Invert() ; // calcolo secondo angolo di rotazione nStat = GetRotationComponent( vtDirH, dCompTSuAxR1, vtAx1, vtAx2, dAngB1, dAngB2, bDet) ; - // aggiornamento direzione fresa su testa + // aggiornamento direzioni fresa e ausiliaria su testa if ( nStat >= 1) { // se indeterminato lo azzero if ( ! bDet) @@ -347,8 +358,13 @@ Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, if ( ! bDet2) { bool bDetX ; vtDirI2.GetRotation( vtDirAn, vtAx1, dAngA2, bDetX) ; + if ( ! bDetX) + dAngA2 = 0 ; } } + // aggiornamento direzioni fresa e ausiliaria su testa + vtDirH2.Rotate( vtAx1, dAngA2) ; + vtDirI2.Rotate( vtAx1, dAngA2) ; } // calcolo primo angolo di rotazione per prima soluzione @@ -361,6 +377,27 @@ Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, if ( ! bDet1) { bool bDetX ; vtDirI1.GetRotation( vtDirAn, vtAx1, dAngA1, bDetX) ; + if ( ! bDetX) + dAngA1 = 0 ; + } + } + // aggiornamento direzioni fresa e ausiliaria su testa + vtDirH1.Rotate( vtAx1, dAngA1) ; + vtDirI1.Rotate( vtAx1, dAngA1) ; + } + + // verifiche per criterio scelta soluzione + if ( nStat >= 2) { + if ( ! VerifyScc( vtDirI2, vtDirAn, m_nCalcSolCh)) + -- nStat ; + } + if ( nStat >= 1) { + if ( ! VerifyScc( vtDirI1, vtDirAn, m_nCalcSolCh)) { + -- nStat ; + // riloco eventuale soluzione rimasta + if ( nStat >= 1) { + dAngA1 = dAngA2 ; + dAngB1 = dAngB2 ; } } } @@ -441,6 +478,32 @@ Machine::GetPositions( const Point3d& ptP, double dAngA, double dAngB, return true ; } +//---------------------------------------------------------------------------- +bool +Machine::VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) +{ + switch ( nSolCh) { + default : + return true ; + case MCH_SCC_ADIR_XP : + return ( vtDirI.x > - EPS_ZERO) ; + case MCH_SCC_ADIR_XM : + return ( vtDirI.x < EPS_ZERO) ; + case MCH_SCC_ADIR_YP : + return ( vtDirI.y > - EPS_ZERO) ; + case MCH_SCC_ADIR_YM : + return ( vtDirI.y < EPS_ZERO) ; + case MCH_SCC_ADIR_ZP : + return ( vtDirI.z > - EPS_ZERO) ; + case MCH_SCC_ADIR_ZM : + return ( vtDirI.z < EPS_ZERO) ; + case MCH_SCC_ADIR_NEAR : + return ( ( vtDirI * vtDirA) > cos( 60 * DEGTORAD)) ; + case MCH_SCC_ADIR_FAR : + return ( ( vtDirI * vtDirA) < cos( 120 * DEGTORAD)) ; + } +} + //---------------------------------------------------------------------------- bool Machine::AdjustAngleInStroke( int nId, double& dAng) diff --git a/MachineLua.cpp b/MachineLua.cpp index 76b7608..3fb36ba 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -358,6 +358,12 @@ Machine::LuaEmtStdHead( lua_State* L) // lettura eventuale campo 'Rot1W' dalla tabella (default 1) double dRot1W = 1 ; LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; + // lettura eventuale campo 'Rot2Stroke' dalla tabella + STROKE Rot2Stroke = { - INFINITO, INFINITO} ; + LuaGetTabFieldParam( L, 1, "Rot2Stroke", Rot2Stroke.v) ; + // lettura eventuale campo 'SolCh' dalla tabella + int nSolCh = MCH_SCC_NONE ; + LuaGetTabFieldParam( L, 1, "SolCh", nSolCh) ; // lettura campo 'Geo' dalla tabella string sGeo ; LuaCheckTabFieldParam( L, 1, "Geo", sGeo) @@ -372,7 +378,8 @@ Machine::LuaEmtStdHead( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della testa standard - if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, dRot1W, sGeo)) + if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, + dRot1W, Rot2Stroke, nSolCh, sGeo)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; @@ -417,6 +424,12 @@ Machine::LuaEmtMultiHead( lua_State* L) // lettura eventuale campo 'Rot1W' dalla tabella (default 1) double dRot1W = 1 ; LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; + // lettura eventuale campo 'Rot2Stroke' dalla tabella + STROKE Rot2Stroke = { - INFINITO, INFINITO} ; + LuaGetTabFieldParam( L, 1, "Rot2Stroke", Rot2Stroke.v) ; + // lettura eventuale campo 'SolCh' dalla tabella + int nSolCh = MCH_SCC_NONE ; + LuaGetTabFieldParam( L, 1, "SolCh", nSolCh) ; // lettura campo 'Geo' dalla tabella string sGeo ; LuaCheckTabFieldParam( L, 1, "Geo", sGeo) @@ -431,7 +444,8 @@ Machine::LuaEmtMultiHead( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della testa multipla - if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, dRot1W, sGeo)) + if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, + dRot1W, Rot2Stroke, nSolCh, sGeo)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; diff --git a/MachiningsMgr.cpp b/MachiningsMgr.cpp index 09f2762..7772234 100644 --- a/MachiningsMgr.cpp +++ b/MachiningsMgr.cpp @@ -359,6 +359,9 @@ MachiningsMgr::GetMachiningNewName( string& sName) const bool MachiningsMgr::AddMachining( const string& sName, int nType) { + // annullo lavorazione corrente + if ( m_pCurrMach != nullptr) + delete m_pCurrMach ; // verifico unicità del nome if ( m_suData.find( sName) != m_suData.end()) return false ; @@ -378,8 +381,6 @@ MachiningsMgr::AddMachining( const string& sName, int nType) bOk = bOk && m_suData.emplace( pMch->m_sName, pMch->m_Uuid).second ; m_bModified = true ; // la rendo la nuova lavorazione corrente - if ( m_pCurrMach != nullptr) - delete m_pCurrMach ; m_pCurrMach = pMch->Clone() ; Release( pMch) ; @@ -390,6 +391,9 @@ MachiningsMgr::AddMachining( const string& sName, int nType) bool MachiningsMgr::CopyMachining( const string& sSource, const string& sName) { + // annullo lavorazione corrente + if ( m_pCurrMach != nullptr) + delete m_pCurrMach ; // verifico unicità del nome if ( m_suData.find( sName) != m_suData.end()) return false ; @@ -410,8 +414,6 @@ MachiningsMgr::CopyMachining( const string& sSource, const string& sName) bOk = bOk && m_suData.emplace( pMch->m_sName, pMch->m_Uuid).second ; m_bModified = true ; // la rendo la nuova lavorazione corrente - if ( m_pCurrMach != nullptr) - delete m_pCurrMach ; m_pCurrMach = pMch->Clone() ; Release( pMch) ;