EgtMachKernel :

- in simulazione a funzione SimSetToolForVmill aggiunti parametri nFlag, dPar1 e dPar2 per additive ( modificate EmtSetToolForVmill e EmtAddToolForVmill)
- in simulazione aggiunta funzione SimEnableToolsForVmill per abilitare/disabilitare le operazioni virtual (aggiunta EmtEnableToolsForVmill).
This commit is contained in:
Dario Sassi
2024-04-26 11:44:37 +02:00
parent e6a03b0b2e
commit e97b9df6d4
6 changed files with 127 additions and 39 deletions
+3 -1
View File
@@ -470,7 +470,9 @@ class MachMgr : public IMachMgr
bool SimAddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) ;
bool SimExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) ;
bool SimOnCollision( int nCdInd, int nObjInd, int& nErr) ;
bool SimSetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst) ;
bool SimSetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, double dPar1, double dPar2,
const INTVECTOR& vVmill, bool bFirst) ;
bool SimEnableToolsForVmill( bool bEnable) ;
int SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ;
// Machine
bool GetHeadAbove( const std::string& sHead) const ;
+14 -2
View File
@@ -183,13 +183,25 @@ MachMgr::SimOnCollision( int nCdInd, int nObjInd, int& nErr)
//----------------------------------------------------------------------------
bool
MachMgr::SimSetToolForVmill( const string& sTool, const string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst)
MachMgr::SimSetToolForVmill( const string& sTool, const string& sHead, int nExit, int nFlag, double dPar1, double dPar2,
const INTVECTOR& vVmill, bool bFirst)
{
// verifico simulatore
if ( m_pSimul == nullptr)
return false ;
// imposto utensile per Vmill
return m_pSimul->SetToolForVmill( sTool, sHead, nExit, vVmill, bFirst) ;
return m_pSimul->SetToolForVmill( sTool, sHead, nExit, nFlag, dPar1, dPar2, vVmill, bFirst) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SimEnableToolsForVmill( bool bEnable)
{
// verifico simulatore
if ( m_pSimul == nullptr)
return false ;
// imposto abilitazione Vmill
return m_pSimul->EnableToolsForVmill( bEnable) ;
}
//----------------------------------------------------------------------------
+1 -1
View File
@@ -374,8 +374,8 @@ class Machine
static int LuaEmtOnCollision( lua_State* L) ;
static int LuaEmtSetToolForVmill( lua_State* L) ;
static int LuaEmtAddToolForVmill( lua_State* L) ;
static int LuaEmtEnableToolsForVmill( lua_State* L) ;
static int LuaEmtMoveAxes( lua_State* L) ;
} ;
//----------------------------------------------------------------------------
+38 -4
View File
@@ -139,6 +139,8 @@ Machine::LuaInit( const string& sMachineName)
m_LuaMgr.RegisterFunction( "EmtSetToolForVmill", Machine::LuaEmtSetToolForVmill) ;
// registro la funzione di impostazione di utensile aggiuntivo per virtual milling in simulazione
m_LuaMgr.RegisterFunction( "EmtAddToolForVmill", Machine::LuaEmtAddToolForVmill) ;
// registro la funzione per abilitare/disabilitare l'esecuzione del virtual milling
m_LuaMgr.RegisterFunction( "EmtEnableToolsForVmill", Machine::LuaEmtEnableToolsForVmill) ;
// registro la funzione di movimento assi in simulazione
m_LuaMgr.RegisterFunction( "EmtMoveAxes", Machine::LuaEmtMoveAxes) ;
@@ -1438,7 +1440,7 @@ Machine::LuaEmtOnCollision( lua_State* L)
int
Machine::LuaEmtSetToolForVmill( lua_State* L)
{
// 4 parametri : sTool, sHead, nExit, vVmill
// 4 o 7 parametri : sTool, sHead, nExit, vVmill [, nFlag , dPar1, dPar2]
string sTool ;
LuaGetParam( L, 1, sTool) ;
string sHead ;
@@ -1447,12 +1449,19 @@ Machine::LuaEmtSetToolForVmill( lua_State* L)
LuaGetParam( L, 3, nExit) ;
INTVECTOR vVmill ;
LuaGetParam( L, 4, vVmill) ;
int nFlag = 0 ;
LuaGetParam( L, 5, nFlag) ;
double dPar1 = 0 ;
LuaGetParam( L, 6, dPar1) ;
double dPar2 = 0 ;
LuaGetParam( L, 7, dPar2) ;
LuaClearStack( L) ;
// verifico ci sia una macchina attiva
if ( m_pMchLua == nullptr)
return luaL_error( L, " Unknown Machine") ;
// imposto dati primo utensile per virtual milling in simulazione
bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimSetToolForVmill( sTool, sHead, nExit, vVmill, true)) ;
bool bOk = ( m_pMchLua->m_pMchMgr != nullptr &&
m_pMchLua->m_pMchMgr->SimSetToolForVmill( sTool, sHead, nExit, nFlag, dPar1, dPar2, vVmill, true)) ;
// assegno risultato
LuaSetParam( L, bOk) ;
return 1 ;
@@ -1462,7 +1471,7 @@ Machine::LuaEmtSetToolForVmill( lua_State* L)
int
Machine::LuaEmtAddToolForVmill( lua_State* L)
{
// 4 parametri : sTool, sHead, nExit, vVmill
// 4 o 7 parametri : sTool, sHead, nExit, vVmill [, nFlag, dPar1, dPar2]
string sTool ;
LuaGetParam( L, 1, sTool) ;
string sHead ;
@@ -1471,12 +1480,37 @@ Machine::LuaEmtAddToolForVmill( lua_State* L)
LuaGetParam( L, 3, nExit) ;
INTVECTOR vVmill ;
LuaGetParam( L, 4, vVmill) ;
int nFlag = 0 ;
LuaGetParam( L, 5, nFlag) ;
double dPar1 = 0 ;
LuaGetParam( L, 6, dPar1) ;
double dPar2 = 0 ;
LuaGetParam( L, 7, dPar2) ;
LuaClearStack( L) ;
// verifico ci sia una macchina attiva
if ( m_pMchLua == nullptr)
return luaL_error( L, " Unknown Machine") ;
// imposto dati utensile aggiuntivo per virtual milling in simulazione
bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimSetToolForVmill( sTool, sHead, nExit, vVmill, false)) ;
bool bOk = ( m_pMchLua->m_pMchMgr != nullptr &&
m_pMchLua->m_pMchMgr->SimSetToolForVmill( sTool, sHead, nExit, nFlag, dPar1, dPar2, vVmill, false)) ;
// assegno risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
int
Machine::LuaEmtEnableToolsForVmill( lua_State* L)
{
// 1 parametro : bEnable
bool bEnable ;
LuaGetParam( L, 1, bEnable) ;
LuaClearStack( L) ;
// verifico ci sia una macchina attiva
if ( m_pMchLua == nullptr)
return luaL_error( L, " Unknown Machine") ;
// imposto abilitazione utensili per virtual milling in simulazione
bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimEnableToolsForVmill( bEnable)) ;
// assegno risultato
LuaSetParam( L, bOk) ;
return 1 ;
+67 -30
View File
@@ -78,6 +78,7 @@ Simulator::Simulator( void)
m_nExit = 0 ;
m_dTDiam = 0 ;
m_bCutOnTip = false ;
m_bEnableVm = false ;
m_dSafeDist = SAFEDIST_STD ;
m_nAxesMask = 0 ;
m_bEnabAxes = true ;
@@ -1017,6 +1018,17 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
}
}
// Posizione e direzione attuali degli utensili e riferimenti dei pezzi (per Vmill)
bool bOkI = true ;
PNTVECTOR vPtNoseI( m_VmTool.size()) ;
VCT3DVECTOR vVtDirI( m_VmTool.size()) ;
VCT3DVECTOR vVtAuxI( m_VmTool.size()) ;
for ( int i = 0 ; i < int( m_VmTool.size()) ; ++ i)
bOkI = GetHeadCurrPosDirAux( m_VmTool[i].sHead, m_VmTool[i].nExit, vPtNoseI[i], vVtDirI[i], vVtAuxI[i]) && bOkI ;
vector<Frame3d> vFrVzmI( m_VmId.size()) ;
for ( int i = 0 ; i < int( m_VmId.size()) ; ++ i)
bOkI = m_pGeomDB->GetGlobFrame( m_VmId[i], vFrVzmI[i]) && bOkI ;
// Dati per eventuale verifica di collisione
int nCdInd, nObjInd ;
bool bCollCheck = true ;
@@ -1053,24 +1065,13 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
m_dCoeff = 1 ;
dMove = ( m_dCoeff - dPrevCoeff) * dDist ;
// Posizione e direzione attuali degli utensili e riferimenti dei pezzi (per Vmill)
bool bOkI = true ;
PNTVECTOR vPtNoseI( m_VmTool.size()) ;
VCT3DVECTOR vVtDirI( m_VmTool.size()) ;
VCT3DVECTOR vVtAuxI( m_VmTool.size()) ;
for ( int i = 0 ; i < int( m_VmTool.size()) ; ++ i)
bOkI = GetHeadCurrPosDirAux( m_VmTool[i].sHead, m_VmTool[i].nExit, vPtNoseI[i], vVtDirI[i], vVtAuxI[i]) && bOkI ;
vector<Frame3d> vFrVzmI( m_VmId.size()) ;
for ( int i = 0 ; i < int( m_VmId.size()) ; ++ i)
bOkI = m_pGeomDB->GetGlobFrame( m_VmId[i], vFrVzmI[i]) && bOkI ;
// Log per debug
if ( ExeGetDebugLevel() >= 10) {
string sOut = "MoveType=" + ToString( nMoveType) + " Coeff=" + ToString( m_dCoeff) ;
LOG_DBG_INFO( GetEMkLogger(), sOut.c_str())
}
// Eseguo movimento rapido o lineare
// Eseguo movimento rapido o lineare (non arco)
if ( nMoveType != 2 && nMoveType != 3) {
// se attivo CollisionCheck approssimo movimento con più step
int nStep = 1 ;
@@ -1102,8 +1103,8 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
}
m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ;
}
// se non è rapido o non c'è verifica collisioni, eseguo eventuale Vmill
if ( nMoveType != 0 || ! NeedCollisionCheck()) {
// se abilitato e non è rapido o non c'è verifica collisioni, eseguo eventuale Vmill
if ( m_bEnableVm && ( nMoveType != 0 || ! NeedCollisionCheck())) {
for ( int j = 0 ; j < int( m_VmTool.size()) ; ++ j) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( m_VmTool[j].sHead, m_VmTool[j].nExit, ptNoseF, vtDirF, vtAuxF) ;
@@ -1188,8 +1189,8 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
}
m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ;
}
// eseguo eventuale Vmill
for ( int j = 0 ; j < int( m_VmTool.size()) ; ++ j) {
// se abilitato, eseguo eventuale Vmill
for ( int j = 0 ; m_bEnableVm && j < int( m_VmTool.size()) ; ++ j) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( m_VmTool[j].sHead, m_VmTool[j].nExit, ptNoseF, vtDirF, vtAuxF) ;
for ( int k = 0 ; k < int( m_VmId.size()) ; ++ k) {
@@ -1245,8 +1246,25 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
double dVal = m_AuxAxesVal[j] * ( 1 - dCurrCoeff) + m_AuxAxesEnd[j] * dCurrCoeff ;
m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ;
}
else {
}
// se abilitato e non è rapido o non c'è verifica collisioni, eseguo eventuale Vmill
if ( m_bEnableVm && ( nMoveType != 0 || ! NeedCollisionCheck())) {
for ( int j = 0 ; j < int( m_VmTool.size()) ; ++ j) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( m_VmTool[j].sHead, m_VmTool[j].nExit, ptNoseF, vtDirF, vtAuxF) ;
for ( int k = 0 ; k < int( m_VmId.size()) ; ++ k) {
Frame3d frVzmF ;
bOkF = m_pGeomDB->GetGlobFrame( m_VmId[k], frVzmF) && bOkF ;
ExecLineVmill( m_VmId[k], j, m_VmTool[j].dTdOffs, m_VmTool[j].dAdOffs,
vPtNoseI[j], vVtDirI[j], vVtAuxI[j], vFrVzmI[k], ptNoseF, vtDirF, vtAuxF, frVzmF) ;
// se ultimo utensile, salvo riferimento per prossimo inizio
if ( j == int( m_VmTool.size()) - 1)
vFrVzmI[k] = frVzmF ;
}
// aggiorno prossimo inizio
vPtNoseI[j] = ptNoseF ;
vVtDirI[j] = vtDirF ;
vVtAuxI[j] = vtAuxF ;
}
}
// eseguo eventuale collision check
@@ -2098,7 +2116,8 @@ Simulator::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, con
//----------------------------------------------------------------------------
bool
Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst)
Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit, int nFlag, double dPar1, double dPar2,
const INTVECTOR& vVmill, bool bFirst)
{
// disabilito eventuale registrazione comandi EXE (riabilitazione automatica)
CmdLogOff cmdLogOff ;
@@ -2108,16 +2127,20 @@ Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit,
// se utensile, testa o uscita non definiti, reset ed esco
if ( IsEmptyOrSpaces( sTool) || IsEmptyOrSpaces( sHead) || nExit < 1) {
ExeVolZmapResetTools( vVmill) ;
if ( bFirst)
m_bEnableVm = false ;
return false ;
}
// imposto utensile come corrente
string sOldTool ; m_pMchMgr->TdbGetCurrToolParam( TPA_NAME, sOldTool) ;
if ( sTool != sOldTool && ! m_pMchMgr->TdbSetCurrTool( sTool)) {
ExeVolZmapResetTools( vVmill) ;
if ( bFirst)
m_bEnableVm = false ;
return false ;
}
// recupero dati utensile
int nFlag = 1 ;
int nInd = 1 ;
int nType ; m_pMchMgr->TdbGetCurrToolParam( TPA_TYPE, nType) ;
double dLen ; m_pMchMgr->TdbGetCurrToolParam( TPA_LEN, dLen) ;
double dDiam ; m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, dDiam) ;
@@ -2125,24 +2148,28 @@ Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit,
double dCornR ; m_pMchMgr->TdbGetCurrToolParam( TPA_CORNRAD, dCornR) ;
double dSideAng ; m_pMchMgr->TdbGetCurrToolParam( TPA_SIDEANG, dSideAng) ;
double dMaxMat ; m_pMchMgr->TdbGetCurrToolParam( TPA_MAXMAT, dMaxMat) ;
string sNotes ; m_pMchMgr->TdbGetCurrToolParam( TPA_USERNOTES, sNotes) ;
bool bAdditive = ( nFlag == 1) ;
// ricerca dell'outline e del diametro gambo
int nExitId = m_pMachine->GetExitId( sHead, nExit) ;
int nToolId = m_pGeomDB->GetFirstNameInGroup( nExitId, sTool) ;
int nOutlineId = m_pGeomDB->GetFirstNameInGroup( nToolId, "Outline") ;
double dMaxStemDiam = dDiam ; m_pGeomDB->GetInfo( nToolId, "D_STEM", dMaxStemDiam) ;
// imposto profilo utensile per Vmill
if ( nOutlineId != GDB_ID_NULL)
ExeVolZmapSetGenTool( vVmill, sTool, nOutlineId, nFlag, bFirst) ;
if ( bAdditive)
ExeVolZmapSetAdditiveTool( vVmill, sTool, dPar1, dPar2, 0, nInd, bFirst) ;
else if ( nOutlineId != GDB_ID_NULL)
ExeVolZmapSetGenTool( vVmill, sTool, nOutlineId, nInd, bFirst) ;
else if ( nType == TT_MORTISE_STD)
ExeVolZmapSetMortiserTool( vVmill, sTool, dLen, dDiam, dThick, dCornR, nFlag, bFirst) ;
ExeVolZmapSetMortiserTool( vVmill, sTool, dLen, dDiam, dThick, dCornR, nInd, bFirst) ;
else if ( nType == TT_CHISEL_STD)
ExeVolZmapSetChiselTool( vVmill, sTool, dLen, dDiam, dDiam, nFlag, bFirst) ;
ExeVolZmapSetChiselTool( vVmill, sTool, dLen, dDiam, dDiam, nInd, bFirst) ;
else if ( nType == TT_SAW_STD || nType == TT_SAW_FLAT)
ExeVolZmapSetSawTool( vVmill, sTool, dLen, dDiam, dThick, 0, dCornR, nFlag, bFirst) ;
ExeVolZmapSetSawTool( vVmill, sTool, dLen, dDiam, dThick, 0, dCornR, nInd, bFirst) ;
else if ( nType == TT_WATERJET)
ExeVolZmapSetStdTool( vVmill, sTool, dLen + 50, dDiam, dCornR, dMaxMat, nFlag, bFirst) ;
ExeVolZmapSetStdTool( vVmill, sTool, dLen + 50, dDiam, dCornR, dMaxMat, nInd, bFirst) ;
else if ( abs( dSideAng) < EPS_ANG_SMALL || abs( dThick) < EPS_SMALL) {
ExeVolZmapSetStdTool( vVmill, sTool, dLen, dDiam, dCornR, dMaxMat, nFlag, bFirst) ;
ExeVolZmapSetStdTool( vVmill, sTool, dLen, dDiam, dCornR, dMaxMat, nInd, bFirst) ;
}
else {
bool bExtra = ( dThick > 0) ;
@@ -2159,7 +2186,7 @@ Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit,
dDelta = 2 * tan( dSideAng * DEGTORAD) * dTipLen ;
double dStemDiam = ( bExtra ? dDiam : dDiam + dDelta) ;
double dTipDiam = ( bExtra ? dDiam - dDelta : dDiam) ;
ExeVolZmapSetAdvTool( vVmill, sTool, dTotLen, dStemDiam, dTipLen, dTipDiam, dCornR, dMaxMat, nFlag, bFirst) ;
ExeVolZmapSetAdvTool( vVmill, sTool, dTotLen, dStemDiam, dTipLen, dTipDiam, dCornR, dMaxMat, nInd, bFirst) ;
}
// eventuali offset per Vmill (per adattare lo ZeroT macchina con quello di Zmap)
double dVmTdOffs = 0 ;
@@ -2183,6 +2210,16 @@ Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit,
if ( sTool != sOldTool)
m_pMchMgr->TdbSetCurrTool( sOldTool) ;
if ( bFirst)
m_bEnableVm = true ;
return true ;
}
//----------------------------------------------------------------------------
bool
Simulator::EnableToolsForVmill( bool bEnable)
{
m_bEnableVm = bEnable ;
return true ;
}
@@ -2256,8 +2293,8 @@ Simulator::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt)
for ( int j = 0 ; j < nAxCount ; ++ j) {
bMoveOk = m_pMchMgr->SetAxisPos( vAxNaEpSt[j].sName, ( 1 - dCoeff) * vPrev[j] + dCoeff * vAxNaEpSt[j].dEndPos) && bMoveOk ;
}
// Eseguo eventuale Vmill
if ( bExecVmill) {
// Se abilitato e richiesto, eseguo eventuale Vmill
if ( m_bEnableVm && bExecVmill) {
for ( int j = 0 ; j < int( m_VmTool.size()) ; ++ j) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( m_VmTool[j].sHead, m_VmTool[j].nExit, ptNoseF, vtDirF, vtAuxF) ;
+4 -1
View File
@@ -56,7 +56,9 @@ class Simulator
bool AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) ;
bool ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) ;
bool OnCollision( int nCdInd, int nObjInd, int& nErr) ;
bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst) ;
bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, double dPar1, double dPar2,
const INTVECTOR& vVmill, bool bFirst) ;
bool EnableToolsForVmill( bool bEnable) ;
int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ;
private :
@@ -166,6 +168,7 @@ class Simulator
int m_nExit ; // indice dell'uscita corrente
double m_dTDiam ; // diametro dell'utensile corrente
bool m_bCutOnTip ; // flag capacità di lavorare di testa dell'utensile corrente
bool m_bEnableVm ; // flag abilitazione Virtual Milling
INTVECTOR m_VmId ; // vettore identificativi Zmap per Virtual Milling
INTVECTOR m_CdId ; // vettore identificativi Zmap per Collision Detection
VMTVECTOR m_VmTool ; // vettore utensili attivi per virtual milling