#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "videoframe.h" #include "jointpointdata.h" #include "agvvelocityramp.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; 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 TcpCalibrationWidget; class TouchOperationWidget; class TcpJogController; class HandEyeCalibrationWidget; class HandEyeMotionWidget; class AgvMapViewWidget; class AgvMapEditorWidget; class TactileHeatmapWidget; class JointFlowEditor; class TaskOrchestrationWidget; class MainWindow : public QMainWindow { Q_OBJECT friend struct JointPointTestAccess; 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 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); 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 combineSelectedJointPoints(); void dispatchJointPoint(int row); void finishJointPoint(quint64 token, bool success, const QString &detail); void stopJointPointMotion(); void executeSelectedJointPoint(); void startJointPointLoop(); void stopJointPointLoop(const QString &reason = QString()); void advanceJointPointLoop(); void refreshRecordedJointPoints(); void refreshJointFlowTable(); void saveSnapshot(); private: void showTaskCameraResult(const QString &cameraId, const QString &title); void updateTaskCameraImage(const QString &cameraId, const QImage &image, const QString &detail); void updateTaskCameraFrame(const QString &cameraId, const VideoFrame &frame, const QString &detail); QWidget *createSystemPage(); QWidget *createArmPage(); QWidget *createCameraPage(); QWidget *createDexHandPage(); QStringList configuredCameraIds() const; void rebuildCameraPreviewGrid(const QStringList &cameraIds); void refreshCameraStreamControls(); void refreshCameraDepthControls(); 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; 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 decelerateAgvManualMotion(); void advanceAgvManualMotion(); void stopAgvManualMotion(bool sendStop = true); void restartAgvMapStream(const QString &mapName = QString(), bool recovering = false); void presentPendingAgvMapFrame(); void clearAgvDisplay(const QString &message, bool preserveMapSelection = false); void updateAgvMapSwitchStatus(); void refreshConfirmedAgvMap(quint64 switchToken); void updateAgvMapRobotPose(); void configureAgvMapDirectConnection(); void updateAgvDirectControls(); bool matchesAgvContext(const QVariantMap &context) const; 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; 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_controllerBaseFrames; QStringList m_controllerTcpFrames; QLabel *m_armPoseSubtitle = nullptr; AudioStreamManager *m_audioManager = nullptr; QuicTestServer *m_quicServer = nullptr; QStackedWidget *m_pages = nullptr; QButtonGroup *m_navGroup = nullptr; QList 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 m_poseMetricValues; TrendWidget *m_trend = nullptr; QTableWidget *m_jointTable = nullptr; QTableWidget *m_motionTable = nullptr; QList m_targetSpins; QList m_targetRadianSpins; QPushButton *m_syncCurrentToTargetButton = nullptr; QDoubleSpinBox *m_moveJVelocitySpin = nullptr; QDoubleSpinBox *m_moveJAccelerationSpin = nullptr; QStringList m_activeArmJointNames; QList 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 m_jointJogPositionLabels; QList m_jointJogPositionSliders; QList m_jointJogMinusButtons; QList m_jointJogPlusButtons; QList 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 m_previousJointVelocities; qint64 m_lastArmTelemetryMs = 0; QHash m_armAlertStates; QHash 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; QLineEdit *m_trajectoryFileNameEdit = nullptr; QDoubleSpinBox *m_trajectoryFrequencySpin = nullptr; QComboBox *m_recordedTrajectoryCombo = nullptr; QDoubleSpinBox *m_trajectoryReplayRatioSpin = nullptr; QDoubleSpinBox *m_trajectoryVelocitySpin = nullptr; QDoubleSpinBox *m_trajectoryAccelerationSpin = nullptr; QDoubleSpinBox *m_trajectoryJerkSpin = nullptr; QLabel *m_trajectoryDirectoryLabel = nullptr; QLabel *m_trajectoryRecordingStatus = nullptr; QTimer *m_trajectoryStatusTimer = nullptr; QPushButton *m_refreshTrajectoriesButton = nullptr; QPushButton *m_trajectoryStartButton = nullptr; QPushButton *m_trajectoryReplayButton = nullptr; QPushButton *m_trajectoryStopButton = nullptr; QPushButton *m_enterTeachingButton = nullptr; QPushButton *m_startTrajectoryRecordingButton = nullptr; QPushButton *m_completeTeachingButton = nullptr; QPushButton *m_stopTrajectoryRecordingButton = nullptr; QPushButton *m_exitTeachingButton = nullptr; QLabel *m_deviceTeachingStateLabel = nullptr; QString m_teachSelectedJoint; QString m_pendingUrdfPath; bool m_armModelLoadScheduled = false; using RecordedJointPoint = ::RecordedJointPoint; struct JointProgramGroup { QString name; QList points; QJsonArray flow; double moveJVelocity = 0.1; double moveJAcceleration = 0.1; }; QList m_jointProgramGroups; int m_activeJointProgramGroup = -1; bool m_updatingJointProgramGroup = false; QList m_recordedJointPoints; QComboBox *m_jointProgramGroupCombo = nullptr; QHash 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; TaskOrchestrationWidget *m_taskOrchestration = 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 m_jointPointLoopRows; QVector 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; quint64 m_jointPointRequestToken = 0; QStringList m_jointPointMovingDevices; bool m_jointPointCapturePending = false; quint64 m_jointPointCaptureToken = 0; QString m_jointPointCaptureName; int m_jointPointCaptureGroup = -1; QComboBox *m_cameraDeviceCombo = nullptr; VideoRenderWidget *m_videoRender = nullptr; QLabel *m_imageMetaLabel = nullptr; QPushButton *m_snapshotButton = nullptr; QPushButton *m_depthSnapshotButton = 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 m_cameraPreviewTiles; QHash m_cameraStreamModes; QHash m_cameraCodecById; QSet m_pendingTaskCameraPreviews; struct TaskCameraResult { QDialog *window = nullptr; VideoRenderWidget *render = nullptr; QLabel *status = nullptr; }; QHash m_taskCameraResults; QString m_taskSnapshotCameraId; QString m_taskCameraRecordingId; QString m_taskCameraRecordingAction; QSet m_runningCameraIds; QString m_activeCameraId; QVariantMap m_activeCameraCapabilities; QHash m_cameraCapabilitiesById; quint64 m_cameraCapabilitiesToken=0; bool m_cameraCapabilityInFlight=false; QImage m_lastImage; bool m_lastImageIsDepth = false; 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 m_dexHandAngleSpins; QList m_dexHandPositionSpins; QList m_dexHandSpeedSpins; QList 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; QLineEdit *m_agvIdEdit = nullptr; QDialog *m_agvStatusDialog = nullptr; QTimer *m_agvStatusRefreshTimer = nullptr; QTimer *m_agvManualVelocityTimer = nullptr; QTimer *m_agvMapRefreshTimer = 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; AgvMapEditorWidget *m_agvMapEditor = nullptr; QWidget *m_agvControlWorkspace = nullptr; QPushButton *m_agvDeleteMapButton = nullptr; QPushButton *m_agvStopMappingButton = 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; QDoubleSpinBox *m_agvLinearAccelerationSpin = nullptr; QDoubleSpinBox *m_agvLinearDecelerationSpin = nullptr; QDoubleSpinBox *m_agvAngularAccelerationSpin = nullptr; QDoubleSpinBox *m_agvAngularDecelerationSpin = nullptr; QComboBox *m_agvMapCombo = nullptr; QComboBox *m_agvMapDirectMode = nullptr; QLineEdit *m_agvMapDirectHost = nullptr; QList m_agvDirectBlockedControls; bool m_agvDirectBusy = false; QString m_agvDirectConfirmedMap; QString m_agvDirectSwitchDetail; QLabel *m_agvMapListSummary = nullptr; QLabel *m_agvMapSwitchStatus = nullptr; QComboBox *m_agvMapRefreshCombo = nullptr; QComboBox *m_agvStationCombo = nullptr; QPushButton *m_agvSwitchMapButton = nullptr; QTableWidget *m_agvStationTable = nullptr; QString m_agvDownloadPath; QVariantMap m_latestAgvState; QImage m_pendingAgvMapImage; QVariantMap m_pendingAgvMapMetadata; QString m_pendingAgvMapDetail; QString m_agvRequestedMap; QString m_agvStreamDeviceId; QString m_agvStreamEndpoint; QString m_agvContextDeviceId; QString m_agvSwitchMapTarget; QString m_agvSwitchMapDevice; QString m_agvSwitchMapEndpoint; bool m_agvSwitchMapDemo = false; bool m_agvMapSwitchPending = false; bool m_agvSwitchMapAccepted = false; quint64 m_agvMapSwitchToken = 0; quint64 m_agvMapSwitchRefreshToken = 0; bool m_agvSwitchMapRuntimeConfirmed = false; bool m_agvSwitchMapUsesDirect = false; double m_agvSwitchMapPreviousTimestamp = 0.0; QString m_agvSwitchMapError; QString m_agvMapReadError; bool m_agvMapEditorBusy = false; AgvManualVelocity m_agvManualVelocity; AgvManualVelocity m_agvManualTarget; QElapsedTimer m_agvManualStepClock; QElapsedTimer m_agvManualReplyClock; QString m_agvManualDeviceId; bool m_agvManualVelocityInFlight = false; quint64 m_agvManualVelocityRequestId = 0; QPointer m_agvManualButton; int m_agvManualKey = 0; bool m_agvManualMotionActive = false; bool m_agvMapStreamActive = false; bool m_agvStreamRequested = false; bool m_agvMapStreamPaused = false; bool m_agvStreamDemo = false; bool m_agvStateAvailable = false; bool m_agvMapRecoveryNeeded = true; bool m_agvMapRecoveryAttempted = false; bool m_agvDeviceRefreshPending = false; bool m_agvMapFramePending = false; bool m_agvStopMappingRetryPending = false; QList 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; QString m_pendingTaskSpeakerCaptureId; QJsonObject m_pendingTaskSpeakerCaptureParameters; 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; };