102 lines
4.6 KiB
C++
102 lines
4.6 KiB
C++
// CoordTransformPanel.h — 手眼标定矩阵加载 + 坐标系转换
|
|||
|
|
#pragma once
|
||
|
|
#include <QObject>
|
||
|
|
#include <opencv2/core.hpp>
|
||
|
|
#include "VisionGuideMatcher.h"
|
||
|
|
namespace Ui { class MainWindowClass; }
|
||
|
|
|
||
|
|
class CoordTransformPanel : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
CoordTransformPanel(Ui::MainWindowClass& ui, QObject* parent);
|
||
|
|
void setCameraPose(const VisionPoseResult& p);
|
||
|
|
bool setCurrentTcpPose(double xMm, double yMm, double zMm,
|
||
|
|
double aDeg, double bDeg, double cDeg,
|
||
|
|
const QString& referenceFrame);
|
||
|
|
void setAxisGuidanceEnabled(bool enabled, bool followAxisTilt);
|
||
|
|
void setSystemBiasCorrection(bool enabled, double xMm, double yMm, double zMm);
|
||
|
|
bool calibrateAxisGuidance(double graspXmm, double graspYmm, double graspZmm,
|
||
|
|
double graspADeg, double graspBDeg, double graspCDeg,
|
||
|
|
const QString& referenceFrame,
|
||
|
|
QString* errorMessage = nullptr);
|
||
|
|
bool axisGuidanceReady() const { return m_axisGuidanceValid; }
|
||
|
|
bool axisGuidanceEnabled() const { return m_axisGuidanceEnabled; }
|
||
|
|
QString axisGuidanceReferenceFrame() const { return m_axisGuidanceReferenceFrame; }
|
||
|
|
QString lastAxisVectorText() const { return m_lastAxisVectorText; }
|
||
|
|
bool transformGraspPose();
|
||
|
|
bool transformActivePose();
|
||
|
|
bool isLoaded() const { return m_loaded; }
|
||
|
|
bool transformedPoseReady() const { return m_transformedPoseReady; }
|
||
|
|
VisionPoseResult transformedPose() const { return m_transformedPose; }
|
||
|
|
QString outputReferenceFrame() const { return m_outputReferenceFrame; }
|
||
|
|
bool currentTcpPoseReady() const { return m_currentTcpPoseValid; }
|
||
|
|
// 兼容现有调用;这里的 robotPose 实际是所选参考坐标系下的抓取位姿 XYZABC。
|
||
|
|
bool robotPoseReady() const { return transformedPoseReady(); }
|
||
|
|
VisionPoseResult robotPose() const { return transformedPose(); }
|
||
|
|
VisionPoseResult activeCameraPose() const { return m_activeCameraPose; }
|
||
|
|
bool activeCameraPoseIsGraspPoint() const { return m_activePointMode == GraspPoint; }
|
||
|
|
bool makeGraspPose(const VisionPoseResult& centerPose,
|
||
|
|
VisionPoseResult& result) const;
|
||
|
|
bool loadFromFile(const QString& path);
|
||
|
|
|
||
|
|
signals:
|
||
|
|
void logMessage(const QString& msg);
|
||
|
|
void poseDisplayRequested(const VisionPoseResult& pose, const QString& mode);
|
||
|
|
void transformedPoseUpdated(const VisionPoseResult& pose,
|
||
|
|
const QString& referenceFrame);
|
||
|
|
|
||
|
|
private slots:
|
||
|
|
void onLoadMatrix();
|
||
|
|
void onShowPartCenter();
|
||
|
|
void onShowGraspPoint();
|
||
|
|
void onTransform();
|
||
|
|
void onGraspOffsetChanged(double valueMm);
|
||
|
|
|
||
|
|
private:
|
||
|
|
enum CameraPointMode { CenterPoint, GraspPoint };
|
||
|
|
bool isEyeInHand() const;
|
||
|
|
bool canTransform() const;
|
||
|
|
bool performTransform(const VisionPoseResult& cameraPose);
|
||
|
|
bool cameraPoseToTransform(const VisionPoseResult& cameraPose,
|
||
|
|
cv::Mat& transform) const;
|
||
|
|
bool currentReferencePartTransform(cv::Mat& transform,
|
||
|
|
QString* errorMessage = nullptr) const;
|
||
|
|
static cv::Mat rotationAligningVectors(const cv::Vec3d& from,
|
||
|
|
const cv::Vec3d& to);
|
||
|
|
void loadAxisGuidanceCalibration();
|
||
|
|
void saveAxisGuidanceCalibration();
|
||
|
|
void updateStates();
|
||
|
|
Ui::MainWindowClass& ui;
|
||
|
|
cv::Mat m_matrix;
|
||
|
|
bool m_loaded = false;
|
||
|
|
bool m_transformedPoseReady = false;
|
||
|
|
bool m_currentTcpPoseValid = false;
|
||
|
|
VisionPoseResult m_centerPose;
|
||
|
|
VisionPoseResult m_activeCameraPose;
|
||
|
|
VisionPoseResult m_transformedPose;
|
||
|
|
CameraPointMode m_activePointMode = CenterPoint;
|
||
|
|
double m_tcpXmm = 0.0;
|
||
|
|
double m_tcpYmm = 0.0;
|
||
|
|
double m_tcpZmm = 0.0;
|
||
|
|
double m_tcpADeg = 0.0;
|
||
|
|
double m_tcpBDeg = 0.0;
|
||
|
|
double m_tcpCDeg = 0.0;
|
||
|
|
bool m_axisGuidanceEnabled = false;
|
||
|
|
bool m_axisGuidanceValid = false;
|
||
|
|
cv::Vec3d m_axisGuidanceReferenceAxis = cv::Vec3d(0.0, 0.0, 1.0);
|
||
|
|
cv::Vec3d m_axisGuidanceAxisInTool = cv::Vec3d(0.0, 0.0, 1.0); // 示教时中心轴在TCP系中的方向
|
||
|
|
cv::Vec3d m_axisGuidancePositionOffset = cv::Vec3d(0.0, 0.0, 0.0); // 标定得到的参考系平移偏差
|
||
|
|
double m_axisGuidanceFixedBDeg = 0.0;
|
||
|
|
double m_axisGuidanceFixedCDeg = 0.0;
|
||
|
|
QString m_axisGuidanceReferenceFrame;
|
||
|
|
QString m_lastAxisVectorText;
|
||
|
|
bool m_systemBiasEnabled = false;
|
||
|
|
cv::Vec3d m_systemBiasMeters = cv::Vec3d(0.0, 0.0, 0.0);
|
||
|
|
QString m_file;
|
||
|
|
QString m_matrixType;
|
||
|
|
QString m_matrixReferenceFrame;
|
||
|
|
QString m_currentTcpReferenceFrame;
|
||
|
|
QString m_outputReferenceFrame;
|
||
|
|
};
|