2 Commits

Author SHA1 Message Date
87a35f5dd4 新增 + 修改
1. 分离空间维(水平)和光谱维(垂直)的bin1和bin2有效窗口的参数:configfile.cpp和ximeaimager.cpp都需要修改相应代码;
2. 为了减少光谱仪的热量累积,加入了usb开电、断电功能,udpserver.cpp需要增加相应开电、断电代码:
3. 使用了云一峰的新板子,linux识别的惯导串口号改变:sbgrecorder.cpp;
2022-10-13 16:30:40 +08:00
374a48022b 修复路径问题
1. 配置文件创建在程序所在目录;
2. csv文件(ximea温度)输出路径改为:/home/programRunLog/hyperspectralLog;
2022-10-09 23:00:15 +08:00
7 changed files with 141 additions and 60 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea .idea
build build
/温度测试
扩展板接口.txt

View File

@ -12,6 +12,8 @@
#include <QFileInfo> #include <QFileInfo>
#include <QString> #include <QString>
#include <QCoreApplication>
#include <QDir>
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
@ -25,7 +27,8 @@ public:
bool isConfigfileExist(); bool isConfigfileExist();
bool parseConfigfile(); bool parseConfigfile();
bool getBin(int &bin); bool getSpectralBin(int &spectralBin);
bool getspatialBin(int &spatialBin);
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety); bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
bool getEffectiveWindowRoi(int &width, int &offsetx); bool getEffectiveWindowRoi(int &width, int &offsetx);
bool getGainOffset(float &gain, float &offset); bool getGainOffset(float &gain, float &offset);

View File

@ -29,6 +29,7 @@
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
#include <qthread.h> #include <qthread.h>
#include <QDir>
#include "configfile.h" #include "configfile.h"

View File

