add,山地所贡嘎山5,初步实现:

1、监听tcp消息,收到位置后触发pica L和is11采集。
2、releases可编译;
This commit is contained in:
tangchao0503
2026-07-10 18:34:29 +08:00
parent 39578dc9fe
commit a49f416551
16 changed files with 247 additions and 64 deletions

View File

@ -8,6 +8,8 @@ const int AppSettings::kDefaultIntegrationTime = 1;
const int AppSettings::kDefaultGain = 0; const int AppSettings::kDefaultGain = 0;
const QString AppSettings::kDefaultSLRDataFolder = QString(); const QString AppSettings::kDefaultSLRDataFolder = QString();
const QString AppSettings::kDefaultDepthCameraDataFolder = QString(); const QString AppSettings::kDefaultDepthCameraDataFolder = QString();
const double AppSettings::kDefaultScanSpeed = 1.0;
const double AppSettings::kDefaultReturnSpeed = 5.0;
AppSettings::AppSettings() AppSettings::AppSettings()
: m_settings(QSettings::IniFormat, QSettings::UserScope, : m_settings(QSettings::IniFormat, QSettings::UserScope,
@ -115,3 +117,23 @@ void AppSettings::setFiberImagerDataFolder(const QString& path)
{ {
m_settings.setValue("General/FiberImagerDataFolder", path); m_settings.setValue("General/FiberImagerDataFolder", path);
} }
double AppSettings::scanSpeed() const
{
return m_settings.value("OneMotorControl/ScanSpeed", kDefaultScanSpeed).toDouble();
}
void AppSettings::setScanSpeed(double value)
{
m_settings.setValue("OneMotorControl/ScanSpeed", value);
}
double AppSettings::returnSpeed() const
{
return m_settings.value("OneMotorControl/ReturnSpeed", kDefaultReturnSpeed).toDouble();
}
void AppSettings::setReturnSpeed(double value)
{
m_settings.setValue("OneMotorControl/ReturnSpeed", value);
}

View File

@ -37,6 +37,14 @@ public:
QString FiberImagerDataFolder() const; QString FiberImagerDataFolder() const;
void setFiberImagerDataFolder(const QString& path); void setFiberImagerDataFolder(const QString& path);
// 扫描速度
double scanSpeed() const;
void setScanSpeed(double value);
// 返回速度
double returnSpeed() const;
void setReturnSpeed(double value);
// 在此处添加更多参数的 getter/setter ... // 在此处添加更多参数的 getter/setter ...
private: private:
@ -54,4 +62,6 @@ private:
static const int kDefaultGain; static const int kDefaultGain;
static const QString kDefaultSLRDataFolder; static const QString kDefaultSLRDataFolder;
static const QString kDefaultDepthCameraDataFolder; static const QString kDefaultDepthCameraDataFolder;
static const double kDefaultScanSpeed;
static const double kDefaultReturnSpeed;
}; };

View File

