diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 6a0e82b..9ed32b4 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/OutputConst.h b/OutputConst.h index 58a90e6..efd2358 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -118,6 +118,7 @@ static const std::string GVAR_R4N = ".R4n" ; // (string) nome del q static const std::string GVAR_MASK = ".MASK" ; // (int) mask associato ai movimenti in rapido static const std::string GVAR_FLAG = ".FLAG" ; // (int) flag associato ad ogni movimento static const std::string GVAR_TDIR = ".TDIR" ; // (Vector3d)versore utensile +static const std::string GVAR_ENABAXES = ".EnabAxes" ; // (bool) flag abilitazione assi attivi per simulazione static const std::string GVAR_AUXAXES = ".AuxAxes" ; // (int) numero assi ausiliari per simulazione static const std::string GVAR_AN = ".AN" ; // (num) valore del N-esimo asse ausiliario per simulazione static const std::string GVAR_ANN = ".ANn" ; // (string) nome del N-esimo asse ausiliario per simulazione diff --git a/Simulator.cpp b/Simulator.cpp index 1631eac..e1c5381 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -44,6 +44,7 @@ Simulator::Simulator( void) m_nAuxSInd = 0 ; m_nAuxETot = 0 ; m_nAuxEInd = 0 ; + m_bEnabAxes = true ; m_AxesName.reserve( 8) ; m_AxesToken.reserve( 8) ; m_AxesLinear.reserve( 8) ; @@ -701,42 +702,65 @@ Simulator::ManageMove( int& nStatus) } } - // Calcolo distanza di movimento - double dSqDist = 0 ; - for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { - // coefficiente moltiplicativo per differenziare assi lineari (primi3) e rotanti (altri) - double dSqCoeff = (( i >= 3) ? 100 : 1) ; - dSqDist += dSqCoeff * ( AxesEnd[i] - m_AxesVal[i]) * ( AxesEnd[i] - m_AxesVal[i]) ; - } - double dDist = sqrt( dSqDist) ; - m_dCoeff += ( nMoveType == 0 ? 4 : 1) * m_dStep / dDist ; - if ( m_dCoeff > 1) - m_dCoeff = 1 ; - - // Eseguo movimento rapido o lineare - if ( nMoveType != 2 && nMoveType != 3) { + if ( m_bEnabAxes) { + // Calcolo distanza di movimento + double dSqDist = 0 ; for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { - double dVal = m_AxesVal[i] * ( 1 - m_dCoeff) + AxesEnd[i] * m_dCoeff ; - m_pMachine->SetAxisPos( m_AxesName[i], dVal) ; + // coefficiente moltiplicativo per differenziare assi lineari (primi3) e rotanti (altri) + double dSqCoeff = (( i < 3) ? 1 : 100) ; + dSqDist += dSqCoeff * ( AxesEnd[i] - m_AxesVal[i]) * ( AxesEnd[i] - m_AxesVal[i]) ; + } + double dDist = sqrt( dSqDist) ; + if ( dDist > EPS_SMALL) { + m_dCoeff += ( nMoveType == 0 ? 4 : 1) * m_dStep / dDist ; + if ( m_dCoeff > 1) + m_dCoeff = 1 ; + } + else + m_dCoeff = 1 ; + + // Eseguo movimento rapido o lineare + if ( nMoveType != 2 && nMoveType != 3) { + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { + double dVal = m_AxesVal[i] * ( 1 - m_dCoeff) + AxesEnd[i] * m_dCoeff ; + m_pMachine->SetAxisPos( m_AxesName[i], dVal) ; + } + } + // Eseguo movimento su arco + else { + // primi due assi lineari + Point3d ptCen = pCamData->GetAxesCen() ; + double dAngCen = pCamData->GetAxesAngCen() ; + Vector3d vtN = pCamData->GetAxesNormDir() ; + Vector3d vtRot = Point3d( m_AxesVal[0], m_AxesVal[1], m_AxesVal[2]) - ptCen ; + vtRot.Rotate( vtN, m_dCoeff * dAngCen) ; + double dDeltaN = ( Point3d( AxesEnd[0], AxesEnd[1], AxesEnd[2]) - ptCen) * vtN ; + m_pMachine->SetAxisPos( m_AxesName[0], ptCen.x + vtRot.x + m_dCoeff * dDeltaN * vtN.x) ; + m_pMachine->SetAxisPos( m_AxesName[1], ptCen.y + vtRot.y + m_dCoeff * dDeltaN * vtN.y) ; + m_pMachine->SetAxisPos( m_AxesName[2], ptCen.z + vtRot.z + m_dCoeff * dDeltaN * vtN.z) ; + // altri assi + for ( size_t i = 3 ; i < m_AxesName.size() ; ++ i) { + double dVal = m_AxesVal[i] * ( 1 - m_dCoeff) + AxesEnd[i] * m_dCoeff ; + m_pMachine->SetAxisPos( m_AxesName[i], dVal) ; + } } } - // Eseguo movimento su arco else { - // primi due assi lineari - Point3d ptCen = pCamData->GetAxesCen() ; - double dAngCen = pCamData->GetAxesAngCen() ; - Vector3d vtN = pCamData->GetAxesNormDir() ; - Vector3d vtRot = Point3d( m_AxesVal[0], m_AxesVal[1], m_AxesVal[2]) - ptCen ; - vtRot.Rotate( vtN, m_dCoeff * dAngCen) ; - double dDeltaN = ( Point3d( AxesEnd[0], AxesEnd[1], AxesEnd[2]) - ptCen) * vtN ; - m_pMachine->SetAxisPos( m_AxesName[0], ptCen.x + vtRot.x + m_dCoeff * dDeltaN * vtN.x) ; - m_pMachine->SetAxisPos( m_AxesName[1], ptCen.y + vtRot.y + m_dCoeff * dDeltaN * vtN.y) ; - m_pMachine->SetAxisPos( m_AxesName[2], ptCen.z + vtRot.z + m_dCoeff * dDeltaN * vtN.z) ; - // altri assi - for ( size_t i = 3 ; i < m_AxesName.size() ; ++ i) { - double dVal = m_AxesVal[i] * ( 1 - m_dCoeff) + AxesEnd[i] * m_dCoeff ; - m_pMachine->SetAxisPos( m_AxesName[i], dVal) ; + // Calcolo distanza di movimento + double dSqDist = 0 ; + for ( size_t i = 0 ; i < m_AuxAxesName.size() ; ++ i) { + // coefficiente moltiplicativo per differenziare assi lineari e rotanti + double dSqCoeff = ( m_AuxAxesLinear[i] ? 1 : 100) ; + dSqDist += dSqCoeff * ( m_AuxAxesEnd[i] - m_AuxAxesVal[i]) * ( m_AuxAxesEnd[i] - m_AuxAxesVal[i]) ; } + double dDist = sqrt( dSqDist) ; + if ( dDist > EPS_SMALL) { + m_dCoeff += ( nMoveType == 0 ? 4 : 1) * m_dStep / dDist ; + if ( m_dCoeff > 1) + m_dCoeff = 1 ; + } + else + m_dCoeff = 1 ; } // Muovo eventuali assi ausiliari @@ -747,8 +771,10 @@ Simulator::ManageMove( int& nStatus) // Se arrivato a fine interpolazione movimento, salvo posizioni e segnalo if ( m_dCoeff > 0.999) { - for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) - m_AxesVal[i] = AxesEnd[i] ; + if ( m_bEnabAxes) { + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) + m_AxesVal[i] = AxesEnd[i] ; + } nStatus = MCH_SIM_END_STEP ; // richiamo gestione evento fine entità if ( ! OnMoveEnd()) { @@ -1046,6 +1072,8 @@ Simulator::OnMoveStart( const CamData* pCamData) bOk = bOk && m_pMachine->LuaResetGlobVar( GetGlobVarAxisValue( i)) ; } } + // reset abilitazione assi attivi + bOk = bOk && m_pMachine->LuaResetGlobVar( GLOB_VAR + GVAR_ENABAXES) ; // reset numero assi ausiliari bOk = bOk && m_pMachine->LuaResetGlobVar( GLOB_VAR + GVAR_AUXAXES) ; @@ -1069,6 +1097,8 @@ Simulator::OnMoveStart( const CamData* pCamData) ResetAuxAxes() ; // recupero i dati di ritorno + if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ENABAXES, m_bEnabAxes)) + m_bEnabAxes = true ; int nNumAuxAxes = 0 ; if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0) return true ; @@ -1113,6 +1143,8 @@ Simulator::OnMoveEnd( void) bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_END) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; + // in ogni caso forzo riabilitazione assi attivi + m_bEnabAxes = true ; return bOk ; } diff --git a/Simulator.h b/Simulator.h index 14073d7..0e59384 100644 --- a/Simulator.h +++ b/Simulator.h @@ -86,6 +86,7 @@ class Simulator int m_nAuxETot ; // numero totale movimenti ausiliari di fine percorso int m_nAuxEInd ; // indice del movimento ausiliario di fine percorso corrente std::string m_sTool ; // nome dell'utensile corrente + bool m_bEnabAxes ; // flag abilitazione movimento assi attivi STRVECTOR m_AxesName ; // nomi degli assi macchina attivi STRVECTOR m_AxesToken ; // token degli assi macchina attivi BOOLVECTOR m_AxesInvert ; // flag di asse con verso invertito