上传文件至 src

This commit is contained in:
Gao 2026-10-08 16:51:28 +08:00
parent f1316b00b7
commit 4054712a35
4 changed files with 694 additions and 320 deletions

View File

@ -1,323 +1,329 @@
#pragma once
#include <QImage>
#include <QHash>
#include <QList>
#include <QMainWindow>
#include <QSet>
#include <QStyle>
#include <QStringList>
#include <QVariantList>
#include <QVariantMap>
#include "videoframe.h"
class QButtonGroup;
class QCheckBox;
class QComboBox;
class QDoubleSpinBox;
class QDialog;
class QEvent;
class QHBoxLayout;
class QGridLayout;
class QLabel;
class QLineEdit;
class QProgressBar;
class QPushButton;
class QResizeEvent;
class QSlider;
class QSpinBox;
class QStackedWidget;
class QTableWidget;
class QTabWidget;
class QTextEdit;
class QTimer;
class QVBoxLayout;
class TrendWidget;
class RobotClient;
class QuicTestServer;
class UrdfViewerWidget;
class AudioStreamManager;
#pragma once
#include <QImage>
#include <QHash>
#include <QList>
#include <QMainWindow>
#include <QSet>
#include <QStyle>
#include <QStringList>
#include <QVariantList>
#include <QVariantMap>
#include "videoframe.h"
class QButtonGroup;
class QCheckBox;
class QComboBox;
class QDoubleSpinBox;
class QDialog;
class QEvent;
class QHBoxLayout;
class QGridLayout;
class QLabel;
class QLineEdit;
class QProgressBar;
class QPushButton;
class QResizeEvent;
class QSlider;
class QSpinBox;
class QStackedWidget;
class QTableWidget;
class QTabWidget;
class QTextEdit;
class QTimer;
class QVBoxLayout;
class TrendWidget;
class RobotClient;
class QuicTestServer;
class UrdfViewerWidget;
class AudioStreamManager;
class VideoRenderWidget;
class AgvMapViewWidget;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
bool eventFilter(QObject *watched, QEvent *event) override;
void changeEvent(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void selectPage(int index);
void toggleConnection();
void updateConnection(bool connected, int latencyMs, const QString &detail);
void updateArmInfo(const QString &deviceId, const QVariantMap &info);
void updateTelemetry(const QString &deviceId, const QVariantList &joints,
const QVariantMap &pose, const QVariantMap &state);
void updateArmTelemetryHealth(const QString &deviceId, bool available,
const QString &detail);
void updateSystemStatus(double cpu, double memory, double disk,
const QVariantList &devices);
void updateSystemInfo(const QVariantMap &info);
void updateImage(const QImage &image, const QString &detail);
void updateVideoFrame(const QString &cameraId, const VideoFrame &frame,
const QString &detail);
void updateCameraStreamState(const QString &cameraId, bool running,
const QString &detail);
void updateCameraRecordingState(bool recording, const QString &detail);
void updateAgvState(const QVariantMap &state, const QVariantMap &navigation);
void updateAgvInventory(const QStringList &maps, const QVariantList &stations);
void handleCommand(const QString &command, bool success, const QString &detail);
void appendLog(const QString &level, const QString &message);
void toggleQuicServer();
void updateQuicRunning(bool running, quint16 port, const QString &detail);
void appendQuicLog(const QString &level, const QString &message);
void sendMoveJ();
void sendMoveJPose();
void saveSnapshot();
private:
QWidget *createSystemPage();
QWidget *createArmPage();
QWidget *createCameraPage();
QStringList configuredCameraIds() const;
void rebuildCameraPreviewGrid(const QStringList &cameraIds);
void refreshCameraStreamControls();
QWidget *createAgvPage();
QWidget *createAudioPage(bool speaker);
QWidget *createRpcPage(const QString &serviceName);
QWidget *createQuicPage();
QWidget *createDiagnosticsPage();
void loadSettings();
void saveSettings();
void setControlsEnabled(bool enabled);
void updateWindowChrome();
void ensureArmModelLoaded();
void rebuildArmJointTables(const QStringList &jointNames);
void rebuildArmJogControls();
void setArmTelemetryEnabled(bool enabled);
void startJointJog(int jointIndex, int direction);
void startCartesianJog(int axisIndex, int direction);
class TcpCalibrationWidget;
class TouchOperationWidget;
class TcpJogController;
class HandEyeCalibrationWidget;
class HandEyeMotionWidget;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
void changeEvent(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void selectPage(int index);
void toggleConnection();
void updateConnection(bool connected, int latencyMs, const QString &detail);
void updateArmInfo(const QString &deviceId, const QVariantMap &info);
void updateTelemetry(const QString &deviceId, const QVariantList &joints,
const QVariantMap &pose, const QVariantMap &state);
void updateArmTelemetryHealth(const QString &deviceId, bool available,
const QString &detail);
void updateSystemStatus(double cpu, double memory, double disk,
const QVariantList &devices);
void updateSystemInfo(const QVariantMap &info);
void updateImage(const QImage &image, const QString &detail);
void updateVideoFrame(const QString &cameraId, const VideoFrame &frame,
const QString &detail);
void updateCameraStreamState(const QString &cameraId, bool running,
const QString &detail);
void updateCameraRecordingState(bool recording, const QString &detail);
void updateAgvState(const QVariantMap &state, const QVariantMap &navigation);
void updateAgvInventory(const QStringList &maps, const QVariantList &stations);
void handleCommand(const QString &command, bool success, const QString &detail);
void appendLog(const QString &level, const QString &message);
void toggleQuicServer();
void updateQuicRunning(bool running, quint16 port, const QString &detail);
void appendQuicLog(const QString &level, const QString &message);
void sendMoveJ();
void sendMoveJPose();
void saveSnapshot();
private:
QWidget *createSystemPage();
QWidget *createArmPage();
QWidget *createCameraPage();
QStringList configuredCameraIds() const;
void rebuildCameraPreviewGrid(const QStringList &cameraIds);
void refreshCameraStreamControls();
QWidget *createAgvPage();
QWidget *createAudioPage(bool speaker);
QWidget *createRpcPage(const QString &serviceName);
QWidget *createQuicPage();
QWidget *createDiagnosticsPage();
void loadSettings();
void saveSettings();
void setControlsEnabled(bool enabled);
void updateWindowChrome();
void ensureArmModelLoaded();
void rebuildArmJointTables(const QStringList &jointNames);
void rebuildArmJogControls();
void startJointJog(int jointIndex, int direction);
void startCartesianJog(int axisIndex, int direction);
void stopArmJog();
void startAgvManualMotion(double vx, double vy, double wz);
void stopAgvManualMotion(bool sendStop = true);
void restartAgvMapStream(const QString &mapName = QString());
void updateArmAlert(const QString &deviceId, const QString &alertKey,
const QString &level, const QString &summary,
const QString &detail = QString());
QString endpoint() const;
void refreshTcpChoices(const QString &savedName = QString());
void updateArmPoseFrames();
bool selectedLocalTcp() const;
void setupHandEye();
void setupTouchOperation();
void syncHandEyeContext();
void updateArmAlert(const QString &deviceId, const QString &alertKey,
const QString &level, const QString &summary,
const QString &detail = QString());
QString endpoint() const;
RobotClient *m_client = nullptr;
AudioStreamManager *m_audioManager = nullptr;
QuicTestServer *m_quicServer = nullptr;
QStackedWidget *m_pages = nullptr;
QButtonGroup *m_navGroup = nullptr;
QList<QPushButton *> m_navButtons;
QWidget *m_windowSurface = nullptr;
QWidget *m_customTitleBar = nullptr;
QLabel *m_titleBarPage = nullptr;
QLabel *m_titleBarBuild = nullptr;
QPushButton *m_minimizeWindowButton = nullptr;
QPushButton *m_maximizeWindowButton = nullptr;
QPushButton *m_closeWindowButton = nullptr;
QSize m_windowChromeSize;
bool m_windowChromeInitialized = false;
bool m_windowChromeMaximized = false;
bool m_updatingWindowChrome = false;
QLineEdit *m_hostEdit = nullptr;
QSpinBox *m_portSpin = nullptr;
QCheckBox *m_demoCheck = nullptr;
QPushButton *m_connectButton = nullptr;
QLabel *m_connectionDot = nullptr;
QLabel *m_connectionText = nullptr;
QLabel *m_latencyLabel = nullptr;
QLabel *m_pageTitle = nullptr;
QLabel *m_pageSubtitle = nullptr;
QHBoxLayout *m_headerLayout = nullptr;
QWidget *m_armHeaderControls = nullptr;
QLabel *m_sidebarEndpointValue = nullptr;
QLabel *m_sidebarQuicValue = nullptr;
QLabel *m_bottomLogLevel = nullptr;
QLabel *m_bottomLogMessage = nullptr;
QLabel *m_bottomVersion = nullptr;
QLabel *m_cpuValue = nullptr;
QLabel *m_memoryValue = nullptr;
QLabel *m_diskValue = nullptr;
QLabel *m_deviceValue = nullptr;
QLabel *m_systemNameValue = nullptr;
QLabel *m_systemVersionValue = nullptr;
QLabel *m_systemOsValue = nullptr;
QLineEdit *m_systemTargetEdit = nullptr;
QPushButton *m_systemRefreshButton = nullptr;
QPushButton *m_systemStopButton = nullptr;
QLineEdit *m_armIdEdit = nullptr;
QComboBox *m_armSideCombo = nullptr;
QPushButton *m_armTelemetryButton = nullptr;
QPushButton *m_armGlobalStopButton = nullptr;
QLabel *m_armDeviceSummary = nullptr;
QLabel *m_servoStatusValue = nullptr;
QLabel *m_faultStatusValue = nullptr;
QList<QLabel *> m_poseMetricValues;
TrendWidget *m_trend = nullptr;
QTableWidget *m_jointTable = nullptr;
QTableWidget *m_motionTable = nullptr;
QList<QDoubleSpinBox *> m_targetSpins;
QStringList m_activeArmJointNames;
QTabWidget *m_motionCommandTabs = nullptr;
QList<QDoubleSpinBox *> m_moveJPoseSpins;
QComboBox *m_moveJPoseBaseLinkCombo = nullptr;
QPushButton *m_copyCurrentPoseButton = nullptr;
QVariantMap m_latestArmPose;
QString m_armDefaultBaseFrame;
QString m_armDefaultTcpFrame;
QTabWidget *m_jogModeTabs = nullptr;
QWidget *m_jointJogRowsHost = nullptr;
QVBoxLayout *m_jointJogRowsLayout = nullptr;
QList<QLabel *> m_jointJogPositionLabels;
QList<QSlider *> m_jointJogPositionSliders;
QList<QPushButton *> m_jointJogMinusButtons;
QList<QPushButton *> m_jointJogPlusButtons;
QList<QLabel *> m_cartesianJogPoseLabels;
QComboBox *m_baseFrameCombo = nullptr;
QComboBox *m_tcpFrameCombo = nullptr;
QSlider *m_jogSpeedSlider = nullptr;
QLabel *m_jogSpeedValue = nullptr;
QPushButton *m_jogStopButton = nullptr;
QHash<QString, double> m_previousJointVelocities;
qint64 m_lastArmTelemetryMs = 0;
QHash<QString, QString> m_armAlertStates;
QHash<QString, qint64> m_armLastAlertPopupMs;
bool m_armJogActive = false;
QDoubleSpinBox *m_velocitySpin = nullptr;
QDoubleSpinBox *m_accelerationSpin = nullptr;
QDoubleSpinBox *m_cartesianVelocitySpin = nullptr;
QDoubleSpinBox *m_cartesianAccelerationSpin = nullptr;
QPushButton *m_sendMoveButton = nullptr;
QPushButton *m_torqueOnButton = nullptr;
QPushButton *m_torqueOffButton = nullptr;
QPushButton *m_clearFaultButton = nullptr;
QComboBox *m_zeroJointCombo = nullptr;
QPushButton *m_calibrateZeroButton = nullptr;
QPushButton *m_stopButton = nullptr;
UrdfViewerWidget *m_urdfViewer = nullptr;
QPushButton *m_teachModeButton = nullptr;
QPushButton *m_teachRestoreButton = nullptr;
QPushButton *m_teachSendButton = nullptr;
QLabel *m_teachSelectedLabel = nullptr;
QDoubleSpinBox *m_teachPositionSpin = nullptr;
QTableWidget *m_teachJointTable = nullptr;
QString m_teachSelectedJoint;
QString m_pendingUrdfPath;
bool m_armModelLoadScheduled = false;
QLineEdit *m_cameraIdEdit = nullptr;
VideoRenderWidget *m_videoRender = nullptr;
QLabel *m_imageMetaLabel = nullptr;
QPushButton *m_snapshotButton = nullptr;
QPushButton *m_cameraStreamButton = nullptr;
QPushButton *m_saveImageButton = nullptr;
QComboBox *m_cameraCodecCombo = nullptr;
QComboBox *m_cameraStreamModeCombo = nullptr;
QLabel *m_cameraStreamStateLabel = nullptr;
QLineEdit *m_cameraRecordPathEdit = nullptr;
QPushButton *m_cameraRecordButton = nullptr;
QLabel *m_cameraRecordStateLabel = nullptr;
QWidget *m_cameraPreviewContainer = nullptr;
QGridLayout *m_cameraPreviewGrid = nullptr;
struct CameraPreviewTile {
QWidget *container = nullptr;
VideoRenderWidget *render = nullptr;
QLabel *status = nullptr;
QLabel *meta = nullptr;
};
QHash<QString, CameraPreviewTile> m_cameraPreviewTiles;
QSet<QString> m_runningCameraIds;
QImage m_lastImage;
bool m_cameraStreaming = false;
bool m_cameraRecording = false;
QLineEdit *m_agvIdEdit = nullptr;
QDialog *m_agvStatusDialog = nullptr;
QTimer *m_agvStatusRefreshTimer = nullptr;
QTimer *m_agvManualVelocityTimer = nullptr;
QLabel *m_agvConnectionValue = nullptr;
QLabel *m_agvPoseValue = nullptr;
QLabel *m_agvMotionValue = nullptr;
QLabel *m_agvBatteryValue = nullptr;
QLabel *m_agvMapValue = nullptr;
QLabel *m_agvNavigationValue = nullptr;
QLabel *m_agvErrorValue = nullptr;
QLabel *m_agvModeValue = nullptr;
QLabel *m_agvMotionStateValue = nullptr;
QLabel *m_agvSafetyValue = nullptr;
QLabel *m_agvPowerValue = nullptr;
QLabel *m_agvTimestampValue = nullptr;
QLabel *m_agvMapOverview = nullptr;
QLabel *m_agvMappingPreview = nullptr;
QLabel *m_agvMappingStateLabel = nullptr;
AgvMapViewWidget *m_agvMapView = nullptr;
QWidget *m_agvControlWorkspace = nullptr;
QPushButton *m_agvDeleteMapButton = nullptr;
QProgressBar *m_agvProgress = nullptr;
QDoubleSpinBox *m_agvXSpin = nullptr;
QDoubleSpinBox *m_agvYSpin = nullptr;
QDoubleSpinBox *m_agvThetaSpin = nullptr;
QDoubleSpinBox *m_agvMaxSpeedSpin = nullptr;
QDoubleSpinBox *m_agvVxSpin = nullptr;
QDoubleSpinBox *m_agvVySpin = nullptr;
QDoubleSpinBox *m_agvWzSpin = nullptr;
QComboBox *m_agvMapCombo = nullptr;
QComboBox *m_agvStationCombo = nullptr;
QTableWidget *m_agvStationTable = nullptr;
QString m_agvDownloadPath;
QVariantMap m_latestAgvState;
double m_agvManualVx = 0.0;
double m_agvManualVy = 0.0;
double m_agvManualWz = 0.0;
bool m_agvManualMotionActive = false;
bool m_agvMapStreamActive = false;
QList<QPushButton *> m_serviceButtons;
QPushButton *m_speakerStreamStartButton = nullptr;
QPushButton *m_speakerStreamStopButton = nullptr;
QPushButton *m_microphoneStreamStartButton = nullptr;
QPushButton *m_microphoneStreamStopButton = nullptr;
QLineEdit *m_speakerIdEdit = nullptr;
QLineEdit *m_microphoneIdEdit = nullptr;
QLineEdit *m_quicBindEdit = nullptr;
QSpinBox *m_quicPortSpin = nullptr;
QLineEdit *m_quicAlpnEdit = nullptr;
QLineEdit *m_quicCertificateEdit = nullptr;
QLineEdit *m_quicPasswordEdit = nullptr;
QPushButton *m_quicToggleButton = nullptr;
QLabel *m_quicStateValue = nullptr;
QLabel *m_quicBoundValue = nullptr;
QLabel *m_quicClientValue = nullptr;
QLabel *m_quicRegistrationValue = nullptr;
QLabel *m_quicHeartbeatValue = nullptr;
QLabel *m_quicDatagramValue = nullptr;
QLabel *m_quicDatagramBytesValue = nullptr;
QLabel *m_quicNodeValue = nullptr;
QLabel *m_quicBootValue = nullptr;
QLabel *m_quicGrpcValue = nullptr;
QLabel *m_quicPeerValue = nullptr;
QTextEdit *m_quicLogView = nullptr;
QTextEdit *m_logView = nullptr;
QLabel *m_endpointValue = nullptr;
QLabel *m_backendValue = nullptr;
QLabel *m_buildValue = nullptr;
bool m_connected = false;
};
TcpCalibrationWidget *m_tcpCalibration = nullptr;
TcpJogController *m_tcpJog = nullptr;
HandEyeCalibrationWidget *m_handEye = nullptr;
HandEyeMotionWidget *m_handEyeMotion = nullptr;
QString m_handEyeOwnedCamera;
TouchOperationWidget *m_touchOperation = nullptr;
QString m_touchOwnedCamera;
QString m_tcpChoiceEndpoint, m_tcpChoiceDevice;
QStringList m_controllerTcpFrames;
QLabel *m_armPoseSubtitle = nullptr;
AudioStreamManager *m_audioManager = nullptr;
QuicTestServer *m_quicServer = nullptr;
QStackedWidget *m_pages = nullptr;
QButtonGroup *m_navGroup = nullptr;
QList<QPushButton *> m_navButtons;
QWidget *m_windowSurface = nullptr;
QWidget *m_customTitleBar = nullptr;
QLabel *m_titleBarPage = nullptr;
QLabel *m_titleBarBuild = nullptr;
QPushButton *m_minimizeWindowButton = nullptr;
QPushButton *m_maximizeWindowButton = nullptr;
QPushButton *m_closeWindowButton = nullptr;
QSize m_windowChromeSize;
bool m_windowChromeInitialized = false;
bool m_windowChromeMaximized = false;
bool m_updatingWindowChrome = false;
QLineEdit *m_hostEdit = nullptr;
QSpinBox *m_portSpin = nullptr;
QCheckBox *m_demoCheck = nullptr;
QPushButton *m_connectButton = nullptr;
QLabel *m_connectionDot = nullptr;
QLabel *m_connectionText = nullptr;
QLabel *m_latencyLabel = nullptr;
QLabel *m_pageTitle = nullptr;
QLabel *m_pageSubtitle = nullptr;
QHBoxLayout *m_headerLayout = nullptr;
QWidget *m_armHeaderControls = nullptr;
QLabel *m_sidebarEndpointValue = nullptr;
QLabel *m_sidebarQuicValue = nullptr;
QLabel *m_bottomLogLevel = nullptr;
QLabel *m_bottomLogMessage = nullptr;
QLabel *m_bottomVersion = nullptr;
QLabel *m_cpuValue = nullptr;
QLabel *m_memoryValue = nullptr;
QLabel *m_diskValue = nullptr;
QLabel *m_deviceValue = nullptr;
QLabel *m_systemNameValue = nullptr;
QLabel *m_systemVersionValue = nullptr;
QLabel *m_systemOsValue = nullptr;
QLineEdit *m_systemTargetEdit = nullptr;
QPushButton *m_systemRefreshButton = nullptr;
QPushButton *m_systemStopButton = nullptr;
QLineEdit *m_armIdEdit = nullptr;
QComboBox *m_armSideCombo = nullptr;
QPushButton *m_armTelemetryButton = nullptr;
QPushButton *m_armGlobalStopButton = nullptr;
QLabel *m_armDeviceSummary = nullptr;
QLabel *m_servoStatusValue = nullptr;
QLabel *m_faultStatusValue = nullptr;
QList<QLabel *> m_poseMetricValues;
TrendWidget *m_trend = nullptr;
QTableWidget *m_jointTable = nullptr;
QTableWidget *m_motionTable = nullptr;
QList<QDoubleSpinBox *> m_targetSpins;
QStringList m_activeArmJointNames;
QTabWidget *m_motionCommandTabs = nullptr;
QList<QDoubleSpinBox *> m_moveJPoseSpins;
QComboBox *m_moveJPoseBaseLinkCombo = nullptr;
QPushButton *m_copyCurrentPoseButton = nullptr;
QVariantMap m_latestArmPose;
QString m_armDefaultBaseFrame;
QString m_armDefaultTcpFrame;
QTabWidget *m_jogModeTabs = nullptr;
QWidget *m_jointJogRowsHost = nullptr;
QVBoxLayout *m_jointJogRowsLayout = nullptr;
QList<QLabel *> m_jointJogPositionLabels;
QList<QSlider *> m_jointJogPositionSliders;
QList<QPushButton *> m_jointJogMinusButtons;
QList<QPushButton *> m_jointJogPlusButtons;
QList<QLabel *> m_cartesianJogPoseLabels;
QComboBox *m_baseFrameCombo = nullptr;
QComboBox *m_tcpFrameCombo = nullptr;
QSlider *m_jogSpeedSlider = nullptr;
QLabel *m_jogSpeedValue = nullptr;
QPushButton *m_jogStopButton = nullptr;
QHash<QString, double> m_previousJointVelocities;
qint64 m_lastArmTelemetryMs = 0;
QHash<QString, QString> m_armAlertStates;
QHash<QString, qint64> m_armLastAlertPopupMs;
bool m_armJogActive = false;
QDoubleSpinBox *m_velocitySpin = nullptr;
QDoubleSpinBox *m_accelerationSpin = nullptr;
QDoubleSpinBox *m_cartesianVelocitySpin = nullptr;
QDoubleSpinBox *m_cartesianAccelerationSpin = nullptr;
QPushButton *m_sendMoveButton = nullptr;
QPushButton *m_torqueOnButton = nullptr;
QPushButton *m_torqueOffButton = nullptr;
QPushButton *m_clearFaultButton = nullptr;
QComboBox *m_zeroJointCombo = nullptr;
QPushButton *m_calibrateZeroButton = nullptr;
QPushButton *m_stopButton = nullptr;
UrdfViewerWidget *m_urdfViewer = nullptr;
QPushButton *m_teachModeButton = nullptr;
QPushButton *m_teachRestoreButton = nullptr;
QPushButton *m_teachSendButton = nullptr;
QLabel *m_teachSelectedLabel = nullptr;
QDoubleSpinBox *m_teachPositionSpin = nullptr;
QTableWidget *m_teachJointTable = nullptr;
QString m_teachSelectedJoint;
QString m_pendingUrdfPath;
bool m_armModelLoadScheduled = false;
QLineEdit *m_cameraIdEdit = nullptr;
VideoRenderWidget *m_videoRender = nullptr;
QLabel *m_imageMetaLabel = nullptr;
QPushButton *m_snapshotButton = nullptr;
QPushButton *m_cameraStreamButton = nullptr;
QPushButton *m_saveImageButton = nullptr;
QComboBox *m_cameraCodecCombo = nullptr;
QComboBox *m_cameraStreamModeCombo = nullptr;
QLabel *m_cameraStreamStateLabel = nullptr;
QLineEdit *m_cameraRecordPathEdit = nullptr;
QPushButton *m_cameraRecordButton = nullptr;
QLabel *m_cameraRecordStateLabel = nullptr;
QWidget *m_cameraPreviewContainer = nullptr;
QGridLayout *m_cameraPreviewGrid = nullptr;
struct CameraPreviewTile {
QWidget *container = nullptr;
VideoRenderWidget *render = nullptr;
QLabel *status = nullptr;
QLabel *meta = nullptr;
};
QHash<QString, CameraPreviewTile> m_cameraPreviewTiles;
QSet<QString> m_runningCameraIds;
QImage m_lastImage;
bool m_cameraStreaming = false;
bool m_cameraRecording = false;
QLineEdit *m_agvIdEdit = nullptr;
QDialog *m_agvStatusDialog = nullptr;
QCheckBox *m_agvStatusSwitch = nullptr;
QTimer *m_agvStatusRefreshTimer = nullptr;
QLabel *m_agvConnectionValue = nullptr;
QLabel *m_agvPoseValue = nullptr;
QLabel *m_agvMotionValue = nullptr;
QLabel *m_agvBatteryValue = nullptr;
QLabel *m_agvMapValue = nullptr;
QLabel *m_agvNavigationValue = nullptr;
QLabel *m_agvErrorValue = nullptr;
QLabel *m_agvModeValue = nullptr;
QLabel *m_agvMotionStateValue = nullptr;
QLabel *m_agvSafetyValue = nullptr;
QLabel *m_agvPowerValue = nullptr;
QLabel *m_agvTimestampValue = nullptr;
QLabel *m_agvMapOverview = nullptr;
QLabel *m_agvMappingPreview = nullptr;
QLabel *m_agvMappingStateLabel = nullptr;
QProgressBar *m_agvProgress = nullptr;
QDoubleSpinBox *m_agvXSpin = nullptr;
QDoubleSpinBox *m_agvYSpin = nullptr;
QDoubleSpinBox *m_agvThetaSpin = nullptr;
QDoubleSpinBox *m_agvMaxSpeedSpin = nullptr;
QDoubleSpinBox *m_agvVxSpin = nullptr;
QDoubleSpinBox *m_agvVySpin = nullptr;
QDoubleSpinBox *m_agvWzSpin = nullptr;
QComboBox *m_agvMapCombo = nullptr;
QComboBox *m_agvStationCombo = nullptr;
QTableWidget *m_agvStationTable = nullptr;
QString m_agvDownloadPath;
QList<QPushButton *> m_serviceButtons;
QPushButton *m_speakerStreamStartButton = nullptr;
QPushButton *m_speakerStreamStopButton = nullptr;
QPushButton *m_microphoneStreamStartButton = nullptr;
QPushButton *m_microphoneStreamStopButton = nullptr;
QLineEdit *m_speakerIdEdit = nullptr;
QLineEdit *m_microphoneIdEdit = nullptr;
QLineEdit *m_quicBindEdit = nullptr;
QSpinBox *m_quicPortSpin = nullptr;
QLineEdit *m_quicAlpnEdit = nullptr;
QLineEdit *m_quicCertificateEdit = nullptr;
QLineEdit *m_quicPasswordEdit = nullptr;
QPushButton *m_quicToggleButton = nullptr;
QLabel *m_quicStateValue = nullptr;
QLabel *m_quicBoundValue = nullptr;
QLabel *m_quicClientValue = nullptr;
QLabel *m_quicRegistrationValue = nullptr;
QLabel *m_quicHeartbeatValue = nullptr;
QLabel *m_quicDatagramValue = nullptr;
QLabel *m_quicDatagramBytesValue = nullptr;
QLabel *m_quicNodeValue = nullptr;
QLabel *m_quicBootValue = nullptr;
QLabel *m_quicGrpcValue = nullptr;
QLabel *m_quicPeerValue = nullptr;
QTextEdit *m_quicLogView = nullptr;
QTextEdit *m_logView = nullptr;
QLabel *m_endpointValue = nullptr;
QLabel *m_backendValue = nullptr;
QLabel *m_buildValue = nullptr;
bool m_connected = false;
};

