2025-07-23 01:35:14 +08:00
|
|
|
|
#ifndef GRABBAGPRESENTER_H
|
|
|
|
|
|
#define GRABBAGPRESENTER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
|
|
|
|
|
#include "IVrConfig.h"
|
|
|
|
|
|
#include "IVrEyeDevice.h"
|
|
|
|
|
|
#include "IYGrabBagStatus.h"
|
|
|
|
|
|
#include "DetectPresenter.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);
|
|
|
|
|
|
|
|
|
|
|
|
// 为所有相机设置状态回调
|
|
|
|
|
|
void SetCameraStatusCallback(VzNL_OnNotifyStatusCBEx fNotify, void* param);
|
|
|
|
|
|
|
2025-07-26 01:10:21 +08:00
|
|
|
|
// 设置默认相机索引
|
|
|
|
|
|
void SetDefaultCameraIndex(int cameraIndex);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前默认相机索引
|
|
|
|
|
|
int GetDefaultCameraIndex() const { return m_currentCameraIndex; }
|
|
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 获取配置对象
|
|
|
|
|
|
IVrConfig* GetConfig() { return m_vrConfig; }
|
2025-07-26 01:10:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取相机列表
|
|
|
|
|
|
std::vector<std::pair<std::string, IVrEyeDevice*>> GetCameraList() const { return m_vrEyeDeviceList; } // 返回相机列表,包括IP地址和设备指针
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 手眼标定矩阵管理
|
|
|
|
|
|
const CalibMatrix GetClibMatrix(int index) const;
|
|
|
|
|
|
|
|
|
|
|
|
// 实现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;
|
2025-07-26 01:10:21 +08:00
|
|
|
|
std::vector<std::pair<std::string, IVrEyeDevice*>> m_vrEyeDeviceList;
|
2025-07-23 01:35:14 +08:00
|
|
|
|
IYGrabBagStatus* m_pStatus = nullptr;
|
|
|
|
|
|
DetectPresenter* m_pDetectPresenter = 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;
|
|
|
|
|
|
|
|
|
|
|
|
// 检测数据缓存 - 直接存储算法格式数据
|
2025-07-26 01:10:21 +08:00
|
|
|
|
std::mutex m_detectionDataMutex;
|
|
|
|
|
|
std::vector<SVzNL3DLaserLine> m_detectionDataCache;
|
2025-07-23 01:35:14 +08:00
|
|
|
|
std::vector<SVzNLXYZRGBDLaserLine> m_detectionDataCacheRGBD;
|
|
|
|
|
|
|
|
|
|
|
|
// 算法参数成员变量
|
|
|
|
|
|
SG_bagPositionParam m_algoParam; // 算法参数
|
|
|
|
|
|
SSG_planeCalibPara m_planeCalibParam; // 默认平面校准参数
|
|
|
|
|
|
std::vector<VrCameraPlaneCalibParam> m_cameraCalibParams; // 多相机调平参数
|
|
|
|
|
|
std::vector<CalibMatrix> m_clibMatrixList; // 手眼标定矩阵列表
|
|
|
|
|
|
VrDebugParam m_debugParam; // 调试参数
|
|
|
|
|
|
|
|
|
|
|
|
// 颜色参数成员变量
|
|
|
|
|
|
SSG_hsvCmpParam m_hsvCmpParam; // HSV颜色比较参数
|
|
|
|
|
|
RGB m_rgbColorPattern; // RGB颜色模式
|
|
|
|
|
|
double m_frontColorTemplate[RGN_HIST_SIZE]; // 颜色模板参数
|
|
|
|
|
|
double m_backColorTemplate[RGN_HIST_SIZE]; // 颜色模板参数
|
|
|
|
|
|
|
|
|
|
|
|
ProjectType m_projectType;
|
|
|
|
|
|
|
|
|
|
|
|
// 调试数据加载器
|
|
|
|
|
|
LaserDataLoader m_dataLoader;
|
|
|
|
|
|
|
|
|
|
|
|
// 配置管理器
|
|
|
|
|
|
std::unique_ptr<ConfigManager> m_pConfigManager;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // GRABBAGPRESENTER_H
|