112 lines
3.8 KiB
C++
112 lines
3.8 KiB
C++
#ifndef TIREHOLEPOSEPRESENTER_H
|
|
#define TIREHOLEPOSEPRESENTER_H
|
|
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <vector>
|
|
|
|
#include "BasePresenter.h"
|
|
#include "CommonDialogCameraLevel.h"
|
|
#include "ConfigManager.h"
|
|
#include "DetectionOutputConverter.h"
|
|
#include "IYTireHolePoseStatus.h"
|
|
#include "LaserDataLoader.h"
|
|
#include "SG_baseDataType.h"
|
|
#include "TireHolePoseTCPProtocol.h"
|
|
#include "VrConvert.h"
|
|
|
|
class DetectPresenter;
|
|
|
|
class TireHolePosePresenter : public BasePresenter,
|
|
public IVrConfigChangeNotify,
|
|
public ICameraLevelCalculator,
|
|
public ICameraLevelResultSaver
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit TireHolePosePresenter(QObject *parent = nullptr);
|
|
~TireHolePosePresenter();
|
|
|
|
int InitApp() override;
|
|
void DeinitApp();
|
|
|
|
bool TriggerDetection(int cameraIndex = -1,
|
|
const RobotPose6D& robotPose = RobotPose6D{});
|
|
|
|
int LoadAndDetect(const QString& fileName);
|
|
void ReconnectCamera();
|
|
|
|
// 轮胎孔定位使用 cornerParam 和 tireParam
|
|
VrCornerParam GetCornerParams() const;
|
|
void SetCornerParams(const VrCornerParam& params);
|
|
QString GetAlgoVersion() const;
|
|
|
|
ConfigManager* GetConfigManager() { return m_pConfigManager; }
|
|
|
|
// 按相机索引取手眼矩阵;未配置时返回单位阵。
|
|
CalibMatrix GetClibMatrix(int cameraIndex) const;
|
|
|
|
void OnConfigChanged(const ConfigResult& configResult) override;
|
|
void SendDetectionResultToClient(const DetectionResult& result);
|
|
|
|
bool CalculatePlaneCalibration(
|
|
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& scanData,
|
|
double planeCalib[9],
|
|
double& planeHeight,
|
|
double invRMatrix[9]) override;
|
|
|
|
bool SaveLevelingResults(double planeCalib[9], double planeHeight, double invRMatrix[9],
|
|
int cameraIndex, const QString& cameraName) override;
|
|
|
|
bool LoadLevelingResults(int cameraIndex, const QString& cameraName,
|
|
double planeCalib[9], double& planeHeight, double invRMatrix[9]) override;
|
|
|
|
protected:
|
|
int InitAlgoParams() override;
|
|
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
|
|
|
|
EVzResultDataType GetDetectionDataType() override
|
|
{
|
|
return keResultDataType_Position;
|
|
}
|
|
|
|
void OnCameraStatusChanged(int cameraIndex, bool isConnected) override;
|
|
void OnWorkStatusChanged(WorkStatus status) override;
|
|
void OnCameraCountChanged(int count) override;
|
|
void OnStatusUpdate(const std::string& statusMessage) override;
|
|
void OnModbusServerStatusChanged(bool isConnected) override;
|
|
void OnModbusWriteCallback(uint16_t startAddress, const uint16_t* data, uint16_t count) override;
|
|
|
|
private:
|
|
int InitTCPServer();
|
|
void stopServer();
|
|
void OnTCPConnectionChanged(bool connected);
|
|
void _SendDetectionResultToTCP(const DetectionResult& detectionResult, int cameraIndex);
|
|
void _PublishDetectionResultToModbus(const DetectionResult& result);
|
|
void _ResetModbusResultRegisters();
|
|
void _UpdateModbusWorkStatus(uint16_t statusValue);
|
|
void _InitializeModbusRegisters();
|
|
RobotPose6D _ReadRobotPoseFromModbus();
|
|
void CheckAndUpdateWorkStatus();
|
|
SSG_planeCalibPara _GetCameraCalibParam(int cameraIndex);
|
|
|
|
private:
|
|
ConfigManager* m_pConfigManager = nullptr;
|
|
|
|
TireHolePoseTCPProtocol* m_pTCPServer = nullptr;
|
|
bool m_bTCPConnected = false;
|
|
RobotPose6D m_currentRobotPose;
|
|
qint64 m_requestTimestamp = 0;
|
|
std::atomic<uint16_t> m_modbusWorkStatus = {0};
|
|
uint16_t m_modbusRobotPoseRegs[12] = {0};
|
|
bool m_modbusRegistersInitialized = false;
|
|
|
|
DetectPresenter* m_pDetectPresenter = nullptr;
|
|
};
|
|
|
|
#endif // TIREHOLEPOSEPRESENTER_H
|