2025-06-08 12:48:04 +08:00
|
|
|
|
#ifndef GRABBAGPRESENTER_H
|
|
|
|
|
|
#define GRABBAGPRESENTER_H
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
#include "IVrConfig.h"
|
|
|
|
|
|
#include "IVrEyeDevice.h"
|
|
|
|
|
|
#include "IYGrabBagStatus.h"
|
|
|
|
|
|
#include "RobotProtocol.h"
|
2025-06-08 23:51:48 +08:00
|
|
|
|
#include "VZNL_Types.h"
|
2025-06-17 00:37:05 +08:00
|
|
|
|
#include "SG_bagPositioning_Export.h"
|
|
|
|
|
|
#include "LaserDataLoader.h"
|
|
|
|
|
|
#include <QImage>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QColor>
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
class GrabBagPresenter
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
GrabBagPresenter();
|
|
|
|
|
|
~GrabBagPresenter();
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
|
int Init();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置状态回调
|
|
|
|
|
|
void SetStatusCallback(IYGrabBagStatus* status);
|
|
|
|
|
|
|
|
|
|
|
|
// 开始检测
|
2025-06-17 00:37:05 +08:00
|
|
|
|
int StartDetection(int cameraIndex = -1); // cameraIndex: -1表示所有相机,0/1/2...表示特定相机
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
// 停止检测
|
|
|
|
|
|
int StopDetection();
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 加载调试数据进行检测
|
|
|
|
|
|
int LoadDebugDataAndDetect(const std::string& filePath);
|
|
|
|
|
|
|
2025-06-08 23:51:48 +08:00
|
|
|
|
IVrEyeDevice* GetEyeDevice(int index);
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 点云转图像
|
|
|
|
|
|
QImage _GeneratePointCloudImage(SVzNL3DLaserLine* scanData, int lineNum,
|
|
|
|
|
|
const std::vector<SSG_peakRgnInfo>& objOps);
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
private:
|
|
|
|
|
|
// 机械臂协议相关方法
|
|
|
|
|
|
int InitRobotProtocol();
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 算法初始化接口
|
|
|
|
|
|
int InitAlgorithmParams();
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 机械臂协议回调函数
|
|
|
|
|
|
void OnRobotConnectionChanged(bool connected);
|
2025-06-20 01:28:00 +08:00
|
|
|
|
bool OnRobotWorkSignal(bool startWork, int cameraIndex);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-08 23:51:48 +08:00
|
|
|
|
// 连接状态检查和更新
|
|
|
|
|
|
void CheckAndUpdateWorkStatus();
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 静态回调函数,用于传递给SDK
|
|
|
|
|
|
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
|
|
|
|
|
|
|
|
|
|
|
// 实例方法,处理回调
|
|
|
|
|
|
void _CameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
|
|
|
|
|
|
2025-06-08 23:51:48 +08:00
|
|
|
|
// 检测数据回调函数
|
|
|
|
|
|
static void _StaticDetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
|
|
|
|
|
|
void _DetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint);
|
|
|
|
|
|
|
|
|
|
|
|
// 算法检测线程
|
|
|
|
|
|
void _AlgoDetectThread();
|
|
|
|
|
|
|
|
|
|
|
|
int _DetectTask();
|
2025-06-17 00:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
// 释放缓存的检测数据
|
|
|
|
|
|
void _ClearDetectionDataCache();
|
|
|
|
|
|
|
|
|
|
|
|
// 发送检测结果给机械臂
|
|
|
|
|
|
void _SendDetectionResultToRobot(const std::vector<SSG_peakRgnInfo>& objOps);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
2025-06-08 23:51:48 +08:00
|
|
|
|
IVrConfig* m_vrConfig = nullptr;
|
|
|
|
|
|
std::vector<IVrEyeDevice*> m_vrEyeDeviceList;
|
|
|
|
|
|
IYGrabBagStatus* m_pStatus = nullptr;
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-08 23:51:48 +08:00
|
|
|
|
RobotProtocol* m_pRobotProtocol = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// 连接状态标志
|
|
|
|
|
|
bool m_bCameraConnected = false; // 相机连接状态
|
|
|
|
|
|
bool m_bRobotConnected = false; // 机械臂连接状态
|
|
|
|
|
|
WorkStatus m_currentWorkStatus = WorkStatus::Error; // 当前工作状态
|
|
|
|
|
|
|
|
|
|
|
|
std::atomic<bool> m_bAlgoDetectThreadRunning = false;
|
|
|
|
|
|
std::mutex m_algoDetectMutex;
|
|
|
|
|
|
std::condition_variable m_algoDetectCondition;
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 检测数据缓存 - 直接存储算法格式数据
|
|
|
|
|
|
std::vector<SVzNL3DLaserLine> m_detectionDataCache;
|
2025-06-08 23:51:48 +08:00
|
|
|
|
std::mutex m_detectionDataMutex;
|
2025-06-17 00:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
// 算法参数成员变量
|
|
|
|
|
|
SG_bagPositionParam m_algoParam; // 算法参数
|
|
|
|
|
|
SSG_planeCalibPara m_planeCalibParam; // 平面校准参数
|
|
|
|
|
|
|
|
|
|
|
|
// 调试数据加载器
|
|
|
|
|
|
LaserDataLoader m_dataLoader;
|
2025-06-08 12:48:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // GRABBAGPRESENTER_H
|