EgtMachKernel 2.4l4 :

- modifiche per virtual milling con più utensili in simulazione.
This commit is contained in:
DarioS
2022-12-28 19:40:24 +01:00
parent f0b00ea95e
commit e5a072c896
7 changed files with 247 additions and 71 deletions
+152 -62
View File
@@ -26,7 +26,9 @@
#include "/EgtDev/Include/EGkCDeSpheClosedSurfTm.h"
#include "/EgtDev/Include/EGkCDeConeFrustumClosedSurfTm.h"
#include "/EgtDev/Include/EGkVolZmap.h"
#include "/EgtDev/Include/EGkGeoVector3d.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EXeCmdLogOff.h"
#include "/EgtDev/Include/EXeConst.h"
#include "/EgtDev/Include/EMkToolConst.h"
#include "/EgtDev/Include/EMkOperationConst.h"
@@ -67,8 +69,6 @@ Simulator::Simulator( void)
m_nAuxEInd = 0 ;
m_nExit = 0 ;
m_dTDiam = 0 ;
m_dVmTdOffs = 0 ;
m_dVmAdOffs = 0 ;
m_dSafeDist = SAFEDIST_STD ;
m_nAxesMask = 0 ;
m_bEnabAxes = true ;
@@ -206,8 +206,8 @@ Simulator::ResetInterpolation( void)
m_nAuxEInd = 0 ;
m_VmId.clear() ;
m_CdId.clear() ;
m_dVmTdOffs = 0 ;
m_dVmAdOffs = 0 ;
m_VmTool.clear() ;
m_CollObj.clear() ;
m_dSafeDist = SAFEDIST_STD ;
m_nAxesMask = 0 ;
m_bEnabAxes = true ;
@@ -472,23 +472,6 @@ Simulator::UpdateTool( bool bFirst, int& nErr)
// aggiorno gli assi macchina
if ( ! UpdateAxes())
return false ;
// eventuali offset per Vmill (per adattare lo ZeroT macchina con quello di Zmap)
int nToolType ; m_pMchMgr->TdbGetCurrToolParam( TPA_TYPE, nToolType) ;
if ( nToolType == TT_MORTISE_STD) {
double dThick ; m_pMchMgr->TdbGetCurrToolParam( TPA_THICK, dThick) ;
m_dVmTdOffs = 0 ;
m_dVmAdOffs = 0.5 * dThick ;
}
else if ( nToolType == TT_SAW_STD || nToolType == TT_SAW_FLAT) {
double dLen ; m_pMchMgr->TdbGetCurrToolParam( TPA_LEN, dLen) ;
double dThick ; m_pMchMgr->TdbGetCurrToolParam( TPA_THICK, dThick) ;
m_dVmTdOffs = ( ( dLen <= dThick) ? -dLen + dThick : 0) ;
m_dVmAdOffs = 0 ;
}
else {
m_dVmTdOffs = 0 ;
m_dVmAdOffs = 0 ;
}
// se cambiato oppure prima volta, lancio lo script di selezione
if ( bDiffTool || bFirst) {
int nCurrErr ;
@@ -1006,9 +989,13 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
m_dCoeff = 1 ;
dMove = ( m_dCoeff - dPrevCoeff) * dDist ;
// Posizione e direzione attuali dell'utensile e riferimento attuale del pezzo (per Vmill)
Point3d ptNoseI ; Vector3d vtDirI ; Vector3d vtAuxI ;
bool bOkI = GetHeadCurrPosDirAux( ptNoseI, vtDirI, vtAuxI) ;
// 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 ;
@@ -1052,12 +1039,15 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
}
// se non è rapido o non c'è verifica collisioni, eseguo eventuale Vmill
if ( nMoveType != 0 || ! NeedCollisionCheck()) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( ptNoseF, vtDirF, vtAuxF) ;
for ( int j = 0 ; j < int( m_VmId.size()) ; ++ j) {
Frame3d frVzmF ;
bOkF = m_pGeomDB->GetGlobFrame( m_VmId[j], frVzmF) && bOkF ;
ExecLineVmill( m_VmId[j], ptNoseI, vtDirI, vtAuxI, vFrVzmI[j], ptNoseF, vtDirF, vtAuxF, frVzmF) ;
for ( int i = 0 ; i < int( m_VmTool.size()) ; ++ i) {
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( m_VmTool[i].sHead, m_VmTool[i].nExit, ptNoseF, vtDirF, vtAuxF) ;
for ( int j = 0 ; j < int( m_VmId.size()) ; ++ j) {
Frame3d frVzmF ;
bOkF = m_pGeomDB->GetGlobFrame( m_VmId[j], frVzmF) && bOkF ;
ExecLineVmill( m_VmId[j], i, m_VmTool[i].dTdOffs, m_VmTool[i].dAdOffs,
vPtNoseI[i], vVtDirI[i], vVtAuxI[i], vFrVzmI[j], ptNoseF, vtDirF, vtAuxF, frVzmF) ;
}
}
}
}
@@ -1124,20 +1114,25 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove)
m_pMachine->SetAxisPos( m_AuxAxesName[j], dVal) ;
}
// eseguo eventuale Vmill
Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ;
bool bOkF = GetHeadCurrPosDirAux( 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], ptNoseI, vtDirI, vtAuxI, vFrVzmI[k], ptNoseF, vtDirF, vtAuxF, frVzmF) ;
// salvo riferimento per prossimo inizio
vFrVzmI[k] = frVzmF ;
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
bCollCheck = bCollCheck && ExecCollisionCheck( nCdInd, nObjInd, nMoveType) ;
// aggiorno prossimo inizio
ptNoseI = ptNoseF ;
vtDirI = vtDirF ;
}
}
}
@@ -1238,30 +1233,33 @@ Simulator::CalcStatusOnError( int nErr)
//----------------------------------------------------------------------------
bool
Simulator::GetHeadCurrPosDirAux( Point3d& ptH, Vector3d& vtH, Vector3d& vtA)
Simulator::GetHeadCurrPosDirAux( const std::string& sHead, int nExit, Point3d& ptH, Vector3d& vtH, Vector3d& vtA)
{
// ci devono essere almeno i tre assi lineari
if ( m_AxesName.size() < 3)
int nHeadId = m_pMachine->GetHeadId( sHead) ;
int nExitId = m_pMachine->GetExitId( sHead, nExit) ;
if ( nHeadId == GDB_ID_NULL || nExitId == GDB_ID_NULL)
return false ;
// recupero le posizioni degli assi lineari
DBLVECTOR vLinAx( 3) ;
for ( size_t i = 0 ; i < 3 ; ++ i)
m_pMachine->GetAxisPos( m_AxesName[i], vLinAx[i]) ;
// recupero le posizioni degli eventuali assi rotanti
DBLVECTOR vRotAx( m_AxesName.size() - 3) ;
for ( size_t i = 3 ; i < m_AxesName.size() ; ++ i)
m_pMachine->GetAxisPos( m_AxesName[i], vRotAx[i-3]) ;
// determino posizione e orientamento della testa
m_pMachine->GetNoseFromPositions( vLinAx[0], vLinAx[1], vLinAx[2], vRotAx, ptH) ;
m_pMachine->GetToolDirFromAngles( vRotAx, vtH) ;
m_pMachine->GetAuxDirFromAngles( vRotAx, vtA) ;
Frame3d frExit ; m_pGeomDB->GetGroupGlobFrame( nExitId, frExit) ;
ptH = frExit.Orig() ;
vtH = frExit.VersZ() ;
vtA = V_NULL ;
int nDirAuxId = m_pGeomDB->GetFirstNameInGroup( nHeadId, MCH_AUX_VECT) ;
if ( nDirAuxId != GDB_ID_NULL) {
const IGeoVector3d* pGV = GetGeoVector3d( m_pGeomDB->GetGeoObj( nDirAuxId)) ;
if ( pGV != nullptr) {
Frame3d frHead ; m_pGeomDB->GetGroupGlobFrame( nHeadId, frHead) ;
vtA = pGV->GetVector() ;
vtA.ToGlob( frHead) ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
Simulator::ExecLineVmill( int nVmId, const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI,
const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF)
Simulator::ExecLineVmill( int nVmId, int nCurrTool, double dVmTdOffs, double dVmAdOffs,
const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI,
const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF)
{
// Recupero Zmap
IVolZmap* pVZM = GetVolZmap( m_pGeomDB->GetGeoObj( nVmId)) ;
@@ -1275,16 +1273,17 @@ Simulator::ExecLineVmill( int nVmId, const Point3d& ptHi, const Vector3d& vtHi,
Vector3d vtHfL = vtHf ; vtHfL.ToLoc( frVzmF) ;
Vector3d vtAfL = vtAf ; vtAfL.ToLoc( frVzmF) ;
// Eventuali offset
ptHiL += m_dVmTdOffs * vtHiL + m_dVmAdOffs * vtAiL ;
ptHfL += m_dVmTdOffs * vtHfL + m_dVmAdOffs * vtAfL ;
ptHiL += dVmTdOffs * vtHiL + dVmAdOffs * vtAiL ;
ptHfL += dVmTdOffs * vtHfL + dVmAdOffs * vtAfL ;
// Log per debug
if ( ExeGetDebugLevel() >= 10) {
string sOut = "Pi=(" + ToString( ptHiL) + ") Vi=(" + ToString( vtHiL) + ") Ai=(" + ToString( vtAiL) +
string sOut = "Zmap=" + ToString( nVmId) + " CurrTool=" + ToString( nCurrTool) +
"Pi=(" + ToString( ptHiL) + ") Vi=(" + ToString( vtHiL) + ") Ai=(" + ToString( vtAiL) +
") Pf=(" + ToString( ptHfL) + ") Vf=(" + ToString( vtHfL) + ") Af=(" + ToString( vtAfL) + ")" ;
LOG_DBG_INFO( GetEMkLogger(), sOut.c_str())
}
// Eseguo
return pVZM->MillingStep( ptHiL, vtHiL, vtAiL, ptHfL, vtHfL, vtAfL) ;
return pVZM->MillingStep( nCurrTool, ptHiL, vtHiL, vtAiL, ptHfL, vtHfL, vtAfL) ;
}
//----------------------------------------------------------------------------
@@ -1950,3 +1949,94 @@ Simulator::AddCollisionObj( int nInd, int nFrameId, int nType, const Vector3d& v
m_CollObj.emplace_back( nInd, nFrameId, nType, vtMove, dPar1, dPar2, dPar3) ;
return true ;
}
//----------------------------------------------------------------------------
bool
Simulator::SetToolForVmill( const string& sTool, const string& sHead, int nExit, const INTVECTOR& vVmill, bool bFirst)
{
// disabilito eventuale registrazione comandi EXE (riabilitazione automatica)
CmdLogOff cmdLogOff ;
// se vVmill vuoto, esco
if ( vVmill.empty())
return true ;
// se utensile, testa o uscita non definiti, reset ed esco
if ( IsEmptyOrSpaces( sTool) || IsEmptyOrSpaces( sHead) || nExit < 1) {
ExeVolZmapResetTools( vVmill) ;
return false ;
}
// imposto utensile come corrente
string sOldTool ; m_pMchMgr->TdbGetCurrToolParam( TPA_NAME, sOldTool) ;
if ( sTool != sOldTool && ! m_pMchMgr->TdbSetCurrTool( sTool)) {
ExeVolZmapResetTools( vVmill) ;
return false ;
}
// recupero dati utensile
int nFlag = 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) ;
double dThick ; m_pMchMgr->TdbGetCurrToolParam( TPA_THICK, dThick) ;
double dCornR ; m_pMchMgr->TdbGetCurrToolParam( TPA_CORNRAD, dCornR) ;
double dSideAng ; m_pMchMgr->TdbGetCurrToolParam( TPA_SIDEANG, dSideAng) ;
double dMaxMat ; m_pMchMgr->TdbGetCurrToolParam( TPA_MAXMAT, dMaxMat) ;
// 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) ;
else if ( nType == TT_MORTISE_STD)
ExeVolZmapSetMortiserTool( vVmill, sTool, dLen, dDiam, dThick, dCornR, nFlag, bFirst) ;
else if ( nType == TT_SAW_STD || nType == TT_SAW_FLAT)
ExeVolZmapSetSawTool( vVmill, sTool, dLen, dDiam, dThick, 0, dCornR, nFlag, bFirst) ;
else if ( nType == TT_WATERJET)
ExeVolZmapSetStdTool( vVmill, sTool, dLen + 50, dDiam, dCornR, dMaxMat, nFlag, bFirst) ;
else if ( abs( dSideAng) < EPS_ANG_SMALL || abs( dThick) < EPS_SMALL) {
if ( dDiam <= dMaxStemDiam)
ExeVolZmapSetStdTool( vVmill, sTool, dLen, dDiam, dCornR, dMaxMat, nFlag, bFirst) ;
else
ExeVolZmapSetSawTool( vVmill, sTool, dLen, dDiam, dMaxMat, 0, dCornR, nFlag, bFirst) ;
}
else {
bool bExtra = ( dThick > 0) ;
double dTipLen = abs( dThick) ;
double dTotLen = ( bExtra ? dLen + dTipLen : dLen) ;
double dDelta ;
if ( dSideAng > 0) {
if ( dCornR < EPS_SMALL)
dDelta = 2 * dTipLen * tan( dSideAng * DEGTORAD) ;
else
dDelta = 2 * ( dCornR * cos( dSideAng * DEGTORAD) + ( dTipLen - dCornR + dCornR * sin( dSideAng * DEGTORAD)) * tan( dSideAng * DEGTORAD)) ;
}
else
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) ;
}
// eventuali offset per Vmill (per adattare lo ZeroT macchina con quello di Zmap)
double dVmTdOffs = 0 ;
double dVmAdOffs = 0 ;
if ( nType == TT_MORTISE_STD) {
dVmTdOffs = 0 ;
dVmAdOffs = 0.5 * dThick ;
}
else if ( nType == TT_SAW_STD || nType == TT_SAW_FLAT) {
dVmTdOffs = ( ( dLen <= dThick) ? -dLen + dThick : 0) ;
dVmAdOffs = 0 ;
}
// inserisco in lista utensili per virtual milling
if ( bFirst) {
m_VmTool.resize( 1) ;
m_VmTool[0] = VmTool( sTool, sHead, nExit, dVmTdOffs, dVmAdOffs) ;
}
else
m_VmTool.emplace_back( sTool, sHead, nExit, dVmTdOffs, dVmAdOffs) ;
// ripristino eventuale diverso utensile corrente
if ( sTool != sOldTool)
m_pMchMgr->TdbSetCurrTool( sOldTool) ;
return true ;
}