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.cpp:class 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
|
|
|
|
|
|
{
|
2026-08-07 15:21:44 +08:00
|
|
|
|
bool useConfiguredBin = true; // 未先检测料框时,是否使用配置文件里的料框近似值
|
2026-08-04 14:23:07 +08:00
|
|
|
|
double binHeight = 120.0; // wd_HRM_getBinSize 使用的料框高度
|
2026-08-07 15:21:44 +08:00
|
|
|
|
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};
|
2026-08-07 15:21:44 +08:00
|
|
|
|
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: 触发开始工作(边沿检测 0→1 触发)
|
|
|
|
|
|
* 地址1: 工作状态(0=正在工作, 1=完成正常, 2=错误)
|
|
|
|
|
|
* 地址2+: 检测结果数据(每点 workpieceType + reserved + 6个float = 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
|