#ifndef IVRCONFIG_H #define IVRCONFIG_H #include #include #include #include #include #include // 包含公共配置结构体 #include "VrCommonConfig.h" #include "VrHandEyeCalibConfig.h" /** * @brief 孔洞检测参数(映射 SHoleDetectionParams) */ struct VrHoleDetectionParam { int neighborCount = 3; // 相邻点连接数 double angleThresholdPos = 30.0; // 正角度阈值(度) double angleThresholdNeg = -30.0; // 负角度阈值(度) double minPitDepth = 1.0; // 最小凹坑深度(mm) double minRadius = 2.0; // 最小孔半径(mm) double maxRadius = 50.0; // 最大孔半径(mm) int expansionSize1 = 5; // 第一环扩展大小 int expansionSize2 = 10; // 第二环扩展大小 int minVTransitionPoints = 1; // V形端点间最小有效过渡点数 double edgeBoundaryFilterDist = 0.0; // 边缘过滤距离(mm) }; /** * @brief 孔洞过滤参数(映射 SHoleFilterParams) */ struct VrHoleFilterParam { double maxEccentricity = 0.99995; // 最大离心率 double minAngularCoverage = 10.0; // 最小角度覆盖(度) double maxRadiusFitRatio = 1.0; // 最大半径拟合比率 double minQualityScore = 0.0; // 最小质量分数 double maxPlaneResidual = 10.0; // 最大平面残差(mm) double maxAngularGap = 90.0; // 最大角度间隙(度) double minInlierRatio = 0.0; // 最小内点比率 double minHoleDepth = 2.5; // 最小孔深(mm) }; /** * @brief 孔洞排序模式枚举(映射 ESortMode) */ enum VrHoleSortMode { HOLE_SORT_NONE = 0, // 不排序 HOLE_SORT_BY_RADIUS = 1, // 按半径排序(最大优先) HOLE_SORT_BY_DEPTH = 2, // 按深度排序(最深优先) HOLE_SORT_BY_QUALITY = 3 // 按质量分数排序(最高优先) }; /** * @brief 姿态输出顺序枚举 * * 定义机械臂姿态数据的输出顺序 */ enum VrPoseOutputOrder { POSE_ORDER_RPY = 0, // Roll, Pitch, Yaw(默认) POSE_ORDER_RYP = 1, // Roll, Yaw, Pitch POSE_ORDER_PRY = 2, // Pitch, Roll, Yaw POSE_ORDER_PYR = 3, // Pitch, Yaw, Roll POSE_ORDER_YRP = 4, // Yaw, Roll, Pitch POSE_ORDER_YPR = 5 // Yaw, Pitch, Roll }; /** * @brief 方向向量反向配置枚举 * * 定义机械臂方向向量的反向配置 * 用于调整相机坐标系到机械臂坐标系的方向向量转换 */ enum VrDirVectorInvert { DIR_INVERT_NONE = 0, // 不反向 DIR_INVERT_XY = 1, // X和Y方向反向 DIR_INVERT_XZ = 2, // X和Z方向反向 DIR_INVERT_YZ = 3 // Y和Z方向反向(默认,兼容原有行为) }; /** * @brief TCP协议和坐标输出配置 * * 默认值参考 Doc/porotol.jpg 协议文档: * - 汇川PLC-easy320: 192.168.0.88:502 * - 配天机械臂: 192.168.0.90:502 */ struct VrPlcRobotServerConfig { int tcpServerPort = 7800; // TCP协议服务端口 int poseOutputOrder = POSE_ORDER_RPY; // 姿态输出顺序,默认RPY int dirVectorInvert = DIR_INVERT_YZ; // 方向向量反向配置,默认YZ反向(兼容原有行为) // 显式赋值构造函数 VrPlcRobotServerConfig& operator=(const VrPlcRobotServerConfig& other) { if (this != &other) { tcpServerPort = other.tcpServerPort; poseOutputOrder = other.poseOutputOrder; dirVectorInvert = other.dirVectorInvert; } return *this; } // 显式复制构造函数 VrPlcRobotServerConfig(const VrPlcRobotServerConfig& other) : tcpServerPort(other.tcpServerPort) , poseOutputOrder(other.poseOutputOrder) , dirVectorInvert(other.dirVectorInvert) { } // 默认构造函数 VrPlcRobotServerConfig() = default; }; /** * @brief 算法参数配置结构 */ struct VrAlgorithmParams { VrHoleDetectionParam detectionParam; // 孔洞检测参数 VrHoleFilterParam filterParam; // 孔洞过滤参数 int sortMode = HOLE_SORT_NONE; // 排序模式 VrPlaneCalibParam planeCalibParam; // 平面校准参数 // 显式赋值构造函数,确保正确的深拷贝 VrAlgorithmParams& operator=(const VrAlgorithmParams& other) { if (this != &other) { detectionParam = other.detectionParam; filterParam = other.filterParam; sortMode = other.sortMode; planeCalibParam = other.planeCalibParam; } return *this; } // 显式复制构造函数 VrAlgorithmParams(const VrAlgorithmParams& other) : detectionParam(other.detectionParam) , filterParam(other.filterParam) , sortMode(other.sortMode) , planeCalibParam(other.planeCalibParam) { } // 默认构造函数 VrAlgorithmParams() = default; }; /** * @brief 配置加载结果 */ struct ConfigResult { std::vector cameraList; std::vector deviceList; VrAlgorithmParams algorithmParams; // 算法参数 std::vector handEyeCalibMatrixList; // 多相机手眼标定矩阵列表 VrDebugParam debugParam; // 调试参数 SerialConfig serialConfig; // 串口配置 VrPlcRobotServerConfig plcRobotServerConfig; // PLC和机械臂服务端配置 // 显式赋值构造函数,确保正确的深拷贝 ConfigResult& operator=(const ConfigResult& other) { if (this != &other) { cameraList = other.cameraList; deviceList = other.deviceList; algorithmParams = other.algorithmParams; handEyeCalibMatrixList = other.handEyeCalibMatrixList; debugParam = other.debugParam; serialConfig = other.serialConfig; plcRobotServerConfig = other.plcRobotServerConfig; } return *this; } // 显式复制构造函数 ConfigResult(const ConfigResult& other) : cameraList(other.cameraList) , deviceList(other.deviceList) , algorithmParams(other.algorithmParams) , handEyeCalibMatrixList(other.handEyeCalibMatrixList) , debugParam(other.debugParam) , serialConfig(other.serialConfig) , plcRobotServerConfig(other.plcRobotServerConfig) { } // 默认构造函数 ConfigResult() = default; }; /** * @brief 配置加载错误代码 */ 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 // 未知错误 }; /** * @brief VrConfig接口类 */ class IVrConfig { public: /** * @brief 虚析构函数 */ virtual ~IVrConfig() {} /** * @brief 创建实例 * @return 实例 */ static bool CreateInstance(IVrConfig** ppVrConfig); /** * @brief 加载配置文件 * @param filePath 配置文件路径 * @param configResult 输出参数,加载的配置结果 * @return 错误代码 (LoadConfigErrorCode): 0=成功, 负值表示错误 */ virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0; /** * @brief 保存配置文件 * @param filePath 配置文件路径 * @param configResult 配置结果 * @return 是否保存成功 */ virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0; /** * @brief 设置配置改变通知回调 * @param notify 通知接口指针 */ virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0; }; #endif // IVRCONFIG_H