View File

@ -0,0 +1,99 @@
#pragma once
#include "touchplanner.h"
#include "touchsequencecontroller.h"
#include "tcptoolstore.h"
#include "videoframe.h"
#include <QWidget>
#include <QImage>
class QComboBox;
class QDoubleSpinBox;
class QSpinBox;
class QCheckBox;
class QLabel;
class QPushButton;
class QTableWidget;
class TouchVideoWidget;
// Page-level workflow. Geometry and motion sequencing live in separate helpers;
// all camera/arm I/O is routed through the existing MainWindow / RobotClient.
class TouchOperationWidget : public QWidget {
Q_OBJECT
public:
explicit TouchOperationWidget(QWidget *parent=nullptr);
void setContext(const QString &endpoint,const QString &device,bool connected,bool demo,
bool reference,const TcpCalibration::Pose &activeOffset);
bool running() const;
public slots:
void reloadCalibrations();
void stop();
void acceptPose(quint64 token,const QString &device,const QVariantMap &pose,
const QVariantMap &state,bool success,const QString &detail);
void acceptImage(quint64 token,const QString &camera,const QImage &image,
const QVariantMap &intrinsics,const QVariantMap &metadata,bool success,const QString &detail);
void acceptFrame(const QString &camera,const VideoFrame &frame,const QString &detail);
void acceptStreamState(const QString &camera,bool running,const QString &detail);
void acceptCommand(const QString &command,bool success,const QString &detail);
signals:
void captureRequested(const QString &device,quint64 token);
void imageRequested(const QString &camera,quint64 token);
void previewRequested(const QString &camera,bool start);
void moveRequested(const QString &device,const QVariantMap &target,double speed,double acceleration,quint64 token);
void stopRequested(const QString &device);
void logMessage(const QString &level,const QString &message);
protected:
void hideEvent(QHideEvent *event) override;
private:
enum class Phase { Idle, Observation, LockBefore, LockImage, LockAfter, Return };
using Pose=TcpCalibration::Pose;
void refresh();
void invalidateFrame();
void invalidatePlan();
void teach(Phase phase);
void readPose();
void lockFrame();
void startPreview();
void stopPreview();
void calculate();
void execute();
void returnObservation(const Pose &current);
void fail(const QString &message);
bool ready() const;
bool selectedTool(Pose &offset) const;
const HandEyeStore::Record *handEye() const;
QString cameraId() const;
QString settingsKey() const;
void loadTeaching();
void saveTeaching();
TouchPlanner::Parameters parameters() const;
bool buildPlane(TouchPlanner::Plane &plane,QString &error) const;
bool resolveTargets(QVector<TouchPlanner::Point> &basePoints,
QVector<TouchPlanner::Point> &cameraPoints,QString &error) const;
void refreshTargetResults();
QString m_endpoint,m_device,m_previewCamera;
bool m_connected=false,m_demo=false,m_reference=false,m_loading=false,m_preview=false;
bool m_observed=false,m_planValid=false;
Pose m_activeOffset{},m_observation{},m_before{},m_lockedFlange{},m_teachingOffset{};
HandEyeStore::Snapshot m_handEyes;
TcpToolStore::Snapshot m_tools;
TouchPlanner::Plan m_plan;
TouchPlanner::CameraModel m_cameraModel;
TouchPlanner::DepthImage m_depth;
QImage m_pendingImage;
qint64 m_beforeAt=0,m_captureAt=0,m_lockedAt=0,m_requestAt=0;
quint64 m_serial=0,m_poseToken=0,m_imageToken=0;
Phase m_phase=Phase::Idle;
QTimer m_timeout;
TouchSequenceController *m_sequence;
TouchVideoWidget *m_video;
QComboBox *m_handEyeChoice,*m_toolChoice,*m_action;
QLabel *m_cameraName,*m_status,*m_observationText;
QLabel *m_conversionStatus;
QCheckBox *m_cameraConfirmed,*m_pathConfirmed;
QPushButton *m_previewButton,*m_stopPreviewButton,*m_lockButton,*m_liveButton,*m_teachObservation;
QPushButton *m_returnButton,*m_calculateButton,*m_executeButton,*m_reloadButton;
QDoubleSpinBox *m_approach,*m_press,*m_lift,*m_speed,*m_contactSpeed,*m_travel;
QSpinBox *m_dwell,*m_gap;
QTableWidget *m_targets,*m_steps;
};

