#ifndef IVRCONFIG_H #define IVRCONFIG_H #include #include #include #include #include #include "VrCommonConfig.h" #include "VrHandEyeCalibConfig.h" /** * @brief 角点检测参数(工件定位算法使用 cornerParam) */ struct VrCornerParam { double minEndingGap = 10.0; double minEndingGap_z = 5.0; double scale = 10.0; double cornerTh = 60.0; double jumpCornerTh_1 = 15.0; double jumpCornerTh_2 = 60.0; }; /** * @brief 北京工件参数 */ struct VrJiuruiWorkpieceParam { double len = 320.0; // 工件长度 (mm) double width = 140.0; // 工件宽度 (mm) double thickness = 48.0; // 工件厚度 (mm) }; /** * @brief 算法参数配置结构(类比 WorkpieceHole 的扁平化风格) * * Jiurui_getWorkpiecePose 接受 SSG_cornerParam + WD_JiuruiWorkpieceParam + SSG_planeCalibPara */ struct VrAlgorithmParams { VrCornerParam cornerParam; VrJiuruiWorkpieceParam workpieceParam; // 多相机平面校准:相机级共享配置 VrPlaneCalibParam planeCalibParam; VrAlgorithmParams& operator=(const VrAlgorithmParams& other) { if (this != &other) { cornerParam = other.cornerParam; workpieceParam = other.workpieceParam; planeCalibParam = other.planeCalibParam; } return *this; } VrAlgorithmParams(const VrAlgorithmParams& other) : cornerParam(other.cornerParam) , workpieceParam(other.workpieceParam) , planeCalibParam(other.planeCalibParam) { } VrAlgorithmParams() = default; }; /** * @brief 配置加载结果(类比 WorkpieceHole 的扁平化风格) */ struct ConfigResult { std::vector cameraList; VrAlgorithmParams algorithmParams; // 共享算法参数 std::vector handEyeCalibMatrixList; // 多相机手眼标定矩阵列表 VrDebugParam debugParam; // 调试参数 SerialConfig serialConfig; // 串口配置 uint16_t tcpPort = 7800; // TCP 端口 int eulerOrder = 11; // 欧拉角输入顺序(机械臂姿态分解) int outputEulerOrder = 10; // 欧拉角输出顺序(姿态合成→展示/下发) int poseOutputOrder = 0; // 姿态输出顺序 int byteOrder = 0; // 数据字节序 // —— 辅助查询:按相机索引查找手眼标定矩阵 —— const VrHandEyeCalibMatrix* FindHandEyeMatrix(int cameraIndex) const { for (const auto& item : handEyeCalibMatrixList) { if (item.cameraIndex == cameraIndex) { return &item; } } return nullptr; } VrHandEyeCalibMatrix* FindHandEyeMatrix(int cameraIndex) { for (auto& item : handEyeCalibMatrixList) { if (item.cameraIndex == cameraIndex) { return &item; } } return nullptr; } VrHandEyeCalibMatrix& EnsureHandEyeMatrix(int cameraIndex) { if (auto* p = FindHandEyeMatrix(cameraIndex)) { return *p; } VrHandEyeCalibMatrix item; item.cameraIndex = cameraIndex; handEyeCalibMatrixList.push_back(item); return handEyeCalibMatrixList.back(); } ConfigResult& operator=(const ConfigResult& other) { if (this != &other) { cameraList = other.cameraList; algorithmParams = other.algorithmParams; handEyeCalibMatrixList = other.handEyeCalibMatrixList; debugParam = other.debugParam; serialConfig = other.serialConfig; tcpPort = other.tcpPort; eulerOrder = other.eulerOrder; outputEulerOrder = other.outputEulerOrder; poseOutputOrder = other.poseOutputOrder; byteOrder = other.byteOrder; } return *this; } ConfigResult(const ConfigResult& other) : cameraList(other.cameraList) , algorithmParams(other.algorithmParams) , handEyeCalibMatrixList(other.handEyeCalibMatrixList) , debugParam(other.debugParam) , serialConfig(other.serialConfig) , tcpPort(other.tcpPort) , eulerOrder(other.eulerOrder) , outputEulerOrder(other.outputEulerOrder) , poseOutputOrder(other.poseOutputOrder) , byteOrder(other.byteOrder) { } ConfigResult() = default; }; enum LoadConfigErrorCode { LOAD_CONFIG_SUCCESS = 0, LOAD_CONFIG_FILE_NOT_FOUND = -1, LOAD_CONFIG_PARSE_ERROR = -2, LOAD_CONFIG_INVALID_FORMAT = -3, LOAD_CONFIG_UNKNOWN_ERROR = -99 }; class IVrConfig { public: virtual ~IVrConfig() {} static bool CreateInstance(IVrConfig** ppVrConfig); virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0; virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0; virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0; }; // ---- 检测输出结构 ---- // 工件位姿输出(来自 Jiurui_getWorkpiecePose 返回的 SSG_pointPose) struct JiuruiWorkpieceDetectOutput { double x = 0.0; double y = 0.0; double z = 0.0; double roll = 0.0; double pitch = 0.0; double yaw = 0.0; // SSG_pointPose 直接输出完整三轴姿态,不需要孔半径 }; // 统一协议输出 struct ProtocolDetectionOutput { bool success = true; int errorCode = 0; QString message; int cameraIndex = 0; qint64 timestamp = 0; std::vector workpieceOutputs; }; #endif // IVRCONFIG_H