EgtMachKernel 1.6p4 :

- ampliata Disposizione con gestione movimenti di pezzi con la testa tramite SpecialApply (che richiama script)
- modifiche a Simulatore per gestire queste disposizioni e aggiunti richiami script su diversi eventi
- modifiche a Generatore per gestire queste disposizioni
- varie altre modifiche e migliorie.
This commit is contained in:
Dario Sassi
2016-05-05 07:31:35 +00:00
parent 06a8b15d99
commit b8965da858
37 changed files with 3234 additions and 1898 deletions
+357 -64
View File
@@ -18,6 +18,7 @@
#include "Disposition.h"
#include "Machining.h"
#include "MachiningConst.h"
#include "OutputConst.h"
#include "/EgtDev/Include/EMkToolConst.h"
#include "/EgtDev/Include/EMkOperationConst.h"
@@ -28,10 +29,14 @@ Simulator::Simulator( void)
{
m_pMchMgr = nullptr ;
m_pGeomDB = nullptr ;
m_pMachine = nullptr ;
m_dStep = 5.0 ;
m_nOpId = GDB_ID_NULL ;
m_nOpInd = 0 ;
m_nCLPathId = GDB_ID_NULL ;
m_nCLPathInd = 0 ;
m_nEntId = GDB_ID_NULL ;
m_nEntInd = 0 ;
m_dCoeff = 0 ;
m_AxesName.reserve( 8) ;
m_AxesVal.reserve( 8) ;
@@ -48,10 +53,12 @@ bool
Simulator::Init( MachMgr* pMchMgr)
{
// verifico ambiente
if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 || pMchMgr->GetGeomDB() == nullptr)
if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 ||
pMchMgr->GetGeomDB() == nullptr || pMchMgr->GetCurrMachine() == nullptr)
return false ;
m_pMchMgr = pMchMgr ;
m_pGeomDB = m_pMchMgr->GetGeomDB() ;
m_pMachine = m_pMchMgr->GetCurrMachine() ;
return true ;
}
@@ -68,22 +75,28 @@ Simulator::Start( void)
// imposto fase iniziale
m_pMchMgr->SetCurrPhase( 1) ;
// verifico la disposizione iniziale della macchinata
int nOpId = m_pMchMgr->GetFirstActiveOperation() ;
if ( m_pMchMgr->GetOperationType( nOpId) != OPER_DISP)
m_nOpId = m_pMchMgr->GetFirstActiveOperation() ;
m_nOpInd = 1 ;
if ( m_pMchMgr->GetOperationType( m_nOpId) != OPER_DISP)
return false ;
// definisco tavola variabili globali
bool bOk = m_pMachine->LuaCreateGlobTable( GLOB_VAR) ;
// richiamo gestione evento inizio e fine disposizione
if ( ! OnDispositionStart( m_nOpId, m_nOpInd, 1, true) ||
! OnDispositionEnd())
return false ;
// cerco la prima lavorazione valida
nOpId = m_pMchMgr->GetNextActiveOperation( nOpId) ;
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ;
while ( nOpId != GDB_ID_NULL) {
if ( IsValidMachiningType( m_pMchMgr->GetOperationType( nOpId)) &&
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
while ( m_nOpId != GDB_ID_NULL) {
if ( IsValidMachiningType( m_pMchMgr->GetOperationType( m_nOpId)) &&
pMch != nullptr && ! pMch->IsEmpty())
break ;
nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ;
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
}
if ( nOpId == GDB_ID_NULL)
if ( m_nOpId == GDB_ID_NULL)
return false ;
m_nOpId = nOpId ;
// aggiornamenti legati al cambio di lavorazione (utensile e assi conseguenti)
if ( ! UpdateTool( true) || ! UpdateAxes())
@@ -93,11 +106,22 @@ Simulator::Start( void)
if ( ! GoHome())
return false ;
// richiamo gestione evento inizio lavorazione
++ m_nOpInd ;
if ( ! OnMachiningStart( m_nOpId, m_nOpInd))
return false ;
// determino il primo percorso di lavoro
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ;
m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
m_nCLPathInd = 0 ;
m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ;
m_nEntInd = 0 ;
m_dCoeff = 0 ;
// richiamo gestione evento inizio percorso di lavoro
++ m_nCLPathInd ;
if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd))
return false ;
return true ;
}
@@ -111,53 +135,131 @@ Simulator::Move( int& nStatus)
nStatus = MCH_SIM_ERR ;
return false ;
}
// Se arrivato alla fine dell'interpolazione, recupero una nuova entità
// Se arrivato alla fine dell'interpolazione
if ( m_dCoeff > 0.999) {
// recupero una nuova entità
m_nEntId = m_pGeomDB->GetNext( m_nEntId) ;
m_dCoeff = 0 ;
}
// Se arrivato alla fine di un percorso di lavoro, recupero un nuovo CLpath
while ( m_nEntId == GDB_ID_NULL) {
m_nCLPathId = m_pGeomDB->GetNextGroup( m_nCLPathId) ;
// se non ce ne sono altri, devo passare a una nuova lavorazione
if ( m_nCLPathId == GDB_ID_NULL)
break ;
m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ;
m_dCoeff = 0 ;
// Se arrivato alla fine di un percorso di lavoro
if ( m_nEntId == GDB_ID_NULL) {
// richiamo gestione evento fine percorso di lavoro
if ( ! OnPathEnd()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// recupero un nuovo CLpath
while ( m_nEntId == GDB_ID_NULL) {
m_nCLPathId = m_pGeomDB->GetNextGroup( m_nCLPathId) ;
// se non ce ne sono altri, devo passare a una nuova lavorazione
if ( m_nCLPathId == GDB_ID_NULL)
break ;
m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ;
m_dCoeff = 0 ;
}
// se trovato nuovo CLpath
if ( m_nEntId != GDB_ID_NULL) {
// richiamo gestione evento inizio percorso di lavoro
++ m_nCLPathInd ;
if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd)) {
nStatus = MCH_SIM_ERR ;
return false ;
}
m_nEntInd = 0 ;
}
}
// Se arrivato alla fine di una lavorazione, recupero la successiva valida
while ( m_nCLPathId == GDB_ID_NULL) {
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
while ( m_nOpId != GDB_ID_NULL) {
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
// se non è una lavorazione, verifico se disposizione con cambio di fase
if ( pMch == nullptr) {
// Se arrivato alla fine di una operazione
if ( m_nCLPathId == GDB_ID_NULL) {
// richiamo gestione evento fine operazione
if ( ! OnOperationEnd()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// recupero la successiva valida
while ( m_nCLPathId == GDB_ID_NULL) {
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
while ( m_nOpId != GDB_ID_NULL) {
// se lavorazione valida
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch != nullptr && ! pMch->IsEmpty()) {
// aggiorno utensile e assi conseguenti
if ( ! UpdateTool() || ! UpdateAxes()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
++ m_nOpInd ;
// richiamo gestione evento inizio lavorazione
if ( ! OnMachiningStart( m_nOpId, m_nOpInd)) {
nStatus = MCH_SIM_ERR ;
return false ;
}
break ;
}
// se disposizione con cambio di fase
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pDisp != nullptr) {
// cambio fase
m_pMchMgr->SetCurrPhase( pDisp->GetPhase()) ;
// aggiorno visualizzazione e breve pausa (200 ms)
ExeDraw() ;
Sleep( 200) ;
}
// se con movimenti autonomi
if ( ! pDisp->IsEmpty()) {
// aggiorno utensile e assi conseguenti
if ( ! UpdateTool() || ! UpdateAxes()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
++ m_nOpInd ;
// richiamo gestione evento inizio disposizione
if ( ! OnDispositionStart( m_nOpId, m_nOpInd, pDisp->GetPhase(), false)) {
nStatus = MCH_SIM_ERR ;
return false ;
}
break ;
}
// altrimenti disposizione passiva
else {
++ m_nOpInd ;
// richiamo gestione evento inizio e fine disposizione
if ( ! OnDispositionStart( m_nOpId, m_nOpInd, pDisp->GetPhase(), true) ||
! OnDispositionEnd()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
// aggiorno visualizzazione e breve pausa (200 ms)
ExeDraw() ;
Sleep( 200) ;
}
}
// passo alla operazione successiva
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
}
// se non ce ne sono altre, sono alla fine
if ( m_nOpId == GDB_ID_NULL) {
nStatus = MCH_SIM_END ;
return false ;
}
// aggiorno gli altri dati
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ;
m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
m_nCLPathInd = 0 ;
m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ;
m_nEntInd = 0 ;
m_dCoeff = 0 ;
// richiamo gestione evento inizio percorso di lavoro
if ( m_nEntId != GDB_ID_NULL) {
++ m_nCLPathInd ;
if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd)) {
nStatus = MCH_SIM_ERR ;
return false ;
}
}
// lavorazione valida
else if ( ! pMch->IsEmpty())
break ;
m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ;
}
// se non ce ne sono altre, sono alla fine
if ( m_nOpId == GDB_ID_NULL) {
nStatus = MCH_SIM_END ;
return false ;
}
// aggiorno gli altri dati
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ;
m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ;
m_dCoeff = 0 ;
// aggiorno utensile e assi conseguenti
if ( ! UpdateTool() || ! UpdateAxes()) {
}
// Se inizio di nuova entità
if ( m_nEntId != GDB_ID_NULL && m_dCoeff < EPS_ZERO) {
++ m_nEntInd ;
// richiamo gestione evento inizio entità
if ( ! OnMoveStart()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
@@ -226,10 +328,16 @@ Simulator::Move( int& nStatus)
// Se arrivato a fine interpolazione movimento, salvo posizioni e segnalo
if ( m_dCoeff > 0.999) {
m_AxesVal = AxesEnd ;
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()) {
nStatus = MCH_SIM_ERR ;
return false ;
}
}
// Altrimenti sto muovendomi in uno step
// Altrimenti sto muovendomi all'interno dello step
else
nStatus = MCH_SIM_OK ;
return true ;
@@ -257,9 +365,11 @@ Simulator::GetToolInfo( string& sName, double& dSpeed)
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
return false ;
// Assegno il nome dell'utensile
if ( m_sTool.empty())
return false ;
sName = m_sTool ;
if ( sName.empty()) {
dSpeed = 0 ;
return true ;
}
// Recupero speed
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
return ( pMch != nullptr && pMch->GetParam( MPA_SPEED, dSpeed)) ;
@@ -305,6 +415,11 @@ Simulator::SetStep( double dStep)
bool
Simulator::Stop( void)
{
// reset stato macchina
OnResetMachine() ;
// rimuovo tavola variabili globali
m_pMachine->LuaResetGlobVar( GLOB_VAR) ;
// reset dello stato
m_nOpId = GDB_ID_NULL ;
m_nCLPathId = GDB_ID_NULL ;
m_nEntId = GDB_ID_NULL ;
@@ -317,25 +432,40 @@ bool
Simulator::UpdateTool( bool bForced)
{
// Recupero l'utensile della lavorazione corrente
string sTool ;
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool))
return false ;
if ( ! m_pMchMgr->TdbSetCurrTool( sTool))
return false ;
// se cambiato oppure forzato, attivo l'utensile della lavorazione
if ( sTool != m_sTool || bForced) {
string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
// se forzato, pulisco la testa
if ( bForced)
m_pMchMgr->ResetHeadSet( sHead) ;
if ( pMch != nullptr) {
string sTool ;
if ( ! pMch->GetParam( MPA_TOOL, sTool))
return false ;
if ( ! m_pMchMgr->TdbSetCurrTool( sTool))
return false ;
// se cambiato oppure forzato, attivo l'utensile della lavorazione
if ( sTool != m_sTool || bForced) {
string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
// se forzato, pulisco la testa
if ( bForced)
m_pMchMgr->ResetHeadSet( sHead) ;
// carico l'utensile
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
}
return true ;
}
// Provo con una disposizione
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pDisp != nullptr) {
// recupero i dati
string sTool ; string sHead ; int nExit ;
pDisp->GetToolData( sTool, sHead, nExit) ;
// carico l'utensile
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
return true ;
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
@@ -354,8 +484,171 @@ Simulator::UpdateAxes( void)
bool
Simulator::GoHome( void)
{
// reset stato macchina
OnResetMachine() ;
// porto la macchina in home
m_pMchMgr->ResetAllAxesPos() ;
// assegno valori home degli assi macchina attivi
return m_pMchMgr->GetAllCalcAxesHomePos( m_AxesVal) ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnOperationEnd( void)
{
// se è una lavorazione
Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch != nullptr) {
// richiamo gestione evento fine lavorazione
return OnMachiningEnd() ;
}
// se è una disposizione
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pDisp != nullptr) {
// richiamo gestione evento fine disposizione
return OnDispositionEnd() ;
}
// errore
return false ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_START))
return true ;
// assegno identificativo e indice disposizione
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPID, nOpId) ;
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPIND, nOpInd) ;
// assegno nuovo indice di fase
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PHASE, nPhase) ;
// assegno flag disposizione passiva
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EMPTY, bEmpty) ;
// chiamo la funzione di inizio disposizione
bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_START) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnDispositionEnd( void)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_END))
return true ;
// chiamo la funzione di fine disposizione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_END) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnMachiningStart( int nOpId, int nOpInd)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_START))
return true ;
// assegno identificativo e indice disposizione
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHID, nOpId) ;
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHIND, nOpInd) ;
// chiamo la funzione di inizio disposizione
bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_START) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnMachiningEnd( void)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_END))
return true ;
// chiamo la funzione di fine disposizione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_END) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnPathStart( int nClPathId, int nClPathInd)
{
// assegno identificativo e indice percorso di lavorazione
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHID, nClPathId) ;
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHIND, nClPathInd) ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START))
return bOk ;
// chiamo la funzione di inizio percorso di lavorazione
bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_START) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnPathEnd( void)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END))
return true ;
// chiamo la funzione di fine percorso di lavorazione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_PATH_END) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnMoveStart( void)
{
// verifico richiesta chiamata funzione
CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ;
if ( pCamData == nullptr)
return false ;
int nFlag = pCamData->GetFlag() ;
if ( nFlag < MIN_CALL_SIMUL_MOVE)
return true ;
// assegno dati
bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEID, m_nEntId) ;
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEIND, m_nEntInd) ;
bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FLAG, nFlag) ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START))
return true ;
// chiamo la funzione
bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_START) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnMoveEnd( void)
{
// verifico richiesta chiamata funzione
CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ;
if ( pCamData == nullptr)
return false ;
int nFlag = pCamData->GetFlag() ;
if ( nFlag < MIN_CALL_SIMUL_MOVE)
return true ;
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END))
return true ;
// chiamo la funzione
bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_END) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Simulator::OnResetMachine( void)
{
// verifico esistenza funzione
if ( ! m_pMachine->LuaExistsFunction( ON_RESET_MACHINE))
return true ;
// eseguo reset macchina
bool bOk = m_pMachine->LuaCallFunction( ON_RESET_MACHINE) ;
return bOk ;
}