240 lines
8.4 KiB
C++
240 lines
8.4 KiB
C++
#ifndef IVRCONFIG_H
|
||
#define IVRCONFIG_H
|
||
|
||
#include <iostream>
|
||
#include <string>
|
||
#include <vector>
|
||
#include <utility>
|
||
#include <algorithm>
|
||
#include <cstring>
|
||
|
||
// 包含公共配置结构体
|
||
#include "VrCommonConfig.h"
|
||
#include "VrHandEyeCalibConfig.h"
|
||
|
||
/**
|
||
* @brief RANSAC 平面分割参数(映射 RansacPlaneSegmentationParams)
|
||
*/
|
||
struct VrRansacPlaneSegmentationParam
|
||
{
|
||
double distanceThreshold = 0.5; // 点到平面距离阈值(mm)
|
||
int maxIterations = 500; // RANSAC 最大迭代次数
|
||
int minPlanePoints = 100; // 最小平面点数
|
||
int maxPlanes = 5; // 最大提取平面数量
|
||
double growthZThreshold = 1.0; // 区域生长时相邻点 Z 差阈值(mm)
|
||
double minPlaneRatio = 0.1; // 平面最小点数占比
|
||
double maxNormalAngleDeg = 30.0; // 平面法向量与Z轴最大夹角(度),<=0 表示不过滤
|
||
};
|
||
|
||
/**
|
||
* @brief 孔洞检测参数(映射 SHoleDetectionParams)
|
||
*/
|
||
struct VrHoleDetectionParam
|
||
{
|
||
double angleThresholdPos = 50.0; // 正角度阈值(度)
|
||
double angleThresholdNeg = -50.0; // 负角度阈值(度)
|
||
double angleSearchDistance = 2.0; // 前后搜索距离 A(mm)
|
||
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 jumpThresholdResidual = 0.0; // 相邻有效点残差跳变阈值
|
||
double gapJumpThresholdResidual = 0.0; // 跨无效点间隙残差跳变阈值
|
||
int maxGapPointsInLine = 12; // 允许跨越的最大无效点数
|
||
double minFeatureSpan = 2.0; // 特征点对最小弧长跨度(mm)
|
||
int residualSmoothWindow = 5; // 残差平滑窗口
|
||
double slopeAngleThreshold = 3.0; // 坡度补充判断阈值(度)
|
||
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
|
||
{
|
||
VrRansacPlaneSegmentationParam ransacParam; // RANSAC 平面分割参数
|
||
VrHoleDetectionParam detectionParam;// 孔洞检测参数
|
||
VrHoleFilterParam filterParam; // 孔洞过滤参数
|
||
int sortMode = HOLE_SORT_NONE; // 排序模式
|
||
VrPlaneCalibParam planeCalibParam; // 平面校准参数
|
||
|
||
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
|
||
if (this != &other) {
|
||
ransacParam = other.ransacParam;
|
||
detectionParam = other.detectionParam;
|
||
filterParam = other.filterParam;
|
||
sortMode = other.sortMode;
|
||
planeCalibParam = other.planeCalibParam;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
VrAlgorithmParams(const VrAlgorithmParams& other)
|
||
: ransacParam(other.ransacParam)
|
||
, detectionParam(other.detectionParam)
|
||
, filterParam(other.filterParam)
|
||
, sortMode(other.sortMode)
|
||
, planeCalibParam(other.planeCalibParam) {
|
||
}
|
||
|
||
VrAlgorithmParams() = default;
|
||
};
|
||
|
||
/**
|
||
* @brief 配置加载结果
|
||
*/
|
||
struct ConfigResult
|
||
{
|
||
std::vector<DeviceInfo> cameraList;
|
||
std::vector<DeviceInfo> deviceList;
|
||
VrAlgorithmParams algorithmParams; // 算法参数
|
||
std::vector<VrHandEyeCalibMatrix> 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:
|
||
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;
|
||
};
|
||
|
||
#endif // IVRCONFIG_H
|