83
src/touchplanner.h Normal file
View File

@ -0,0 +1,83 @@
#pragma once
#include "handeyestore.h"
#include <QPointF>
#include <QVector>
#include <QByteArray>
// Offline geometry only. All distances are metres and all angles are ZYX radians.
// The caller owns frame provenance, observation matching, controller reach/IK
// checks, collision clearance, and execution; no hardware is accessed here.
namespace TouchPlanner {
using Pose = TcpCalibration::Pose;
using Matrix = TcpCalibration::Matrix;
using Point = std::array<double, 3>;
struct CameraModel {
int width = 0, height = 0;
double fx = 0, fy = 0, cx = 0, cy = 0;
std::vector<double> distortion; // OpenCV Brown order: k1,k2,p1,p2[,k3[,k4,k5,k6]].
};
struct Plane {
Point origin{};
Point normal{}; // Unit outward normal, toward the taught observation tip.
Point orientationRad{}; // Selected-tip orientation from the first contact teach.
};
struct DepthImage {
int width = 0, height = 0;
QByteArray data; // Owning raw little-endian samples, aligned to native RGB.
bool float32 = false;
double metresPerUnit = 0; // Explicit transport contract, never inferred from type.
};
struct Parameters {
double approachM = .01;
double contactOffsetM = 0; // Positive presses inward, opposite the outward normal.
double doubleLiftM = .003;
double contactVelocityMps = .01;
double travelVelocityMps = .03;
double accelerationMps2 = .1;
int contactDwellMs = 80;
int doubleIntervalMs = 100;
double maxTravelM = .3; // Radius from observation AND maximum movement per segment.
double maxReachM = 2; // Conservative base-origin sphere, not a substitute for IK.
double maxCameraRangeM = 3;
};
enum class Action { SingleTap, DoubleTap, Swipe };
struct Step {
QString label;
Pose target{}; // Target of the controller's existing active TCP.
double velocityMps = 0;
double accelerationMps2 = 0;
int pauseMs = 0; // Applied after the target has been reached.
};
struct Plan {
QVector<Step> steps;
QVector<Point> contacts; // Unpressed surface points in base coordinates.
};
// All functions leave output unchanged on failure and clear error on success.
bool teachPlane(const std::array<Pose, 3> &selectedContacts,
const Pose &observationSelected, Plane &plane, QString *error = nullptr);
bool cameraTransform(const HandEyeStore::Record &record, const Pose &lockedBaseFlange,
Matrix &baseCamera, QString *error = nullptr);
// Exact-size intrinsics only; callers must establish the RGB distortion model.
// Supports fx/fy/cx/cy + coeffs, or camera_matrix + distortion. Does not rescale.
bool cameraModel(const QVariantMap &intrinsics, int imageWidth, int imageHeight,
CameraModel &camera, QString *error = nullptr);
bool resolvePixels(const QVector<QPointF> &pixels, const CameraModel &camera,
const Matrix &baseCamera, const Plane &plane, const Parameters &parameters,
QVector<Point> &points, QString *error = nullptr);
bool resolveDepthPixels(const QVector<QPointF> &pixels, const CameraModel &camera,
const DepthImage &depth, const Matrix &baseCamera,
const Parameters &parameters, QVector<Point> &basePoints,
QVector<Point> &cameraPoints, QString *error = nullptr);
bool validateDepthSwipe(const QVector<QPointF> &pixels, const CameraModel &camera,
const DepthImage &depth, const Matrix &baseCamera,
const Parameters &parameters, QString *error = nullptr);
// Single/double tap visit 1-2 contacts sequentially, returning to observation after
// each. Swipe requires two distinct contacts. All use approach/contact/retract.
bool buildPlan(Action action, const QVector<Point> &points, const Plane &plane,
const Pose &observationActive, const Pose &flangeActive,
const Pose &flangeSelected, const Parameters &parameters,
Plan &plan, QString *error = nullptr, bool depthTargets = false);
}

