EgtMachKernel :

- in svuotature chiuse migliorata scelta lato ottimale di inizio
- altri sviluppi in SimulatorMP.
This commit is contained in:
Dario Sassi
2024-09-09 09:30:14 +02:00
parent 4b835a27be
commit 431246b472
11 changed files with 303 additions and 173 deletions
+231 -150
View File
@@ -50,6 +50,7 @@ static const double COLL_STEP = 10. ;
static const double SQ_COEFF_ROT_MOVE = 100. ;
static const double COEFF_LIM = 0.999 ;
static const double SAFEDIST_STD = 5.0 ;
static const int ERR_NONE = 0 ;
static const int ERR_OUTSTROKE = 1 ;
static const int ERR_COLLISION = 11 ;
static const int ERR_TOOL_SEL = 21 ;
@@ -78,6 +79,7 @@ SimulatorMP::SimulatorMP( void)
m_nEntId = GDB_ID_NULL ;
m_nEntInd = 0 ;
m_dCoeff = 0 ;
m_bChangedTool = false ;
m_nAuxSTot = 0 ;
m_nAuxSInd = 0 ;
m_nAuxETot = 0 ;
@@ -127,6 +129,9 @@ SimulatorMP::Init( MachMgr* pMchMgr)
m_pMachine = m_pMchMgr->GetCurrMachine() ;
m_pPerfCnt = new PerformanceCounter ;
m_nStatus = SIS_INITIALIZED ;
if ( ExeGetDebugLevel() >= 1)
LOG_INFO( GetEMkLogger(), " * SimulatorMP *")
return true ;
}
@@ -159,6 +164,7 @@ SimulatorMP::Start( bool bFirst)
m_nExit = 0 ;
m_dTDiam = 0 ;
m_bCutOnTip = false ;
m_bChangedTool = false ;
ResetInterpolation() ;
ResetAxes() ;
ResetAuxAxes() ;
@@ -180,6 +186,7 @@ SimulatorMP::Start( bool bFirst)
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep) ;
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_VER, GetEMkVer()) ;
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MACHNAME, m_pMachine->GetMachineName()) ;
m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MPSIM, true) ;
// Se appena entrati in simulazione
if ( m_nStatus == SIS_INITIALIZED) {
@@ -194,7 +201,7 @@ SimulatorMP::Start( bool bFirst)
// Arrivo alla preparazione per la prima lavorazione
int nStatus ;
if ( ! FindAndManageOperationStart( true, bFirst, nStatus) && nStatus != MCH_SIM_STOP)
if ( ! FindAndManageOperationStart( true, bFirst, m_bChangedTool, nStatus) && nStatus != MCH_SIM_STOP)
bOk = false ;
// se sono ancora su disposizione
if ( m_pMchMgr->GetOperationType( m_nOpId) == OPER_DISP) {
@@ -312,14 +319,16 @@ SimulatorMP::Move( int& nStatus)
return false ;
}
// Se arrivato alla fine di una operazione
if ( m_nCLPathId == GDB_ID_NULL) {
// Se arrivato alla fine di una operazione o appena scaricato utensile
if ( m_nCLPathId == GDB_ID_NULL || m_bChangedTool) {
// gestione fine operazione
if ( ! ManageOperationEnd( nStatus))
if ( m_nCLPathId == GDB_ID_NULL && ! ManageOperationEnd( nStatus))
return false ;
// ricerca e gestione nuova operazione
if ( ! FindAndManageOperationStart( false, false, nStatus))
if ( ! FindAndManageOperationStart( false, false, m_bChangedTool, nStatus))
return false ;
if ( m_bChangedTool)
return true ;
// se non ce ne sono altre, sono alla fine
if ( m_nOpId == GDB_ID_NULL) {
OnProgramEnd() ;
@@ -489,111 +498,126 @@ SimulatorMP::GoHome( void)
//----------------------------------------------------------------------------
bool
SimulatorMP::UpdateTool( bool bFirst, int& nErr)
SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
// Recupero l'utensile della lavorazione corrente
// Reset stato
nErr = ERR_NONE ;
// Recupero la lavorazione corrente
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch != nullptr) {
// recupero nome e dati nuovo utensile
string sTuuid, sTool ;
if ( ! pMch->GetParam( MPA_TUUID, sTuuid) ||
! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool))
return false ;
string sTcPos ; string sHead ; int nExit ;
if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) {
if ( m_pMchMgr->TdbSetCurrTool( sTool)) {
m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ;
m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
}
// ripristino l'utensile corrente
m_pMchMgr->TdbSetCurrTool( m_sTool) ;
if ( pMch == nullptr)
return false ;
// Recupero nome e dati nuovo utensile
string sTuuid, sTool ;
if ( ! pMch->GetParam( MPA_TUUID, sTuuid) ||
! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool))
return false ;
string sTcPos ; string sHead ; int nExit ;
if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) {
if ( m_pMchMgr->TdbSetCurrTool( sTool)) {
m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ;
m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
}
// verifico se cambierà
bool bDiffTool = ( sTool != m_sTool) ;
// se cambierà ed esiste il corrente, lo scarico
if ( bDiffTool && ! m_sTool.empty()) {
// eventuale lancio script per scarico utensile
int nCurrErr ;
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
}
// se prima volta, pulisco la testa
if ( bFirst)
m_pMchMgr->ResetHeadSet( sHead) ;
// recupero la lavorazione corrente e imposto la nuova
int nCurrMchId = m_pMchMgr->GetCurrMachining() ;
m_pMchMgr->SetCurrMachining( m_nOpId) ;
// carico l'utensile (e lo rendo corrente)
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
m_sHead = sHead ;
m_nExit = nExit ;
m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ;
double dTipFeed = 0 ;
m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ;
m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ;
// ripristino la lavorazione corrente
m_pMchMgr->SetCurrMachining( nCurrMchId) ;
// aggiorno gli assi macchina
if ( ! UpdateAxes())
return false ;
// se cambiato oppure prima volta, lancio lo script di selezione
if ( bDiffTool || bFirst) {
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
}
return ( nErr == 0) ;
// ripristino l'utensile corrente
m_pMchMgr->TdbSetCurrTool( m_sTool) ;
}
// Provo con una disposizione
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pDisp != nullptr) {
// recupero i dati
string sTool ; string sHead ; int nExit ; string sTcPos ;
pDisp->GetToolData( sTool, sHead, nExit, sTcPos) ;
// se esiste utensile corrente e cambierà, lo scarico
if ( ! m_sTool.empty() && sTool != m_sTool) {
// eventuale lancio script per scarico utensile
int nCurrErr ;
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
}
// carico l'utensile
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
m_sHead = sHead ;
m_nExit = nExit ;
m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ;
double dTipFeed = 0 ;
m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ;
m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ;
// aggiorno gli assi macchina
if ( ! UpdateAxes())
return false ;
// eventuale lancio script
// verifico se cambierà
bool bDiffTool = ( sTool != m_sTool) ;
// se cambierà ed esiste il corrente, lo scarico
if ( bDiffTool && ! m_sTool.empty() && ! bDeselected) {
// eventuale lancio script per scarico utensile
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != 0 ? nErr : nCurrErr) ;
if ( OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
bDeselected = true ;
return true ;
}
else {
nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
return ( nErr == 0) ;
}
return false ;
bDeselected = false ;
// se prima volta, pulisco la testa
if ( bFirst)
m_pMchMgr->ResetHeadSet( sHead) ;
// recupero la lavorazione corrente e imposto la nuova
int nCurrMchId = m_pMchMgr->GetCurrMachining() ;
m_pMchMgr->SetCurrMachining( m_nOpId) ;
// carico l'utensile (e lo rendo corrente)
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
m_sHead = sHead ;
m_nExit = nExit ;
m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ;
double dTipFeed = 0 ;
m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ;
m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ;
// ripristino la lavorazione corrente
m_pMchMgr->SetCurrMachining( nCurrMchId) ;
// aggiorno gli assi macchina
if ( ! UpdateAxes())
return false ;
// se cambiato oppure prima volta, lancio lo script di selezione
if ( bDiffTool || bFirst) {
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
}
return ( nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
bool
SimulatorMP::UpdateDispositionTool( bool bFirst, int& nErr)
{
// Reset stato di errore da script
nErr = ERR_NONE ;
// Recupero la disposizione
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pDisp == nullptr)
return false ;
// Recupero i dati
string sTool ; string sHead ; int nExit ; string sTcPos ;
pDisp->GetToolData( sTool, sHead, nExit, sTcPos) ;
// se esiste utensile corrente e cambierà, lo scarico
if ( ! m_sTool.empty() && sTool != m_sTool) {
// eventuale lancio script per scarico utensile
int nCurrErr ;
if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) {
nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
}
// carico l'utensile
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
m_sHead = sHead ;
m_nExit = nExit ;
m_pMchMgr->TdbGetCurrToolParam( TPA_DIAM, m_dTDiam) ;
double dTipFeed = 0 ;
m_pMchMgr->TdbGetCurrToolParam( TPA_TIPFEED, dTipFeed) ;
m_bCutOnTip = ( dTipFeed > EPS_MACH_LEN_PAR) ;
// aggiorno gli assi macchina
if ( ! UpdateAxes())
return false ;
// eventuale lancio script
int nCurrErr ;
if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) {
nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ;
if ( nCurrErr != ERR_COLLISION)
return false ;
}
return ( nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -680,18 +704,20 @@ SimulatorMP::ResetAuxAxes( void)
//----------------------------------------------------------------------------
bool
SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus)
SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChangedTool, int& nStatus)
{
// verifico parametri
if ( ! bStart)
bFirst = false ;
// recupero la nuova operazione
if ( bStart) {
m_nOpId = m_pMchMgr->GetFirstActiveOperation() ;
m_nOpInd = 0 ;
if ( ! bChangedTool) {
if ( bStart) {
m_nOpId = m_pMchMgr->GetFirstActiveOperation() ;
m_nOpInd = 0 ;
}
else
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
}
else
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
// ciclo sulle successive operazioni
while ( m_nOpId != GDB_ID_NULL) {
// se lavorazione valida
@@ -700,12 +726,14 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
bool bOk = true ;
// aggiorno utensile e assi conseguenti
int nErr ;
if ( ! UpdateTool( bFirst, nErr)) {
if ( ! UpdateMachiningTool( bFirst, bChangedTool, nErr)) {
string sOut = "Err=" + ToString( nErr) ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
nStatus = CalcStatusOnError( nErr) ;
bOk = false ;
return false ;
}
if ( bChangedTool)
return true ;
++ m_nOpInd ;
// imposto la lavorazione come corrente
m_pMchMgr->SetCurrMachining( m_nOpId) ;
@@ -719,12 +747,10 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
m_pGeomDB->GetInfo( nClId, KEY_MAXMAX, vAxMax) ;
// richiamo gestione evento inizio lavorazione
if ( ! OnMachiningStart( m_nOpId, m_nOpInd, ptMin, ptMax, vAxMin, vAxMax)) {
nStatus = CalcStatusOnError( 0) ;
bOk = false ;
}
if ( ! bOk)
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
break ;
}
return true ;
}
// se disposizione con cambio di fase
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
@@ -746,7 +772,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
if ( ! bEmpty) {
// richiamo gestione evento appena prima di inizio disposizione
if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) {
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
}
// cambio fase
@@ -754,7 +780,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
// se previsto, aggiorno utensile e assi conseguenti
if ( pDisp->IsWithTool()) {
int nErr ;
if ( ! UpdateTool( bFirst, nErr)) {
if ( ! UpdateDispositionTool( bFirst, nErr)) {
nStatus = CalcStatusOnError( nErr) ;
return false ;
}
@@ -762,7 +788,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
++ m_nOpInd ;
// richiamo gestione evento inizio disposizione
if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) {
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
}
// se ci sono movimenti manuali, aggiorno visualizzazione e breve pausa (200 ms)
@@ -774,7 +800,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
else {
// richiamo gestione evento appena prima di inizio disposizione
if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand)) {
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
}
// cambio fase
@@ -783,7 +809,7 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus
// richiamo gestione evento inizio e fine disposizione
if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand) ||
! OnDispositionEnd()) {
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
}
// se non è inizio, aggiorno visualizzazione e breve pausa (200 ms)
@@ -819,7 +845,7 @@ SimulatorMP::ManageOperationEnd( int& nStatus)
}
// gestione stato
if ( ! bOk)
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return bOk ;
}
@@ -881,7 +907,7 @@ SimulatorMP::FindAndManagePathStart( int& nStatus)
m_nAuxETot = 0 ;
// richiamo gestione evento inizio percorso di lavoro
if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd, m_nAuxSTot, ptStart, ptEnd, vtExtr, ptMin, ptMax, vAxMin, vAxMax, dElev)) {
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return false ;
}
}
@@ -912,7 +938,7 @@ SimulatorMP::ManagePathEnd( int& nStatus)
bool bOk = OnPathEnd( m_nAuxETot) ;
// gestione stato
if ( ! bOk)
nStatus = CalcStatusOnError( 0) ;
nStatus = CalcStatusOnError( ERR_NONE) ;
return bOk ;
}
@@ -1381,8 +1407,8 @@ SimulatorMP::GetHeadCurrPosDirAux( const std::string& sHead, int nExit, Point3d&
//----------------------------------------------------------------------------
bool
SimulatorMP::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)
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)) ;
@@ -1709,7 +1735,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit,
bool bFirst, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// reset oggetti per verifica collisione con grezzo
m_CollObj.clear() ;
// assegno il nome dell'utensile, la testa e l'uscita
@@ -1755,7 +1781,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit,
ResetAuxAxes() ;
int nNumAuxAxes = 0 ;
if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0)
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
m_AuxAxesName.reserve( nNumAuxAxes) ;
m_AuxAxesToken.reserve( nNumAuxAxes) ;
m_AuxAxesInvert.reserve( nNumAuxAxes) ;
@@ -1790,7 +1816,7 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit,
}
}
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -1798,7 +1824,7 @@ bool
SimulatorMP::OnToolDeselect( const string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// assegno il prossimo utensile
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTOOL, sNextTool) ;
// assegno la prossima testa
@@ -1818,7 +1844,7 @@ SimulatorMP::OnToolDeselect( const string& sNextTool, const string& sNextHead, i
UpdateAxesPos() ;
// verifico codice di errore
bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -1916,7 +1942,7 @@ bool
SimulatorMP::OnPathStartAux( int nInd, const string& sAS, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START_AUX))
return true ;
@@ -1930,7 +1956,7 @@ SimulatorMP::OnPathStartAux( int nInd, const string& sAS, int& nErr)
UpdateAxesPos() ;
// verifico codice di errore
bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -1938,7 +1964,7 @@ bool
SimulatorMP::OnPathEndAux( int nInd, const string& sAE, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END_AUX))
return true ;
@@ -1952,7 +1978,7 @@ SimulatorMP::OnPathEndAux( int nInd, const string& sAE, int& nErr)
UpdateAxesPos() ;
// verifico codice di errore
bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -1960,7 +1986,7 @@ bool
SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// recupero e assegno i dati
// dati generali e reset errore
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEID, m_nEntId) ;
@@ -2025,7 +2051,7 @@ SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData,
// verifico codice di errore
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
if ( nErr != 0)
if ( nErr != ERR_NONE)
return false ;
// forzo aggiornamento posizione assi (possono essere stati mossi nello script)
@@ -2095,7 +2121,7 @@ SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData,
m_AuxAxesEnd.emplace_back( dEnd) ;
m_AuxAxesLink.emplace_back( 0) ;
if ( ! m_pMachine->VerifyOutstroke( sName, dEnd)) {
nErr = 1 ;
nErr = ERR_OUTSTROKE ;
bOk = false ;
}
}
@@ -2116,7 +2142,7 @@ bool
SimulatorMP::OnMoveEnd( int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END))
return true ;
@@ -2129,7 +2155,7 @@ SimulatorMP::OnMoveEnd( int& nErr)
UpdateAxesPos() ;
// verifico codice di errore
m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ;
return ( bOk && nErr == 0) ;
return ( bOk && nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -2137,7 +2163,7 @@ bool
SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr)
{
// reset stato di errore da script
nErr = 0 ;
nErr = ERR_NONE ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_COLLISION))
return true ;
@@ -2165,7 +2191,7 @@ SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr)
ExeDraw() ;
}
return ( nErr == 0) ;
return ( nErr == ERR_NONE) ;
}
//----------------------------------------------------------------------------
@@ -2218,7 +2244,7 @@ SimulatorMP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, c
//----------------------------------------------------------------------------
bool
SimulatorMP::SetToolForVmill( const string& sTool, const string& sHead, int nExit, int nFlag, double dPar1, double dPar2,
const INTVECTOR& vVmill, bool bFirst)
const INTVECTOR& vVmill, bool bFirst)
{
// disabilito eventuale registrazione comandi EXE (riabilitazione automatica)
CmdLogOff cmdLogOff ;
@@ -2332,9 +2358,9 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt)
if ( vAxNaEpSt.empty())
return SIM_AXMV_RES_ERR ;
// Salvo i dati di movimento
m_CmdData.emplace_back( 1, nMoveType, vAxNaEpSt) ;
m_CmdData.emplace_back( nMoveType, vAxNaEpSt) ;
// Log dati
if ( ExeGetDebugLevel() >= 5) {
if ( ExeGetDebugLevel() >= 4) {
string sOut = "Save=SimulMoveAxes," + ToString( nMoveType) ;
for ( int i = 0 ; i < int( vAxNaEpSt.size()) ; ++ i)
sOut += "," + vAxNaEpSt[i].sName +
@@ -2346,6 +2372,20 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt)
return SIM_AXMV_RES_OK ;
}
//----------------------------------------------------------------------------
bool
SimulatorMP::SaveCmd( int nType, int nPar, const string& sPar)
{
// Salvo il comando
m_CmdData.emplace_back( nType, nPar, sPar) ;
// Log dati
if ( ExeGetDebugLevel() >= 4) {
string sOut = "Save=SimulSaveCmd," + ToString( nType) + "," + ToString( nPar) + "," + sPar ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
}
return false ;
}
//----------------------------------------------------------------------------
bool
SimulatorMP::ExecCmdData( int& nStatus)
@@ -2354,7 +2394,7 @@ SimulatorMP::ExecCmdData( int& nStatus)
auto& CmdCurr = m_CmdData[m_nCmdInd] ;
// Stampe di debug
if ( ExeGetDebugLevel() >= 5) {
if ( ExeGetDebugLevel() >= 4) {
if ( CmdCurr.nType == 1) {
string sOut = "Cmd=SimulMoveAxes," + ToString( CmdCurr.nMoveType) ;
for ( int i = 0 ; i < int( CmdCurr.vAxNaEpSt.size()) ; ++ i)
@@ -2363,9 +2403,13 @@ SimulatorMP::ExecCmdData( int& nStatus)
"," + ToString( CmdCurr.vAxNaEpSt[i].dStep, 3) ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
}
else {
string sOut = "Cmd=SimulSaveCmd," + ToString( CmdCurr.nType) + "," + ToString( CmdCurr.nPar) + "," + CmdCurr.sPar ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
}
}
// Eseguo
// Eseguo movimento assi
if ( CmdCurr.nType == 1) {
// Numero assi da muovere
int nAxCount = int( CmdCurr.vAxNaEpSt.size()) ;
@@ -2378,7 +2422,7 @@ SimulatorMP::ExecCmdData( int& nStatus)
// Posizione e direzione attuali degli utensili e riferimenti dei pezzi (per Vmill)
bool bExecVmill = (( CmdCurr.nMoveType != 0 || ! NeedCollisionCheck()) && ! m_VmTool.empty() && ! m_VmId.empty()) ;
PNTVECTOR vPtNoseI ;
VCT3DVECTOR vVtDirI ;
VCT3DVECTOR vVtDirI ;
VCT3DVECTOR vVtAuxI ;
vector<Frame3d> vFrVzmI ;
if ( bExecVmill) {
@@ -2461,14 +2505,51 @@ SimulatorMP::ExecCmdData( int& nStatus)
UpdateAxesPos() ;
return false ;
}
UpdateAxesPos() ;
// Aggiorno dati interpolazione
if ( m_dCmdCoeff > COEFF_LIM) {
m_nCmdInd += 1 ;
m_dCmdCoeff = 0 ;
}
}
UpdateAxesPos() ;
// Aggiorno dati interpolazione
if ( m_dCmdCoeff > COEFF_LIM) {
// eseguo impostazione stato
else if ( CmdCurr.nType == 2) {
// imposto
if ( ! m_pGeomDB->SetStatus( CmdCurr.nPar, ( CmdCurr.sPar == "ON" ? GDB_ST_ON : GDB_ST_OFF))) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// Aggiorno indice comandi eseguiti
m_nCmdInd += 1 ;
m_dCmdCoeff = 0 ;
}
// eseguo impostazione modo
else if ( CmdCurr.nType == 3) {
// imposto
if ( ! m_pGeomDB->SetMode( CmdCurr.nPar, ( CmdCurr.sPar == "STD" ? GDB_MD_STD : GDB_MD_HIDDEN))) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// Aggiorno indice comandi eseguiti
m_nCmdInd += 1 ;
m_dCmdCoeff = 0 ;
}
// eseguo chiamata funzione
else if ( CmdCurr.nType == 5) {
// chiamo la funzione
if ( ! m_pMachine->LuaCallFunction( CmdCurr.sPar)) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// Aggiorno indice comandi eseguiti
m_nCmdInd += 1 ;
m_dCmdCoeff = 0 ;
}
// altrimenti errore
else {
nStatus = MCH_SIM_ERR ;
return false ;
}
return true ;
}