186 lines
5.1 KiB
C
Raw Normal View History

#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 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;
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)
, 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;
};
// 统一协议输出
struct ProtocolDetectionOutput {
bool success = true;
int errorCode = 0;
QString message;
int cameraIndex = 0;
qint64 timestamp = 0;
std::vector<TireHoleDetectOutput> tireHoleOutputs;
};
#endif // IVRCONFIG_H