128 lines
5.3 KiB
C++
128 lines
5.3 KiB
C++
#pragma once
|
|||
|
|
#include <QWidget>
|
||
|
|
#include <QJsonObject>
|
||
|
|
#include <QJsonArray>
|
||
|
|
#include <QSet>
|
||
|
|
#include <QElapsedTimer>
|
||
|
|
#include <future>
|
||
|
|
#include "MeasurePanel.h"
|
||
|
|
#include "YoloDetector.h"
|
||
|
|
#include "BoardPoseEstimator.h"
|
||
|
|
|
||
|
|
class CameraPanel;
|
||
|
|
class YoloDetector;
|
||
|
|
class QComboBox;
|
||
|
|
class QDoubleSpinBox;
|
||
|
|
class QSpinBox;
|
||
|
|
class QLineEdit;
|
||
|
|
class QLabel;
|
||
|
|
class QPushButton;
|
||
|
|
class QTableWidget;
|
||
|
|
class QThread;
|
||
|
|
class QVBoxLayout;
|
||
|
|
|
||
|
|
struct MeasurementSelection {
|
||
|
|
VisionPoseResult pose;
|
||
|
|
QString source = QStringLiteral("NONE");
|
||
|
|
QString error;
|
||
|
|
};
|
||
|
|
|
||
|
|
class MeasurementOptionsPanel : public QWidget {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
MeasurementOptionsPanel(CameraPanel* camera, YoloDetector* yolo,
|
||
|
|
VisionGuideMatcher* matcher, StereoPoseFusion* fusion,
|
||
|
|
MeasurePanel* legacy, QWidget* parent = nullptr,const QString& setupFile = QString());
|
||
|
|
~MeasurementOptionsPanel();
|
||
|
|
static MeasurementSelection selectPose(int mode, const VisionPoseResult& left,
|
||
|
|
const VisionPoseResult& right, const StereoPoseFusion::FusionResult& fusion);
|
||
|
|
static MeasurementSelection enforceDeadline(MeasurementSelection selection,
|
||
|
|
qint64 elapsedMs, qint64 deadlineMs);
|
||
|
|
static QJsonObject poseJson(const VisionPoseResult& pose);
|
||
|
|
static VisionPoseResult offsetPose(const VisionPoseResult& pose,double offsetMm);
|
||
|
|
static QRect selectTargetRoi(const QVector<YoloResult>& parts, const QSize& imageSize,
|
||
|
|
int selectionMode, const QRect& hint = QRect());
|
||
|
|
static QJsonObject graspTarget(const VisionPoseResult& pose,
|
||
|
|
const QJsonArray& photographRobot, const QJsonObject& calibration,double offsetMm=4.4);
|
||
|
|
static QJsonObject graspTargets(const MeasurementCaptureSnapshot& snapshot,
|
||
|
|
const QJsonArray& photographRobot, const QJsonObject& calibration,double offsetMm=4.4);
|
||
|
|
static QJsonObject graspTargetOnPlane(const VisionPoseResult& pose,const QJsonArray& photographRobot,
|
||
|
|
const QJsonObject& calibration,const QJsonArray& validatedTool1Point,double offsetMm=4.4);
|
||
|
|
static QJsonObject graspTargetKeepingXY(const VisionPoseResult& pose,const QJsonArray& photographRobot,
|
||
|
|
const QJsonObject& calibration,const QJsonArray& validatedTool1Point,double offsetMm=4.4);
|
||
|
|
static QJsonObject boardNormalWorld(const QJsonObject& board,const QJsonArray& photographRobot,
|
||
|
|
const QJsonObject& calibration);
|
||
|
|
signals:
|
||
|
|
void logMessage(const QString& message);
|
||
|
|
void busyChanged(bool busy);
|
||
|
|
void resultImage(const QString& name, const QImage& image);
|
||
|
|
private:
|
||
|
|
friend class MeasurementOptionsTest;
|
||
|
|
void start();
|
||
|
|
void setBusy(bool busy);
|
||
|
|
void complete(MeasurementCaptureSnapshot snapshot, QJsonObject record,
|
||
|
|
const MeasurementSelection& selected);
|
||
|
|
void renderResult();
|
||
|
|
void saveData();
|
||
|
|
void writeArchive(QJsonObject record, const MeasurementCaptureSnapshot& snapshot,
|
||
|
|
const QImage& result, bool images);
|
||
|
|
void calculateGrasp();
|
||
|
|
void refreshCameraPoses();
|
||
|
|
void invalidateGraspTargets();
|
||
|
|
void createTraySetupControls(QVBoxLayout* layout);
|
||
|
|
void createTeachReferenceControls(QVBoxLayout* layout);
|
||
|
|
QString selectedHeightMethod() const;
|
||
|
|
bool usesTeachPlane() const;
|
||
|
|
void measureBoard(bool offline);
|
||
|
|
void measureBoardImage(const QImage& image,const QString& source,qint64 captureBeginMs=0,
|
||
|
|
qint64 captureEndMs=0,bool measurementLocked=false);
|
||
|
|
void completeBoard(const BoardPoseEstimate& result,const MeasurementCaptureSnapshot& capture,
|
||
|
|
QJsonObject record,const QString& failure);
|
||
|
|
void applyBoardNormal();
|
||
|
|
void resetTraySetup();
|
||
|
|
void importTeachReference();
|
||
|
|
void saveTeachReference();
|
||
|
|
void updateSetupStatus();
|
||
|
|
void saveSetup();
|
||
|
|
void loadSetup();
|
||
|
|
QJsonObject traySetupState() const;
|
||
|
|
void restoreTraySetup(const QJsonObject& state);
|
||
|
|
void selectTray();
|
||
|
|
QJsonObject effectiveCalibration() const;
|
||
|
|
QJsonArray robotInput() const;
|
||
|
|
void fillPose(int row, const VisionPoseResult& pose);
|
||
|
|
QString rootPath() const;
|
||
|
|
CameraPanel* m_camera;
|
||
|
|
YoloDetector* m_yolo;
|
||
|
|
VisionGuideMatcher* m_matcher;
|
||
|
|
StereoPoseFusion* m_fusion;
|
||
|
|
MeasurePanel* m_legacy;
|
||
|
|
QComboBox* m_traySelector;
|
||
|
|
QComboBox *m_mode, *m_refinement, *m_yoloSelection, *m_posePoint, *m_heightMethod;
|
||
|
|
QDoubleSpinBox *m_minScore, *m_greediness, *m_offset;
|
||
|
|
QSpinBox *m_deadline;
|
||
|
|
QLineEdit *m_robot[6], *m_planePoint[3], *m_planeAngles[3], *m_boardRobot[6], *m_boardDescription;
|
||
|
|
QString m_calibrationPath;
|
||
|
|
QPushButton *m_start, *m_draw, *m_save, *m_grasp;
|
||
|
|
QPushButton *m_measureBoard, *m_importBoard, *m_applyNormal, *m_resetSetup,
|
||
|
|
*m_importTeach, *m_saveTeach, *m_browseDescription;
|
||
|
|
QLabel *m_status, *m_source, *m_saved;
|
||
|
|
QLabel *m_boardStatus, *m_normalStatus, *m_teachStatus;
|
||
|
|
QTableWidget *m_values, *m_boardValues;
|
||
|
|
bool m_busy=false, m_timedOut=false, m_saveBusy=false;
|
||
|
|
quint64 m_generation=0;
|
||
|
|
QThread* m_worker=nullptr;
|
||
|
|
QSet<QThread*> m_archiveWorkers;
|
||
|
|
std::shared_future<void> m_archiveTail;
|
||
|
|
QJsonObject m_record;
|
||
|
|
MeasurementCaptureSnapshot m_snapshot;
|
||
|
|
QImage m_resultImage;
|
||
|
|
QString m_setupFile;
|
||
|
|
int m_currentTrayId=1;
|
||
|
|
QJsonObject m_trayProfiles;
|
||
|
|
QJsonObject m_activeNormal, m_boardRecord;
|
||
|
|
QJsonArray m_normalSamples, m_activeTeach;
|
||
|
|
MeasurementCaptureSnapshot m_boardCapture;
|
||
|
|
bool m_normalRequired=false,m_loadingSetup=false;
|
||
|
|
};
|