@ -32,6 +32,7 @@ void CommunicationViaTCP::onNewConnection()
m_bConnected = true; m_bConnected = true;
m_tcpSocket = m_tcpServer->nextPendingConnection(); m_tcpSocket = m_tcpServer->nextPendingConnection();
connect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(onTcpSocketDisconnected())); connect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(onTcpSocketDisconnected()));
connect(m_tcpSocket, &QTcpSocket::readyRead, this, &CommunicationViaTCP::receiveData);
emit connected(); emit connected();
} }
@ -49,6 +50,32 @@ void CommunicationViaTCP::onTcpSocketDisconnected()
m_tcpSocket->deleteLater(); m_tcpSocket->deleteLater();
} }
void CommunicationViaTCP::receiveData()
{
if (!isConnected())
{
qWarning() << "receiveData: No client connected";
return;
}
QByteArray data = m_tcpSocket->readAll();
if (data.isEmpty())
{
return;
}
bool ok;
int position = QString::fromUtf8(data).toInt(&ok);
if (ok)
{
qDebug() << "Received position:" << position;
emit positionReceived(position);
} else
{
qWarning() << "Failed to parse position data:" << data;
}
}
int CommunicationViaTCP::sendCommand(const QString cmd) int CommunicationViaTCP::sendCommand(const QString cmd)
{ {
if (!isConnected()) { if (!isConnected()) {

View File

@ -37,9 +37,11 @@ namespace MotorParams {
public Q_SLOTS: public Q_SLOTS:
void onNewConnection(); void onNewConnection();
void receiveData();
void onTcpSocketDisconnected(); void onTcpSocketDisconnected();
signals: signals:
void commandSendResult(int bytesWritten, const QString& error = QString()); void commandSendResult(int bytesWritten, const QString& error = QString());
void positionReceived(int position);
}; };
} }

View File

@ -9,6 +9,7 @@ FodisWindow::FodisWindow(QWidget* parent)
m_FiberImagerThread = new QThread(); m_FiberImagerThread = new QThread();
m_JinspFiberImagerOperation = new JinspFiberImager(false, JinspFiberImagerConfig::instance().portName().toStdString(), "JINSP"); m_JinspFiberImagerOperation = new JinspFiberImager(false, JinspFiberImagerConfig::instance().portName().toStdString(), "JINSP");
connect(m_JinspFiberImagerOperation, &JinspFiberImager::spectalCaptured, this, &FodisWindow::spectalCaptured); connect(m_JinspFiberImagerOperation, &JinspFiberImager::spectalCaptured, this, &FodisWindow::spectalCaptured);
connect(m_JinspFiberImagerOperation, &JinspFiberImager::exposureCompleteSignal, this, &FodisWindow::exposureCompleteSignal);
m_JinspFiberImagerOperation->moveToThread(m_FiberImagerThread); m_JinspFiberImagerOperation->moveToThread(m_FiberImagerThread);
m_FiberImagerThread->start(); m_FiberImagerThread->start();

View File

@ -44,6 +44,8 @@ signals:
void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame); void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame);
void exposureCompleteSignal();
private: private:
Ui::FodisWindow ui; Ui::FodisWindow ui;
QThread* m_FiberImagerThread; QThread* m_FiberImagerThread;

View File

@ -11,15 +11,30 @@ GonggaShanRecordCtl::GonggaShanRecordCtl(QWidget* parent)
GonggaShanRecordCtl::~GonggaShanRecordCtl() GonggaShanRecordCtl::~GonggaShanRecordCtl()
{ {
tcpServer6005->deleteLater();
} }
void GonggaShanRecordCtl::startListen() void GonggaShanRecordCtl::startListen()
{ {
MotorParams::TCPConnectionParams tcpConnectionParams6005;
tcpConnectionParams6005.port = ui.spinbox_Port->text().toInt();
tcpConnectionParams6005.serverIP = "192.168.1.2";
tcpServer6005 = new MotorParams::CommunicationViaTCP(tcpConnectionParams6005, this);
connect(tcpServer6005, &MotorParams::CommunicationViaTCP::positionReceived, this, &GonggaShanRecordCtl::startRecord);
} }
void GonggaShanRecordCtl::stopListen() void GonggaShanRecordCtl::stopListen()
{ {
disconnect(tcpServer6005, &MotorParams::CommunicationViaTCP::positionReceived, this, &GonggaShanRecordCtl::startRecord);
tcpServer6005->deleteLater();
}
void GonggaShanRecordCtl::startRecord(int position)
{
//<2F><>¼λ<C2BC><CEBB>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
emit startRcordSignal();
} }

View File

@ -4,9 +4,12 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <vector> #include <vector>
#include <QPointer>
#include "ui_gonggashanCtl.h" #include "ui_gonggashanCtl.h"
#include "CommunicationViaTCP.h"
class GonggaShanRecordCtl : public QDialog class GonggaShanRecordCtl : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -20,15 +23,15 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
// Emitted when user changes any of the R/G/B wavelength values // Emitted when user changes any of the R/G/B wavelength values
void startRcordHsiSignal(); void startRcordSignal();
void stopRcordHsiSignal();
void startRcordFodisSignal();
private Q_SLOTS: private Q_SLOTS:
void startListen(); void startListen();
void stopListen(); void stopListen();
void startRecord(int position);
private: private:
Ui::gongga_control ui; Ui::gongga_control ui;
QPointer<MotorParams::CommunicationViaTCP> tcpServer6005;
}; };

