2026-03-28 10:49:55 +08:00
|
|
|
#ifndef SCREWPOSITIONPRESENTER_H
|
|
|
|
|
#define SCREWPOSITIONPRESENTER_H
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
#include <atomic>
|
|
|
|
|
#include <cstdint>
|
2026-03-28 10:49:55 +08:00
|
|
|
#include <memory>
|
2026-04-15 11:08:31 +08:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <vector>
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
#include "BasePresenter.h"
|
2026-04-15 11:08:31 +08:00
|
|
|
#include "CommonDialogCameraLevel.h"
|
2026-03-28 10:49:55 +08:00
|
|
|
#include "ConfigManager.h"
|
2026-04-10 20:02:57 +08:00
|
|
|
#include "DetectionOutputConverter.h"
|
2026-03-28 10:49:55 +08:00
|
|
|
#include "IYScrewPositionStatus.h"
|
2026-04-15 11:08:31 +08:00
|
|
|
#include "LaserDataLoader.h"
|
2026-03-28 10:49:55 +08:00
|
|
|
#include "SG_baseDataType.h"
|
2026-04-15 11:08:31 +08:00
|
|
|
#include "ScrewPositionTCPProtocol.h"
|
2026-03-28 10:49:55 +08:00
|
|
|
#include "VrConvert.h"
|
|
|
|
|
|
|
|
|
|
class DetectPresenter;
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
class ScrewPositionPresenter : public BasePresenter,
|
|
|
|
|
public IVrConfigChangeNotify,
|
|
|
|
|
public ICameraLevelCalculator,
|
|
|
|
|
public ICameraLevelResultSaver
|
2026-03-28 10:49:55 +08:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ScrewPositionPresenter(QObject *parent = nullptr);
|
|
|
|
|
~ScrewPositionPresenter();
|
|
|
|
|
|
|
|
|
|
int InitApp() override;
|
|
|
|
|
void DeinitApp();
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
bool TriggerDetection(int cameraIndex = -1,
|
|
|
|
|
DetectionType detectionType = DETECTION_TYPE_SCREW,
|
|
|
|
|
const RobotPose6D& robotPose = RobotPose6D{});
|
2026-03-28 10:49:55 +08:00
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
int LoadAndDetect(const QString& fileName, DetectionType detectionType = DETECTION_TYPE_SCREW);
|
2026-03-28 10:49:55 +08:00
|
|
|
void ReconnectCamera();
|
|
|
|
|
|
|
|
|
|
struct AlgoParams {
|
|
|
|
|
VrScrewParam screwParam;
|
|
|
|
|
VrCornerParam cornerParam;
|
|
|
|
|
VrOutlierFilterParam filterParam;
|
|
|
|
|
VrTreeGrowParam growParam;
|
|
|
|
|
};
|
2026-04-15 11:08:31 +08:00
|
|
|
|
2026-03-28 10:49:55 +08:00
|
|
|
AlgoParams GetAlgoParams() const;
|
|
|
|
|
void SetAlgoParams(const AlgoParams& params);
|
2026-04-08 22:12:47 +08:00
|
|
|
QString GetAlgoVersion() const;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
ConfigManager* GetConfigManager() { return m_pConfigManager; }
|
|
|
|
|
CalibMatrix GetClibMatrix(int index) const;
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
void OnConfigChanged(const ConfigResult& configResult) override;
|
2026-03-28 10:49:55 +08:00
|
|
|
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],
|
2026-04-15 11:08:31 +08:00
|
|
|
int cameraIndex, const QString& cameraName) override;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
bool LoadLevelingResults(int cameraIndex, const QString& cameraName,
|
2026-04-15 11:08:31 +08:00
|
|
|
double planeCalib[9], double& planeHeight, double invRMatrix[9]) override;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
int InitAlgoParams() override;
|
|
|
|
|
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
EVzResultDataType GetDetectionDataType() override
|
|
|
|
|
{
|
2026-03-28 10:49:55 +08:00
|
|
|
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;
|
2026-04-15 11:08:31 +08:00
|
|
|
void OnModbusServerStatusChanged(bool isConnected) override;
|
|
|
|
|
void OnModbusWriteCallback(uint16_t startAddress, const uint16_t* data, uint16_t count) override;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
private:
|
2026-04-15 11:08:31 +08:00
|
|
|
int InitTCPServer();
|
2026-03-28 10:49:55 +08:00
|
|
|
void stopServer();
|
|
|
|
|
void OnTCPConnectionChanged(bool connected);
|
|
|
|
|
void _SendDetectionResultToTCP(const DetectionResult& detectionResult, int cameraIndex);
|
2026-04-15 11:08:31 +08:00
|
|
|
void _PublishDetectionResultToModbus(const DetectionResult& result);
|
|
|
|
|
void _ResetModbusResultRegisters();
|
|
|
|
|
void _UpdateModbusWorkStatus(uint16_t statusValue);
|
|
|
|
|
void _InitializeModbusRegisters();
|
|
|
|
|
RobotPose6D _ReadRobotPoseFromModbus();
|
2026-03-28 10:49:55 +08:00
|
|
|
void CheckAndUpdateWorkStatus();
|
|
|
|
|
SSG_planeCalibPara _GetCameraCalibParam(int cameraIndex);
|
|
|
|
|
|
|
|
|
|
private:
|
2026-04-15 11:08:31 +08:00
|
|
|
ConfigManager* m_pConfigManager = nullptr;
|
|
|
|
|
|
|
|
|
|
ScrewPositionTCPProtocol* m_pTCPServer = nullptr;
|
|
|
|
|
bool m_bTCPConnected = false;
|
|
|
|
|
DetectionType m_currentDetectionType = DETECTION_TYPE_SCREW;
|
|
|
|
|
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;
|
|
|
|
|
std::vector<CalibMatrix> m_clibMatrixList;
|
2026-03-28 10:49:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SCREWPOSITIONPRESENTER_H
|