186
src/touchvideowidget.cpp Normal file
View File

@ -0,0 +1,186 @@
#include "touchvideowidget.h"
#include <QMouseEvent>
#include <QPainter>
#include <cmath>
namespace {
QRect imageRectangle(const QSize &widgetSize, const QSize &imageSize)
{
if (widgetSize.isEmpty() || imageSize.isEmpty()) return {};
QSize target = imageSize;
target.scale(widgetSize, Qt::KeepAspectRatio);
return QRect((widgetSize.width() - target.width()) / 2,
(widgetSize.height() - target.height()) / 2,
target.width(), target.height());
}
QRectF frameRectangle(const QSize &widgetSize, const QSize &imageSize, VideoPixelFormat format)
{
if (format == VideoPixelFormat::RGBA) return imageRectangle(widgetSize, imageSize);
if (widgetSize.isEmpty() || imageSize.isEmpty()) return {};
// The GL video renderer preserves fractional dimensions and centres the
// quad exactly; its geometry differs from the integer RGBA image path.
const double scale = qMin(double(widgetSize.width()) / imageSize.width(),
double(widgetSize.height()) / imageSize.height());
const QSizeF target(imageSize.width() * scale, imageSize.height() * scale);
return QRectF((widgetSize.width() - target.width()) / 2,
(widgetSize.height() - target.height()) / 2,
target.width(), target.height());
}
bool mapPoint(const QPointF &position, const QRectF &area, const QSize &imageSize, QPointF *pixel)
{
if (!pixel || !std::isfinite(position.x()) || !std::isfinite(position.y())
|| imageSize.isEmpty() || area.isEmpty()
|| position.x() < area.x() || position.y() < area.y()
|| position.x() >= area.x() + area.width()
|| position.y() >= area.y() + area.height()) return false;
const double x = (position.x() - area.x()) * imageSize.width() / area.width() - .5;
const double y = (position.y() - area.y()) * imageSize.height() / area.height() - .5;
*pixel = QPointF(qBound(0.0, x, double(imageSize.width() - 1)),
qBound(0.0, y, double(imageSize.height() - 1)));
return true;
}
}
TouchVideoWidget::TouchVideoWidget(QWidget *parent) : VideoRenderWidget(parent)
{
setMinimumSize(320, 240);
}
void TouchVideoWidget::present(const VideoFrame &frame)
{
if (!frame.isValid()) return;
m_latestFrame = frame;
if (m_locked) return;
m_imageSize = QSize(frame.width, frame.height);
setFrame(frame);
}
bool TouchVideoWidget::lockImage(const QImage &image)
{
if (image.isNull()) return false;
m_locked = true;
m_imageSize = image.size();
m_lockedFormat = VideoPixelFormat::RGBA;
setImage(image);
clearSelection();
setCursor(Qt::CrossCursor);
return true;
}
bool TouchVideoWidget::lockFrame(const VideoFrame &frame)
{
if (!frame.isValid()) return false;
m_locked = true;
m_imageSize = QSize(frame.width, frame.height);
m_lockedFormat = frame.format;
// VideoFrame keeps its backing AVFrame alive through its shared owner.
// Keep the exact frame, including timestamps and matching intrinsics.
setFrame(frame);
clearSelection();
setCursor(Qt::CrossCursor);
return true;
}
void TouchVideoWidget::unlock()
{
m_locked = false;
m_lockedFormat = VideoPixelFormat::Invalid;
clearSelection();
unsetCursor();
if (m_latestFrame.isValid()) {
m_imageSize = QSize(m_latestFrame.width, m_latestFrame.height);
setFrame(m_latestFrame);
} else {
m_imageSize = {};
VideoRenderWidget::clearFrame();
}
}
void TouchVideoWidget::clearFrame(const QString &message)
{
m_latestFrame = {};
m_imageSize = {};
m_locked = false;
m_lockedFormat = VideoPixelFormat::Invalid;
clearSelection();
unsetCursor();
VideoRenderWidget::clearFrame(message);
}
void TouchVideoWidget::clearSelection()
{
if (m_points.isEmpty()) return;
m_points.clear();
update();
emit pointsChanged();
}
void TouchVideoWidget::setMaxPoints(int count)
{
count = qBound(1, count, 2);
if (count == m_maxPoints) return;
m_maxPoints = count;
clearSelection();
}
bool TouchVideoWidget::mapToImage(const QPointF &position, const QSizeF &widgetSize,
const QSize &imageSize, QPointF *pixel)
{
if (!std::isfinite(widgetSize.width()) || !std::isfinite(widgetSize.height())
|| widgetSize.isEmpty() || imageSize.isEmpty()) return false;
return mapPoint(position, imageRectangle(widgetSize.toSize(), imageSize), imageSize, pixel);
}
void TouchVideoWidget::mousePressEvent(QMouseEvent *event)
{
QPointF pixel;
if (event->button() != Qt::LeftButton || !m_locked
|| !mapPoint(event->localPos(), frameRectangle(size(), m_imageSize, m_lockedFormat), m_imageSize, &pixel)) {
VideoRenderWidget::mousePressEvent(event);
return;
}
if (m_points.size() >= m_maxPoints) m_points.clear();
m_points.append(pixel);
update();
emit pointsChanged();
event->accept();
}
void TouchVideoWidget::paintGL()
{
VideoRenderWidget::paintGL();
if (!m_locked || m_points.isEmpty() || m_imageSize.isEmpty()) return;
const QRectF area = frameRectangle(size(), m_imageSize, m_lockedFormat);
if (area.isEmpty()) return;
QVector<QPointF> screenPoints;
for (const QPointF &point : m_points) {
screenPoints.append(QPointF(area.x() + (point.x() + .5) * area.width() / m_imageSize.width(),
area.y() + (point.y() + .5) * area.height() / m_imageSize.height()));
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setClipRect(area);
painter.setPen(QPen(QColor(QStringLiteral("#f4d26c")), 2));
if (screenPoints.size() == 2) painter.drawLine(screenPoints[0], screenPoints[1]);
for (int i = 0; i < screenPoints.size(); ++i) {
const QPointF center = screenPoints[i];
painter.setPen(QPen(i == 0 ? QColor(QStringLiteral("#4cdd9b"))
: QColor(QStringLiteral("#ffac60")), 2));
painter.setBrush(QColor(14, 17, 21, 180));
painter.drawEllipse(center, 7, 7);
const QString label = i == 0 ? QStringLiteral("A") : QStringLiteral("B");
const qreal labelWidth = painter.fontMetrics().horizontalAdvance(label) + 8;
const qreal labelHeight = painter.fontMetrics().height() + 4;
const qreal left = qBound(qreal(area.left()), center.x() + 11,
qMax(qreal(area.left()), area.x() + area.width() - labelWidth));
const qreal top = qBound(qreal(area.top()), center.y() - labelHeight - 3,
qMax(qreal(area.top()), area.y() + area.height() - labelHeight));
const QRectF labelRect(left, top, labelWidth, labelHeight);
painter.fillRect(labelRect, QColor(14, 17, 21, 210));
painter.drawText(labelRect, Qt::AlignCenter, label);
}
}