GrabBag/GrabBagApp/Presenter/Inc/GrabBagPresenter.h

127 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GRABBAGPRESENTER_H
#define GRABBAGPRESENTER_H
#include <condition_variable>
#include "IVrConfig.h"
#include "IVrEyeDevice.h"
#include "IYGrabBagStatus.h"
#include "RobotProtocol.h"
#include "VZNL_Types.h"
#include "SG_bagPositioning_Export.h"
#include "LaserDataLoader.h"
#include "PathManager.h"
#include <QImage>
#include <QPainter>
#include <QColor>
class GrabBagPresenter : public IVrConfigChangeNotify
{
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;
// 静态回调函数,供外部使用
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
private:
// 机械臂协议相关方法
int InitRobotProtocol();
// 算法初始化接口
int InitAlgorithmParams();
// 机械臂协议回调函数
void OnRobotConnectionChanged(bool connected);
bool OnRobotWorkSignal(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;
// 连接状态标志
bool m_bCameraConnected = false; // 相机连接状态
bool m_bRobotConnected = 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;
};
#endif // GRABBAGPRESENTER_H