CmvrControlStation/src/mainwindow.h

453 lines
18 KiB
C
Raw Normal View History

2026-09-18 16:22:20 +08:00
#pragma once
#include <QImage>
#include <QJsonArray>
2026-09-18 16:22:20 +08:00
#include <QHash>
#include <QList>
#include <QMainWindow>
#include <QSet>
#include <QStyle>
#include <QStringList>
#include <QVariantList>
#include <QVariantMap>
#include <QVector>
2026-09-18 16:22:20 +08:00
#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 QSettings;
class QSlider;
2026-09-18 16:22:20 +08:00
class QSpinBox;
class QStackedWidget;
class QTableWidget;
class QTabWidget;
class QTextEdit;
class QTimer;
class QVBoxLayout;
2026-09-18 16:22:20 +08:00
class TrendWidget;
class RobotClient;
class QuicTestServer;
class UrdfViewerWidget;
class AudioStreamManager;
class VideoRenderWidget;
class TcpCalibrationWidget;
class TouchOperationWidget;
class TcpJogController;
class HandEyeCalibrationWidget;
class HandEyeMotionWidget;
class AgvMapViewWidget;
class TactileHeatmapWidget;
class JointFlowEditor;
2026-09-18 16:22:20 +08:00
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;
2026-09-18 16:22:20 +08:00
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);
2026-09-18 16:22:20 +08:00
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 updateDexHandStatus(const QString &deviceId, bool initialized,
bool hasTactileFeedback,
const QString &model,
const QVariantList &freedoms);
void updateDexHandTactile(const QString &deviceId, int rows, int cols,
const QVariantList &values, quint64 frameCount);
2026-09-18 16:22:20 +08:00
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 recordCurrentJointPoint();
void executeSelectedJointPoint();
void startJointPointLoop();
void stopJointPointLoop(const QString &reason = QString());
void advanceJointPointLoop();
void refreshRecordedJointPoints();
void refreshJointFlowTable();
2026-09-18 16:22:20 +08:00
void saveSnapshot();
private:
QWidget *createSystemPage();
QWidget *createArmPage();
QWidget *createCameraPage();
QWidget *createDexHandPage();
2026-09-18 16:22:20 +08:00
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 loadJointPrograms(QSettings &legacySettings);
void saveJointPrograms();
void storeCurrentJointProgramGroup();
void activateJointProgramGroup(int index);
QString jointProgramsFilePath() const;
2026-09-18 16:22:20 +08:00
void setControlsEnabled(bool enabled);
void updateWindowChrome();
void ensureArmModelLoaded();
void rebuildArmJointTables(const QStringList &jointNames);
void rebuildArmJogControls();
void refreshArmJogAvailability();
void setArmTelemetryEnabled(bool enabled);
void startJointJog(int jointIndex, int direction);
void startCartesianJog(int axisIndex, int direction);
void stopArmJog();
void refreshTcpChoices(const QString &savedName = QString());
void updateArmPoseFrames();
bool selectedLocalTcp() const;
void setupHandEye();
void setupTouchOperation();
void syncHandEyeContext();
void startAgvManualMotion(double vx, double vy, double wz);
void stopAgvManualMotion(bool sendStop = true);
void restartAgvMapStream(const QString &mapName = QString());
void presentPendingAgvMapFrame();
void updateArmAlert(const QString &deviceId, const QString &alertKey,
const QString &level, const QString &summary,
const QString &detail = QString());
2026-09-18 16:22:20 +08:00
QString endpoint() const;
RobotClient *m_client = nullptr;
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;
2026-09-18 16:22:20 +08:00
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;
2026-09-18 16:22:20 +08:00
TrendWidget *m_trend = nullptr;
QTableWidget *m_jointTable = nullptr;
QTableWidget *m_motionTable = nullptr;
QList<QDoubleSpinBox *> m_targetSpins;
QList<QDoubleSpinBox *> m_targetRadianSpins;
QPushButton *m_syncCurrentToTargetButton = nullptr;
QDoubleSpinBox *m_moveJVelocitySpin = nullptr;
QDoubleSpinBox *m_moveJAccelerationSpin = nullptr;
2026-09-18 16:22:20 +08:00
QStringList m_activeArmJointNames;
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;
QLabel *m_jogReadyLabel = 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;
2026-09-18 16:22:20 +08:00
QDoubleSpinBox *m_velocitySpin = nullptr;
QDoubleSpinBox *m_accelerationSpin = nullptr;
QDoubleSpinBox *m_cartesianVelocitySpin = nullptr;
QDoubleSpinBox *m_cartesianAccelerationSpin = nullptr;
2026-09-18 16:22:20 +08:00
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;
struct RecordedJointPoint {
QString name;
QString side;
QString deviceId;
QStringList jointNames;
QVector<double> positions;
};
struct JointProgramGroup {
QString name;
QList<RecordedJointPoint> points;
QJsonArray flow;
double moveJVelocity = 0.1;
double moveJAcceleration = 0.1;
};
QList<JointProgramGroup> m_jointProgramGroups;
int m_activeJointProgramGroup = -1;
bool m_updatingJointProgramGroup = false;
QList<RecordedJointPoint> m_recordedJointPoints;
QComboBox *m_jointProgramGroupCombo = nullptr;
QHash<QString, double> m_latestArmJointPositions;
QLineEdit *m_jointPointNameEdit = nullptr;
QTableWidget *m_jointPointTable = nullptr;
QLabel *m_jointPointDetailLabel = nullptr;
QSpinBox *m_jointPointLoopCount = nullptr;
QDoubleSpinBox *m_jointPointInterval = nullptr;
QDoubleSpinBox *m_jointFlowVelocitySpin = nullptr;
QDoubleSpinBox *m_jointFlowAccelerationSpin = nullptr;
QSpinBox *m_jointFlowGroupCount = nullptr;
JointFlowEditor *m_jointFlowEditor = nullptr;
QDialog *m_jointFlowDialog = nullptr;
QPushButton *m_recordJointPointButton = nullptr;
QPushButton *m_runJointPointButton = nullptr;
QPushButton *m_deleteJointPointButton = nullptr;
QPushButton *m_startJointPointLoopButton = nullptr;
QPushButton *m_stopJointPointLoopButton = nullptr;
QLabel *m_jointPointLoopStatus = nullptr;
QVector<int> m_jointPointLoopRows;
QVector<double> m_jointPointExecutionWaits;
QStringList m_jointPointExecutionNodeIds;
int m_jointPointLoopCursor = 0;
int m_jointPointLoopsCompleted = 0;
int m_jointPointLoopTarget = 0;
bool m_jointPointLoopActive = false;
bool m_jointPointMovePending = false;
quint64 m_jointPointLoopGeneration = 0;
bool m_jointPointDispatching = false;
2026-09-18 16:22:20 +08:00
QComboBox *m_cameraDeviceCombo = nullptr;
2026-09-18 16:22:20 +08:00
VideoRenderWidget *m_videoRender = nullptr;
QLabel *m_imageMetaLabel = nullptr;
QPushButton *m_snapshotButton = nullptr;
QPushButton *m_depthSnapshotButton = nullptr;
2026-09-18 16:22:20 +08:00
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;
QHash<QString, QString> m_cameraStreamModes;
2026-09-18 16:22:20 +08:00
QSet<QString> m_runningCameraIds;
QString m_activeCameraId;
QVariantMap m_activeCameraCapabilities;
quint64 m_cameraCapabilitiesToken=0;
bool m_cameraCapabilityInFlight=false;
2026-09-18 16:22:20 +08:00
QImage m_lastImage;
bool m_lastImageIsDepth = false;
2026-09-18 16:22:20 +08:00
bool m_cameraStreaming = false;
bool m_cameraRecording = false;
QComboBox *m_dexHandDeviceCombo = nullptr;
QLabel *m_dexHandStateLabel = nullptr;
QTableWidget *m_dexHandStateTable = nullptr;
QTabWidget *m_dexHandCommandTabs = nullptr;
QList<QDoubleSpinBox *> m_dexHandAngleSpins;
QList<QDoubleSpinBox *> m_dexHandPositionSpins;
QList<QDoubleSpinBox *> m_dexHandSpeedSpins;
QList<QDoubleSpinBox *> m_dexHandForceSpins;
QTimer *m_dexHandRefreshTimer = nullptr;
QWidget *m_dexHandTactilePanel = nullptr;
TactileHeatmapWidget *m_dexHandTactileHeatmap = nullptr;
QLabel *m_dexHandTactileStateLabel = nullptr;
QPushButton *m_dexHandTactileStartButton = nullptr;
QPushButton *m_dexHandTactileStopButton = nullptr;
bool m_dexHandHasTactileFeedback = false;
qint64 m_lastDexHandTactileUiUpdateMs = 0;
2026-09-18 16:22:20 +08:00
QLineEdit *m_agvIdEdit = nullptr;
QDialog *m_agvStatusDialog = nullptr;
QTimer *m_agvStatusRefreshTimer = nullptr;
QTimer *m_agvManualVelocityTimer = nullptr;
QTimer *m_agvMapRefreshTimer = nullptr;
2026-09-18 16:22:20 +08:00
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;
QPushButton *m_agvStopMappingButton = nullptr;
2026-09-18 16:22:20 +08:00
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_agvMapRefreshCombo = nullptr;
2026-09-18 16:22:20 +08:00
QComboBox *m_agvStationCombo = nullptr;
QTableWidget *m_agvStationTable = nullptr;
QString m_agvDownloadPath;
QVariantMap m_latestAgvState;
QImage m_pendingAgvMapImage;
QVariantMap m_pendingAgvMapMetadata;
QString m_pendingAgvMapDetail;
double m_agvManualVx = 0.0;
double m_agvManualVy = 0.0;
double m_agvManualWz = 0.0;
bool m_agvManualMotionActive = false;
bool m_agvMapStreamActive = false;
bool m_agvMapFramePending = false;
bool m_agvStopMappingRetryPending = false;
2026-09-18 16:22:20 +08:00
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;
2026-09-18 16:22:20 +08:00
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;
};