150 lines
5.3 KiB
C++
150 lines
5.3 KiB
C++
#ifndef CGLLINELASERDEVICE_H
|
||
#define CGLLINELASERDEVICE_H
|
||
|
||
#include "IGlLineLaserDevice.h"
|
||
#include "phoskey_ss.h"
|
||
|
||
#include <thread>
|
||
#include <atomic>
|
||
#include <mutex>
|
||
#include <condition_variable>
|
||
#include <vector>
|
||
#include <string>
|
||
|
||
/**
|
||
* @brief CGlLineLaserDevice 实现类
|
||
*
|
||
* 将 gl_linelaser_sdk (phoskey_ss) 的接口适配到 IVrEyeDevice 接口。
|
||
* 数据转换:gl_linelaser_sdk 的 int32_t 轮廓数据(单位0.01um)转换为
|
||
* SVzLaserLineData 的 SVzNL3DPosition 格式(单位mm)。
|
||
*/
|
||
class CGlLineLaserDevice : public IGlLineLaserDevice
|
||
{
|
||
public:
|
||
CGlLineLaserDevice();
|
||
~CGlLineLaserDevice();
|
||
|
||
// ============ 实现 IVrEyeDevice 接口 ============
|
||
|
||
int InitDevice() override;
|
||
|
||
int SetStatusCallback(VzNL_OnNotifyStatusCBEx fNotify, void *param) override;
|
||
|
||
int OpenDevice(const char* sIP, bool bRGBD = false, bool bSwing = true, bool bFillLaser = true) override;
|
||
|
||
int GetVersion(SVzNLVersionInfo& sVersionInfo) override;
|
||
|
||
int GetDevInfo(SVzNLEyeDeviceInfoEx& sDeviceInfo) override;
|
||
|
||
int CloseDevice() override;
|
||
|
||
int StartDetect(VzNL_AutoOutputLaserLineExCB fCallFunc, EVzResultDataType eDataType, void *param) override;
|
||
|
||
bool IsDetectIng() override;
|
||
|
||
int StopDetect() override;
|
||
|
||
int SetDetectROI(SVzNLRect& leftROI, SVzNLRect& rightROI) override;
|
||
int GetDetectROI(SVzNLRect& leftROI, SVzNLRect& rightROI) override;
|
||
|
||
int SetEyeExpose(unsigned int& exposeTime) override;
|
||
int GetEyeExpose(unsigned int& exposeTime) override;
|
||
|
||
int SetEyeGain(unsigned int& gain) override;
|
||
int GetEyeGain(unsigned int& gain) override;
|
||
|
||
int SetFrame(int& frame) override;
|
||
int GetFrame(int& frame) override;
|
||
|
||
bool IsSupport() override;
|
||
|
||
int SetRGBDExposeThres(float& value) override;
|
||
int GetRGBDExposeThres(float& value) override;
|
||
|
||
int SetFilterHeight(double& dHeight) override;
|
||
int GetFilterHeight(double& dHeight) override;
|
||
|
||
int GetSwingSpeed(float& fSpeed) override;
|
||
int SetSwingSpeed(float& fSpeed) override;
|
||
|
||
int SetSwingAngle(float& fMin, float& fMax) override;
|
||
int GetSwingAngle(float& fMin, float& fMax) override;
|
||
|
||
int SetWorkRange(double& dMin, double& dMax) override;
|
||
int GetWorkRange(double& dMin, double& dMax) override;
|
||
|
||
// ============ 实现 IGlLineLaserDevice 专用接口 ============
|
||
|
||
int GetProfileDataWidth() override;
|
||
double GetXPitch() override;
|
||
double GetYPitch() override;
|
||
int SetYPitch(double pitch) override;
|
||
int SetBatchLines(unsigned int batchLines) override;
|
||
unsigned int GetBatchLines() override;
|
||
int SwitchProgram(int programNo) override;
|
||
int GetModelInfo(char* model, char* serialNumber) override;
|
||
int GetMeasureRange(double& xMin, double& xMax, double& zMin, double& zMax) override;
|
||
|
||
private:
|
||
// 设备状态
|
||
int m_nDeviceId = 0; // 设备ID
|
||
bool m_bDeviceOpen = false; // 设备是否打开
|
||
std::string m_strDeviceIP; // 设备IP
|
||
|
||
// 设备信息
|
||
GLX8_2_ModelInfo m_modelInfo; // 型号信息
|
||
int m_nProfileWidth = 4096; // 轮廓数据宽度
|
||
double m_dXPitch = 0.01; // X方向间距 (mm)
|
||
double m_dYPitch = 1.0; // Y方向间距 (mm),用户设置
|
||
|
||
// 批处理参数
|
||
unsigned int m_nBatchLines = 200; // 批处理行数
|
||
|
||
// 回调相关
|
||
VzNL_AutoOutputLaserLineExCB m_pDetectCallback = nullptr;
|
||
void* m_pDetectCallbackParam = nullptr;
|
||
EVzResultDataType m_eDataType = keResultDataType_Position;
|
||
|
||
VzNL_OnNotifyStatusCBEx m_pStatusCallback = nullptr;
|
||
void* m_pStatusCallbackParam = nullptr;
|
||
|
||
// 数据采集线程
|
||
std::thread m_detectThread;
|
||
std::atomic<bool> m_bDetecting{false};
|
||
std::atomic<bool> m_bStopDetect{false};
|
||
std::mutex m_detectMutex;
|
||
std::condition_variable m_detectCondition;
|
||
|
||
// 数据缓存
|
||
std::vector<int32_t> m_profileBuffer; // 轮廓数据缓存
|
||
std::vector<uint8_t> m_intensityBuffer; // 亮度数据缓存
|
||
std::vector<SVzNL3DPosition> m_positionBuffer; // 转换后的位置数据
|
||
|
||
// 帧计数
|
||
unsigned long long m_ullFrameIndex = 0;
|
||
unsigned long long m_ullTimeStamp = 0;
|
||
|
||
// 内部方法
|
||
|
||
/**
|
||
* @brief 数据采集线程函数(主动轮询模式,参考 test_deal_atch_datas)
|
||
*/
|
||
void DetectThreadFunc();
|
||
|
||
/**
|
||
* @brief 获取批处理数据(参考 test_batch_datas 的流程)
|
||
*/
|
||
void GetBatchData();
|
||
|
||
/**
|
||
* @brief 将 gl_linelaser_sdk 的轮廓数据转换为 SVzNL3DPosition
|
||
* @param profileData 轮廓数据(int32_t,单位0.01um)
|
||
* @param count 数据点数
|
||
* @param lineIndex 当前行索引
|
||
* @return 转换后的位置数据数组
|
||
*/
|
||
void ConvertProfileToPosition(const int32_t* profileData, int count, int lineIndex);
|
||
};
|
||
|
||
#endif // CGLLINELASERDEVICE_H
|