@ -43,17 +43,32 @@ bool Configfile::parseConfigfile()
} }
} }
bool Configfile::getBin(int &bin) bool Configfile::getSpectralBin(int &spectralBin)
{ {
try try
{ {
bin = cfg.lookup("bin"); spectralBin = cfg.lookup("spectralBin");
return true; return true;
} }
catch(const SettingNotFoundException &nfex) catch(const SettingNotFoundException &nfex)
{ {
cerr << "No 'bin' setting in configuration file." << endl; cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::getspatialBin(int &spatialBin)
{
try
{
spatialBin = cfg.lookup("spatialBin");
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spatialBin' setting in configuration file." << endl;
return false; return false;
} }
} }
@ -62,22 +77,41 @@ bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int &
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window"]; int spatialBin;
int count = effective_window.getLength(); int spectralBin;
getspatialBin(spatialBin);
getSpectralBin(spectralBin);
int bin; string spatialBinString;
getBin(bin); if(spatialBin == 1)
{
spatialBinString = "bin1";
}
else
{
spatialBinString = "bin2";
}
const Setting &spatialArgument = root["effective_window"][spatialBinString]["spatial"];
if(!(spatialArgument.lookupValue("width", width)
&& spatialArgument.lookupValue("offsetx", offsetx)))
{
return false;
}
const Setting &window = effective_window[bin-1]; string spectralBinString;
string name = window.getName(); if(spectralBin == 1)
{
if(!(window.lookupValue("width", width) spectralBinString = "bin1";
&& window.lookupValue("offsetx", offsetx) }
&& window.lookupValue("height", height) else
&& window.lookupValue("offsety", offsety))) {
spectralBinString = "bin2";
}
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if(!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{ {
return false; return false;
} }
@ -95,16 +129,25 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window_roi"]; const Setting &effective_window = root["effective_window_roi"];
int count = effective_window.getLength(); int count = effective_window.getLength();
int bin; int spatialBin;
getBin(bin); getspatialBin(spatialBin);
const Setting &window = effective_window[bin-1]; string spatialBinString;
if(spatialBin == 1)
{
spatialBinString = "spatialBin1";
}
else
{
spatialBinString = "spatialBin2";
}
const Setting &window = effective_window[spatialBinString];
string name = window.getName(); string name = window.getName();
if(!(window.lookupValue("width", width) if(!(window.lookupValue("width", width)
@ -127,16 +170,25 @@ bool Configfile::getGainOffset(float &gain, float &offset)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &gainOffset = root["gainOffset"]; const Setting &gainOffset = root["gainOffset"];
int count = gainOffset.getLength(); int count = gainOffset.getLength();
int bin; int spectralBin;
getBin(bin); getSpectralBin(spectralBin);
const Setting &gainOffsetSetting = gainOffset[bin-1]; string spectralBinString;
if(spectralBin == 1)
{
spectralBinString = "spectralBin1";
}
else
{
spectralBinString = "spectralBin2";
}
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName(); string name = gainOffsetSetting.getName();
if(!(gainOffsetSetting.lookupValue("gain", gain) if(!(gainOffsetSetting.lookupValue("gain", gain)
@ -159,64 +211,69 @@ bool Configfile::createConfigFile()
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
static const char *output_file = "ximea.cfg";
Config cfg; Config cfg;
Setting &root = cfg.getRoot(); Setting &root = cfg.getRoot();
// Add some settings to the configuration. // Add some settings to the configuration.
Setting &bin = root.add("bin", Setting::TypeInt) = 1;
Setting &SN = root.add("SN", Setting::TypeString) = "0098"; Setting &SN = root.add("SN", Setting::TypeString) = "0098";
Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 1;
Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &effective_window = root.add("effective_window", Setting::TypeGroup); Setting &effective_window = root.add("effective_window", Setting::TypeGroup);
Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup); Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup);
Setting &effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup);
Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup); Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup);
Setting &effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup);
effective_window_Bin1.add("width", Setting::TypeInt) = 1392; effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1392;
effective_window_Bin1.add("offsetx", Setting::TypeInt) = 272; effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 272;
effective_window_Bin1.add("height", Setting::TypeInt) = 300; effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
effective_window_Bin1.add("offsety", Setting::TypeInt) = 348; effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
effective_window_Bin2.add("width", Setting::TypeInt) = 712; effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 712;
effective_window_Bin2.add("offsetx", Setting::TypeInt) = 128; effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 128;
effective_window_Bin2.add("height", Setting::TypeInt) = 151; effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
effective_window_Bin2.add("offsety", Setting::TypeInt) = 174; effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup); Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup);
Setting &effective_window_roi_Bin1 = effective_window_roi.add("bin1", Setting::TypeGroup); Setting &effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup);
Setting &effective_window_roi_Bin2 = effective_window_roi.add("bin2", Setting::TypeGroup); Setting &effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup);
effective_window_roi_Bin1.add("width", Setting::TypeInt) = 1364; effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364;
effective_window_roi_Bin1.add("offsetx", Setting::TypeInt) = 14; effective_window_roi_spatialBin1.add("offsetx", Setting::TypeInt) = 14;
// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300; // effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300;
// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348; // effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348;
effective_window_roi_Bin2.add("width", Setting::TypeInt) = 682; effective_window_roi_spatialBin2.add("width", Setting::TypeInt) = 682;
effective_window_roi_Bin2.add("offsetx", Setting::TypeInt) = 15; effective_window_roi_spatialBin2.add("offsetx", Setting::TypeInt) = 15;
// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151; // effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151;
// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174; // effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174;
Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup); Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup);
Setting &gainOffsetBin1 = gainOffset.add("bin1", Setting::TypeGroup); Setting &gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup);
Setting &gainOffsetBin2 = gainOffset.add("bin2", Setting::TypeGroup); Setting &gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup);
gainOffsetBin1.add("gain", Setting::TypeFloat) = 2.00313433; gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433;
gainOffsetBin1.add("offset", Setting::TypeFloat) = -300.46283157590585; gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585;
gainOffsetBin2.add("gain", Setting::TypeFloat) = 4.00626868; gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868;
gainOffsetBin2.add("offset", Setting::TypeFloat) = -299.46126663407176; gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
// Write out the new configuration. // Write out the new configuration.
QString output_file = QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() + "ximea.cfg");
try try
{ {
cfg.writeFile(output_file); cfg.writeFile(output_file.toStdString().c_str());
cerr << "New configuration successfully written to: " << output_file << endl; cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;
} }
catch(const FileIOException &fioex) catch(const FileIOException &fioex)
{ {
cerr << "I/O error while writing configuration file: " << output_file << endl; cerr << "I/O error while writing configuration file: " << output_file.toStdString().c_str() << endl;
return true; return true;
} }

View File

@ -53,7 +53,7 @@ void sbgtc::SbgRecorder::openSerialPort()
} }
// QString portname = "sbg_serial_port"; // QString portname = "sbg_serial_port";
QString portname = "ttyS4"; QString portname = "ttyUSB2";
m_serial->setPortName(portname); m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite); m_serial->open(QIODevice::ReadWrite);

