399 lines
14 KiB
C++
399 lines
14 KiB
C++
#ifndef IVRCONFIG_H
|
|
#define IVRCONFIG_H
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <cmath>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <QMetaType>
|
|
#include <QString>
|
|
|
|
#include "ILedDisplayDevice.h"
|
|
#include "IRsLidarDevice.h"
|
|
#include "IVisionApplicationStatus.h"
|
|
#include "VrCommonConfig.h"
|
|
|
|
struct VrGuideDecisionParam
|
|
{
|
|
double lateralTolerance = 100.0;
|
|
double angleTolerance = 5.0;
|
|
};
|
|
|
|
struct VrPlaneParkingParam
|
|
{
|
|
double parkingPointX = 0.0;
|
|
double parkingPointY = 0.0;
|
|
double parkingPointZ = 0.0;
|
|
double guideLinePointX = 0.0;
|
|
double guideLinePointY = 20000.0;
|
|
double guideLinePointZ = 0.0;
|
|
double guidingRange = 50000.0;
|
|
double parkingRange = 10000.0;
|
|
double distFromNoseToWheel = 4000.0;
|
|
};
|
|
|
|
struct VrPlaneGroundCalibrationParam
|
|
{
|
|
double planeCalib[9] = {1.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0,
|
|
0.0, 0.0, 1.0};
|
|
double planeHeight = -1.0;
|
|
double invRMatrix[9] = {1.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0,
|
|
0.0, 0.0, 1.0};
|
|
};
|
|
|
|
struct VrPlaneTreeGrowParam
|
|
{
|
|
double yDeviationMax = 300.0;
|
|
double zDeviationMax = 300.0;
|
|
int maxLineSkipNum = 10;
|
|
double maxSkipDistance = 300.0;
|
|
double minLTypeTreeLen = 500.0;
|
|
double minVTypeTreeLen = 500.0;
|
|
};
|
|
|
|
struct VrParkingProcessParam
|
|
{
|
|
double approachStartDistance = 15000.0;
|
|
double slowDistance = 5000.0;
|
|
double stopDistanceTolerance = 300.0;
|
|
double stoppedShortMinDistance = 300.0;
|
|
double maxApproachSpeed = 3000.0;
|
|
double stoppedSpeedThreshold = 100.0;
|
|
double speedFilterAlpha = 0.3;
|
|
int stopStableFrames = 5;
|
|
int stoppedShortStableFrames = 5;
|
|
int lostFrameThreshold = 5;
|
|
int completedHoldFrames = 3;
|
|
};
|
|
|
|
struct VrModelRecognitionParam
|
|
{
|
|
double modelVerifyDistance = 12000.0;
|
|
double confidenceThreshold = 0.6;
|
|
int maxRecognitionAttempts = 2;
|
|
};
|
|
|
|
struct VrAlgorithmParams
|
|
{
|
|
VrPlaneParkingParam planeParkingParam;
|
|
VrPlaneGroundCalibrationParam groundCalibrationParam;
|
|
VrPlaneTreeGrowParam treeGrowParam;
|
|
VrGuideDecisionParam guideDecisionParam;
|
|
VrParkingProcessParam processParam;
|
|
VrModelRecognitionParam modelRecognitionParam;
|
|
|
|
VrAlgorithmParams() = default;
|
|
VrAlgorithmParams(const VrAlgorithmParams&) = default;
|
|
VrAlgorithmParams& operator=(const VrAlgorithmParams&) = default;
|
|
};
|
|
|
|
struct UdpBroadcastConfig
|
|
{
|
|
bool enabled = false;
|
|
std::string address = "239.255.0.1";
|
|
int port = 8800;
|
|
std::string targetId = "T001";
|
|
std::string parkId = "P01";
|
|
};
|
|
|
|
struct MvsCameraConfig
|
|
{
|
|
bool enabled = true;
|
|
std::string serialNumber;
|
|
int deviceIndex = 0;
|
|
};
|
|
|
|
struct HttpServerConfig
|
|
{
|
|
bool enabled = true;
|
|
std::string address = "0.0.0.0";
|
|
int port = 8801;
|
|
int maxQueued = 16;
|
|
int maxThreads = 4;
|
|
};
|
|
|
|
struct ConfigResult
|
|
{
|
|
std::vector<DeviceInfo> cameraList;
|
|
MvsCameraConfig mvsCamera;
|
|
RsLidarConfig lidarConfig;
|
|
LedDisplayConfig ledDisplayConfig;
|
|
UdpBroadcastConfig udpBroadcastConfig;
|
|
HttpServerConfig httpServerConfig;
|
|
VrAlgorithmParams algorithmParams;
|
|
VrDebugParam debugParam;
|
|
|
|
ConfigResult() = default;
|
|
ConfigResult(const ConfigResult&) = default;
|
|
ConfigResult& operator=(const ConfigResult&) = default;
|
|
|
|
void Normalize()
|
|
{
|
|
cameraList.clear();
|
|
|
|
DeviceInfo camera;
|
|
camera.index = 1;
|
|
camera.name = "平面相机";
|
|
camera.ip = mvsCamera.serialNumber;
|
|
camera.baseDistance = 0.0;
|
|
cameraList.push_back(camera);
|
|
|
|
if (mvsCamera.deviceIndex < 0) {
|
|
mvsCamera.deviceIndex = 0;
|
|
}
|
|
|
|
VrGuideDecisionParam& guide = algorithmParams.guideDecisionParam;
|
|
if (!std::isfinite(guide.lateralTolerance) || guide.lateralTolerance < 0.0) {
|
|
guide.lateralTolerance = 100.0;
|
|
}
|
|
if (!std::isfinite(guide.angleTolerance) || guide.angleTolerance < 0.0 || guide.angleTolerance > 180.0) {
|
|
guide.angleTolerance = 5.0;
|
|
}
|
|
|
|
VrPlaneParkingParam& parking = algorithmParams.planeParkingParam;
|
|
if (!std::isfinite(parking.parkingPointX)) parking.parkingPointX = 0.0;
|
|
if (!std::isfinite(parking.parkingPointY)) parking.parkingPointY = 0.0;
|
|
if (!std::isfinite(parking.parkingPointZ)) parking.parkingPointZ = 0.0;
|
|
if (!std::isfinite(parking.guideLinePointX)) parking.guideLinePointX = parking.parkingPointX;
|
|
if (!std::isfinite(parking.guideLinePointY)) parking.guideLinePointY = parking.parkingPointY + 20000.0;
|
|
if (!std::isfinite(parking.guideLinePointZ)) parking.guideLinePointZ = parking.parkingPointZ;
|
|
const double guideDx = parking.guideLinePointX - parking.parkingPointX;
|
|
const double guideDy = parking.guideLinePointY - parking.parkingPointY;
|
|
const double guideDz = parking.guideLinePointZ - parking.parkingPointZ;
|
|
if (std::sqrt(guideDx * guideDx + guideDy * guideDy + guideDz * guideDz) < 20000.0) {
|
|
parking.guideLinePointX = parking.parkingPointX;
|
|
parking.guideLinePointY = parking.parkingPointY + 20000.0;
|
|
parking.guideLinePointZ = parking.parkingPointZ;
|
|
}
|
|
if (!std::isfinite(parking.guidingRange) || parking.guidingRange <= 0.0) {
|
|
parking.guidingRange = 50000.0;
|
|
}
|
|
if (!std::isfinite(parking.parkingRange) || parking.parkingRange <= 0.0) {
|
|
parking.parkingRange = 10000.0;
|
|
}
|
|
if (!std::isfinite(parking.distFromNoseToWheel) || parking.distFromNoseToWheel < 0.0) {
|
|
parking.distFromNoseToWheel = 4000.0;
|
|
}
|
|
|
|
VrPlaneGroundCalibrationParam& ground = algorithmParams.groundCalibrationParam;
|
|
for (int i = 0; i < 9; ++i) {
|
|
const double identityValue = (i % 4 == 0) ? 1.0 : 0.0;
|
|
if (!std::isfinite(ground.planeCalib[i])) ground.planeCalib[i] = identityValue;
|
|
if (!std::isfinite(ground.invRMatrix[i])) ground.invRMatrix[i] = identityValue;
|
|
}
|
|
if (!std::isfinite(ground.planeHeight)) ground.planeHeight = -1.0;
|
|
|
|
VrPlaneTreeGrowParam& tree = algorithmParams.treeGrowParam;
|
|
if (!std::isfinite(tree.yDeviationMax) || tree.yDeviationMax <= 0.0) tree.yDeviationMax = 300.0;
|
|
if (!std::isfinite(tree.zDeviationMax) || tree.zDeviationMax <= 0.0) tree.zDeviationMax = 300.0;
|
|
if (tree.maxLineSkipNum < -1) tree.maxLineSkipNum = 10;
|
|
if (!std::isfinite(tree.maxSkipDistance) || tree.maxSkipDistance < -1.0) tree.maxSkipDistance = 300.0;
|
|
if (!std::isfinite(tree.minLTypeTreeLen) || tree.minLTypeTreeLen < 0.0) tree.minLTypeTreeLen = 500.0;
|
|
if (!std::isfinite(tree.minVTypeTreeLen) || tree.minVTypeTreeLen < 0.0) tree.minVTypeTreeLen = 500.0;
|
|
|
|
VrParkingProcessParam& process = algorithmParams.processParam;
|
|
if (!std::isfinite(process.approachStartDistance) || process.approachStartDistance < 0.0) process.approachStartDistance = 15000.0;
|
|
if (!std::isfinite(process.slowDistance) || process.slowDistance < 0.0) process.slowDistance = 5000.0;
|
|
if (!std::isfinite(process.stopDistanceTolerance) || process.stopDistanceTolerance < 0.0) process.stopDistanceTolerance = 300.0;
|
|
if (!std::isfinite(process.stoppedShortMinDistance) || process.stoppedShortMinDistance < 0.0) process.stoppedShortMinDistance = 300.0;
|
|
if (!std::isfinite(process.maxApproachSpeed) || process.maxApproachSpeed < 0.0) process.maxApproachSpeed = 3000.0;
|
|
if (!std::isfinite(process.stoppedSpeedThreshold) || process.stoppedSpeedThreshold < 0.0) process.stoppedSpeedThreshold = 100.0;
|
|
if (!std::isfinite(process.speedFilterAlpha) || process.speedFilterAlpha < 0.0 || process.speedFilterAlpha > 1.0) process.speedFilterAlpha = 0.3;
|
|
if (process.stopStableFrames <= 0) process.stopStableFrames = 5;
|
|
if (process.stoppedShortStableFrames <= 0) process.stoppedShortStableFrames = 5;
|
|
if (process.lostFrameThreshold <= 0) process.lostFrameThreshold = 5;
|
|
if (process.completedHoldFrames <= 0) process.completedHoldFrames = 3;
|
|
process.slowDistance = (std::max)(process.slowDistance,
|
|
process.stopDistanceTolerance);
|
|
process.approachStartDistance = (std::max)(process.approachStartDistance,
|
|
process.slowDistance);
|
|
process.stoppedShortMinDistance = (std::max)(process.stoppedShortMinDistance,
|
|
process.stopDistanceTolerance);
|
|
process.maxApproachSpeed = (std::max)(process.maxApproachSpeed,
|
|
process.stoppedSpeedThreshold);
|
|
|
|
VrModelRecognitionParam& model = algorithmParams.modelRecognitionParam;
|
|
if (!std::isfinite(model.modelVerifyDistance) || model.modelVerifyDistance < 0.0) model.modelVerifyDistance = 12000.0;
|
|
if (!std::isfinite(model.confidenceThreshold) || model.confidenceThreshold < 0.0 || model.confidenceThreshold > 1.0) model.confidenceThreshold = 0.6;
|
|
if (model.maxRecognitionAttempts <= 0) model.maxRecognitionAttempts = 2;
|
|
|
|
if (udpBroadcastConfig.address.empty()) {
|
|
udpBroadcastConfig.address = "239.255.0.1";
|
|
}
|
|
if (udpBroadcastConfig.port <= 0 || udpBroadcastConfig.port > 65535) {
|
|
udpBroadcastConfig.port = 8800;
|
|
}
|
|
if (udpBroadcastConfig.targetId.empty()) {
|
|
udpBroadcastConfig.targetId = "T001";
|
|
}
|
|
if (udpBroadcastConfig.parkId.empty()) {
|
|
udpBroadcastConfig.parkId = "P01";
|
|
}
|
|
if (httpServerConfig.address.empty()) {
|
|
httpServerConfig.address = "0.0.0.0";
|
|
}
|
|
if (httpServerConfig.port <= 0 || httpServerConfig.port > 65535) {
|
|
httpServerConfig.port = 8801;
|
|
}
|
|
if (httpServerConfig.maxQueued <= 0) {
|
|
httpServerConfig.maxQueued = 16;
|
|
}
|
|
if (httpServerConfig.maxThreads <= 0) {
|
|
httpServerConfig.maxThreads = 4;
|
|
}
|
|
if (ledDisplayConfig.ip.empty()) {
|
|
ledDisplayConfig.ip = "192.168.1.100";
|
|
}
|
|
if (ledDisplayConfig.port <= 0 || ledDisplayConfig.port > 65535) {
|
|
ledDisplayConfig.port = 5005;
|
|
}
|
|
if (ledDisplayConfig.slaveId < 0 || ledDisplayConfig.slaveId > 65535) {
|
|
ledDisplayConfig.slaveId = 0xFFFE;
|
|
}
|
|
if (ledDisplayConfig.startAddress < 0 || ledDisplayConfig.startAddress > 31) {
|
|
ledDisplayConfig.startAddress = 0;
|
|
}
|
|
if (ledDisplayConfig.timeoutMs < 100) {
|
|
ledDisplayConfig.timeoutMs = 1000;
|
|
}
|
|
if (ledDisplayConfig.controllerType < 0 || ledDisplayConfig.controllerType > 255) {
|
|
ledDisplayConfig.controllerType = 0xFE;
|
|
}
|
|
if (ledDisplayConfig.areaX < 0) {
|
|
ledDisplayConfig.areaX = 0;
|
|
}
|
|
if (ledDisplayConfig.areaY < 0) {
|
|
ledDisplayConfig.areaY = 0;
|
|
}
|
|
if (ledDisplayConfig.areaWidth <= 0) {
|
|
ledDisplayConfig.areaWidth = 64;
|
|
}
|
|
if (ledDisplayConfig.areaHeight <= 0) {
|
|
ledDisplayConfig.areaHeight = 32;
|
|
}
|
|
if (ledDisplayConfig.dynamicTimeoutSec < 0 || ledDisplayConfig.dynamicTimeoutSec > 65535) {
|
|
ledDisplayConfig.dynamicTimeoutSec = 10;
|
|
}
|
|
if (ledDisplayConfig.displayMode < 1 || ledDisplayConfig.displayMode > 7) {
|
|
ledDisplayConfig.displayMode = 1;
|
|
}
|
|
if (ledDisplayConfig.speed < 0 || ledDisplayConfig.speed > 24) {
|
|
ledDisplayConfig.speed = 2;
|
|
}
|
|
if (ledDisplayConfig.stayTime < 0 || ledDisplayConfig.stayTime > 255) {
|
|
ledDisplayConfig.stayTime = 10;
|
|
}
|
|
}
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
struct ParkingSpaceGuidePosition : public PositionData<double>
|
|
{
|
|
ParkingSpaceGuidePosition() : PositionData<double>() {}
|
|
ParkingSpaceGuidePosition(double x, double y, double z,
|
|
double roll, double pitch, double yaw)
|
|
: PositionData<double>(x, y, z, roll, pitch, yaw)
|
|
{
|
|
}
|
|
};
|
|
|
|
enum class ParkingGuideState : int
|
|
{
|
|
Unknown = 0,
|
|
DockingStarted = 1,
|
|
Capturing = 2,
|
|
Tracking = 3,
|
|
ApproachRate = 4,
|
|
CenterLineAligned = 5,
|
|
Slow = 6,
|
|
AzimuthGuidance = 7,
|
|
StopPositionReached = 8,
|
|
DockingCompleted = 9,
|
|
Overshot = 10,
|
|
StoppedShort = 11,
|
|
Waiting = 12,
|
|
SlowBadWeather = 13,
|
|
SlowAircraftLost = 14,
|
|
AircraftVerificationFailed = 15,
|
|
GateBlocked = 16,
|
|
ViewBlocked = 17,
|
|
SbuStop = 18,
|
|
TooFast = 19,
|
|
EmergencyStop = 20,
|
|
ChocksOn = 21,
|
|
SystemError = 22,
|
|
SystemFailure = 23,
|
|
PowerFailure = 24
|
|
};
|
|
|
|
inline ParkingGuideState ParkingGuideStateFromCode(int guideStateCode)
|
|
{
|
|
if (guideStateCode < static_cast<int>(ParkingGuideState::Unknown) ||
|
|
guideStateCode > static_cast<int>(ParkingGuideState::PowerFailure)) {
|
|
return ParkingGuideState::Unknown;
|
|
}
|
|
|
|
return static_cast<ParkingGuideState>(guideStateCode);
|
|
}
|
|
|
|
struct ParkingSpaceGuideInfo
|
|
{
|
|
QString targetId;
|
|
QString parkId;
|
|
QString modelType;
|
|
bool hasException = false;
|
|
double distance = 0.0;
|
|
double lateralOffset = 0.0;
|
|
double angle = 0.0;
|
|
double aircraftSpeed = 0.0;
|
|
double confidence = 0.0;
|
|
int guideStateCode = 0;
|
|
QString guideText;
|
|
};
|
|
|
|
struct DetectionResult : public DetectionResultData<ParkingSpaceGuidePosition>
|
|
{
|
|
std::vector<ParkingSpaceGuideInfo> parkingSpaceInfoList;
|
|
QString message;
|
|
};
|
|
|
|
struct ParkingSpaceGuideDetectOutput
|
|
{
|
|
bool success = true;
|
|
int errorCode = 0;
|
|
QString message;
|
|
int cameraIndex = 1;
|
|
qint64 timestamp = 0;
|
|
std::vector<ParkingSpaceGuideInfo> guideOutputs;
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(ParkingSpaceGuidePosition)
|
|
Q_DECLARE_METATYPE(ParkingSpaceGuideInfo)
|
|
Q_DECLARE_METATYPE(DetectionResult)
|
|
|
|
#endif // IVRCONFIG_H
|