#include "pch.h" #include "M_AutoDiagnosisManager/DiagnosisProcessor.h" #include "M_AutoDiagnosisManager/DiagnosisManager.h" //#include "CHReviewSetting/SystemInfo.h" #define M_PI 3.14159265358979323846 #define ToRadian(degree) ( (degree) * (M_PI/180.0) ) #define ToDegree(radian) ( (radian) * (180.0/M_PI) ) enum MotorOriginDirection { MotorOriginDir_LeftTop = 0, MotorOriginDir_RightTop, MotorOriginDir_LeftBottom, MotorOriginDir_RightBottom, MotorOriginDir_Count }; CDiagnosisProcessor::CDiagnosisProcessor() { m_pDP2P = NULL; m_bStartProcess = FALSE; } CDiagnosisProcessor::~CDiagnosisProcessor() { } BOOL CDiagnosisProcessor::StartProcess(int nProcessMode/* = 0*/) { BOOL bRet = FALSE; CDiagnosisProcessData* pThreadData = new CDiagnosisProcessData(this); if (pThreadData) { pThreadData->nProcessMode = nProcessMode; bRet = CreateWorkThread(pThreadData); m_bStartProcess = bRet; } return bRet; } void CDiagnosisProcessor::StopProcess() { m_bStartProcess = FALSE; int nSelModuleIndex = m_pDP2P->IDP2P_GetSelectedModuleIndex(); m_pDP2P->IDP2P_SetAFMTracking(nSelModuleIndex, FALSE); //m_pDP2P->IDP2P_DiagnosisSendCompleteSig(); CloseWorkThread(); } void CDiagnosisProcessor::WorkThreadProcess(PVOID pParameter) { if (pParameter == NULL) return; CString strMessage = ""; CDiagnosisProcessData* pProcessData = static_cast(pParameter); int nProcessMode = pProcessData->nProcessMode; switch (nProcessMode) { case DiagnosisMode_All: //taek ProcessAll 일때와 아닐때를 구분하자 m_pManager->m_bProcessAll = true; ProcessAll(); break; //#3514_LYW_CF AOI Review 자가진단 기능 개선_START case DiagnosisMode_Review : strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisMode_Review START")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); m_pManager->m_bProcessAll = false; if (IsCommandStop()) return; m_pDP2P->IDP2P_SetDialogTap(0); ProcessSquareness(); Sleep(1000); if (IsCommandStop()) return; m_pDP2P->IDP2P_SetDialogTap(1); ProcessFlatness(); Sleep(1000); if (ProcessDiagnosisJudge(nProcessMode) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisJudge FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisMode_Review END")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); break; case DiagnosisMode_Wsi: strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisMode_WSI START")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); m_pManager->m_bProcessAll = false; if (IsCommandStop()) return; m_pDP2P->IDP2P_UpdateDialog(7); ProcessWsi(); Sleep(1000); if (ProcessDiagnosisJudge(nProcessMode) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisJudge FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisMode_WSI END")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); break; case DiagnosisMode_Squareness: m_pManager->m_bProcessAll = false; ProcessSquareness(); Sleep(1000); if (ProcessDiagnosisJudge(nProcessMode) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisJudge FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } break; //#3514_LYW_CF AOI Review 자가진단 기능 개선_END case DiagnosisMode_Flatness: m_pManager->m_bProcessAll = false; ProcessFlatness(); Sleep(1000); if (ProcessDiagnosisJudge(nProcessMode) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisJudge FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } break; case DiagnosisMode_Flatness_Manual: m_pManager->m_bProcessAll = false; // ProcessFlatness_Manual(); break; case DiagnosisMode_Simulation: m_pManager->m_bProcessAll = false; // ProcessSimulation(); break; } //m_pManager->SaveDiagnosisFile(); } int CDiagnosisProcessor::ProcessAll() { if (IsCommandStop()) return 1; CString strMessage = ""; m_pDP2P->IDP2P_UpdateDialog(7);//WSI Result 칸 초기화 //if (m_pDP2P == NULL) return 0; m_pDP2P->IDP2P_SetDialogTap(0); ProcessSquareness(); Sleep(1000); if (IsCommandStop()) return 1; if ( m_pManager->GetDiagnosisInfo()->GetPanelCount_Wsi() > 0) { m_pDP2P->IDP2P_SetDialogTap(2); ProcessWsi(); Sleep(1000); if (IsCommandStop()) return 1; } m_pDP2P->IDP2P_SetDialogTap(1); ProcessFlatness(); //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //Sleep(2000); Sleep(1000); if (ProcessDiagnosisJudge(DiagnosisMode_All) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] DiagnosisJudge FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } //#3514_LYW_CF AOI Review 자가진단 기능 개선_START m_pManager->m_bProcessAll = false; return 1; } int CDiagnosisProcessor::ProcessSquareness() { m_pDP2P->IDP2P_UpdateDialog(3); if (m_pDP2P == NULL || m_pManager == NULL) return 0; int nResultCount = 0; for(int i=0; i<2;i++) { CDiagnosisInfo* pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) { m_pDP2P->IDP2P_UpdateDialog(4); return 0; } //int nSelModuleIndex = m_pDP2P->IDP2P_GetSelectedModuleIndex(); int nSelModuleIndex = i; int nPanelCount = pSettingInfo->GetPanelCount_Squareness(); CDiagnosisResult* pSettingResult = pSettingInfo->GetSettingResult_Squareness(nSelModuleIndex); if (pSettingResult == NULL) { m_pDP2P->IDP2P_UpdateDialog(4); return 0; } CDiagnosisResult* pProcessResult = m_pManager->GetDiagnosisResult_Squareness(nSelModuleIndex); if (pProcessResult == NULL) { m_pDP2P->IDP2P_UpdateDialog(4); return 0; } DWORD dwTime = GetTickCount(), dwTimeMotionEnd = 0; CString strMessage = _T(""); if (nSelModuleIndex == 0) { m_pDP2P->IDP2P_MotorGo(1, 300, 400); if (m_pDP2P->IDP2P_GetMotionEnd(1) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(4); return FALSE; } } else { m_pDP2P->IDP2P_MotorGo(0, 300, 400); if (m_pDP2P->IDP2P_GetMotionEnd(0) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(4); return FALSE; } } pProcessResult->SetPanelCount_Squareness(nPanelCount); double dPosX = 0, dPosY = 0; int nIndex = 0; for (int nIdx=0; nIdxIDP2P_UpdateDialog(4); return 1; } SPositionData* pSettingPoint = pSettingResult->GetPositionData_Squareness(nIdx); if (pSettingPoint == NULL) continue; if (nSelModuleIndex == 0) { if (nIdx == 0) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX();//1039.367; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY();// 258.97; } else if (nIdx == 1) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX3(); // 1039.383; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY3(); // 2562.295; } else if (nIdx == 2) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX5(); // 1039.367 + a; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY5(); // 258.97; } } else { if (nIdx == 0) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX2();// 1704.449; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY2();// 59.723; } else if (nIdx == 1) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX4(); // 1704.407; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY4(); // 2363.057; } else if (nIdx == 2) { pSettingPoint->dPosX = pSettingInfo->GetReviewPanelPosX6(); // 1704.449 + a; pSettingPoint->dPosY = pSettingInfo->GetReviewPanelPosY6(); // 59.723; } } // move panel m_pDP2P->IDP2P_MotorGo(nSelModuleIndex, pSettingPoint->dPosX, pSettingPoint->dPosY); if (m_pDP2P->IDP2P_GetMotionEnd(nSelModuleIndex) == FALSE) continue; int stTime = GetTickCount(); while (1) { //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //if (11000 <= GetTickCount() - stTime) //#3514_LYW_CF AOI Review 자가진단 기능 개선_END if (1500 <= GetTickCount() - stTime) { break; } } m_pDP2P->IDP2P_SetAFMTracking(nSelModuleIndex, TRUE); //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //Sleep(1000); Sleep(1000); //#3514_LYW_CF AOI Review 자가진단 기능 개선_END CString strimagename; strimagename.Format(_T("%s_Module[%d]Index[%d].bmp"), m_pManager->m_strResultImageFileName, nSelModuleIndex, nIdx); // find mark at panel double dFindPixX = 0., dFindPixY = 0.; if (m_pDP2P->IDP2P_FindPanelCenter(nSelModuleIndex, dFindPixX, dFindPixY, strimagename) == FALSE) { strMessage.Format(_T("[CDiagnosisProcessor] find mark at panel FAIL")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); continue; } m_pDP2P->IDP2P_SetAFMTracking(nSelModuleIndex, FALSE); stTime = GetTickCount(); while (1) { if (1000 <= GetTickCount() - stTime) { break; } } if (nSelModuleIndex == 1) { nResultCount = nIdx + 3; } else { nResultCount = nIdx; } // set result SPositionData* pResultPoint = pProcessResult->GetPositionData_Squareness(nResultCount); if (pResultPoint == NULL) continue; pResultPoint->nIndex = nResultCount; pResultPoint->nPosMode = nIdx; pResultPoint->nModuleIdx = nSelModuleIndex; pResultPoint->bProcsss = TRUE; pResultPoint->dPixelX = dFindPixX; pResultPoint->dPixelY = dFindPixY; pResultPoint->dPosX = pSettingPoint->dPosX; pResultPoint->dPosY = pSettingPoint->dPosY; nResultCount += 1; m_pDP2P->IDP2P_UpdateDialog(0); // update calc theta } // calc gantry squareness CalculateSquareness(nSelModuleIndex); //if (CalculateSquareness() == FALSE) return FALSE; strMessage.Format(_T("[AutoDiagnosisProcessor] ProcessSquareness Time [%d]ms"), GetTickCount() - dwTime); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); // make history data m_pManager->SaveDiangosisHistory_Squareness(); //taek 측정 히스토리 남긴다 m_pManager->SaveDiagnosisFile_Squareness(); m_pDP2P->IDP2P_UpdateDialog(0); // update calc theta if (nSelModuleIndex == 1) { m_pDP2P->IDP2P_MotorGo(1, 300, 400); if (m_pDP2P->IDP2P_GetMotionEnd(1) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(4); return FALSE; } } } m_pDP2P->IDP2P_UpdateDialog(4); return TRUE; } int CDiagnosisProcessor::ProcessWsi() { m_pDP2P->IDP2P_UpdateDialog(5); //버튼 끄기 if (m_pDP2P == NULL || m_pManager == NULL) return 0; const CDiagnosisInfo* pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return 0; } int nSelModuleIndex = -1; int nPanelCount = pSettingInfo->GetPanelCount_Wsi(); double dXpos = 0; double dYpos = 0; for (int i = 0; i < nPanelCount; i++) { nSelModuleIndex = i; m_pManager->setWSIVLSIEnd(FALSE); if (nSelModuleIndex == -1) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } if (nSelModuleIndex == 0) { m_pDP2P->IDP2P_MotorGo(1, 300, 400); if (m_pDP2P->IDP2P_IsGantryMotionEnd(1) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } dXpos = pSettingInfo->GetPanelPosX_Wsi(); dYpos = pSettingInfo->GetPanelPosY_Wsi(); } else { m_pDP2P->IDP2P_MotorGo(0, 300, 400); if (m_pDP2P->IDP2P_IsGantryMotionEnd(0) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } dXpos = pSettingInfo->GetPanelPosX2_Wsi(); dYpos = pSettingInfo->GetPanelPosY2_Wsi(); } DWORD dwTime = GetTickCount(), dwTimeMotionEnd = 0; CString strMessage = _T(""); if (IsCommandStop()) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return 1; } m_pDP2P->IDP2P_SetWsiManualMeasure(nSelModuleIndex, dXpos, dYpos); // move panel //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //Sleep(2000); Sleep(1000); //#3514_LYW_CF AOI Review 자가진단 기능 개선_END m_pDP2P->IDP2P_MotorGo(nSelModuleIndex, dXpos, dYpos); if (m_pDP2P->IDP2P_IsGantryMotionEnd(nSelModuleIndex) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } int stTime = GetTickCount(); while (1) { //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //if (10000 <= GetTickCount() - stTime) if (11000 <= GetTickCount() - stTime) //#3514_LYW_CF AOI Review 자가진단 기능 개선_END { break; } } m_pDP2P->IDP2P_WsiMotorMotionEnd(nSelModuleIndex, dXpos, dYpos); int tickcount = GetTickCount(); while (1) { Sleep(50); if (m_pManager->getWSIVLSIEnd() == true) { strMessage.Format(_T("[AutoDiagnosisProcessor] WSI VLSI END")); if (nSelModuleIndex == 1) { m_pDP2P->IDP2P_MotorGo(1, 300, 400); if (m_pDP2P->IDP2P_IsGantryMotionEnd(1) == FALSE) { m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } } // make history data m_pManager->SaveDiangosisHistory_Wsi(); //taek 측정 히스토리 남긴다 //taek 종료 되기 전에 save m_pManager->SaveDiagnosisFile_Wsi(); break; } if (30000 <= (GetTickCount() - tickcount)) { strMessage.Format(_T("[AutoDiagnosisProcessor] WSI VLSI OVER TIME")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return FALSE; } } //} } m_pDP2P->IDP2P_UpdateDialog(6); //버튼 켜기 return TRUE; } int CDiagnosisProcessor::ProcessFlatness() { if (m_pDP2P == NULL || m_pManager == NULL) return 0; CString strMessage = ""; CDiagnosisInfo * pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) return 0; //#3514_LYW_CF AOI Review 자가진단 기능 개선_START if (pSettingInfo->GetFlastnessSkipMode() == TRUE) { strMessage.Format(_T("[CDiagnosisProcessor] FlastnessSkipMode!")); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); return 0; } //#3514_LYW_CF AOI Review 자가진단 기능 개선_END int nSelModuleIndex = m_pDP2P->IDP2P_GetSelectedModuleIndex(); int nFlatnessMode = pSettingInfo->GetFlatnessMode(); int nTotalCount = pSettingInfo->GetRangeCount_Flatness(); CDiagnosisResult * pProcessResult = m_pManager->GetDiagnosisResult_Flatness(); if (pProcessResult == NULL) return 0; pProcessResult->SetRangeCount_Flatness(nTotalCount); pProcessResult->SetFlatnessMode(nFlatnessMode); pProcessResult->SetPositionData_Flatness(nTotalCount); SPositionData * pResultPoint = pProcessResult->GetPositionData_Flatness(0); if (pResultPoint == NULL) return 0; int nGlassSizeX = pSettingInfo->GetGlassSizeX_Flatness(); int nGlassSizeY = pSettingInfo->GetGlassSizeY_Flatness(); int nAFDelay = pSettingInfo->GetAFDelay(); pProcessResult->PathScheduling_Flatness(pResultPoint, nGlassSizeX, nGlassSizeY); m_pDP2P->IDP2P_MotorGo(1, 0, 0); if (m_pDP2P->IDP2P_IsGantryMotionEnd(1) == FALSE) { return FALSE; } for (int nIdx = 0; nIdx < nTotalCount; nIdx++) { if (IsCommandStop()) return 1; double dZpos = 0.; if (nIdx == 0) // if 1st point, afm tracking on { // AF Home m_pDP2P->IDP2P_AFMHomePosition(0); //#3514_LYW_CF AOI Review 자가진단 기능 개선_START //Sleep(5000); Sleep(1000); //#3514_LYW_CF AOI Review 자가진단 기능 개선_END m_pDP2P->IDP2P_SetAFMTracking(0, TRUE); Sleep(500); } // if (nIdx == 0) // { // pResultPoint[nIdx].dPosX = 657.425 // ; // pResultPoint[nIdx].dPosY = 540.14 // ; // } // else if (nIdx == 1) // { // pResultPoint[nIdx].dPosX = 657.425 // ; // pResultPoint[nIdx].dPosY = 2278.636 // ; // } // else if (nIdx == 2) // { // pResultPoint[nIdx].dPosX = 2096.944 // ; // pResultPoint[nIdx].dPosY = 540.141 // ; // } // else if (nIdx == 3) // { // pResultPoint[nIdx].dPosX = 2096.944 // ; // pResultPoint[nIdx].dPosY = 2278.636; // } //1. 모터를 이동 m_pDP2P->IDP2P_MotorGo(0, pResultPoint[nIdx].dPosX, pResultPoint[nIdx].dPosY); if (m_pDP2P->IDP2P_GetMotionEnd(0) == FALSE) continue; //2. AF Delay Sleep(nAFDelay); //3. Z축 값 얻어오기 m_pDP2P->IDP2P_GetAFMZPosition(0, dZpos); // set result pResultPoint[nIdx].dPosZ = dZpos/1000.0; m_pDP2P->IDP2P_SetDlgFlatness(nIdx); } //AFM Tracking OFF m_pDP2P->IDP2P_SetAFMTracking(0, FALSE); // make 3d data file m_pManager->SaveDiagnosis3DImageFile_Flatness(); // make result file m_pManager->SaveDiagnosisFile_Flatness(nFlatnessMode); m_pDP2P->IDP2P_UpdateDialog(2); return TRUE; } int CDiagnosisProcessor::ProcessFlatness_Manual() { if (m_pDP2P == NULL) return 0; int nSelModuleIndex = m_pDP2P->IDP2P_GetSelectedModuleIndex(); double dPosZ = 0.; // AF Home m_pDP2P->IDP2P_AFMHomePosition(nSelModuleIndex); Sleep(5000); // AF Tracking ON m_pDP2P->IDP2P_SetAFMTracking(nSelModuleIndex, TRUE); Sleep(500); // get Z Value m_pDP2P->IDP2P_GetAFMZPosition(nSelModuleIndex, dPosZ); //AFM Tracking OFF m_pDP2P->IDP2P_SetAFMTracking(nSelModuleIndex, FALSE); CString strPosZ; strPosZ.Format(_T("Position Z : %6lf"), dPosZ); AfxMessageBox(strPosZ); return TRUE; } int CDiagnosisProcessor::ProcessSimulation() { if (m_pDP2P == NULL || m_pManager == NULL) return 0; CDiagnosisInfo * pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) return 0; int nSelModuleIndex = m_pDP2P->IDP2P_GetSelectedModuleIndex(); int nFlatnessMode = pSettingInfo->GetFlatnessMode(); int nTotalCount = pSettingInfo->GetRangeCount_Flatness(); CDiagnosisResult * pProcessResult = m_pManager->GetDiagnosisResult_Flatness(); if (pProcessResult == NULL) return 0; pProcessResult->SetRangeCount_Flatness(nTotalCount); pProcessResult->SetFlatnessMode(nFlatnessMode); pProcessResult->SetPositionData_Flatness(nTotalCount); SPositionData * pResultPoint = pProcessResult->GetPositionData_Flatness(nSelModuleIndex); if (pResultPoint == NULL) return 0; int nGlassSizeX = pSettingInfo->GetGlassSizeX_Flatness(); int nGlassSizeY = pSettingInfo->GetGlassSizeY_Flatness(); int nAFDelay = pSettingInfo->GetAFDelay(); pProcessResult->PathScheduling_Flatness(pResultPoint, nGlassSizeX, nGlassSizeY); double dTempPosZ = 0.; for (int nIdx = 0; nIdx < nTotalCount; nIdx++) { pResultPoint[nIdx].dPosZ = dTempPosZ++; Sleep(50); m_pDP2P->IDP2P_SetDlgFlatness(nIdx); } // make 3d data file m_pManager->SaveDiagnosis3DImageFile_Flatness(); // make result file m_pManager->SaveDiagnosisFile_Flatness(nFlatnessMode); return TRUE; } int CDiagnosisProcessor::ProcessDiagnosisJudge(int nMode) { for (int i = 0; i < 2; i++) { int nSelModuleIndex = i; CDiagnosisInfo* pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) { m_pDP2P->IDP2P_UpdateDialog(4); return 0; } CDiagnosisResult* pProcessResult = m_pManager->GetDiagnosisResult_Squareness(nSelModuleIndex); // 0412 kyh 직각도 측정 모듈에 대한 결과정보 if (pProcessResult == NULL) { m_pDP2P->IDP2P_UpdateDialog(4); return 0; } CDiagnosisResult* pProcessWSIResult = m_pManager->GetDiagnosisResult_Wsi(nSelModuleIndex); // 0412 kyh WSI 측정 모듈에 대한 결과 정보 if (pProcessWSIResult == NULL) { m_pDP2P->IDP2P_UpdateDialog(6); return 0; } CString strMessage = _T(""); if (nMode == DiagnosisMode_All || nMode == DiagnosisMode_Review || nMode == DiagnosisMode_Squareness) { double dDate = (90 - pProcessResult->GetGantryDegree()); if (abs(dDate) >= abs(pSettingInfo->GetJudgeData_Degree())) // 0412 kyh 직각도에서 나온 Dgree 값이 설정한 Judge 값보다 크거나 같을경우 { m_pDP2P->IDP2P_DiagnosisSendJudgeAlarm(); // 알람 발생 strMessage.Format(_T("[Judge Data] [Gantry %d]Diagnosis Error ! GantryDegree[%lf] Judge[%lf]"), i, dDate, pSettingInfo->GetJudgeData_Degree()); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } } if (nMode == DiagnosisMode_All || nMode == DiagnosisMode_Wsi) { if (pProcessWSIResult->getWSI_RTB() >= pSettingInfo->GetJudgeData_3Sigma() || pProcessWSIResult->getWSI_RTB() <= 0) // 0412 kyh WSI 표준편차 비교 { m_pDP2P->IDP2P_DiagnosisSendJudgeAlarm(); // 알람 발생 strMessage.Format(_T("[Judge Data] [WSI %d]Diagnosis Error ! WSI RTB[%lf] Judge[%lf]"), i, pProcessWSIResult->getWSI_RTB(), pSettingInfo->GetJudgeData_3Sigma()); m_pDP2P->IDP2P_DisplayMessage(0, strMessage); } } } //#3407 KYH 자가진단 Judge 판정 및 알람 발생 기능 ADD END //컴플릿트 신호 보내기 m_pDP2P->IDP2P_DiagnosisSendCompleteSig(); return 1; } BOOL CDiagnosisProcessor::CalculateSquareness(int nIndex) { if (m_pDP2P == NULL || m_pManager == NULL) return 0; int nSelModuleIndex = nIndex; // setting info const CDiagnosisInfo* pSettingInfo = m_pManager->GetDiagnosisInfo(); if (pSettingInfo == NULL) return 0; const CDiagnosisResult* pSettingResult = pSettingInfo->GetSettingResult_Squareness(nSelModuleIndex); if (pSettingResult == NULL) return 0; // find result CDiagnosisResult* pProcessResult = m_pManager->GetDiagnosisResult_Squareness(nSelModuleIndex); if (pProcessResult == NULL) return 0; int nPanelCount = pProcessResult->GetPanelCount_Squareness(); double dFrameWidth = pSettingInfo->GetCameraFrameWidth(); double dFrameHeight = pSettingInfo->GetCameraFrameHeight(); double dResol = pSettingInfo->GetCameraResolution(); // calc image direction //enum MotorOriginDirection { MotorOriginDir_LeftTop=0, MotorOriginDir_RightTop, MotorOriginDir_LeftBottom, MotorOriginDir_RightBottom, MotorOriginDir_Count }; int nDirX[2] = { 0, }, nDirY[2] = { 0, }; int nMotorDir = m_pDP2P->IDP2P_GetOrigionMotorDir() + nSelModuleIndex; switch (nMotorDir) { case MotorOriginDir_LeftTop: nDirX[nSelModuleIndex] = 1; nDirY[nSelModuleIndex] = 1; break; case MotorOriginDir_LeftBottom: nDirX[nSelModuleIndex] = 1; nDirY[nSelModuleIndex] = -1; break; case MotorOriginDir_RightTop: nDirX[nSelModuleIndex] = -1; nDirY[nSelModuleIndex] = 1; break; case MotorOriginDir_RightBottom: nDirX[nSelModuleIndex] = -1; nDirY[nSelModuleIndex] = -1; break; } switch (nPanelCount) { case 2: { double dMotorPosX[2] = { 0, }; double dMotorPosY[2] = { 0, }; double dPixelPosX[2] = { 0, }; double dPixelPosY[2] = { 0, }; for (int nIdx = 0; nIdx < nPanelCount; nIdx++) { const SPositionData* pSettingPos = pSettingResult->GetPositionData_Squareness(nIdx); const SPositionData* pDataPos = pProcessResult->GetPositionData_Squareness(nIdx); if (pSettingPos == NULL || pDataPos == NULL) continue; dMotorPosX[nIdx] = pSettingPos->dPosX; dMotorPosY[nIdx] = pSettingPos->dPosY; dPixelPosX[nIdx] = pDataPos->dPixelX; dPixelPosY[nIdx] = pDataPos->dPixelY; } // calc degree double dCenter2MarkX[2] = { 0, }; double dCenter2MarkY[2] = { 0, }; dCenter2MarkX[0] = (dPixelPosX[0] - dFrameWidth / 2) * dResol; dCenter2MarkX[1] = (dPixelPosX[1] - dFrameWidth / 2) * dResol; dCenter2MarkY[0] = (dPixelPosY[0] - dFrameHeight / 2) * dResol; dCenter2MarkY[1] = (dPixelPosY[1] - dFrameHeight / 2) * dResol; double dx = abs((dMotorPosX[0] + dCenter2MarkX[0] * nDirX[nSelModuleIndex]) - (dMotorPosX[1] + dCenter2MarkX[1] * nDirX[nSelModuleIndex])); double dy = abs((dMotorPosY[0] + dCenter2MarkY[0] * nDirY[nSelModuleIndex]) - (dMotorPosY[1] + dCenter2MarkY[1] * nDirY[nSelModuleIndex])); double dRadian = -1.0 * atan(dx / dy); double dDegree = ToDegree(dRadian); // trans degree dDegree = 90 - dDegree; pProcessResult->SetGantryDegree(dDegree); break; } case 3: { double dMotorPosX[3] = { 0, }; double dMotorPosY[3] = { 0, }; double dPixelPosX[3] = { 0, }; double dPixelPosY[3] = { 0, }; for (int nIdx = 0; nIdx < nPanelCount; nIdx++) { //LYW 210811 const SPositionData* pSettingPos; const SPositionData* pDataPos; if (nSelModuleIndex == 1) { pSettingPos = pSettingResult->GetPositionData_Squareness(nIdx); pDataPos = pProcessResult->GetPositionData_Squareness(nIdx + 3); } else { pSettingPos = pSettingResult->GetPositionData_Squareness(nIdx); pDataPos = pProcessResult->GetPositionData_Squareness(nIdx); } //LYW 210811 if (pSettingPos == NULL || pDataPos == NULL) continue; dMotorPosX[nIdx] = pSettingPos->dPosX; dMotorPosY[nIdx] = pSettingPos->dPosY; dPixelPosX[nIdx] = pDataPos->dPixelX; dPixelPosY[nIdx] = pDataPos->dPixelY; } // calc gantry degree double dCenter2MarkX[3] = { 0, }; double dCenter2MarkY[3] = { 0, }; dCenter2MarkX[0] = (dPixelPosX[0] - dFrameWidth / 2) * dResol; dCenter2MarkY[0] = (dPixelPosY[0] - dFrameHeight / 2) * dResol; dCenter2MarkX[1] = (dPixelPosX[1] - dFrameWidth / 2) * dResol; dCenter2MarkY[1] = (dPixelPosY[1] - dFrameHeight / 2) * dResol; double dx = abs((dMotorPosX[0] + dCenter2MarkX[0] * nDirX[nSelModuleIndex]) - (dMotorPosX[1] + dCenter2MarkX[1] * nDirX[nSelModuleIndex])); double dy = abs((dMotorPosY[0] + dCenter2MarkY[0] * nDirY[nSelModuleIndex]) - (dMotorPosY[1] + dCenter2MarkY[1] * nDirY[nSelModuleIndex])); double dRadian = -1.0 * atan(dx / dy); double dGantryDegree = ToDegree(dRadian); // calc x scale degree dCenter2MarkX[2] = (dPixelPosX[2] - dFrameWidth / 2) * dResol; dCenter2MarkY[2] = (dPixelPosY[2] - dFrameHeight / 2) * dResol; dx = abs((dMotorPosX[0] + dCenter2MarkX[0] * nDirX[nSelModuleIndex]) - (dMotorPosX[2] + dCenter2MarkX[2] * nDirX[nSelModuleIndex])); dy = abs((dMotorPosY[0] + dCenter2MarkY[0] * nDirY[nSelModuleIndex]) - (dMotorPosY[2] + dCenter2MarkY[2] * nDirY[nSelModuleIndex])); dRadian = -1.0 * atan(dy / dx); double dScaleDegree = ToDegree(dRadian); // trans degree - select //double dDegree = 90 - dGantryDegree; double dDegree = 90 - dGantryDegree - dScaleDegree; // calc virtual x panel position double dv = 0., dx2 = 0., dy2 = 0.; if (dy > dx) { dx2 = dy; dv = dx2 / cos(dRadian); dy2 = dx2 * tan(dRadian); SPositionData* dataCalc = pProcessResult->GetPositionData_CalcResult(); if (dataCalc) { dataCalc->dPosAssemX = dMotorPosX[0] + dv; dataCalc->dPosAssemY = dMotorPosY[0] + dy2; } } //taek 210105 pProcessResult->SetGantryDegree(dDegree); pProcessResult->SetXScaleDegree(dScaleDegree); break; } default: break; } return TRUE; }