EgtMachKernel :

- modifiche per virtual milling (sperimentale).
This commit is contained in:
Dario Sassi
2018-01-15 09:59:08 +00:00
parent 650b0ebcc2
commit 3f1a871b5a
5 changed files with 118 additions and 14 deletions
+91 -14
View File
@@ -20,6 +20,9 @@
#include "Machining.h"
#include "MachiningConst.h"
#include "OutputConst.h"
#include "DllMain.h"
#include "/EgtDev/Include/EGkVolZmap.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EMkToolConst.h"
#include "/EgtDev/Include/EMkOperationConst.h"
#include "/EgtDev/Include/EgtNumUtils.h"
@@ -47,6 +50,7 @@ Simulator::Simulator( void)
m_nAuxSInd = 0 ;
m_nAuxETot = 0 ;
m_nAuxEInd = 0 ;
m_nVmId = GDB_ID_NULL ;
m_bEnabAxes = true ;
m_AxesName.reserve( 8) ;
m_AxesToken.reserve( 8) ;
@@ -761,7 +765,6 @@ Simulator::ManagePathEndAux( int& nStatus)
bool
Simulator::ManageMove( int& nStatus)
{
// Recupero posizione finale
const CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ;
if ( pCamData == nullptr) {
@@ -815,44 +818,73 @@ Simulator::ManageMove( int& nStatus)
double dSqCoeff = (( i < 3) ? 1 : 100) ;
dSqDist += dSqCoeff * ( AxesEnd[i] - m_AxesVal[i]) * ( AxesEnd[i] - m_AxesVal[i]) ;
}
double dPrevCoeff = m_dCoeff ;
double dDist = sqrt( dSqDist) ;
if ( dDist > EPS_SMALL) {
m_dCoeff += ( nMoveType == 0 ? 4 : 1) * m_dStep / dDist ;
int nStep = int( max( dDist / ( ( nMoveType == 0 ? 4 : 1) * m_dStep), 1.)) ;
m_dCoeff += 1. / nStep ;
if ( m_dCoeff > 1)
m_dCoeff = 1 ;
}
else
m_dCoeff = 1 ;
// Posizione e direzione attuali dell'utensile (per Vmill)
Point3d ptNoseI ; Vector3d vtDirI ;
bool bOkI = GetHeadCurrPosDir( ptNoseI, vtDirI) ;
// Eseguo movimento rapido o lineare
if ( nMoveType != 2 && nMoveType != 3) {
// assegno posizioni finali
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 eventuale Vmill
if ( m_nVmId != GDB_ID_NULL) {
Point3d ptNoseF ; Vector3d vtDirF ;
bool bOkF = GetHeadCurrPosDir( ptNoseF, vtDirF) ;
ExecVmillOnLine( ptNoseI, vtDirI, ptNoseF, vtDirF) ;
}
}
// Eseguo movimento su arco
else {
// primi due assi lineari
// dati dell'arco
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) ;
double dDiffAng = ( m_dCoeff - dPrevCoeff) * dAngCen ;
Vector3d vtRot = Point3d( m_AxesVal[0], m_AxesVal[1], m_AxesVal[2]) - ptCen ;
vtRot.Rotate( vtN, dPrevCoeff * dAngCen) ;
// approssimo movimento con 1 o più step a seconda ci sia Vmill
int nStep = 1 ;
if ( m_nVmId != GDB_ID_NULL)
nStep = int( max( abs( dDiffAng) / 15.0, 1.)) ;
for ( int i = 1 ; i <= nStep ; ++ i) {
double dCurrCoeff = dPrevCoeff + ( m_dCoeff - dPrevCoeff) / nStep * i ;
vtRot.Rotate( vtN, dDiffAng / nStep) ;
m_pMachine->SetAxisPos( m_AxesName[0], ptCen.x + vtRot.x + dCurrCoeff * dDeltaN * vtN.x) ;
m_pMachine->SetAxisPos( m_AxesName[1], ptCen.y + vtRot.y + dCurrCoeff * dDeltaN * vtN.y) ;
m_pMachine->SetAxisPos( m_AxesName[2], ptCen.z + vtRot.z + dCurrCoeff * dDeltaN * vtN.z) ;
for ( size_t j = 3 ; j < m_AxesName.size() ; ++ j) {
double dVal = m_AxesVal[j] * ( 1 - dCurrCoeff) + AxesEnd[j] * dCurrCoeff ;
m_pMachine->SetAxisPos( m_AxesName[j], dVal) ;
}
// eseguo eventuale Vmill
if ( m_nVmId != GDB_ID_NULL) {
Point3d ptNoseF ; Vector3d vtDirF ;
bool bOkF = GetHeadCurrPosDir( ptNoseF, vtDirF) ;
ExecVmillOnLine( ptNoseI, vtDirI, ptNoseF, vtDirF) ;
ptNoseI = ptNoseF ;
vtDirI = vtDirF ;
}
}
}
}
else {
// Calcolo distanza di movimento
double dSqDist = 0 ;
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) ;
@@ -860,7 +892,8 @@ Simulator::ManageMove( int& nStatus)
}
double dDist = sqrt( dSqDist) ;
if ( dDist > EPS_SMALL) {
m_dCoeff += ( nMoveType == 0 ? 4 : 1) * m_dStep / dDist ;
int nStep = int( max( dDist / ( ( nMoveType == 0 ? 4 : 1) * m_dStep), 1.)) ;
m_dCoeff += 1. / nStep ;
if ( m_dCoeff > 1)
m_dCoeff = 1 ;
}
@@ -894,6 +927,46 @@ Simulator::ManageMove( int& nStatus)
return true ;
}
//----------------------------------------------------------------------------
bool
Simulator::GetHeadCurrPosDir( Point3d& ptH, Vector3d& vtH)
{
// ci devono essere almeno i tre assi lineari
if ( m_AxesName.size() < 3)
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) ;
return true ;
}
//----------------------------------------------------------------------------
bool
Simulator::ExecVmillOnLine( const Point3d& ptHi, const Vector3d& vtHi, const Point3d& ptHf, const Vector3d& vtHf)
{
// Recupero Zmap
IVolZmap* pVZM = GetVolZmap( m_pGeomDB->GetGeoObj( m_nVmId)) ;
if ( pVZM == nullptr)
return false ;
// Porto gli estremi nel riferimento dello Zmap
Frame3d frVZM ;
m_pGeomDB->GetGlobFrame( m_nVmId, frVZM) ;
Point3d ptHiL = ptHi ; ptHiL.ToLoc( frVZM) ;
Vector3d vtHiL = vtHi ; vtHiL.ToLoc( frVZM) ;
Point3d ptHfL = ptHf ; ptHfL.ToLoc( frVZM) ;
Vector3d vtHfL = vtHf ; vtHfL.ToLoc( frVZM) ;
// Eseguo
return pVZM->MillingStep( ptHiL, vtHiL, ptHfL, vtHfL) ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnDispositionStarting( int nOpId, int nOpInd, int nPhase,
@@ -957,6 +1030,10 @@ Simulator::OnDispositionEnd( void)
return true ;
// chiamo la funzione di fine disposizione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_END) ;
// recupero i dati di ritorno
int nVmId = GDB_ID_NULL ;
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_VMILL, nVmId) ;
m_nVmId = nVmId ;
// forzo aggiornamento posizione assi (possono essere stati mossi nello script)
UpdateAxesPos() ;
return bOk ;