forked from xin/TowerOptoSifAndSpectral
机载第一版
This commit is contained in:
@ -1,6 +1,12 @@
|
||||
#include "AbstractFSController.h"
|
||||
#include "ZZ_Math_HDRONLY.h"
|
||||
#include <math.h>
|
||||
void Delay_MSec(ZZ_U16 usMS)
|
||||
{
|
||||
QEventLoop qeLoop;
|
||||
QTimer::singleShot(usMS, &qeLoop, SLOT(quit()));
|
||||
qeLoop.exec();
|
||||
}
|
||||
CAbstractFSController::CAbstractFSController(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
iFlagInit = 0;
|
||||
@ -13,6 +19,11 @@ CAbstractFSController::CAbstractFSController(QObject* parent /*= nullptr*/)
|
||||
m_qstrCalFilePath = "/home/data/Cal";
|
||||
|
||||
m_vecNonLinearCalP.clear();
|
||||
for (int i=0;i<10;i++) {
|
||||
m_taginfolast.ITtimeChange[i] =true;
|
||||
m_taginfolast.LastMAXValue[i] = 0;
|
||||
m_taginfolast.lastITTIME[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CAbstractFSController::~CAbstractFSController()
|
||||
@ -21,6 +32,7 @@ CAbstractFSController::~CAbstractFSController()
|
||||
{
|
||||
delete m_pFSCtrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int CAbstractFSController::SetRunParas(int iThreadID, FSInfo fsInfo)
|
||||
@ -135,8 +147,19 @@ int CAbstractFSController::GetDeviceAttr(DeviceAttribute &daAttr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::PerformAutoExposure()
|
||||
int CAbstractFSController::PerformAutoExposure(int position)
|
||||
{
|
||||
if (position!=0) {
|
||||
// m_taginfolast.ITtimeChange[position] = true;
|
||||
m_taginfolast.lastITTIME[position] = m_taginfolast.lastITTIME[0]*0.5 ;
|
||||
m_pFSCtrl->SetExposureTime(m_taginfolast.lastITTIME[position] );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||
using namespace ZZ_MATH;
|
||||
float fPredictedExposureTime;
|
||||
@ -153,7 +176,7 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
bool bIsValueOverflow = false;
|
||||
bool bIsLastValueOverflow = false;
|
||||
|
||||
int iExposureTime = 0;
|
||||
int iExposureTime = 1000;
|
||||
float fTempExposureTime = 0;
|
||||
double fLastExposureTime = 0.1;
|
||||
int iRepeatCount = 0;
|
||||
@ -177,9 +200,9 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
break;
|
||||
}
|
||||
//m_pFSCtrl->SetExposureTime(5000);
|
||||
m_pFSCtrl->GetExposureTime(iExposureTime);
|
||||
qDebug() << "Current ExpTime:" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
//m_pFSCtrl->SetExposureTime(2500);
|
||||
// m_pFSCtrl->GetExposureTime(iExposureTime);
|
||||
// qDebug() << "Current ExpTime:" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
m_pFSCtrl->SetExposureTime(iExposureTime);
|
||||
//fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||
fTempExposureTime = iExposureTime;
|
||||
|
||||
@ -270,7 +293,8 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
// {
|
||||
// qDebug() << "Success:PerformAutoExposure. Value" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
// }
|
||||
|
||||
m_taginfolast.ITtimeChange[position] = true;
|
||||
m_taginfolast.lastITTIME[position] = m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||
iRes = m_pFSCtrl->SetExposureTime(m_daDeviceAttr.iMinIntegrationTimeInMS);
|
||||
if (iRes != 0)
|
||||
{
|
||||
@ -301,7 +325,8 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
//{
|
||||
//qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to 30sec";
|
||||
//}
|
||||
|
||||
m_taginfolast.ITtimeChange[position] = true;
|
||||
m_taginfolast.lastITTIME[position] =m_daDeviceAttr.iMaxIntegrationTimeInMS - 1;
|
||||
iRes = m_pFSCtrl->SetExposureTime(m_daDeviceAttr.iMaxIntegrationTimeInMS - 1);
|
||||
if (iRes != 0)
|
||||
{
|
||||
@ -315,7 +340,8 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
m_taginfolast.ITtimeChange[position] = true;
|
||||
m_taginfolast.lastITTIME[position] =(int)iExposureTime;
|
||||
iRes = m_pFSCtrl->SetExposureTime((int)iExposureTime);
|
||||
if (iRes != 0)
|
||||
{
|
||||
@ -335,11 +361,69 @@ int CAbstractFSController::PerformAutoExposure()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::TakeDarkFrame()
|
||||
{
|
||||
qDebug() << "Starting TakeDarkFrame" << " Thread ID:" << m_iThreadID;
|
||||
int CAbstractFSController::ComputExposure(int position) {
|
||||
if (position==0) {
|
||||
|
||||
m_vecDataFrameDark.push_back(TakeOneFrame());
|
||||
|
||||
int lastittime=m_taginfolast.lastITTIME[position];
|
||||
int lastmaxvalue=m_taginfolast.LastMAXValue[position];
|
||||
|
||||
int maxallowvalue=m_fsInfo.lDepth * m_fsInfo.fMaxFactor;
|
||||
int minallowvalue=m_fsInfo.lDepth * m_fsInfo.fMinFactor;
|
||||
if (lastmaxvalue>maxallowvalue) {
|
||||
if (lastmaxvalue>=m_fsInfo.lDepth) {
|
||||
lastittime=lastittime/2;
|
||||
|
||||
}else {
|
||||
lastittime=lastittime*(maxallowvalue*1.0/lastmaxvalue)*0.95;
|
||||
}
|
||||
|
||||
m_taginfolast.ITtimeChange[position]=true;
|
||||
m_taginfolast.lastITTIME[position]=lastittime;
|
||||
m_pFSCtrl->SetExposureTime(lastittime);
|
||||
qDebug()<< "Set exposure time for position"<<position<<" to "<<lastittime;
|
||||
return lastittime;
|
||||
|
||||
}
|
||||
if (lastmaxvalue<minallowvalue) {
|
||||
lastittime=lastittime*(minallowvalue*1.0/lastmaxvalue)*1.05;
|
||||
if (lastittime>=60000) {
|
||||
lastittime=60000;
|
||||
}
|
||||
m_taginfolast.ITtimeChange[position]=true;
|
||||
m_taginfolast.lastITTIME[position]=lastittime;
|
||||
m_pFSCtrl->SetExposureTime(lastittime);
|
||||
qDebug()<< "Set exposure time for position"<<position<<" to "<<lastittime;
|
||||
return lastittime;
|
||||
}
|
||||
m_taginfolast.ITtimeChange[position]=false;
|
||||
m_pFSCtrl->SetExposureTime(lastittime);
|
||||
qDebug()<< "Set exposure time for position"<<position<<" to "<<lastittime;
|
||||
return lastittime;
|
||||
}
|
||||
int lasttimeindev=0;
|
||||
m_pFSCtrl->GetExposureTime(lasttimeindev);
|
||||
|
||||
m_pFSCtrl->SetExposureTime(m_taginfolast.lastITTIME[0]*0.5);
|
||||
if (lasttimeindev!=m_taginfolast.lastITTIME[0]*0.5) {
|
||||
Delay_MSec(lasttimeindev);
|
||||
}
|
||||
qDebug()<< "Set exposure time for position"<<position<<" to "<<m_taginfolast.lastITTIME[0]*0.5;
|
||||
return m_taginfolast.lastITTIME[0]*0.5;
|
||||
|
||||
}
|
||||
|
||||
int CAbstractFSController::TakeDarkFrame(int position)
|
||||
{
|
||||
int shuttertime = 0;
|
||||
m_pFSCtrl->GetExposureTime(shuttertime);
|
||||
qDebug() << "Starting TakeDarkFrame" << " position ID:" << position<<" ITtime:"<<shuttertime<<"\n";
|
||||
if (m_taginfolast.ITtimeChange[0]) {
|
||||
m_taginfolast.LastDarkframe[position]=TakeOneFrame();
|
||||
}
|
||||
|
||||
|
||||
m_vecDataFrameDark.push_back(m_taginfolast.LastDarkframe[position]);
|
||||
|
||||
|
||||
qDebug() << "Stop TakeDarkFrame" << " Thread ID:" << m_iThreadID;
|
||||
@ -347,13 +431,77 @@ int CAbstractFSController::TakeDarkFrame()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::TakeSignalFrame()
|
||||
|
||||
int CAbstractFSController::ComputeMaxValue(DataFrame Data) {
|
||||
ZZ_S32 *pData = Data.lData;
|
||||
int number = 4096;
|
||||
int maxvalue=0;
|
||||
for (int i=0;i<number-1;i++) {
|
||||
if (pData[i]>maxvalue) {
|
||||
maxvalue=pData[i];
|
||||
}
|
||||
}
|
||||
return maxvalue;
|
||||
|
||||
// if (number <= 10) {
|
||||
// // 如果数据量小,直接排序计算
|
||||
// int sum = 0;
|
||||
// for (int i = 0; i < number; i++) {
|
||||
// sum += pData[i];
|
||||
// }
|
||||
// return number > 0 ? sum / number : 0;
|
||||
// }
|
||||
//
|
||||
// // 复制数据(或者直接操作原数组如果允许修改)
|
||||
// std::vector<int> temp(pData, pData + number);
|
||||
//
|
||||
// // 使用nth_element找到第10大的元素
|
||||
// std::nth_element(temp.begin(), temp.begin() + 9, temp.end(), std::greater<int>());
|
||||
//
|
||||
// // 计算前10个最大值的平均
|
||||
// int sum = 0;
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// sum += temp[i];
|
||||
// }
|
||||
//
|
||||
// return sum / 10;
|
||||
|
||||
|
||||
|
||||
|
||||
// int maxvalue[10]={0};
|
||||
// ZZ_S32 *pData=Data.lData;
|
||||
// int number=4096;
|
||||
// //获取pdata中最大的10个值
|
||||
// for (int i=0;i<number;i++) {
|
||||
// int val=pData[i];
|
||||
// for (int j=0;j<10;j++) {
|
||||
// if (val>maxvalue[j]) {
|
||||
// //插入到maxvalue中
|
||||
// for (int k=9;k>j;k--) {
|
||||
// maxvalue[k]=maxvalue[k-1];
|
||||
// }
|
||||
// maxvalue[j]=val;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
int CAbstractFSController::TakeSignalFrame(int position)
|
||||
{
|
||||
qDebug() << "Starting TakeSignal" << " Thread ID:" << m_iThreadID;
|
||||
int shuttertime = 0;
|
||||
m_pFSCtrl->GetExposureTime(shuttertime);
|
||||
qDebug() << "Starting TakeSignal" << " position" << position<<" ITtime:"<<shuttertime<<"\n";
|
||||
|
||||
m_vecDataFrameSignal.push_back(TakeOneFrame());
|
||||
|
||||
// todo: compute max ten value 计算前10个值平均值
|
||||
m_taginfolast.LastMAXValue[position]=ComputeMaxValue(m_vecDataFrameSignal.at(m_vecDataFrameSignal.size()-1));
|
||||
if (m_taginfolast.LastMAXValue[position]>=65535) {
|
||||
m_vecDataFrameSignal.at(m_vecDataFrameSignal.size()-1).bIsValid=false;
|
||||
}
|
||||
qDebug() << "Stop TakeSignal" << " Thread ID:" << m_iThreadID;
|
||||
qDebug()<< "Max 10 Average Value:" << m_taginfolast.LastMAXValue[position] << " Thread ID:" << m_iThreadID;
|
||||
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||
return 0;
|
||||
}
|
||||
@ -417,6 +565,8 @@ DataFrame CAbstractFSController::TakeOneFrame()
|
||||
// return dfTemp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CAbstractFSController::SaveDataFile()
|
||||
{
|
||||
return 0;
|
||||
@ -460,7 +610,7 @@ int CAbstractFSController::LoadQEProLinearCalibrationFile()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::StartAcquisitionSignal()
|
||||
int CAbstractFSController::StartAcquisitionSignal(int position)
|
||||
{
|
||||
//
|
||||
qDebug() << "Starting acq Signal" << " Thread ID:" << m_iThreadID;
|
||||
@ -471,18 +621,24 @@ int CAbstractFSController::StartAcquisitionSignal()
|
||||
// m_pFSCtrl->GetExposureTime(iii);
|
||||
// m_pFSCtrl->SingleShot(struDF);
|
||||
|
||||
PerformAutoExposure();
|
||||
TakeSignalFrame();
|
||||
if (m_taginfolast.lastITTIME[position]==0) {
|
||||
PerformAutoExposure(position);
|
||||
}else {
|
||||
ComputExposure(position);
|
||||
}
|
||||
|
||||
|
||||
TakeSignalFrame(position);
|
||||
|
||||
qDebug() << "Stop acq Signal" << " Thread ID:" << m_iThreadID;
|
||||
emit SignalAcqFinished_Signal(m_iThreadID, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::StartAcquisitionDark()
|
||||
int CAbstractFSController::StartAcquisitionDark(int position)
|
||||
{
|
||||
qDebug() << "Starting acq Dark" << " Thread ID:" << m_iThreadID;
|
||||
TakeDarkFrame();
|
||||
TakeDarkFrame(position);
|
||||
qDebug() << "Stop acq Dark"<< " Thread ID:" << m_iThreadID;
|
||||
emit SignalAcqFinished_Dark(m_iThreadID, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user