281 lines
9.0 KiB
C
Raw Normal View History

#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
// 包含公共配置结构体
#include "VrCommonConfig.h"
/**
* @brief
*/
struct VrOutlierFilterParam
{
double continuityTh = 20.0; // 连续性阈值噪声滤除。当相邻点的z跳变大于此门限时检查是否为噪声
double outlierTh = 5.0; // 离群点判断阈值,若长度小于此值,视为噪声
};
/**
* @brief 线
*/
struct VrLineSegParam
{
double distScale = 3.0; // 计算方向角的窗口比例因子
double segGapTh_y = 3.0; // Y方向间隔阈值大于此值认为是分段
double segGapTh_z = 10.0; // Z方向间隔阈值大于此值认为是分段
};
/**
* @brief
*/
struct VrTreeGrowParam
{
int maxLineSkipNum = 10; // 生长时允许跳过的最大线条数
double yDeviation_max = 10.0; // 生长时允许的最大Y偏差
double maxSkipDistance = 10.0; // 最大跳跃距离
double zDeviation_max = 10.0; // 生长时允许的最大Z偏差
double minLTypeTreeLen = 100.0; // L型树的最小长度
double minVTypeTreeLen = 100.0; // V型树的最小长度
};
/**
* @brief
*/
struct VrWorkpieceHoleParam
{
int workpieceType = 0; // 工件类型
double holeDiameter = 6.0; // 孔直径 (mm)
double holeDist_L = 40.0; // 孔间距_长 (mm)
double holeDist_W = 32.0; // 孔间距_宽 (mm)
};
2026-02-01 14:51:16 +08:00
/**
* @brief
*/
struct VrHandEyeCalibMatrix
{
double matrix[16] = {
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
int eulerOrder = 11; // 欧拉角顺序默认11=sZYX外旋ZYX
};
/**
* @brief PLC Modbus
*
* PLC D Modbus
* D寄存器 + 40001 = Modbus地址
* = D寄存器 + 1
*
*
* D1000 -> Modbus 41001 -> 1001
* D1002 -> Modbus 41003 -> 1003
* D2000 -> Modbus 42001 -> 2001
*/
struct VrPlcRegisterConfig
{
int addrPhotoRequest = 1001; // D1000: 拍照请求寄存器地址(读:=1触发拍照
int addrDataComplete = 1003; // D1002: 数据输出完成标志寄存器地址(写:=1完成
int addrCoordDataStart = 2002; // D2000: 坐标数据起始寄存器地址
// 显式赋值构造函数
VrPlcRegisterConfig& operator=(const VrPlcRegisterConfig& other) {
if (this != &other) {
addrPhotoRequest = other.addrPhotoRequest;
addrDataComplete = other.addrDataComplete;
addrCoordDataStart = other.addrCoordDataStart;
}
return *this;
}
// 显式复制构造函数
VrPlcRegisterConfig(const VrPlcRegisterConfig& other)
: addrPhotoRequest(other.addrPhotoRequest)
, addrDataComplete(other.addrDataComplete)
, addrCoordDataStart(other.addrCoordDataStart) {
}
// 默认构造函数
VrPlcRegisterConfig() = default;
};
/**
* @brief PLC和机械臂服务端配置
*
* Doc/porotol.jpg
* - PLC-easy320: 192.168.0.88:502
* - : 192.168.0.90:502
*/
struct VrPlcRobotServerConfig
{
std::string plcServerIp = "192.168.0.88"; // PLC服务端IP地址汇川PLC-easy320
int plcServerPort = 502; // PLC服务端端口Modbus TCP默认502
std::string robotServerIp = "192.168.0.90"; // 机械臂服务端IP地址配天机械臂
int robotServerPort = 502; // 机械臂服务端端口Modbus TCP默认502
VrPlcRegisterConfig registerConfig; // PLC 寄存器地址配置
// 显式赋值构造函数
VrPlcRobotServerConfig& operator=(const VrPlcRobotServerConfig& other) {
if (this != &other) {
plcServerIp = other.plcServerIp;
plcServerPort = other.plcServerPort;
robotServerIp = other.robotServerIp;
robotServerPort = other.robotServerPort;
registerConfig = other.registerConfig;
}
return *this;
}
// 显式复制构造函数
VrPlcRobotServerConfig(const VrPlcRobotServerConfig& other)
: plcServerIp(other.plcServerIp)
, plcServerPort(other.plcServerPort)
, robotServerIp(other.robotServerIp)
, robotServerPort(other.robotServerPort)
, registerConfig(other.registerConfig) {
}
// 默认构造函数
VrPlcRobotServerConfig() = default;
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrOutlierFilterParam filterParam; // 离群点滤波参数
VrLineSegParam lineSegParam; // 线段分割参数
VrTreeGrowParam growParam; // 树生长参数
VrPlaneCalibParam planeCalibParam; // 平面校准参数
VrWorkpieceHoleParam workpieceHoleParam; // 工件孔参数
// 显式赋值构造函数,确保正确的深拷贝
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
filterParam = other.filterParam;
lineSegParam = other.lineSegParam;
growParam = other.growParam;
planeCalibParam = other.planeCalibParam;
workpieceHoleParam = other.workpieceHoleParam;
}
return *this;
}
// 显式复制构造函数
VrAlgorithmParams(const VrAlgorithmParams& other)
: filterParam(other.filterParam)
, lineSegParam(other.lineSegParam)
, growParam(other.growParam)
, planeCalibParam(other.planeCalibParam)
, workpieceHoleParam(other.workpieceHoleParam) {
}
// 默认构造函数
VrAlgorithmParams() = default;
};
/**
* @brief
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
2026-02-01 14:51:16 +08:00
VrAlgorithmParams algorithmParams; // 算法参数
VrHandEyeCalibMatrix handEyeCalibMatrix; // 手眼标定矩阵
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
VrPlcRobotServerConfig plcRobotServerConfig; // PLC和机械臂服务端配置
// 显式赋值构造函数,确保正确的深拷贝
ConfigResult& operator=(const ConfigResult& other) {
if (this != &other) {
cameraList = other.cameraList;
deviceList = other.deviceList;
algorithmParams = other.algorithmParams;
2026-02-01 14:51:16 +08:00
handEyeCalibMatrix = other.handEyeCalibMatrix;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
2026-02-01 14:51:16 +08:00
plcRobotServerConfig = other.plcRobotServerConfig;
}
return *this;
}
// 显式复制构造函数
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, deviceList(other.deviceList)
, algorithmParams(other.algorithmParams)
2026-02-01 14:51:16 +08:00
, handEyeCalibMatrix(other.handEyeCalibMatrix)
, debugParam(other.debugParam)
2026-02-01 14:51:16 +08:00
, 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