95 lines
3.3 KiB
C++
95 lines
3.3 KiB
C++
#ifndef WORKPIECEPOSITIONPRESENTER_H
|
||
#define WORKPIECEPOSITIONPRESENTER_H
|
||
|
||
#include <QTimer>
|
||
#include <mutex>
|
||
#include <vector>
|
||
#include <memory>
|
||
#include <future>
|
||
#include "BasePresenter.h"
|
||
#include "IYWorkpiecePositionStatus.h"
|
||
#include "IBinocularMarkReceiver.h"
|
||
#include "IEpicEyeDevice.h"
|
||
#include "IVrConfig.h"
|
||
|
||
/**
|
||
* @brief 工件定位Presenter
|
||
*
|
||
* 继承自BasePresenter,使用BinocularMark和EpicEye设备进行工件定位
|
||
* 不使用BasePresenter的激光相机功能,而是使用自己的设备管理
|
||
*/
|
||
class WorkpiecePositionPresenter : public BasePresenter
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit WorkpiecePositionPresenter(QObject *parent = nullptr);
|
||
~WorkpiecePositionPresenter();
|
||
|
||
// 获取配置管理器
|
||
IVrConfig* GetConfigManager() { return m_pConfig; }
|
||
|
||
// ============ 重写 BasePresenter 的检测方法 ============
|
||
int StartDetection(int cameraIndex = -1, bool isAuto = true) override;
|
||
int StopDetection() override;
|
||
|
||
protected:
|
||
// ============ 实现 BasePresenter 纯虚函数 ============
|
||
int InitApp() override;
|
||
int InitAlgoParams() override;
|
||
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
|
||
EVzResultDataType GetDetectionDataType() override;
|
||
void OnCameraStatusChanged(int cameraIndex, bool isConnected) override;
|
||
|
||
// ============ 重写 BasePresenter 虚函数 ============
|
||
void OnWorkStatusChanged(WorkStatus status) override;
|
||
void OnStatusUpdate(const std::string& statusMessage) override;
|
||
|
||
private slots:
|
||
void onMarkReconnectTimeout();
|
||
void onEpicEyeReconnectTimeout();
|
||
|
||
private:
|
||
// 初始化方法
|
||
int InitConfig();
|
||
int InitBinocularMarkReceiver();
|
||
int InitEpicEyeDevice();
|
||
|
||
// 回调处理
|
||
void OnMarkResult(const std::vector<VrMark3D>& marks, qint64 timestamp, int errorCode);
|
||
void OnMarkConnectionChanged(bool connected);
|
||
|
||
// 算法处理
|
||
int CalculateWorkpieceCenter(const std::vector<VrMark3D>& marks, const PointCloudData& pointCloud, WorkpieceCenterPosition& centerPosition);
|
||
|
||
// 连接方法
|
||
int ConnectToBinocularMark();
|
||
int ConnectToEpicEye();
|
||
|
||
private:
|
||
// 配置相关
|
||
IVrConfig* m_pConfig = nullptr;
|
||
ConfigResult m_configResult;
|
||
|
||
// BinocularMark 设备
|
||
IBinocularMarkReceiver* m_pMarkReceiver = nullptr;
|
||
std::string m_binocularMarkIp;
|
||
quint16 m_binocularMarkPort = 0;
|
||
bool m_bMarkConnected = false;
|
||
QTimer* m_pMarkReconnectTimer = nullptr;
|
||
|
||
// EpicEye 设备
|
||
IEpicEyeDevice* m_pEpicEyeDevice = nullptr;
|
||
std::string m_epicEyeIp;
|
||
bool m_bEpicEyeConnected = false;
|
||
QTimer* m_pEpicEyeReconnectTimer = nullptr;
|
||
|
||
// 检测相关
|
||
bool m_bDetecting = false;
|
||
std::mutex m_detectMutex;
|
||
std::vector<VrMark3D> m_lastMarks;
|
||
std::shared_ptr<std::future<void>> m_detectionFuture;
|
||
};
|
||
|
||
#endif // WORKPIECEPOSITIONPRESENTER_H
|