新的一轴采集逻辑控制器
This commit is contained in:
@ -441,3 +441,163 @@ void TwoMotionCaptureCoordinator::processNextPathLine()
|
||||
m_isMoving2XMin = true;
|
||||
emit moveTo(loc, speed, 1000);
|
||||
}
|
||||
|
||||
OneMotionCaptureCoordinator::OneMotionCaptureCoordinator(
|
||||
IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_motorCtrl(motorCtrl)
|
||||
, m_cameraCtrl(cameraCtrl)
|
||||
, m_isRunning(false)
|
||||
{
|
||||
connect(this, SIGNAL(moveTo(int, double, double, int)),
|
||||
m_motorCtrl, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(moveSignal(int, bool, double, int)), m_motorCtrl, SLOT(move(int, bool, double, int)));
|
||||
connect(this, &OneMotionCaptureCoordinator::stopMotorSignal, m_motorCtrl, &IrisMultiMotorController::stop);
|
||||
|
||||
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
|
||||
this, &OneMotionCaptureCoordinator::handleMotorStoped);
|
||||
//connect(m_motorCtrl, &IrisMultiMotorController::moveFailed,
|
||||
// this, &OneMotionCaptureCoordinator::handleError);
|
||||
|
||||
connect(this, &OneMotionCaptureCoordinator::startRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::start_record);
|
||||
connect(this, &OneMotionCaptureCoordinator::stopRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::stop_record);
|
||||
connect(m_cameraCtrl, &ImagerOperationBase::RecordFinishedSignal_WhenFrameNumberMeet,
|
||||
this, &OneMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
|
||||
}
|
||||
|
||||
OneMotionCaptureCoordinator::~OneMotionCaptureCoordinator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::startStepMotion(OneMotionCapturePathLine pathLine)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_isRunning)
|
||||
{
|
||||
emit errorOccurred("Sequence already running");
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = true;
|
||||
m_pathLine = pathLine;
|
||||
|
||||
getLocBeforeStart();
|
||||
m_pathLine.startPosition = m_locBeforeStart[0];
|
||||
m_pathLine.timestamp1 = QDateTime::currentDateTime();
|
||||
|
||||
//移动马达并开始采集高光谱
|
||||
emit moveSignal(0, false, m_pathLine.speedRecord, 1000);
|
||||
emit startRecordHSISignal();
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::stopStepMotion()
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_cameraCtrl != nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet()
|
||||
{
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::getLocBeforeStart()
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool received = false;
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
QMetaObject::Connection conn = QObject::connect(m_motorCtrl, &IrisMultiMotorController::locationSignal,
|
||||
[&](std::vector<double> pos) {
|
||||
m_locBeforeStart = pos;
|
||||
received = true;
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
QMetaObject::invokeMethod(m_motorCtrl, "getLoc", Qt::QueuedConnection);
|
||||
timer.start(3000);
|
||||
|
||||
loop.exec();
|
||||
|
||||
disconnect(conn);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::move2LocBeforeStart()
|
||||
{
|
||||
std::cout << "\nmove2LocBeforeStart." << std::endl;
|
||||
|
||||
emit moveTo(0, m_locBeforeStart[0], m_pathLine.speedBack, 1000);
|
||||
|
||||
m_isRunning = false;
|
||||
}
|
||||
|
||||
bool OneMotionCaptureCoordinator::saveToCsv(const QString& filename)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out << "startTime,stopTime,startPosition,stopPosition\n";
|
||||
|
||||
out << m_pathLine.timestamp1.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< m_pathLine.timestamp2.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< QString::number(m_pathLine.startPosition, 'f', 4) << ","
|
||||
<< QString::number(m_pathLine.stopPosition, 'f', 4) << "\n";
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleMotorStoped(int motorID, double pos)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
// 记录位置信息
|
||||
m_pathLine.stopPosition = pos;
|
||||
m_pathLine.timestamp2 = QDateTime::currentDateTime();
|
||||
|
||||
//光谱仪停止采集,马达回到初始位置
|
||||
emit stopRecordHSISignal();
|
||||
if (m_cameraCtrl != nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
move2LocBeforeStart();
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleCaptureComplete(double index)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleError(const QString& error)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
m_isRunning = false;
|
||||
emit errorOccurred(error);
|
||||
}
|
||||
|
@ -105,3 +105,65 @@ private:
|
||||
|
||||
int m_numCurrentPathLine;
|
||||
};
|
||||
|
||||
|
||||
struct OneMotionCapturePathLine
|
||||
{
|
||||
double startPosition;
|
||||
double stopPosition;
|
||||
double speedRecord;
|
||||
double speedBack;
|
||||
|
||||
QDateTime timestamp1;//开始
|
||||
QDateTime timestamp2;//结束
|
||||
|
||||
OneMotionCapturePathLine()
|
||||
: startPosition(0), stopPosition(0), speedRecord(0), speedBack(0),
|
||||
timestamp1(QDateTime::currentDateTime()), timestamp2(QDateTime::currentDateTime()) {}
|
||||
};
|
||||
Q_DECLARE_METATYPE(OneMotionCapturePathLine);
|
||||
|
||||
class OneMotionCaptureCoordinator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OneMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent = nullptr);
|
||||
~OneMotionCaptureCoordinator();
|
||||
|
||||
bool saveToCsv(const QString& filename);
|
||||
|
||||
public slots:
|
||||
void startStepMotion(OneMotionCapturePathLine pathLine);
|
||||
void stopStepMotion();
|
||||
|
||||
void handleCaptureCompleteWhenFrameNumberMeet();
|
||||
|
||||
signals:
|
||||
void sequenceComplete(int);
|
||||
void errorOccurred(const QString& error);
|
||||
void moveTo(int, double, double, int);
|
||||
void moveSignal(int, bool, double, int);
|
||||
void stopMotorSignal(int axis);
|
||||
|
||||
void startRecordHSISignal();
|
||||
void stopRecordHSISignal();
|
||||
|
||||
private slots:
|
||||
void handleMotorStoped(int motorID, double pos);
|
||||
void handleCaptureComplete(double index);
|
||||
void handleError(const QString& error);
|
||||
|
||||
private:
|
||||
IrisMultiMotorController* m_motorCtrl;
|
||||
ImagerOperationBase* m_cameraCtrl;
|
||||
OneMotionCapturePathLine m_pathLine;
|
||||
mutable QMutex m_dataMutex;
|
||||
|
||||
bool m_isRunning;
|
||||
|
||||
std::vector<double> m_locBeforeStart;
|
||||
void getLocBeforeStart();
|
||||
void move2LocBeforeStart();
|
||||
};
|
@ -302,7 +302,6 @@ HPPA::HPPA(QWidget *parent)
|
||||
|
||||
//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
omc = new OneMotorControl();
|
||||
connect(omc, SIGNAL(startRecordLineSignal(int)), this, SLOT(recordHyperSpecImg(int)));
|
||||
|
||||
dock_omc = new QDockWidget(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), this);
|
||||
dock_omc->setObjectName("mDockOneMotorControl");
|
||||
@ -341,19 +340,6 @@ HPPA::HPPA(QWidget *parent)
|
||||
}
|
||||
}
|
||||
|
||||
void HPPA::recordHyperSpecImg(int status)
|
||||
{
|
||||
if (status == 1)
|
||||
{
|
||||
emit StartRecordSignal();//<2F><><EFBFBD>俪ʼ<E4BFAA>ɼ<EFBFBD><C9BC>ź<EFBFBD>
|
||||
}
|
||||
else if (status == 0)
|
||||
{
|
||||
m_Imager->setRecordControlState(false);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HPPA::recordFromRobotArm(int fileCounter)
|
||||
{
|
||||
//qDebug() << "recordFromRobotArm" << fileCounter;
|
||||
@ -585,7 +571,7 @@ void HPPA::onStartRecordStep1()
|
||||
{
|
||||
m_RecordState -= 1;
|
||||
|
||||
string tmp = imgPath + "_" + std::to_string(1) + ".bil";
|
||||
string tmp = imgPath + "_" + std::to_string(0) + ".bil";
|
||||
int x = _access(tmp.c_str(), 0);
|
||||
if (!x)//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ھ<EFBFBD>ִ<EFBFBD>д<EFBFBD>if<69>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
{
|
||||
@ -650,11 +636,12 @@ void HPPA::onStartRecordStep1()
|
||||
//Ӧ<><D3A6><EFBFBD>ȿ<EFBFBD><C8BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>Dzɼ<C7B2><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>俪ʼ<E4BFAA>ɼ<EFBFBD><C9BC>źţ<C5BA>
|
||||
m_Imager->setFileName2Save(imgPath);
|
||||
m_Imager->setFrameNumber(this->frame_number->text().toInt());
|
||||
omc->moveMotorAndRecordHyperSpecImg(500);
|
||||
omc->setImager(m_Imager);
|
||||
omc->run();
|
||||
}
|
||||
else
|
||||
{
|
||||
omc->moveMotor2StartPosAndStopRecord();
|
||||
omc->stop();
|
||||
m_RecordState -= 1;
|
||||
|
||||
ui.action_start_recording->setText(QString::fromLocal8Bit("<EFBFBD>ɼ<EFBFBD>"));
|
||||
@ -963,7 +950,7 @@ void HPPA::onLeftMouseButtonPressed(int x, int y)
|
||||
|
||||
FileOperation * fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryFromString();
|
||||
string imgPath = directory + "\\" + m_FilenameLineEdit->text().toStdString() + "_" + std::to_string(m_TabWidgetCurrentIndex + 1) + ".bil";
|
||||
string imgPath = directory + "\\" + m_FilenameLineEdit->text().toStdString() + "_" + std::to_string(m_TabWidgetCurrentIndex) + ".bil";
|
||||
|
||||
ImageReaderWriter *ImageReader = new ImageReaderWriter(imgPath.c_str());
|
||||
|
||||
@ -2361,12 +2348,6 @@ void HPPA::onRecordFinishedSignal_WhenFrameNumberMeet()
|
||||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||||
|
||||
m_RecordState++;//<2F><><EFBFBD>Զ<EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
|
||||
if (checkedName == "mAction_1AxisMotor")
|
||||
{
|
||||
omc->moveMotor2StartPosAndStopRecord();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HPPA::onRecordFinishedSignal_WhenFrameNumberNotMeet()
|
||||
|
@ -350,7 +350,6 @@ public Q_SLOTS:
|
||||
void requestFinished(QNetworkReply* reply);
|
||||
|
||||
void recordFromRobotArm(int fileCounter);
|
||||
void recordHyperSpecImg(int status);
|
||||
|
||||
void createOneMotorScenario();
|
||||
signals:
|
||||
|
@ -53,10 +53,6 @@ void OneMotorControl::onConnectMotor()
|
||||
connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement()));
|
||||
connect(this, SIGNAL(rangeMeasurement(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int)));
|
||||
|
||||
connect(this, SIGNAL(recordHyperSpecImgOneMotorSignal(int, double, double)), m_multiAxisController, SLOT(recordHyperSpecImgOneMotor(int, double, double)));
|
||||
|
||||
connect(m_multiAxisController, SIGNAL(startRecordLineSignal(int)), this, SIGNAL(startRecordLineSignal(int)));
|
||||
|
||||
connect(this, SIGNAL(testConnectivitySignal(int, int)), m_multiAxisController, SLOT(testConnectivity(int, int)));
|
||||
connect(m_multiAxisController, SIGNAL(broadcastConnectivity(std::vector<int>)), this, SLOT(display_motors_connectivity(std::vector<int>)));
|
||||
|
||||
@ -121,15 +117,36 @@ void OneMotorControl::onxMotorStop()
|
||||
emit stopSignal(0);
|
||||
}
|
||||
|
||||
void OneMotorControl::moveMotorAndRecordHyperSpecImg(int updateIntervalMs)
|
||||
void OneMotorControl::setImager(ImagerOperationBase* imager)
|
||||
{
|
||||
double runSpeed = ui.speed_lineEdit->text().toDouble();
|
||||
double returnSpeed = ui.return_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit recordHyperSpecImgOneMotorSignal(updateIntervalMs, runSpeed, returnSpeed);
|
||||
m_Imager = imager;
|
||||
}
|
||||
|
||||
void OneMotorControl::moveMotor2StartPosAndStopRecord()
|
||||
void OneMotorControl::run()
|
||||
{
|
||||
m_multiAxisController->cancelRecord();
|
||||
if (m_coordinator == nullptr)
|
||||
{
|
||||
qRegisterMetaType<OneMotionCapturePathLine>("OneMotionCapturePathLine");
|
||||
m_coordinator = new OneMotionCaptureCoordinator(m_multiAxisController, m_Imager);
|
||||
connect(this, SIGNAL(start(OneMotionCapturePathLine)), m_coordinator, SLOT(startStepMotion(OneMotionCapturePathLine)));
|
||||
connect(this, SIGNAL(stopStepMotionSignal()), m_coordinator, SLOT(stopStepMotion()));
|
||||
|
||||
connect(m_coordinator, SIGNAL(sequenceComplete(int)), this, SLOT(onSequenceComplete()));
|
||||
}
|
||||
|
||||
OneMotionCapturePathLine tmp;
|
||||
tmp.speedRecord = ui.speed_lineEdit->text().toDouble();
|
||||
tmp.speedBack = ui.return_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit start(tmp);
|
||||
}
|
||||
|
||||
void OneMotorControl::stop()
|
||||
{
|
||||
emit stopStepMotionSignal();
|
||||
}
|
||||
|
||||
void OneMotorControl::onSequenceComplete()
|
||||
{
|
||||
emit sequenceComplete();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "IrisMultiMotorController.h"
|
||||
#include "fileOperation.h"
|
||||
#include "CaptureCoordinator.h"
|
||||
|
||||
class OneMotorControl : public QDialog
|
||||
{
|
||||
@ -15,8 +16,10 @@ public:
|
||||
OneMotorControl(QWidget* parent = nullptr);
|
||||
~OneMotorControl();
|
||||
|
||||
void moveMotorAndRecordHyperSpecImg(int updateIntervalMs);
|
||||
void moveMotor2StartPosAndStopRecord();
|
||||
void setImager(ImagerOperationBase* imager);
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
@ -32,6 +35,8 @@ public Q_SLOTS:
|
||||
void onxMotorLeft();
|
||||
void onxMotorStop();
|
||||
|
||||
void onSequenceComplete();
|
||||
|
||||
signals:
|
||||
void moveSignal(int, bool, double, int);
|
||||
void move2LocSignal(int, double, double, int);
|
||||
@ -42,12 +47,17 @@ signals:
|
||||
void zeroStartSignal(int);
|
||||
void testConnectivitySignal(int, int);
|
||||
|
||||
void recordHyperSpecImgOneMotorSignal(int updateIntervalMs, double runSpeed, double returnSpeed);
|
||||
void start(OneMotionCapturePathLine);
|
||||
void stopStepMotionSignal();
|
||||
|
||||
void sequenceComplete();
|
||||
|
||||
void startRecordLineSignal(int);
|
||||
private:
|
||||
Ui::OneMotorControl_UI ui;
|
||||
|
||||
QThread m_motorThread;
|
||||
IrisMultiMotorController* m_multiAxisController;
|
||||
|
||||
OneMotionCaptureCoordinator* m_coordinator = nullptr;
|
||||
ImagerOperationBase* m_Imager;
|
||||
};
|
||||
|
Reference in New Issue
Block a user