From b5065db6415c664b3de3e9b6549622152489a063 Mon Sep 17 00:00:00 2001 From: tangchao Date: Wed, 16 Feb 2022 12:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=8D=93=E5=93=A5ap?= =?UTF-8?q?t=E7=9A=84=E8=87=AA=E5=8A=A8=E6=9B=9D=E5=85=89=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source_Files/ATPControl_Serial_QT.cpp | 396 ++++++++++++------ .../calibration_console/Source_Files/main.cpp | 6 +- 2 files changed, 282 insertions(+), 120 deletions(-) diff --git a/othersoft/calibration_console/Source_Files/ATPControl_Serial_QT.cpp b/othersoft/calibration_console/Source_Files/ATPControl_Serial_QT.cpp index 1fd9803..82f1948 100644 --- a/othersoft/calibration_console/Source_Files/ATPControl_Serial_QT.cpp +++ b/othersoft/calibration_console/Source_Files/ATPControl_Serial_QT.cpp @@ -397,137 +397,299 @@ int ZZ_ATPControl_Serial_Qt::Init_Self() int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float& fPredictedExposureTime) { - using namespace ZZ_MATH; - int iDeviceDepth = 65535; +// using namespace ZZ_MATH; +// int iDeviceDepth = 65535; +// +// bool bFlagIsOverTrying = false; +// bool bFlagIsLowerMinExposureTime = false; +// bool bFlagIsOverMaxExposureTime = false; +// bool bFlagIsAutoExposureOK = false; +// bool bFlagIsAutoExposureFailed = false; +// +// bool bIsValueOverflow = false; +// bool bIsLastValueOverflow = false; +// +// float fExposureTime = 0; +// float fTempExposureTime = 0; +// double fLastExposureTime = 0.1; +// int iRepeatCount = 0; +// +// int iRes = SetExposureTime(2000);//need change to load from files +// if (iRes != 0) +// { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1"; +// return 1; +// } +// +// while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed) +// { +// DataFrame dfTemp; +// +// if (iRepeatCount++ > 30) +// { +// bFlagIsAutoExposureFailed = true; +// bFlagIsOverTrying = true; +// break; +// } +// +// fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS; +// fTempExposureTime = fExposureTime; +// +// iRes = SingleShot(dfTemp); +// if (iRes != 0) +// { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2"; +// return 2; +// } +// +// HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels); +// +// double dSum = 0; +// int iCount = m_daDeviceAttr.iPixels / 100; +// for (int i = 0; i < iCount; i++) +// { +// dSum += dfTemp.lData[i]; +// } +// double dTemp = dSum / iCount; +// +// if (dTemp >= iDeviceDepth * 0.99) +// { +// bIsValueOverflow = true; +// if (!bIsLastValueOverflow) +// { +// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; +// } +// else +// { +// fExposureTime = fExposureTime / 2; +// } +// } +// +// else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor) +// { +// bFlagIsAutoExposureOK = 1; +// } +// else if (dTemp > iDeviceDepth * fMaxScaleFactor) +// { +// bIsValueOverflow = true; +// if (!bIsLastValueOverflow) +// { +// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; +// } +// else +// { +// fExposureTime = fExposureTime * 3 / 4; +// } +// } +// else if (dTemp < iDeviceDepth * fMinScaleFactor) +// { +// bIsValueOverflow = false; +// if (bIsLastValueOverflow) +// { +// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; +// } +// else +// { +// double dFactor; +// dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor); +// fExposureTime = (float)(fExposureTime / dFactor); +// } +// if (/*fExposureTime > 100 || */fExposureTime < 10) +// { +// bFlagIsAutoExposureOK = false; +// bFlagIsAutoExposureFailed = true; +// bFlagIsLowerMinExposureTime = true; +// } +// } +// bIsLastValueOverflow = bIsValueOverflow; +// fLastExposureTime = fTempExposureTime; +// +// if (fExposureTime > 13000) +// { +// bFlagIsAutoExposureOK = false; +// bFlagIsAutoExposureFailed = true; +// fPredictedExposureTime = 13000; +// iRes = SetExposureTime(13000); +// if (iRes != 0) +// { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3"; +// return 3; +// } +// bFlagIsOverMaxExposureTime = true; +// break; +// } +// +// iRes = SetExposureTime((int)fExposureTime); +// if (iRes != 0) +// { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4"; +// return 3; +// } +// } +// fPredictedExposureTime = fExposureTime; +// return 0; - bool bFlagIsOverTrying = false; - bool bFlagIsLowerMinExposureTime = false; - bool bFlagIsOverMaxExposureTime = false; - bool bFlagIsAutoExposureOK = false; - bool bFlagIsAutoExposureFailed = false; + int m_iThreadID=0; +// qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID; + using namespace ZZ_MATH; +// float fPredictedExposureTime; + int iDeviceDepth = 65535; - bool bIsValueOverflow = false; - bool bIsLastValueOverflow = false; - float fExposureTime = 0; - float fTempExposureTime = 0; - double fLastExposureTime = 0.1; - int iRepeatCount = 0; - int iRes = SetExposureTime(2000);//need change to load from files - if (iRes != 0) - { - qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1"; - return 1; - } +// qDebug() << "MAX---Min" << fMaxScaleFactor << "---" << fMinScaleFactor << " Thread ID:" << m_iThreadID; - while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed) - { - DataFrame dfTemp; + bool bFlagIsOverTrying = false; + bool bFlagIsLowerMinExposureTime = false; + bool bFlagIsOverMaxExposureTime = false; + bool bFlagIsAutoExposureOK = false; + bool bFlagIsAutoExposureFailed = false; - if (iRepeatCount++ > 30) - { - bFlagIsAutoExposureFailed = true; - bFlagIsOverTrying = true; - break; - } + bool bIsValueOverflow = false; + bool bIsLastValueOverflow = false; - fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS; - fTempExposureTime = fExposureTime; + int iExposureTime = 0; + float fTempExposureTime = 0; + double fLastExposureTime = 0.1; + int iRepeatCount = 0; - iRes = SingleShot(dfTemp); - if (iRes != 0) - { - qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2"; - return 2; - } + //int iRes = m_pFSCtrl->SetExposureTime(1000);//need change to load from files + int iRes = 0; + if (iRes != 0) + { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1" << " Thread ID:" << m_iThreadID; + return 1; + } - HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels); + while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed) + { + DataFrame dfTemp; - double dSum = 0; - int iCount = m_daDeviceAttr.iPixels / 100; - for (int i = 0; i < iCount; i++) - { - dSum += dfTemp.lData[i]; - } - double dTemp = dSum / iCount; + if (iRepeatCount++ > 30) + { + bFlagIsAutoExposureFailed = true; + bFlagIsOverTrying = true; + break; + } + //m_pFSCtrl->SetExposureTime(5000); + GetExposureTime(iExposureTime); +// qDebug() << "Current ExpTime:" << iExposureTime << " Thread ID:" << m_iThreadID; + //m_pFSCtrl->SetExposureTime(2500); + //fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS; + fTempExposureTime = iExposureTime; - if (dTemp >= iDeviceDepth * 0.99) - { - bIsValueOverflow = true; - if (!bIsLastValueOverflow) - { - fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; - } - else - { - fExposureTime = fExposureTime / 2; - } - } + iRes = SingleShot(dfTemp); + //iRes = m_pFSCtrl->SingleShot(dfTemp); + if (iRes != 0) + { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2" << " Thread ID:" << m_iThreadID; + return 2; + } + + HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels); + + double dSum = 0; + int iCount = m_daDeviceAttr.iPixels / 200; + for (int i = 0; i < iCount; i++) + { + dSum += dfTemp.lData[i]; + } + double dTemp = dSum / iCount; + +// qDebug() << "Avg " << dTemp << " Thread ID:" << m_iThreadID; + + if (dTemp >= iDeviceDepth * 0.99) + { + bIsValueOverflow = true; + if (!bIsLastValueOverflow) + { + iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2; + } + else + { + iExposureTime = iExposureTime / 2; + } + } + + else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor) + { +// qDebug() << "trace bFlagIsAutoExposureOK =1 " << iExposureTime << " Thread ID:" << m_iThreadID; + bFlagIsAutoExposureOK = 1; + } + else if (dTemp > iDeviceDepth * fMaxScaleFactor) + { + bIsValueOverflow = true; + if (!bIsLastValueOverflow) + { + iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2; + } + else + { + iExposureTime = iExposureTime * 3 / 4; + } + } + else if (dTemp < iDeviceDepth * fMinScaleFactor) + { + bIsValueOverflow = false; + if (bIsLastValueOverflow) + { + iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2; + } + else + { + double dFactor; + dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor); + iExposureTime = (float)(iExposureTime / dFactor); + } + if (/*fExposureTime > 100 || */iExposureTime < 10) + { + bFlagIsAutoExposureOK = false; + bFlagIsAutoExposureFailed = true; + bFlagIsLowerMinExposureTime = true; + } + } + bIsLastValueOverflow = bIsValueOverflow; + fLastExposureTime = fTempExposureTime; + + if (iExposureTime > 120000) + { + bFlagIsAutoExposureOK = false; + bFlagIsAutoExposureFailed = true; + float fPredictedExposureTime = 120000; + iRes = SetExposureTime(120000); + if (iRes != 0) + { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3" << " Thread ID:" << m_iThreadID; + return 3; + } + else + { + //qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to 30sec"; +// qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to " << m_daDeviceAttr.iMaxIntegrationTimeInMS << "MS" << " Thread ID:" << m_iThreadID; + } + bFlagIsOverMaxExposureTime = true; + break; + } + + iRes = SetExposureTime((int)iExposureTime); + if (iRes != 0) + { +// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4" << " Thread ID:" << m_iThreadID; + return 3; + } + else + { + qDebug() << "Success:PerformAutoExposure. Value" << iExposureTime << " Thread ID:" << m_iThreadID; + } + } + fPredictedExposureTime = iExposureTime; +// qDebug() << "--------------------------Stop PerformAutoExposure" << " Thread ID:" << m_iThreadID; + //emit SignalAcqFinished(m_iThreadID, 1); + + return 0; - else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor) - { - bFlagIsAutoExposureOK = 1; - } - else if (dTemp > iDeviceDepth * fMaxScaleFactor) - { - bIsValueOverflow = true; - if (!bIsLastValueOverflow) - { - fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; - } - else - { - fExposureTime = fExposureTime * 3 / 4; - } - } - else if (dTemp < iDeviceDepth * fMinScaleFactor) - { - bIsValueOverflow = false; - if (bIsLastValueOverflow) - { - fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2; - } - else - { - double dFactor; - dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor); - fExposureTime = (float)(fExposureTime / dFactor); - } - if (/*fExposureTime > 100 || */fExposureTime < 10) - { - bFlagIsAutoExposureOK = false; - bFlagIsAutoExposureFailed = true; - bFlagIsLowerMinExposureTime = true; - } - } - bIsLastValueOverflow = bIsValueOverflow; - fLastExposureTime = fTempExposureTime; - if (fExposureTime > 13000) - { - bFlagIsAutoExposureOK = false; - bFlagIsAutoExposureFailed = true; - fPredictedExposureTime = 13000; - iRes = SetExposureTime(13000); - if (iRes != 0) - { - qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3"; - return 3; - } - bFlagIsOverMaxExposureTime = true; - break; - } - iRes = SetExposureTime((int)fExposureTime); - if (iRes != 0) - { - qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4"; - return 3; - } - } - fPredictedExposureTime = fExposureTime; - return 0; } diff --git a/othersoft/calibration_console/Source_Files/main.cpp b/othersoft/calibration_console/Source_Files/main.cpp index 986a295..fee67c6 100644 --- a/othersoft/calibration_console/Source_Files/main.cpp +++ b/othersoft/calibration_console/Source_Files/main.cpp @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) //自动曝光 logout("
AutoExpose!"); -// m_FiberSpectrometer->autoExpose(); + m_FiberSpectrometer->autoExpose(); //程序sleep:等待关闭快门 @@ -173,7 +173,7 @@ CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *qu QCommandLineOption averageTimes("a", "Average times.", "average_times"); averageTimes.setDefaultValue("5");//设置默认参数 - parser.addOption(averageTimes); + parser.addOption(averageTimes);// QCommandLineOption position("position", "Position.", "position"); parser.addOption(position); @@ -401,7 +401,7 @@ CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *qu } else//默认参数 { - query->calFileOutputName = ""; + query->calFileOutputName = "";//使用此参数时,如果query->calFileOutputName为空 → 会给此变量赋值 } // const QStringList positionalArguments = parser.positionalArguments();