View File

@ -88,6 +88,10 @@ void UdpServer::processPendingDatagrams()
case 1://启动系统: 打开sbg串口并采集数据打开光谱仪 case 1://启动系统: 打开sbg串口并采集数据打开光谱仪
{ {
std::cout<<"1代表启动系统!"<<std::endl; std::cout<<"1代表启动系统!"<<std::endl;
system("sudo gpio write 10 1");
sleep(4);//睡眠4秒等待电脑打开usb电源以便给相机供电
emit systemStart(); emit systemStart();
break; break;
@ -110,6 +114,9 @@ void UdpServer::processPendingDatagrams()
emit systemStop(); emit systemStop();
sleep(4);//睡眠4秒等待
system("sudo gpio write 10 0");
//QCoreApplication::quit(); //QCoreApplication::quit();
break; break;
} }

View File

@ -9,7 +9,8 @@ XimeaImager::XimeaImager()
//connect(this, SIGNAL(recordFinished()),this, SLOT()); //connect(this, SIGNAL(recordFinished()),this, SLOT());
m_configfile.setConfigfilePath("ximea.cfg"); QString ximeaCfgFile = QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() + "ximea.cfg");
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
if(!m_configfile.isConfigfileExist()) if(!m_configfile.isConfigfileExist())
m_configfile.createConfigFile(); m_configfile.createConfigFile();
m_configfile.parseConfigfile(); m_configfile.parseConfigfile();
@ -36,14 +37,16 @@ void XimeaImager::openImger()
//std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<<std::endl; //std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<<std::endl;
m_imager.connect(); m_imager.connect();
bool ret; bool ret, ret1, ret2;
int bin=0; int spatialBin;
ret = m_configfile.getBin(bin); int spectralBin;
if (ret) ret1 = m_configfile.getspatialBin(spatialBin);
ret2 = m_configfile.getSpectralBin(spectralBin);
if (ret1 & ret2)
{ {
bool haha = m_imager.setSpectralBin(bin); bool haha = m_imager.setSpectralBin(spectralBin);
bool haha2 = m_imager.setSpatialBin(bin); bool haha2 = m_imager.setSpatialBin(spatialBin);
} }
float gain, offset;//用于生成头文件中的波长信息 float gain, offset;//用于生成头文件中的波长信息
@ -80,7 +83,10 @@ void XimeaImager::openImger()
m_iImagerState = 101; m_iImagerState = 101;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
m_ximeaTemperatureCSVPath = "/home/rock/programRunLog/ximeaTemperature.csv"; QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
m_ximeaTemperatureCSVPath = QDir::cleanPath(QString::fromStdString("/home/programRunLog/hyperspectralLog") + QDir::separator() + "ximeaTemperature_" + currentTime + ".csv");
// m_ximeaTemperatureCSVPath = "/home/ximeaTemperature.csv";
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath); emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);
} }
catch(int xiApiErrorCodes) catch(int xiApiErrorCodes)
@ -128,7 +134,7 @@ void XimeaImager::setFramerate(double framerate)
{ {
m_imager.set_framerate(framerate); m_imager.set_framerate(framerate);
int maxExposureTimeInUs=1/framerate*1000000*0.8; int maxExposureTimeInUs=1/framerate*1000000*0.01;
setExposureTime(maxExposureTimeInUs); setExposureTime(maxExposureTimeInUs);
// setExposureTime(1000); // setExposureTime(1000);
@ -480,6 +486,10 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
// { // {
// break; // break;
// } // }
// if(m_iFrameCounter/getFramerate() > 5*60) //这个判断会导致丢帧率的大幅升高5% → 20%,推测原因:除法耗时;
// {
// break;
// }
// unsigned char pixel = *(unsigned char*)image.bp;//Default value: XI_MONO8 // unsigned char pixel = *(unsigned char*)image.bp;//Default value: XI_MONO8
// unsigned short pixel =*(unsigned short*)image.bp;//XI_RAW16 // unsigned short pixel =*(unsigned short*)image.bp;//XI_RAW16
@ -669,6 +679,7 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app); ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app);
ximeaErrorFile<< xiApiErrorCodes << "\n"; ximeaErrorFile<< xiApiErrorCodes << "\n";
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:未处理ximea异常代码"<< xiApiErrorCodes <<std::endl;
ximeaErrorFile.close(); ximeaErrorFile.close();