374 lines
9.2 KiB
C++
374 lines
9.2 KiB
C++
#pragma once
|
||
#include <QDateTime>
|
||
#include <QObject>
|
||
#include <QMutex>
|
||
#include <QMetaType>
|
||
|
||
#include "ImagerOperationBase.h"
|
||
#include "IrisMultiMotorController.h"
|
||
|
||
struct PathLine
|
||
{
|
||
double targetYPosition;
|
||
double actualYPosition;
|
||
double speedTargetYPosition;
|
||
|
||
double targetXMinPosition;
|
||
double actualXMinPosition;
|
||
double speedTargetXMinPosition;
|
||
|
||
double targetXMaxPosition;
|
||
double actualXMaxPosition;
|
||
double speedTargetXMaxPosition;
|
||
|
||
QDateTime timestamp1;//开始航线
|
||
QDateTime timestamp2;//开始采集高光谱
|
||
QDateTime timestamp3;//结束采集高光谱
|
||
|
||
PathLine(double targetYPosition_=0, double targetXMinPosition_ = 0, double targetXMaxPosition_ = 0)
|
||
: targetYPosition(targetYPosition_), actualYPosition(0), speedTargetYPosition(0),
|
||
targetXMinPosition(targetXMinPosition_), actualXMinPosition(0), speedTargetXMinPosition(0),
|
||
targetXMaxPosition(targetXMaxPosition_), actualXMaxPosition(0), speedTargetXMaxPosition(0),
|
||
timestamp1(QDateTime::currentDateTime()), timestamp2(QDateTime::currentDateTime()), timestamp3(QDateTime::currentDateTime()) {}
|
||
};
|
||
Q_DECLARE_METATYPE(PathLine);
|
||
//Q_DECLARE_METATYPE(QVector<PathLine>);
|
||
|
||
class TwoMotionCaptureCoordinator : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
TwoMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||
QObject* parent = nullptr);
|
||
~TwoMotionCaptureCoordinator();
|
||
|
||
QVector<PathLine> pathLines() const;
|
||
|
||
signals:
|
||
void sequenceComplete(int);//0:所有采集线正常运行完成,1:用户主动取消采集
|
||
void back2OriginSignal();
|
||
void gotoRecordLineNumSignal(int lineNum);
|
||
void startRecordLineNumSignal(int lineNum);
|
||
void finishRecordLineNumSignal(int lineNum);
|
||
|
||
void startRecordHSISignal(int lineNum);
|
||
void stopRecordHSISignal(int lineNum);
|
||
|
||
void errorOccurred(const QString& error);
|
||
void moveTo(int, double, double, int);
|
||
void moveTo(const std::vector<double>, const std::vector<double>, int);
|
||
void stopMotorSignal(int axis);
|
||
|
||
void recordState(bool state);
|
||
|
||
public slots:
|
||
void handleCaptureCompleteWhenFrameNumberMeet();
|
||
|
||
private slots:
|
||
void start(QVector<PathLine> pathLines);
|
||
void stop();
|
||
void getRecordState();
|
||
|
||
void handlePositionReached(int motorID, double pos);
|
||
void handleError(const QString& error);
|
||
|
||
void move2LocBeforeStart();
|
||
|
||
private:
|
||
void processNextPathLine();
|
||
void startRecordHsi();
|
||
void isBack2Origin();
|
||
void getLocBeforeStart();
|
||
double getThre(double targetLoc, double actualLoc);
|
||
|
||
double getTimeDiffMinutes(QDateTime startTime, QDateTime endTime);
|
||
bool savePathLinesToCsv(QString filename= QString());
|
||
|
||
IrisMultiMotorController* m_motorCtrl;
|
||
ImagerOperationBase* m_cameraCtrl=nullptr;
|
||
QVector<PathLine> m_pathLines;
|
||
mutable QMutex m_dataMutex;
|
||
|
||
bool m_isRunning;
|
||
bool m_isValidCapturing;
|
||
bool m_isMoving2YTargeLoc;
|
||
bool m_isMoving2XMin;
|
||
bool m_isMoving2XMax;
|
||
|
||
int m_retryLimit = 3;
|
||
int m_retryTimesMoving2YTargeLoc;
|
||
int m_retryTimesMoving2XMin;
|
||
int m_retryTimesMoving2XMax;
|
||
|
||
bool m_isImagerFrameNumberMeet;//光谱仪帧数限制到了,主动停止采集
|
||
std::vector<double> m_locBeforeStart;
|
||
|
||
bool m_isMoving2XStartLoc;
|
||
bool m_isMoving2YStartLoc;
|
||
|
||
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_cam_stop_before_motorback(int);
|
||
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;
|
||
bool m_isHypercamStopRecord = false;
|
||
|
||
std::vector<double> m_locBeforeStart;
|
||
void getLocBeforeStart();
|
||
void move2LocBeforeStart();
|
||
};
|
||
|
||
class DarkAndWhiteCaptureCoordinator : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
DarkAndWhiteCaptureCoordinator(int model, IrisMultiMotorController* motorCtrl,
|
||
ImagerOperationBase* cameraCtrl,
|
||
QObject* parent = nullptr);
|
||
~DarkAndWhiteCaptureCoordinator();
|
||
|
||
public slots:
|
||
void startStepMotion(double speed);
|
||
|
||
void handleCaptureCompleteWhenFrameNumberMeet();
|
||
|
||
signals:
|
||
void sequenceComplete(int);
|
||
void moveTo(int, double, double, int);
|
||
void moveSignal(int, bool, double, int);
|
||
void stopMotorSignal(int axis);
|
||
|
||
void startRecordHSISignal();
|
||
|
||
private slots:
|
||
void handleMotorStoped(int motorID, double pos);
|
||
void handleCaptureComplete(double index);
|
||
|
||
private:
|
||
IrisMultiMotorController* m_motorCtrl;
|
||
ImagerOperationBase* m_cameraCtrl;
|
||
mutable QMutex m_dataMutex;
|
||
|
||
bool m_isRunning;
|
||
|
||
double m_speed;
|
||
int m_model;//0:dark,1:white
|
||
|
||
std::vector<double> m_locBeforeStart;
|
||
void getLocBeforeStart();
|
||
void move2LocBeforeStart();
|
||
};
|
||
|
||
|
||
class TwoMotor1PosCoordinator : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
TwoMotor1PosCoordinator(IrisMultiMotorController* motorCtrl,
|
||
QObject* parent = nullptr);
|
||
~TwoMotor1PosCoordinator();
|
||
|
||
public slots:
|
||
void moveToTarget(double xTarget, double yTarget, double xSpeed, double ySpeed);
|
||
void back2origin();
|
||
|
||
signals:
|
||
void ArrivalSignal(double xPos, double yPos);
|
||
void back2OriginSignal();
|
||
void errorOccurred(const QString& error);
|
||
void moveTo(int, double, double, int);
|
||
void moveTo(const std::vector<double>, const std::vector<double>, int);
|
||
void stopMotorSignal(int axis);
|
||
|
||
private slots:
|
||
void handlePositionReached(int motorID, double pos);
|
||
|
||
private:
|
||
void moveToTargetPrivate(double xTarget, double yTarget, double xSpeed, double ySpeed);
|
||
double getErrorRate(double targetLoc, double actualLoc);
|
||
bool checkArrival();
|
||
void move2Origin();
|
||
|
||
IrisMultiMotorController* m_motorCtrl;
|
||
mutable QMutex m_dataMutex;
|
||
|
||
bool m_isMoving2Target;
|
||
bool m_isMoving2Origin;
|
||
|
||
double m_targetX;
|
||
double m_targetY;
|
||
double m_speedX;
|
||
double m_speedY;
|
||
|
||
double m_actualX;
|
||
double m_actualY;
|
||
|
||
int m_retryLimit = 3;
|
||
int m_retryTimesX;
|
||
int m_retryTimesY;
|
||
|
||
bool m_xReached;
|
||
bool m_yReached;
|
||
};
|
||
|
||
class OneMotionCoordinator : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
OneMotionCoordinator(IrisMultiMotorController* motorCtrl, QObject* parent = nullptr);
|
||
~OneMotionCoordinator();
|
||
|
||
public slots:
|
||
void moveToTarget(double position, double speed);
|
||
|
||
signals:
|
||
void sequenceComplete(int status);
|
||
void ArrivalSignal(double position);
|
||
void moveTo(int, double, double, int);
|
||
|
||
private slots:
|
||
void handlePositionReached(int motorID, double position);
|
||
|
||
private:
|
||
bool checkArrival();
|
||
double getErrorRate(double targetLoc, double actualLoc);
|
||
|
||
IrisMultiMotorController* m_motorCtrl;
|
||
mutable QMutex m_dataMutex;
|
||
|
||
double m_targetPosition;
|
||
double m_speed;
|
||
double m_actualPosition;
|
||
bool m_isMoving;
|
||
|
||
int m_retryLimit = 3;
|
||
int m_retryTimes;
|
||
bool m_reached;
|
||
};
|
||
|
||
|
||
|
||
// 数据记录结构体
|
||
struct PositionsLogData
|
||
{
|
||
double targetPosition; // 目标位置
|
||
double actualPosition; // 实际马达位置
|
||
double exposureTime; //
|
||
QDateTime timestamp; // 时间戳
|
||
|
||
PositionsLogData(double target = 0, double actual = 0.0, double exposure = 0.0)
|
||
: targetPosition(target), actualPosition(actual),
|
||
exposureTime(exposure ), timestamp(QDateTime::currentDateTime()) {
|
||
}
|
||
};
|
||
|
||
// 协调控制器
|
||
class OneMotorMultiPosCoordinator : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
OneMotorMultiPosCoordinator(IrisMultiMotorController* motorCtrl,
|
||
ImagerOperationBase* cameraCtrl,
|
||
QObject* parent = nullptr);
|
||
~OneMotorMultiPosCoordinator();
|
||
|
||
QVector<PositionsLogData> getAllPositionData() const;
|
||
bool saveToCsv(const QString& filename);
|
||
|
||
public slots:
|
||
void startStepMotion(double speed, std::vector<double> locations);
|
||
void stopStepMotion();
|
||
|
||
signals:
|
||
void progressChanged(int progress);
|
||
void sequenceComplete(int status);
|
||
void sequenceStopped();
|
||
void errorOccurred(const QString& error);
|
||
void moveTo(int, double, double, int);
|
||
void getFocusIndexSobel();
|
||
void zeroStart(int motorID);
|
||
|
||
void hyperAutoExposureDoneSignal(double exposureTime);
|
||
|
||
private slots:
|
||
void handlePositionReached(int motorID, double pos);
|
||
void handleCaptureComplete(double index);
|
||
void handleError(const QString& error);
|
||
void handleZeroComplete(int motorID, double pos);
|
||
|
||
private:
|
||
void processNextPosition();
|
||
void startMotionSequence();
|
||
|
||
IrisMultiMotorController* m_motorCtrl;
|
||
ImagerOperationBase* m_cameraCtrl;
|
||
QVector<PositionsLogData> m_positionData;
|
||
mutable QMutex m_dataMutex;
|
||
|
||
double m_currentPos;
|
||
bool m_isRunning;
|
||
double m_speed;
|
||
|
||
int m_iStepInterval;
|
||
int m_iStepIntervalRealTime;
|
||
int m_counter;
|
||
bool m_isZeroing;
|
||
|
||
std::vector<double> m_locations;
|
||
};
|