347 lines
11 KiB
C
Raw Permalink Normal View History

2026-08-04 14:23:07 +08:00
#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
// 包含公共配置结构体
#include "VrCommonConfig.h"
/**
* @brief 姿
*
*
* 姿 WorkpieceHole
*/
struct VrToolParam
{
int eulerOrder = 11; // 工具补偿欧拉角顺序,默认外旋 ZYX
double rotX = 0.0; // 工具姿态 X 轴补偿 (deg)
double rotY = 0.0; // 工具姿态 Y 轴补偿 (deg)
double rotZ = 0.0; // 工具姿态 Z 轴补偿 (deg)
double offsetX = 0.0; // 目标点 X 偏移 (mm)
double offsetY = 0.0; // 目标点 Y 偏移 (mm)
double offsetZ = 0.0; // 目标点 Z 偏移 (mm)
};
/**
* @brief
*/
struct VrWorkpieceModelParam
{
// 模型及运行库由应用按平台从固定安装目录自动加载。
double minimumScore = 0.6;
// 2D模型类别到 hybridPosePositioning 工件类型的映射。
// 默认对齐 hybridPosePositioning_test.cppclass 0/1/2 -> workpieceType 1/2/3。
// 配置值 <=0 表示忽略该2D类别用于只启用其中两种工件的现场配置。
int class0WorkpieceType = 1;
int class1WorkpieceType = 2;
int class2WorkpieceType = 3;
int WorkpieceTypeForClass(int classId) const {
switch (classId) {
case 0: return class0WorkpieceType;
case 1: return class1WorkpieceType;
case 2: return class2WorkpieceType;
default: return 0;
}
}
};
struct VrFullImageCaptureParam
{
unsigned int exposure = 50000; // 在线全图二维采集临时曝光
unsigned int gain = 2; // 在线全图二维采集临时增益
};
struct VrBinParam
{
bool useConfiguredBin = true; // 未先检测料框时,是否使用配置文件里的料框近似值
2026-08-04 14:23:07 +08:00
double binHeight = 120.0; // wd_HRM_getBinSize 使用的料框高度
double length = 10000.0;
double width = 10000.0;
2026-08-04 14:23:07 +08:00
double binTopZ = 0.0;
double center[3] = {0.0, 0.0, 0.0};
double bottomNormal[3] = {0.0, 0.0, 1.0};
double xDir[3] = {1.0, 0.0, 0.0};
double yDir[3] = {0.0, 1.0, 0.0};
double minRectVertex[4][3] = {{-5000.0, -5000.0, 0.0},
{ 5000.0, -5000.0, 0.0},
{ 5000.0, 5000.0, 0.0},
{-5000.0, 5000.0, 0.0}};
2026-08-04 14:23:07 +08:00
};
struct VrRotorCoreParam
{
double radius = 45.0;
double height = 20.0;
};
/**
* @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 Modbus Server 0-based
*
*
* 0: 沿 01
* 1: 0=, 1=, 2=
* 2+: workpieceType + reserved + 6float = 14
*/
struct VrPlcRegisterConfig
{
int addrTrigger = 0; // 触发寄存器地址客户写软件读后清0
int addrWorkStatus = 1; // 工作状态寄存器地址(软件写,客户读)
int addrCoordDataStart = 2; // 坐标数据起始寄存器地址
// 显式赋值构造函数
VrPlcRegisterConfig& operator=(const VrPlcRegisterConfig& other) {
if (this != &other) {
addrTrigger = other.addrTrigger;
addrWorkStatus = other.addrWorkStatus;
addrCoordDataStart = other.addrCoordDataStart;
}
return *this;
}
// 显式复制构造函数
VrPlcRegisterConfig(const VrPlcRegisterConfig& other)
: addrTrigger(other.addrTrigger)
, addrWorkStatus(other.addrWorkStatus)
, addrCoordDataStart(other.addrCoordDataStart) {
}
// 默认构造函数
VrPlcRegisterConfig() = default;
};
/**
* @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 Modbus
*
* Modbus
* 16 Modbus 1
*/
enum VrByteOrder
{
BYTE_ORDER_BIG_ENDIAN = 0, // 标准字顺序 (ABCD),高位字在低地址
BYTE_ORDER_LITTLE_ENDIAN = 1 // 字交换 (CDAB),低位字在低地址
};
/**
* @brief TCP/IP Modbus
*
* robotServerPort TCP/IP
* Modbus TCP Server 5020 502
*/
struct VrPlcRobotServerConfig
{
int robotServerPort = 7800; // TCP/IP 文本协议服务端监听端口
VrPlcRegisterConfig registerConfig; // Modbus 寄存器地址配置
int poseOutputOrder = POSE_ORDER_RPY; // 姿态输出顺序默认RPY
int dirVectorInvert = DIR_INVERT_YZ; // 方向向量反向配置默认YZ反向兼容原有行为
int byteOrder = BYTE_ORDER_BIG_ENDIAN; // 浮点寄存器字顺序,默认 ABCD
// 显式赋值构造函数
VrPlcRobotServerConfig& operator=(const VrPlcRobotServerConfig& other) {
if (this != &other) {
robotServerPort = other.robotServerPort;
registerConfig = other.registerConfig;
poseOutputOrder = other.poseOutputOrder;
dirVectorInvert = other.dirVectorInvert;
byteOrder = other.byteOrder;
}
return *this;
}
// 显式复制构造函数
VrPlcRobotServerConfig(const VrPlcRobotServerConfig& other)
: robotServerPort(other.robotServerPort)
, registerConfig(other.registerConfig)
, poseOutputOrder(other.poseOutputOrder)
, dirVectorInvert(other.dirVectorInvert)
, byteOrder(other.byteOrder) {
}
// 默认构造函数
VrPlcRobotServerConfig() = default;
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrPlaneCalibParam planeCalibParam; // 算法输入的地面标定参数
VrToolParam toolParam; // 结果位姿补偿参数
VrWorkpieceModelParam modelParam; // 左目二维定位置信度
VrFullImageCaptureParam fullImageCaptureParam; // 在线全图二维采集参数
VrBinParam binParam; // 料框检测/默认料框参数
VrRotorCoreParam rotorCoreParam; // 转子钢芯算法参数
// 显式赋值构造函数,确保正确的深拷贝
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
planeCalibParam = other.planeCalibParam;
toolParam = other.toolParam;
modelParam = other.modelParam;
fullImageCaptureParam = other.fullImageCaptureParam;
binParam = other.binParam;
rotorCoreParam = other.rotorCoreParam;
}
return *this;
}
// 显式复制构造函数
VrAlgorithmParams(const VrAlgorithmParams& other)
: planeCalibParam(other.planeCalibParam)
, toolParam(other.toolParam)
, modelParam(other.modelParam)
, fullImageCaptureParam(other.fullImageCaptureParam)
, binParam(other.binParam)
, rotorCoreParam(other.rotorCoreParam) {
}
// 默认构造函数
VrAlgorithmParams() = default;
};
/**
* @brief
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams; // 算法参数
VrHandEyeCalibMatrix handEyeCalibMatrix; // 手眼标定矩阵
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
VrPlcRobotServerConfig plcRobotServerConfig; // TCP 服务端和 Modbus 寄存器配置
// 显式赋值构造函数,确保正确的深拷贝
ConfigResult& operator=(const ConfigResult& other) {
if (this != &other) {
cameraList = other.cameraList;
deviceList = other.deviceList;
algorithmParams = other.algorithmParams;
handEyeCalibMatrix = other.handEyeCalibMatrix;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
plcRobotServerConfig = other.plcRobotServerConfig;
}
return *this;
}
// 显式复制构造函数
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, deviceList(other.deviceList)
, algorithmParams(other.algorithmParams)
, handEyeCalibMatrix(other.handEyeCalibMatrix)
, 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