193 lines
5.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <QString>
#include "VrCommonConfig.h"
#include "VrHandEyeCalibConfig.h"
/**
* @brief 角点检测参数(轮胎孔定位算法使用 cornerParam
*/
struct VrCornerParam
{
double minEndingGap = 10.0;
double minEndingGap_z = 5.0;
double scale = 10.0;
double cornerTh = 60.0;
double jumpCornerTh_1 = 15.0;
double jumpCornerTh_2 = 60.0;
};
/**
* @brief 轮胎参数
*/
struct VrTireParam
{
double diameter = 500.0;
double thickness = 140.0;
};
/**
* @brief 算法参数配置结构(类比 WorkpieceHole 的扁平化风格)
*
* sx_getTireHolePose 接受 SSG_cornerParam + WD_tireParam + SSG_planeCalibPara
*/
struct VrAlgorithmParams
{
VrCornerParam cornerParam;
VrTireParam tireParam;
// 多相机平面校准:相机级共享配置
VrPlaneCalibParam planeCalibParam;
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
cornerParam = other.cornerParam;
tireParam = other.tireParam;
planeCalibParam = other.planeCalibParam;
}
return *this;
}
VrAlgorithmParams(const VrAlgorithmParams& other)
: cornerParam(other.cornerParam)
, tireParam(other.tireParam)
, planeCalibParam(other.planeCalibParam) {
}
VrAlgorithmParams() = default;
};
/**
* @brief 配置加载结果(类比 WorkpieceHole 的扁平化风格)
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
VrAlgorithmParams algorithmParams; // 共享算法参数
std::vector<VrHandEyeCalibMatrix> handEyeCalibMatrixList; // 多相机手眼标定矩阵列表
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
uint16_t tcpPort = 7800; // TCP 端口
int eulerOrder = 11; // 欧拉角输入顺序(机械臂姿态分解)
int outputEulerOrder = 10; // 欧拉角输出顺序(姿态合成→展示/下发)
int poseOutputOrder = 0; // 姿态输出顺序
int byteOrder = 0; // 数据字节序
// —— 辅助查询:按相机索引查找手眼标定矩阵 ——
const VrHandEyeCalibMatrix* FindHandEyeMatrix(int cameraIndex) const
{
for (const auto& item : handEyeCalibMatrixList) {
if (item.cameraIndex == cameraIndex) {
return &item;
}
}
return nullptr;
}
VrHandEyeCalibMatrix* FindHandEyeMatrix(int cameraIndex)
{
for (auto& item : handEyeCalibMatrixList) {
if (item.cameraIndex == cameraIndex) {
return &item;
}
}
return nullptr;
}
VrHandEyeCalibMatrix& EnsureHandEyeMatrix(int cameraIndex)
{
if (auto* p = FindHandEyeMatrix(cameraIndex)) {
return *p;
}
VrHandEyeCalibMatrix item;
item.cameraIndex = cameraIndex;
handEyeCalibMatrixList.push_back(item);
return handEyeCalibMatrixList.back();
}
ConfigResult& operator=(const ConfigResult& other)
{
if (this != &other) {
cameraList = other.cameraList;
algorithmParams = other.algorithmParams;
handEyeCalibMatrixList = other.handEyeCalibMatrixList;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
tcpPort = other.tcpPort;
eulerOrder = other.eulerOrder;
outputEulerOrder = other.outputEulerOrder;
poseOutputOrder = other.poseOutputOrder;
byteOrder = other.byteOrder;
}
return *this;
}
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, algorithmParams(other.algorithmParams)
, handEyeCalibMatrixList(other.handEyeCalibMatrixList)
, debugParam(other.debugParam)
, serialConfig(other.serialConfig)
, tcpPort(other.tcpPort)
, eulerOrder(other.eulerOrder)
, outputEulerOrder(other.outputEulerOrder)
, poseOutputOrder(other.poseOutputOrder)
, byteOrder(other.byteOrder)
{
}
ConfigResult() = default;
};
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
};
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;
};
// ---- 检测输出结构 ----
// 轮胎孔输出(来自 sx_getTireHolePose 返回的 WD_HolePositionInfo
struct TireHoleDetectOutput {
double x = 0.0;
double y = 0.0;
double z = 0.0;
double roll = 0.0;
double pitch = 0.0;
double yaw = 0.0;
double holeR = 0.0;
};
// 统一协议输出
struct ProtocolDetectionOutput {
bool success = true;
int errorCode = 0;
QString message;
int cameraIndex = 0;
qint64 timestamp = 0;
std::vector<TireHoleDetectOutput> tireHoleOutputs;
};
#endif // IVRCONFIG_H