View File

@ -1057,16 +1057,18 @@ void HPPA::initControlTabwidget()
m_tmc->setWindowFlags(Qt::Widget); m_tmc->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_tmc, QString::fromLocal8Bit("2轴控制")); ui.controlTabWidget->addTab(m_tmc, QString::fromLocal8Bit("2轴控制"));
//贡嘎山定时采集
m_gonggaShanRecordCtl = new GonggaShanRecordCtl(this);
m_gonggaShanRecordCtl->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_gonggaShanRecordCtl, QString::fromLocal8Bit("触发采集"));
//is11 //is11
m_fodisWindow = new FodisWindow(this); m_fodisWindow = new FodisWindow(this);
connect(m_fodisWindow, &FodisWindow::spectalCaptured, this, &HPPA::showFiberImagerSpectral); connect(m_fodisWindow, &FodisWindow::spectalCaptured, this, &HPPA::showFiberImagerSpectral);
m_fodisWindow->setWindowFlags(Qt::Widget); m_fodisWindow->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_fodisWindow, QString::fromLocal8Bit("FODIS")); ui.controlTabWidget->addTab(m_fodisWindow, QString::fromLocal8Bit("FODIS"));
// setupGonggashanAutoRecordConnection();
m_gonggaShanRecordCtl = new GonggaShanRecordCtl(this);
m_gonggaShanRecordCtl->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_gonggaShanRecordCtl, QString::fromLocal8Bit("触发采集"));
// Connect ImageControl band change to re-render (m_ic created in initControlTabwidget) // Connect ImageControl band change to re-render (m_ic created in initControlTabwidget)
@ -1074,6 +1076,37 @@ void HPPA::initControlTabwidget()
// this, SLOT(onBandSelectionChanged(double, double, double))); // this, SLOT(onBandSelectionChanged(double, double, double)));
} }
void HPPA::setupGonggashanAutoRecordConnection()
{
connect(m_gonggaShanRecordCtl, &GonggaShanRecordCtl::startRcordSignal, this, &HPPA::onGonggashanRecord);
connect(m_fodisWindow, &FodisWindow::exposureCompleteSignal, this, &HPPA::onStartRecordStep1);
connect(m_omc, &OneMotorControl::sequenceComplete, m_fodisWindow, &FodisWindow::closeFiberImager);
}
void HPPA::onGonggashanRecord()
{
//设置文件名
//AppSettings::instance().setFrameRate(f);
//AppSettings::instance().setIntegrationTime(e);
//AppSettings::instance().setDataFolder(filePath);
QString dateStr = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
//QString fi = AppSettings::instance().fileName() + "_" + dateStr;
AppSettings::instance().setFileName(dateStr);
this->frame_number->setText("100000");
//连接马达和光谱仪
m_omc->connectMotor(false);
if (!testImagerVality())
{
onconnect();
}
m_fodisWindow->openFiberImager();
}
void HPPA::recordFromRobotArm(int fileCounter) void HPPA::recordFromRobotArm(int fileCounter)
{ {
if (!testImagerVality()) if (!testImagerVality())

View File

@ -362,6 +362,9 @@ private:
QChart* m_FiberImagerChart; QChart* m_FiberImagerChart;
void showFiberImagerSpectral(DeviceAttribute attribute, DataFrame dataFrame); void showFiberImagerSpectral(DeviceAttribute attribute, DataFrame dataFrame);
void setupGonggashanAutoRecordConnection();
void onGonggashanRecord();
public Q_SLOTS: public Q_SLOTS:
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath); void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
void focusPlotSpectralImg(int state); void focusPlotSpectralImg(int state);

View File

@ -60,7 +60,7 @@
<TargetName>Spectral Insight</TargetName> <TargetName>Spectral Insight</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Header;$(IncludePath)</IncludePath> <IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Header;D:\cpp_project_vs2022\HPPA\JinspSpectralmeterControl;$(IncludePath)</IncludePath>
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\vincecontrol_vs2017_release;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Release;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\IrisMultiMotorController\x64\Release;C:\XIMEA\API\xiAPI;C:\Program Files\OrbbecSDK 2.7.6\lib;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Library;$(LibraryPath)</LibraryPath> <LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\vincecontrol_vs2017_release;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Release;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\IrisMultiMotorController\x64\Release;C:\XIMEA\API\xiAPI;C:\Program Files\OrbbecSDK 2.7.6\lib;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Library;$(LibraryPath)</LibraryPath>
<TargetName>Spectral Insight</TargetName> <TargetName>Spectral Insight</TargetName>
</PropertyGroup> </PropertyGroup>
@ -71,11 +71,12 @@
</Link> </Link>
<ClCompile> <ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link> <Link>
<AdditionalDependencies>opencv_world3411.lib;vincecontrol.lib;gdal_i.lib;resonon-basler.lib;resonon-allied.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;EDSDK.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>opencv_world3411.lib;vincecontrol.lib;gdal_i.lib;resonon-basler.lib;resonon-allied.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;EDSDK.lib;JinspSpectralmeterControl.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>

View File

@ -1,6 +1,7 @@
// //
// Created by 73505 on 2023/5/7. // Created by 73505 on 2023/5/7.
// //
#include <algorithm>
#include "JinspFiberImager.h" #include "JinspFiberImager.h"
@ -12,7 +13,7 @@ JinspFiberImager::JinspFiberImager(bool bIsUSBMode, std::string ucPortNumber, st
m_record = false; m_record = false;
m_captureIntervalMilliseconds = 5 * 1000; m_captureIntervalMilliseconds = 1 * 1000;
qRegisterMetaType<DeviceAttribute>("DeviceAttribute"); qRegisterMetaType<DeviceAttribute>("DeviceAttribute");
qRegisterMetaType<DataFrame>("DataFrame"); qRegisterMetaType<DataFrame>("DataFrame");
@ -188,73 +189,108 @@ void JinspFiberImager::recordTarget(int recordTimes, QString path)
void JinspFiberImager::autoExpose() void JinspFiberImager::autoExpose()
{ {
// float fPredictedExposureTime; int allowMaxExposure = 6000;
// m_FiberSpectrometer->PerformAutoExposure(0.6,0.9,fPredictedExposureTime);
//tc
DeviceAttribute attribute; DeviceAttribute attribute;
getDeviceAttribute(attribute); getDeviceAttribute(attribute);
int iterations = 0;//记录自动曝光已经迭代的次数 const ZZ_U32 maxPixelValue = m_MaxValueOfFiberSpectrometer;
int maxIterations = 10;//允许最大的迭代次数 const double targetMinRatio = 0.80;
const double targetMaxRatio = 0.90;
const ZZ_U32 targetMin = maxPixelValue * targetMinRatio;
const ZZ_U32 targetMax = maxPixelValue * targetMaxRatio;
ZZ_U32 thresholdValue = m_MaxValueOfFiberSpectrometer * 0.8;//最佳线性区间为80% ZZ_U32 thresholdLow = targetMin;
ZZ_U16 range = 10000; ZZ_U32 thresholdHigh = targetMax;
//设置初始曝光时间 // 自适应初始曝光时间:先快速探测亮度水平
int exposureTimeInMS = 200; int exposureTime = 10;
setExposureTime(exposureTimeInMS); setExposureTime(exposureTime);
DataFrame dataFrame;
singleShot(dataFrame);
ZZ_S32 maxValue = GetMaxValue(dataFrame.lData, attribute.iPixels);
// int exposureTime; // 探测阶段:快速逼近目标区间
// m_FiberSpectrometer->GetExposureTime(exposureTime); if (maxValue > 0)
emit sendExposureTimeSignal(exposureTimeInMS);
DataFrame integratingSphereData_tmp;
ZZ_S32 maxValue;
while (true)
{ {
if (iterations > maxIterations)//是否超过允许的最大迭代次数 // 预测达到目标区间所需的曝光时间
ZZ_U32 targetValue = (targetMin + targetMax) / 2;
double predictedRatio = static_cast<double>(targetValue) / maxValue;
// 曝光时间与亮度为对数关系,使用对数预测更准确
double logRatio = log(static_cast<double>(targetValue) / maxValue + 0.001);
int predictedExposure = static_cast<int>(exposureTime * pow(predictedRatio, 0.7));
if (predictedExposure < 1)
predictedExposure = 1;
if (predictedExposure > allowMaxExposure)
predictedExposure = allowMaxExposure;
//predictedExposure = std::clamp(predictedExposure, 1, allowMaxExposure);
exposureTime = predictedExposure;
setExposureTime(exposureTime);
singleShot(dataFrame);
maxValue = GetMaxValue(dataFrame.lData, attribute.iPixels);
}
emit sendExposureTimeSignal(exposureTime);
// 二分查找阶段:在目标区间内精确查找
int lowExposure = 1;
int highExposure = allowMaxExposure;
int iterations = 0;
const int maxIterations = 10;
while (iterations < maxIterations)
{
// 检查是否已在目标区间内
if (maxValue >= thresholdLow && maxValue <= thresholdHigh)
{ {
std::cout << "自动曝光完成 - 曝光时间:" << exposureTime
<< "ms, 最大值:" << maxValue << std::endl;
break; break;
} }
singleShot(integratingSphereData_tmp); // 获取当前曝光时间
maxValue = GetMaxValue(integratingSphereData_tmp.lData, attribute.iPixels); m_FiberSpectrometer->GetExposureTime(exposureTime);
if (maxValue < thresholdValue && maxValue < (thresholdValue - range))//曝光时间过小 if (maxValue < thresholdLow)
{ {
double scale = 1 + ((double)(thresholdValue - maxValue) / (double)thresholdValue); // 曝光不足,增大曝光时间 - 使用二分策略
lowExposure = exposureTime;
int exposureTime; int newExposure = (exposureTime + highExposure) / 2;
m_FiberSpectrometer->GetExposureTime(exposureTime); if (newExposure <= exposureTime)
m_FiberSpectrometer->SetExposureTime(exposureTime * scale); {
newExposure = exposureTime * 2;
emit sendExposureTimeSignal(exposureTime); }
exposureTime = std::min(newExposure, allowMaxExposure);
std::cout << "自动曝光-----------" << "最大值为" << maxValue << std::endl; std::cout << "自动曝光 +++ (" << iterations << ") 曝光时间:"
<< exposureTime << "ms, 最大值:" << maxValue << std::endl;
} }
else if (maxValue > thresholdValue)//曝光时间过大 else
{ {
double scale = 1 - ((double)(maxValue - thresholdValue) / (double)thresholdValue); // 曝光过度,减小曝光时间 - 使用二分策略
highExposure = exposureTime;
int exposureTime; int newExposure = (lowExposure + exposureTime) / 2;
m_FiberSpectrometer->GetExposureTime(exposureTime); if (newExposure >= exposureTime) {
m_FiberSpectrometer->SetExposureTime(exposureTime * scale); newExposure = exposureTime / 2;
}
emit sendExposureTimeSignal(exposureTime); exposureTime = std::max(newExposure, 1);
std::cout << "自动曝光 --- (" << iterations << ") 曝光时间:"
std::cout << "自动曝光++++++++++++" << "最大值为" << maxValue << std::endl; << exposureTime << "ms, 最大值:" << maxValue << std::endl;
}
else//找到最佳曝光时间,跳出while循环
{
break;
} }
setExposureTime(exposureTime);
singleShot(dataFrame);
maxValue = GetMaxValue(dataFrame.lData, attribute.iPixels);
emit sendExposureTimeSignal(exposureTime);
iterations++; iterations++;
} }
int a = 2; if (iterations >= maxIterations) {
std::cout << "自动曝光达到最大迭代次数,最终曝光时间:"
<< exposureTime << "ms, 最大值:" << maxValue << std::endl;
}
} }
ZZ_S32 JinspFiberImager::GetMaxValue(ZZ_S32 * dark, int number) ZZ_S32 JinspFiberImager::GetMaxValue(ZZ_S32 * dark, int number)
@ -291,6 +327,7 @@ void JinspFiberImager::OpenFiberImagerAndRecord()
//曝光 //曝光
autoExpose(); autoExpose();
emit exposureCompleteSignal();
//采集 //采集
m_record = true; m_record = true;

View File

@ -65,4 +65,6 @@ public slots:
signals: signals:
void sendExposureTimeSignal(int exposureTime); void sendExposureTimeSignal(int exposureTime);
void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame); void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame);
void exposureCompleteSignal();
}; };

