2025-12-10 00:01:32 +08:00
|
|
|
|
#ifndef WORKPIECEPOSITIONPRESENTER_H
|
|
|
|
|
|
#define WORKPIECEPOSITIONPRESENTER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <memory>
|
2025-12-27 09:34:02 +08:00
|
|
|
|
#include <future>
|
|
|
|
|
|
#include "BasePresenter.h"
|
2025-12-10 00:01:32 +08:00
|
|
|
|
#include "IYWorkpiecePositionStatus.h"
|
|
|
|
|
|
#include "IBinocularMarkReceiver.h"
|
|
|
|
|
|
#include "IEpicEyeDevice.h"
|
|
|
|
|
|
#include "IVrConfig.h"
|
|
|
|
|
|
|
2025-12-27 09:34:02 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 工件定位Presenter
|
|
|
|
|
|
*
|
|
|
|
|
|
* 继承自BasePresenter,使用BinocularMark和EpicEye设备进行工件定位
|
|
|
|
|
|
* 不使用BasePresenter的激光相机功能,而是使用自己的设备管理
|
|
|
|
|
|
*/
|
|
|
|
|
|
class WorkpiecePositionPresenter : public BasePresenter
|
2025-12-10 00:01:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit WorkpiecePositionPresenter(QObject *parent = nullptr);
|
|
|
|
|
|
~WorkpiecePositionPresenter();
|
|
|
|
|
|
|
2025-12-27 09:34:02 +08:00
|
|
|
|
// 获取配置管理器
|
2025-12-10 00:01:32 +08:00
|
|
|
|
IVrConfig* GetConfigManager() { return m_pConfig; }
|
|
|
|
|
|
|
2025-12-27 09:34:02 +08:00
|
|
|
|
// ============ 重写 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;
|
|
|
|
|
|
|
2025-12-10 00:01:32 +08:00
|
|
|
|
private slots:
|
|
|
|
|
|
void onMarkReconnectTimeout();
|
|
|
|
|
|
void onEpicEyeReconnectTimeout();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2025-12-27 09:34:02 +08:00
|
|
|
|
// 初始化方法
|
2025-12-10 00:01:32 +08:00
|
|
|
|
int InitConfig();
|
|
|
|
|
|
int InitBinocularMarkReceiver();
|
|
|
|
|
|
int InitEpicEyeDevice();
|
2025-12-27 09:34:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 回调处理
|
2025-12-10 00:01:32 +08:00
|
|
|
|
void OnMarkResult(const std::vector<VrMark3D>& marks, qint64 timestamp, int errorCode);
|
|
|
|
|
|
void OnMarkConnectionChanged(bool connected);
|
2025-12-27 09:34:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 算法处理
|
2025-12-10 00:01:32 +08:00
|
|
|
|
int CalculateWorkpieceCenter(const std::vector<VrMark3D>& marks, const PointCloudData& pointCloud, WorkpieceCenterPosition& centerPosition);
|
2025-12-27 09:34:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 连接方法
|
2025-12-10 00:01:32 +08:00
|
|
|
|
int ConnectToBinocularMark();
|
|
|
|
|
|
int ConnectToEpicEye();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2025-12-27 09:34:02 +08:00
|
|
|
|
// 配置相关
|
|
|
|
|
|
IVrConfig* m_pConfig = nullptr;
|
2025-12-10 00:01:32 +08:00
|
|
|
|
ConfigResult m_configResult;
|
2025-12-27 09:34:02 +08:00
|
|
|
|
|
|
|
|
|
|
// BinocularMark 设备
|
|
|
|
|
|
IBinocularMarkReceiver* m_pMarkReceiver = nullptr;
|
2025-12-10 00:01:32 +08:00
|
|
|
|
std::string m_binocularMarkIp;
|
2025-12-27 09:34:02 +08:00
|
|
|
|
quint16 m_binocularMarkPort = 0;
|
|
|
|
|
|
bool m_bMarkConnected = false;
|
|
|
|
|
|
QTimer* m_pMarkReconnectTimer = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// EpicEye 设备
|
|
|
|
|
|
IEpicEyeDevice* m_pEpicEyeDevice = nullptr;
|
2025-12-10 00:01:32 +08:00
|
|
|
|
std::string m_epicEyeIp;
|
2025-12-27 09:34:02 +08:00
|
|
|
|
bool m_bEpicEyeConnected = false;
|
|
|
|
|
|
QTimer* m_pEpicEyeReconnectTimer = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// 检测相关
|
|
|
|
|
|
bool m_bDetecting = false;
|
|
|
|
|
|
std::mutex m_detectMutex;
|
2025-12-10 00:01:32 +08:00
|
|
|
|
std::vector<VrMark3D> m_lastMarks;
|
2025-12-27 09:34:02 +08:00
|
|
|
|
std::shared_ptr<std::future<void>> m_detectionFuture;
|
2025-12-10 00:01:32 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // WORKPIECEPOSITIONPRESENTER_H
|