314 lines
10 KiB
C++
314 lines
10 KiB
C++
#include "Controller.h"
|
|
#include "../Purifier/XTPurifier.h"
|
|
#include "../Purifier/HBD3Purifier.h"
|
|
#include "../camera/GalaxyCamera.h"
|
|
#include "../camera/OPTCamera.h"
|
|
//#include "../Purifier/G4Purifier.h"
|
|
#include "../Purifier/M1Purifier.h"
|
|
#include "../PLC/SignalService.h"
|
|
#include "../Logger.h"
|
|
#include "../SystemInfo.h"
|
|
|
|
|
|
Controller::Controller()
|
|
: m_Machine(nullptr)
|
|
, m_CoreCommunication(nullptr)
|
|
, m_Axis(nullptr)
|
|
, m_StateCtrlWrapper(nullptr)
|
|
, m_SysParamWrapper(nullptr)
|
|
, m_AxisRecordWrapper(nullptr)
|
|
, m_SignalStateWrapper(nullptr)
|
|
, m_sendTdExitFlag(false)
|
|
, m_reg(nullptr){
|
|
|
|
|
|
}
|
|
|
|
|
|
Controller::~Controller() {
|
|
StopSend();
|
|
|
|
m_CoreCommunication->Shutdown();
|
|
DELP(m_CoreCommunication);
|
|
DELP(m_Axis);
|
|
DELP(m_StateCtrlWrapper);
|
|
DELP(m_SysParamWrapper);
|
|
DELP(m_AxisRecordWrapper);
|
|
DELP(m_SignalStateWrapper);
|
|
|
|
if (m_ComServer) m_ComServer->Shutdown();
|
|
DELP(m_ComServer);
|
|
DELP(m_RemoteClient);
|
|
DELP(m_MachineCtrl);
|
|
DELP(m_ScannerCtrl);
|
|
|
|
if (m_InfraredTemp){
|
|
m_InfraredTemp->Shutdown();
|
|
DELP(m_InfraredTemp);
|
|
}
|
|
|
|
DELP(m_Calibration);
|
|
DELP(m_Purifier);
|
|
DELP(m_reg);
|
|
|
|
BaseCtrl::SUninit();
|
|
}
|
|
|
|
|
|
void Controller::Init(){
|
|
BaseCtrl::SInit();
|
|
m_jobController.SInit();
|
|
|
|
m_CoreCommunication = new CoreCommunication();
|
|
m_CoreCommunication->SetIOCfgWrapper(ConfigManager::GetInstance()->GetIoCfgWrapper());
|
|
m_CoreCommunication->SetSysParamWrapper(m_SysParamWrapper);
|
|
m_CoreCommunication->SetPLCAxis(m_Axis);
|
|
m_CoreCommunication->SetAlarmStateWrapper(m_SignalStateWrapper);
|
|
m_CoreCommunication->SetAxisRecordWrapper(m_AxisRecordWrapper);
|
|
m_CoreCommunication->Init();
|
|
m_CoreCommunication->Startup();
|
|
|
|
m_SysParamWrapper = new SysParamWrapper;
|
|
m_SysParamWrapper->Init(m_CoreCommunication);
|
|
m_StateCtrlWrapper = new StateCtrlWrapper;
|
|
m_StateCtrlWrapper->Init(m_CoreCommunication);
|
|
m_AxisRecordWrapper = new AxisRecordWrapper;
|
|
m_AxisRecordWrapper->Init(m_CoreCommunication);
|
|
|
|
m_SignalStateWrapper = new SignalStateWrapper();
|
|
m_Machine = ConfigManager::GetInstance()->GetMachine();
|
|
m_Machine->InitSignal(m_SignalStateWrapper, m_CoreCommunication);
|
|
//m_Machine->InitSysParam(m_SysParamWrapper, m_CoreCommunication);
|
|
m_Axis = new PLCAxis(m_SysParamWrapper, m_StateCtrlWrapper);
|
|
m_Machine->SetAxisAndSignal(m_SysParamWrapper, m_AxisRecordWrapper, m_Axis);
|
|
|
|
SignalService::GetInstance().SetSignalStateCtrl(m_SignalStateWrapper);
|
|
|
|
m_MachineCtrl = new MachineCtrl();
|
|
m_MachineCtrl->Init(m_CoreCommunication, m_SysParamWrapper, m_SignalStateWrapper, m_Axis);
|
|
|
|
m_Machine->SetMachineCtrl(m_MachineCtrl);
|
|
m_MachineCtrl->MachineStartup();
|
|
|
|
m_MachineCfg = ConfigManager::GetInstance()->GetMachineCfg();
|
|
m_ComServer = new ComServer(); //辅机服务
|
|
m_ComServer->Init();
|
|
|
|
m_ScannerCtrl = new ScannerCtrl(/*m_ServoManager*/);
|
|
m_ScannerCtrl->SetJobController(&m_jobController);
|
|
m_ScannerCtrl->Init();
|
|
m_ScannerCtrl->SetScannerPowerClient(m_ComServer->m_ScannerPowerClient);
|
|
|
|
m_ComServer->m_ScannerPowerClient->Init();
|
|
m_ComServer->Startup();
|
|
|
|
m_RemoteClient = new RemoteClient(nullptr, nullptr/*m_ScannerCtrl*/);
|
|
m_RemoteClient->Init();
|
|
//m_RemoteClient->SetCamera( nullptr /*m_Camera*/);
|
|
if (m_RemoteClient->GetConfig()->m_Enable->GetValue()) {
|
|
m_RemoteClient->StartRemote();
|
|
}
|
|
m_ScannerCtrl->SetRemoteClient(m_RemoteClient);
|
|
|
|
m_ScannerCtrl->SetMachineCtrl(m_MachineCtrl);
|
|
|
|
switch (m_MachineCfg->m_PulifierType->GetValue())
|
|
{
|
|
//case PurifierTypeCfg::HBD_PURIFIER_1: {
|
|
// m_Purifier = new HBD1Purifier(m_GTSController->GetDacState(),m_ScannerCtrl);
|
|
//
|
|
//}break;
|
|
case PurifierTypeCfg::XT: {
|
|
m_Purifier = new XTPurifier(m_ScannerCtrl);
|
|
}break;
|
|
case PurifierTypeCfg::HBD_PURIFIER_3: {
|
|
m_Purifier = new HBD3Purifier(m_ScannerCtrl);
|
|
}break;
|
|
case PurifierTypeCfg::M1: {
|
|
m_Purifier = new M1Purifier(m_ScannerCtrl);
|
|
}break;
|
|
//case PurifierTypeCfg::HBD_PURIFIER_2: {
|
|
// m_Purifier = new HBD2Purifier(m_GTSController->GetDacState(), m_ScannerCtrl);
|
|
//}break;
|
|
default:
|
|
m_Purifier = new XTPurifier(m_ScannerCtrl);
|
|
}
|
|
m_Purifier->Init();
|
|
|
|
m_reg = new Registration();
|
|
|
|
m_ExtCfg = ConfigManager::GetInstance()->GetExtCfg();
|
|
if (m_ExtCfg->m_CameraType == ExtCfg::Galaxy) {
|
|
m_Camera = new GalaxyCamera();
|
|
}
|
|
else if (m_ExtCfg->m_CameraType == ExtCfg::OPT) {
|
|
m_Camera = new OPTCamera();
|
|
}
|
|
else {
|
|
m_Camera = new GalaxyCamera();
|
|
}
|
|
if (m_ExtCfg->m_UseCamera) {
|
|
if (m_Camera->Init()) {
|
|
m_Camera->StartUp();
|
|
}
|
|
}
|
|
|
|
m_jobController.StartLoadPrepareJob();
|
|
|
|
m_InfraredTempCfg = ConfigManager::GetInstance()->GetInfraredTempCfg();
|
|
m_InfraredTemp = new InfraredTemp();
|
|
m_InfraredTemp->Init();
|
|
m_InfraredTemp->SetJobCtrl(&m_jobController);
|
|
if (m_InfraredTempCfg->m_IsEnable) {
|
|
m_InfraredTemp->Startup();
|
|
}
|
|
|
|
m_ScannerCtrl->SetInfraredTemp(m_InfraredTemp);
|
|
}
|
|
|
|
|
|
void Controller::StartSend() {
|
|
StopSend();
|
|
|
|
m_sendTdExitFlag = false;
|
|
m_sendParamThread = std::thread([this] {
|
|
while (!m_sendTdExitFlag) {
|
|
m_ComServer->SendToClients();
|
|
m_Purifier->SendToClients();
|
|
|
|
//轴参数
|
|
m_Axis->m_Mold->GetState()->SendToClients(AXISMOLD);
|
|
m_Axis->m_MoldSlave->GetState()->SendToClients(AXISMOLDSLAVE);
|
|
m_Axis->m_Clean->GetState()->SendToClients(AXISCLEAN);
|
|
m_Axis->m_CleanSlave->GetState()->SendToClients(AXISCLEANSLAVE);
|
|
m_Axis->m_Load->GetState()->SendToClients(AXISLOAD);
|
|
m_Axis->m_Arm->GetState()->SendToClients(AXISMARM);
|
|
m_Axis->m_Supply->GetState()->SendToClients(AXISMSUPPLY);
|
|
m_Axis->m_Ele->GetState()->SendToClients(AXISELE);
|
|
m_Axis->m_EleSlave->GetState()->SendToClients(AXISELESLAVE);
|
|
|
|
//扫描参数
|
|
static int count = 0;
|
|
++count;
|
|
if (count == 2) { //发送频率降低
|
|
m_ScannerCtrl->SendToClients();
|
|
m_Camera->SendToClients();
|
|
count = 0;
|
|
}
|
|
|
|
m_jobController.SendToClients();
|
|
|
|
this_thread::sleep_for(std::chrono::milliseconds(250));
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
void Controller::StopSend() {
|
|
m_sendTdExitFlag = true;
|
|
if (m_sendParamThread.joinable()) m_sendParamThread.join();
|
|
|
|
}
|
|
|
|
|
|
void Controller::UpdateFile(const string& filePath) {
|
|
m_jobController.LoadJob(filePath);
|
|
}
|
|
|
|
|
|
void Controller::PreperBeforeShow() {
|
|
bool isOpenContinue = false; //返回
|
|
FileProcessor* pjp = m_jobController.GetJob();
|
|
//if (g_log->m_LogDao->GetCheckJob(pjp->GetJobUid(), m_JobAssist.continueJob))
|
|
//{
|
|
// isOpenContinue = true;
|
|
//}
|
|
//vector<PartAddition*> partv;
|
|
//g_log->m_LogDao->FindPartAddition(pjp->GetJobUid(), partv);
|
|
//for (size_t paIndex = 0; paIndex < partv.size(); ++paIndex)
|
|
//{
|
|
// PartAddition* pa = partv[paIndex];
|
|
// MetaData::Part* sourcePart = pjp->GetMetaData()->GetPart(pa->m_SourcePart);
|
|
// MetaData::Part* newPart = sourcePart->CopyPart(pjp->GetMetaData()->GetPartVec().size());
|
|
// newPart->id = pa->m_NewPart;
|
|
// pjp->GetMetaData()->AddPart(newPart);
|
|
// m_Renderer->AddPart(newPart);
|
|
// m_PrevRenderer->AddPart(newPart);
|
|
|
|
//}
|
|
//for (size_t paIndex = 0; paIndex < partv.size(); ++paIndex) {
|
|
// delete partv[paIndex];
|
|
//}
|
|
//partv.clear();
|
|
|
|
//vector<int> partIds;
|
|
//pjp->GetMetaData()->GetPartIds(partIds);
|
|
//g_log->m_LogDao->AddPartPos(pjp->GetJobUid(), partIds);
|
|
|
|
//vector<PartPosBean*> partPosv;
|
|
|
|
//g_log->m_LogDao->FindPartPos(pjp->GetJobUid(), partPosv);
|
|
//for (size_t paIndex = 0; paIndex < partPosv.size(); ++paIndex)
|
|
//{
|
|
// MetaData::Part* ppb = pjp->GetMetaData()->GetPart(partPosv[paIndex]->m_PartId);
|
|
// if (ppb) {
|
|
// ppb->partPosBean.m_XOffset = partPosv[paIndex]->m_XOffset;
|
|
// ppb->partPosBean.m_YOffset = partPosv[paIndex]->m_YOffset;
|
|
// ppb->partPosBean.m_RotateAngle = partPosv[paIndex]->m_RotateAngle;
|
|
// ppb->partPosBean.m_Radians = (float)MathHelper::DegreesToRadians((double)ppb->partPosBean.m_RotateAngle);
|
|
// ppb->partPosBean.m_PartCenterX = ppb->partPosBean.m_XOffset + ppb->partPosBean.m_SrcPartCenterX;
|
|
// ppb->partPosBean.m_PartCenterY = ppb->partPosBean.m_YOffset + ppb->partPosBean.m_SrcPartCenterY;
|
|
// Part* prev_part = m_PrevRenderer->GetPart(ppb->id);
|
|
// if (prev_part)prev_part->UpdateOffset();
|
|
// Part* print_part = m_Renderer->GetPart(ppb->id);
|
|
// if (print_part)print_part->UpdateOffset();
|
|
// }
|
|
//}
|
|
|
|
//for (size_t paIndex = 0; paIndex < partPosv.size(); ++paIndex) {
|
|
// delete partPosv[paIndex];
|
|
//}
|
|
//partPosv.clear();
|
|
|
|
g_log->TraceInfo(g_LngManager->Log_AddTask->ShowText(), pjp->GetJobFileName().c_str());
|
|
|
|
if (m_InfraredTemp->IsConnect() && BaseCtrl::IsStandBy()) {
|
|
pjp->GetMetaData()->LoadPrevLayerByIndex(0);
|
|
///m_UIController.m_InfraredTemp->FindContours(false);
|
|
//m_UIController.m_InfraredTemp->GetLayerRegions(i);
|
|
}
|
|
vector<MetaData::Part*> partve = pjp->GetMetaData()->GetPartVec();
|
|
m_InfraredTemp->ClearTempRegion();
|
|
for (size_t partIndex = 0; partIndex < partve.size(); partIndex++) {
|
|
MetaData::Part* part = partve[partIndex];
|
|
TempRegion* tr = new TempRegion(part->id);
|
|
tr->SetAvgSize(m_InfraredTempCfg->m_AvgCalcValueType->GetValue());
|
|
tr->m_PartMinX = part->dimensions->xmin - 2.0;
|
|
tr->m_PartMaxX = part->dimensions->xmax + 2.0;
|
|
tr->m_PartMinY = part->dimensions->ymin - 2.0;
|
|
tr->m_PartMaxY = part->dimensions->ymax + 2.0;
|
|
tr->m_LastWaitTemp = m_InfraredTempCfg->m_ChillDowmTemp->GetValue();
|
|
//m_UIController.m_InfraredTemp->TranRect(part->dimensions->xmin,part->dimensions->ymin,part->dimensions->xmax,part->dimensions->ymax,tr->startX,tr->startY,tr->endX,tr->endY);
|
|
m_InfraredTemp->CalcRefRegion(tr);
|
|
m_InfraredTemp->AddTempRegion(tr);
|
|
}
|
|
m_Calibration->UpdateData(pjp->GetMetaData());
|
|
|
|
}
|
|
|
|
void Controller::ContinueTask() {
|
|
m_JobAssist.continueJob.m_IsContinue = true;
|
|
FileProcessor* pjp = m_jobController.GetJob();
|
|
pjp->SetJobbean(m_JobAssist.continueJob);
|
|
if (m_JobAssist.continueJob.m_PrintedLayerIndex + 1 < pjp->GetLayerCount()) {
|
|
pjp->SetStartIndex(m_JobAssist.continueJob.m_PrintedLayerIndex + 1);
|
|
pjp->GetMetaData()->CalcRemainTime(m_JobAssist.continueJob.m_PrintedLayerIndex + 1);
|
|
}
|
|
|
|
pjp->GetMetaData()->LoadLayerByIndex(m_JobAssist.continueJob.m_PrintedLayerIndex + 1);
|
|
g_SystemInfo->m_StateBean.remainMil = pjp->GetMetaData()->GetRemainTime();
|
|
g_SystemInfo->m_StateBean.realCostSeconds = m_JobAssist.continueJob.m_PrintSecond;
|
|
g_SystemInfo->m_StateBean.layerIndex = m_JobAssist.continueJob.m_PrintedLayerIndex;
|
|
g_SystemInfo->m_StateBean.jobProgress = g_SystemInfo->m_StateBean.layerIndex / g_SystemInfo->m_StateBean.maxLayerIndex;
|
|
} |