View File

@ -16,6 +16,19 @@ OneMotorControl::OneMotorControl(QWidget* parent) : QDialog(parent)
connect(this->ui.zero_start_btn, SIGNAL(released()), this, SLOT(zeroStart())); connect(this->ui.zero_start_btn, SIGNAL(released()), this, SLOT(zeroStart()));
connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement())); connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement()));
// 从 AppSettings 读取速度参数
AppSettings& settings = AppSettings::instance();
ui.speed_lineEdit->setText(QString::number(settings.scanSpeed()));
ui.return_speed_lineEdit->setText(QString::number(settings.returnSpeed()));
// 连接信号,当控件数值变化时保存到 AppSettings
connect(ui.speed_lineEdit, &QLineEdit::editingFinished, [this]() {
AppSettings::instance().setScanSpeed(ui.speed_lineEdit->text().toDouble());
});
connect(ui.return_speed_lineEdit, &QLineEdit::editingFinished, [this]() {
AppSettings::instance().setReturnSpeed(ui.return_speed_lineEdit->text().toDouble());
});
} }
OneMotorControl::~OneMotorControl() OneMotorControl::~OneMotorControl()
@ -25,13 +38,21 @@ OneMotorControl::~OneMotorControl()
} }
void OneMotorControl::onConnectMotor() void OneMotorControl::onConnectMotor()
{
connectMotor(true);
}
void OneMotorControl::connectMotor(bool isNotification)
{ {
if (getMotorsConnectionStatus()) if (getMotorsConnectionStatus())
{ {
QMessageBox msgBox; if (isNotification)
msgBox.setText(QString::fromLocal8Bit("马达已连接!")); {
msgBox.exec(); QMessageBox msgBox;
msgBox.setText(QString::fromLocal8Bit("马达已连接!"));
msgBox.exec();
}
return; return;
} }

View File

@ -8,6 +8,7 @@
#include "fileOperation.h" #include "fileOperation.h"
#include "CaptureCoordinator.h" #include "CaptureCoordinator.h"
#include "MotorWindowBase.h" #include "MotorWindowBase.h"
#include "AppSettings.h"
class OneMotorControl : public QDialog, public MotorWindowBase class OneMotorControl : public QDialog, public MotorWindowBase
{ {
@ -27,6 +28,8 @@ public:
bool getMotorsConnectionStatus(); bool getMotorsConnectionStatus();
void connectMotor(bool isNotification);
public Q_SLOTS: public Q_SLOTS:
void onConnectMotor(); void onConnectMotor();

View File

@ -37,7 +37,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.13.2_msvc2017_64</QtInstall> <QtInstall>5.13.2_msvc2017_64</QtInstall>
<QtModules>core</QtModules> <QtModules>core;serialport</QtModules>
<QtBuildConfig>release</QtBuildConfig> <QtBuildConfig>release</QtBuildConfig>
</PropertyGroup> </PropertyGroup>
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')"> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
@ -58,6 +58,7 @@
<IncludePath>D:\cpp_library\eigen-3.4-rc1;$(IncludePath)</IncludePath> <IncludePath>D:\cpp_library\eigen-3.4-rc1;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<IncludePath>D:\cpp_library\eigen-3.4-rc1;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile> <ClCompile>