150 lines
5.3 KiB
C++
150 lines
5.3 KiB
C++
#ifndef GRABBAGPRESENTER_H
|
||
#define GRABBAGPRESENTER_H
|
||
|
||
#include <condition_variable>
|
||
|
||
#include "IVrConfig.h"
|
||
#include "IVrEyeDevice.h"
|
||
#include "IYGrabBagStatus.h"
|
||
#include "RobotProtocol.h"
|
||
#include "SerialProtocol.h"
|
||
#include "VZNL_Types.h"
|
||
#include "SG_bagPositioning_Export.h"
|
||
#include "LaserDataLoader.h"
|
||
#include "PathManager.h"
|
||
#include "ConfigManager.h"
|
||
#include <QImage>
|
||
#include <QPainter>
|
||
#include <QColor>
|
||
#include <memory>
|
||
|
||
class GrabBagPresenter : public IVrConfigChangeNotify, public IConfigChangeListener
|
||
{
|
||
public:
|
||
GrabBagPresenter();
|
||
~GrabBagPresenter();
|
||
|
||
// 初始化
|
||
int Init();
|
||
|
||
// 设置状态回调
|
||
void SetStatusCallback(IYGrabBagStatus* status);
|
||
|
||
// 开始检测
|
||
int StartDetection(int cameraIndex = -1, bool isAuto = true); // cameraIndex: -1表示所有相机,1/2...表示特定相机
|
||
|
||
// 停止检测
|
||
int StopDetection();
|
||
|
||
// 加载调试数据进行检测
|
||
int LoadDebugDataAndDetect(const std::string& filePath);
|
||
|
||
IVrEyeDevice* GetEyeDevice(int index);
|
||
|
||
// 相机列表管理相关函数
|
||
std::vector<IVrEyeDevice*> GetCameraList();
|
||
int GetCameraCount();
|
||
void GetCameraListWithNames(std::vector<IVrEyeDevice*>& cameraList, std::vector<QString>& cameraNames);
|
||
bool IsCameraConnected(int index);
|
||
|
||
// 为所有相机设置状态回调
|
||
void SetCameraStatusCallback(VzNL_OnNotifyStatusCBEx fNotify, void* param);
|
||
|
||
// 获取配置对象
|
||
IVrConfig* GetConfig() { return m_vrConfig; }
|
||
|
||
// 实现IVrConfigChangeNotify接口
|
||
virtual void OnConfigChanged(const ConfigResult& configResult) override;
|
||
|
||
// 实现IConfigChangeListener接口
|
||
virtual void OnSystemConfigChanged(const SystemConfig& config) override;
|
||
virtual void OnCameraParamChanged(int cameraIndex, const CameraUIParam& cameraParam) override;
|
||
virtual void OnAlgorithmParamChanged(const VrAlgorithmParams& algorithmParams) override;
|
||
|
||
// 配置管理
|
||
ConfigManager* GetConfigManager() { return m_pConfigManager.get(); }
|
||
|
||
// 静态回调函数,供外部使用
|
||
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
||
|
||
private:
|
||
// 机械臂协议相关方法
|
||
int InitRobotProtocol();
|
||
|
||
// 串口协议相关方法
|
||
int InitSerialProtocol();
|
||
|
||
// 算法初始化接口
|
||
int InitAlgorithmParams();
|
||
|
||
// 机械臂协议回调函数
|
||
void OnRobotConnectionChanged(bool connected);
|
||
bool OnRobotWorkSignal(bool startWork, int cameraIndex);
|
||
|
||
// 串口协议回调函数
|
||
void OnSerialConnectionChanged(bool connected);
|
||
bool OnSerialWorkSignal(bool startWork, int cameraIndex);
|
||
|
||
// 连接状态检查和更新
|
||
void CheckAndUpdateWorkStatus();
|
||
|
||
// 实例方法,处理回调
|
||
void _CameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
||
|
||
// 检测数据回调函数
|
||
static void _StaticDetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
|
||
void _DetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint);
|
||
|
||
// 算法检测线程
|
||
void _AlgoDetectThread();
|
||
|
||
int _DetectTask();
|
||
|
||
// 释放缓存的检测数据
|
||
void _ClearDetectionDataCache();
|
||
|
||
// 发送检测结果给机械臂
|
||
void _SendDetectionResultToRobot(const DetectionResult& detectionResult, int cameraIndex);
|
||
|
||
// 根据相机索引获取调平参数
|
||
SSG_planeCalibPara _GetCameraCalibParam(int cameraIndex);
|
||
|
||
private:
|
||
IVrConfig* m_vrConfig = nullptr;
|
||
std::vector<IVrEyeDevice*> m_vrEyeDeviceList;
|
||
IYGrabBagStatus* m_pStatus = nullptr;
|
||
|
||
RobotProtocol* m_pRobotProtocol = nullptr;
|
||
SerialProtocol* m_pSerialProtocol = nullptr;
|
||
|
||
// 连接状态标志
|
||
bool m_bCameraConnected = false; // 相机连接状态
|
||
bool m_bRobotConnected = false; // 机械臂连接状态
|
||
bool m_bSerialConnected = false; // 串口连接状态
|
||
WorkStatus m_currentWorkStatus = WorkStatus::Error; // 当前工作状态
|
||
int m_currentCameraIndex = 0; // 当前使用的相机编号
|
||
|
||
std::atomic<bool> m_bAlgoDetectThreadRunning = false;
|
||
std::mutex m_algoDetectMutex;
|
||
std::condition_variable m_algoDetectCondition;
|
||
|
||
// 检测数据缓存 - 直接存储算法格式数据
|
||
std::vector<SVzNL3DLaserLine> m_detectionDataCache;
|
||
std::mutex m_detectionDataMutex;
|
||
|
||
// 算法参数成员变量
|
||
SG_bagPositionParam m_algoParam; // 算法参数
|
||
SSG_planeCalibPara m_planeCalibParam; // 默认平面校准参数
|
||
std::vector<VrCameraPlaneCalibParam> m_cameraCalibParams; // 多相机调平参数
|
||
VrDebugParam m_debugParam; // 调试参数
|
||
double m_clibMatrix[16]; // 手眼标定矩阵
|
||
|
||
// 调试数据加载器
|
||
LaserDataLoader m_dataLoader;
|
||
|
||
// 配置管理器
|
||
std::unique_ptr<ConfigManager> m_pConfigManager;
|
||
};
|
||
|
||
#endif // GRABBAGPRESENTER_H
|