From 16a283e1bc463242adef3f52d49ed60a4b7e67a2 Mon Sep 17 00:00:00 2001 From: DarioS Date: Sun, 19 Jun 2022 11:07:07 +0200 Subject: [PATCH] EgtMachKernel : - modifiche varie per plunge di Mortising. --- Mortising.cpp | 141 +++++++++++++++++++++++++++++--------------------- Mortising.h | 5 +- 2 files changed, 85 insertions(+), 61 deletions(-) diff --git a/Mortising.cpp b/Mortising.cpp index f204c2c..fc9cd3d 100644 --- a/Mortising.cpp +++ b/Mortising.cpp @@ -1291,12 +1291,12 @@ Mortising::ProcessPath( int nPathId, int nPvId, int nClId) if ( FromString( ExtractInfo( m_Params.m_sUserNotes, "MaxElev="), dMaxElev) && dElev > dMaxElev) dElev = dMaxElev ; - // affondamento speciale da note untente + // affondamento speciale da note untente (!!! da trasformare in parametro come gli altri !!!) int nPlunge = 0 ; FromString( ExtractInfo( m_Params.m_sUserNotes, "Plunge="), nPlunge) ; // verifico che lo step dell'utensile sia sensato - double dOkStep = ( nPlunge != 0 ? m_Params.m_dStep : 0) ; + double dOkStep = ( nPlunge == MORTISE_PLUNGE_STEP ? m_Params.m_dStep : 0) ; const double MIN_ZSTEP = 1.0 ; if ( dOkStep >= EPS_SMALL && dOkStep < MIN_ZSTEP) { dOkStep = MIN_ZSTEP ; @@ -1315,7 +1315,7 @@ Mortising::ProcessPath( int nPathId, int nPvId, int nClId) } // se lo step supera la capacità dell'utensile - if ( m_Params.m_dStep > m_TParams.m_dMaxMat + EPS_SMALL) { + if ( dOkStep > m_TParams.m_dMaxMat + EPS_SMALL) { dOkStep = m_TParams.m_dMaxMat ; string sInfo = "Warning in Mortising : machining step (" + ToString( m_Params.m_dStep, 1) + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; @@ -1384,9 +1384,7 @@ Mortising::ProcessPath( int nPathId, int nPvId, int nClId) SetAuxDir( vtAux) ; // Calcolo la mortasatura - Point3d ptStart ; pCompo->GetStartPoint( ptStart) ; - Point3d ptEnd ; pCompo->GetEndPoint( ptEnd) ; - if ( ! GenerateMortisingCl( ptStart, ptEnd, vtTool, dDepth, dElev, dOkStep, nPlunge)) + if ( ! GenerateMortisingCl( pCompo, vtTool, dDepth, dElev, dOkStep, nPlunge)) return false ; } @@ -1472,7 +1470,65 @@ Mortising::GenerateMortisingPv( int nPathId, const ICurveComposite* pCompo) //---------------------------------------------------------------------------- bool -Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtTool, double dDepth, double dElev, +Mortising::GenerateMortisingCl( const ICurveComposite* pCompo, const Vector3d& vtTool, + double dDepth, double dElev, double dOkStep, int nPlunge) +{ + // inizio e fine + Point3d ptStart ; pCompo->GetStartPoint( ptStart) ; + Point3d ptEnd ; pCompo->GetEndPoint( ptEnd) ; + + // verifico se affondamento ripetuto è veramente tale + if ( ( nPlunge == MORTISE_PLUNGE_START_END || nPlunge == MORTISE_PLUNGE_START_TO_END) && Dist( ptStart, ptEnd) < 10 * EPS_SMALL) + nPlunge = MORTISE_PLUNGE_START ; + + // se affondamento inizio e fine + if ( nPlunge == MORTISE_PLUNGE_START_END) { + // affondamento iniziale + if ( ! GenerateOnePlungeCl( ptStart, ptEnd, vtTool, dDepth, dElev, dOkStep, MORTISE_PLUNGE_START, true)) + return false ; + // affondamento finale + if ( ! GenerateOnePlungeCl( ptStart, ptEnd, vtTool, dDepth, dElev, dOkStep, MORTISE_PLUNGE_END, false)) + return false ; + } + + // se alrimenti affondamenti ripetuti da inizio a fine con ritorno basso + else if ( nPlunge == MORTISE_PLUNGE_START_TO_END) { + // distanza e vettore spostamento laterale + Vector3d vtDir = ptEnd - ptStart ; + double dLen = vtDir.Len() ; + vtDir.Normalize() ; + // affondamenti iniziale e intermedi + int kMax = ( int) floor( dLen / m_TParams.m_dDiam) ; + for ( int k = 0 ; k <= kMax ; ++ k) { + Point3d ptNewStart = ptStart + vtDir * k * m_TParams.m_dDiam ; + // se non è finale + if ( k != kMax || ! AreSamePointEpsilon( ptNewStart, ptEnd, 10 * EPS_SMALL)) { + if ( ! GenerateOnePlungeCl( ptNewStart, ptEnd, vtTool, dDepth, dElev, dOkStep, MORTISE_PLUNGE_START, k == 0)) + return false ; + } + } + // affondamento finale + if ( ! GenerateOnePlungeCl( ptEnd, ptStart, vtTool, dDepth, dElev, dOkStep, MORTISE_PLUNGE_STEP, false)) + return false ; + } + + // altrimenti affondamento singolo + else { + if ( ! GenerateOnePlungeCl( ptStart, ptEnd, vtTool, dDepth, dElev, dOkStep, nPlunge, true)) + return false ; + } + + // reset dati di movimento + ResetMoveData() ; + // incremento numero di mortasature + ++ m_nMortises ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Mortising::GenerateOnePlungeCl( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtTool, double dDepth, double dElev, double dOkStep, int nPlunge, bool bFirst) { // compensazione elevazione/affondamento @@ -1481,7 +1537,7 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co // determino se l'inizio dell'attacco è esattamente sotto il grezzo, nel qual caso ricalcolo l'elevazione double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() + m_pMchMgr->GetDeltaSafeZ( m_TParams.m_sHead) ; double dStartElev = 0 ; - Point3d ptLi = ( nPlunge != 2 ? ptStart : ptEnd) + vtTool * dDelta ; + Point3d ptLi = ( nPlunge != MORTISE_PLUNGE_END ? ptStart : ptEnd) + vtTool * dDelta ; bool bUnderStart = GetPointUnderRaw( ptLi, vtTool, 0, GetRadiusForStartEndElevation(), m_TParams.m_dLen, false, dSafeZ, vtTool, dStartElev) ; // altrimenti ridetermino elevazione su inizio percorso di lavoro @@ -1489,31 +1545,24 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co GetElevation( m_nPhase, ptLi, vtTool, GetRadiusForStartEndElevation(), vtTool, dStartElev) ; // 1 -> punto approccio - int nFirstFlag = bFirst ? 1 : 0 ; + int nFirstFlag = ( bFirst ? 1 : 0) ; SetFlag( nFirstFlag) ; - Point3d ptP1 = ( nPlunge != 2 ? ptStart : ptEnd) + vtTool * ( dDelta + dStartElev + dSafeZ) ; - int nStart = bFirst ? AddRapidStart( ptP1) : AddRapidMove( ptP1) ; + Point3d ptP1 = ( nPlunge != MORTISE_PLUNGE_END ? ptStart : ptEnd) + vtTool * ( dDelta + dStartElev + dSafeZ) ; + int nStart = ( bFirst ? AddRapidStart( ptP1) : AddRapidMove( ptP1)) ; if ( nStart == GDB_ID_NULL) return false ; SetFlag( 0) ; // 2 -> punto fuori (se diverso dal precedente) if ( m_Params.m_dStartPos < dSafeZ - 10 * EPS_SMALL) { - Point3d ptP2 = ( nPlunge != 2 ? ptStart : ptEnd) + vtTool * ( dDelta + m_Params.m_dStartPos) ; + Point3d ptP2 = ( nPlunge != MORTISE_PLUNGE_END ? ptStart : ptEnd) + vtTool * ( dDelta + m_Params.m_dStartPos) ; if ( AddRapidMove( ptP2) == GDB_ID_NULL) return false ; } - // determino numero e affondamento degli step - if ( dOkStep < EPS_SMALL) - dOkStep = dElev ; - int nStep = max( 1, static_cast( ceil( dElev / dOkStep))) ; - double dStep = dElev / nStep ; - const double RETURN_DIST = 10 ; - - // eseguo ciclo a seconda del tipo di step + // eseguo ciclo a seconda del tipo di affondamento Point3d ptLast ; - if ( nPlunge == 1 || nPlunge == 3) { + if ( nPlunge == MORTISE_PLUNGE_START) { // 3 -> punto in affondamento SetFeed( GetStartFeed()) ; SetFlag( 0) ; @@ -1522,7 +1571,7 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co return false ; ptLast = ptP3 ; } - else if ( nPlunge == 2) { + else if ( nPlunge == MORTISE_PLUNGE_END) { // 3 -> punto in affondamento SetFeed( GetStartFeed()) ; SetFlag( 0) ; @@ -1532,6 +1581,13 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co ptLast = ptP3 ; } else { + // determino numero e affondamento degli step + if ( dOkStep < EPS_SMALL) + dOkStep = dElev ; + int nStep = max( 1, static_cast( ceil( dElev / dOkStep))) ; + double dStep = dElev / nStep ; + const double RETURN_DIST = 10 ; + // a seconda del tipo switch ( m_Params.m_nStepType) { default : // ZIGZAG for ( int i = 1 ; i <= nStep ; ++ i) { @@ -1547,7 +1603,7 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co ptLast = (( i % 2 == 1) ? ptEnd : ptStart) ; Point3d ptP4 = ptLast + ( dDelta - i * dStep) * vtTool ; if ( AddLinearMove( ptP4) == GDB_ID_NULL) - return false ; + return false ; } break ; case MORTISE_ST_ONEWAY : @@ -1564,7 +1620,7 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co ptLast = ptEnd ; Point3d ptP4 = ptLast + ( dDelta - i * dStep) * vtTool ; if ( AddLinearMove( ptP4) == GDB_ID_NULL) - return false ; + return false ; // 5 -> ritorno sull'inizio, se non ultimo punto if ( i < nStep) { // retrocedo @@ -1572,13 +1628,13 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co SetFlag( 0) ; Point3d ptP5a = ptP4 + RETURN_DIST * vtTool ; if ( AddLinearMove( ptP5a) == GDB_ID_NULL) - return false ; + return false ; // ritorno sopra inizio SetFeed( GetFeed()) ; SetFlag( 0) ; Point3d ptP5b = ptP3 + RETURN_DIST * vtTool ; if ( AddLinearMove( ptP5b) == GDB_ID_NULL) - return false ; + return false ; } } break ; @@ -1601,39 +1657,6 @@ Mortising::GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, co if ( AddLinearMove( ptP6) == GDB_ID_NULL) return false ; - if ( nPlunge == 3) { - - Vector3d vtDir = ptEnd - ptStart ; - double dLen = vtDir.Len() ; - vtDir.Normalize() ; - - int kMax = ( int) floor( dLen / m_TParams.m_dDiam) ; - for ( int k = 1 ; k <= kMax ; k ++) { - Point3d ptNewStart = ptStart + vtDir * k * m_TParams.m_dDiam ; - // se ultimo punto verifico non sia già quello finale - if ( k == kMax && AreSamePointEpsilon( ptNewStart, ptEnd, 10 * EPS_SMALL)) { - if ( ! GenerateMortisingCl( ptEnd, ptStart, vtTool, dDepth, dElev, dOkStep, 0, false)) - return false ; - } - else { - if ( ! GenerateMortisingCl( ptNewStart, ptEnd, vtTool, dDepth, dElev, dOkStep, 1, false)) - return false ; - } - } - // evenutale ultimo punto - Point3d ptLast = ptStart + vtDir * kMax * m_TParams.m_dDiam ; - if ( ! AreSamePointEpsilon( ptEnd, ptLast, 10 * EPS_SMALL)) - if ( ! GenerateMortisingCl( ptEnd, ptStart, vtTool, dDepth, dElev, dOkStep, 0, false)) - return false ; - } - - if ( bFirst) { - // reset dati di movimento - ResetMoveData() ; - // incremento numero di mortasature - ++ m_nMortises ; - } - return true ; } diff --git a/Mortising.h b/Mortising.h index 07d3336..f4f345a 100644 --- a/Mortising.h +++ b/Mortising.h @@ -74,8 +74,9 @@ class Mortising : public Machining bool ProcessPath( int nPathId, int nPvId, int nClId) ; bool CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double dThick, double& dElev) const ; bool GenerateMortisingPv( int nPathId, const ICurveComposite* pCompo) ; - bool GenerateMortisingCl( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtTool, double dDepth, double dElev, double dOkStep, - int nPlunge, bool bFirst = true) ; + bool GenerateMortisingCl( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dElev, double dOkStep, int nPlunge) ; + bool GenerateOnePlungeCl( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtTool, double dDepth, double dElev, double dOkStep, + int nPlunge, bool bFirst) ; double GetRadiusForStartEndElevation( void) const ; private :