From 208be59b2a865b671f90ea1a1868fb0db73072b9 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 13 May 2015 16:04:24 -0700 Subject: [PATCH] commit --- QGCApplication.pro | 3 +- .../PX4/AirframeComponentController.cc | 4 - .../PX4/AirframeComponentController.h | 1 - .../PX4/PX4AutoPilotPlugin.cc | 3 - src/AutoPilotPlugins/PX4/SensorsComponent.cc | 6 +- src/AutoPilotPlugins/PX4/SensorsComponent.qml | 264 +++++++++--------- .../PX4/SensorsComponentController.cc | 12 +- .../PX4/SensorsComponentController.h | 9 +- src/FactSystem/FactControls/FactPanel.qml | 8 +- .../FactControls/FactPanelController.cc | 6 +- .../FactControls/FactPanelController.h | 1 + src/QGCApplication.cc | 10 + src/QmlControls/QGCViewDialog.qml | 9 +- src/QmlControls/QGCViewPanel.qml | 9 +- 14 files changed, 172 insertions(+), 173 deletions(-) diff --git a/QGCApplication.pro b/QGCApplication.pro index 3e28b74f5..469e24000 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -548,7 +548,8 @@ SOURCES += \ # INCLUDEPATH += \ - src/VehicleSetup + src/VehicleSetup \ + src/AutoPilotPlugins/PX4 \ FORMS += \ src/VehicleSetup/SetupView.ui \ diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc index 8f96cacfd..ef516a8be 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc @@ -38,14 +38,10 @@ bool AirframeComponentController::_typesRegistered = false; AirframeComponentController::AirframeComponentController(void) : - _uas(NULL), _currentVehicleIndex(0), _autostartId(0), _showCustomConfigPanel(false) { - _uas = UASManager::instance()->getActiveUAS(); - Q_ASSERT(_uas); - if (!_typesRegistered) { _typesRegistered = true; qmlRegisterUncreatableType("QGroundControl.Controllers", 1, 0, "AiframeType", "Can only reference AirframeType"); diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.h b/src/AutoPilotPlugins/PX4/AirframeComponentController.h index 79cfdcbf8..8a3f1a50b 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.h +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.h @@ -66,7 +66,6 @@ signals: private: static bool _typesRegistered; - UASInterface* _uas; QVariantList _airframeTypes; QString _currentAirframeType; QString _currentVehicleName; diff --git a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc index 412042180..0cfaa0487 100644 --- a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc +++ b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc @@ -75,9 +75,6 @@ PX4AutoPilotPlugin::PX4AutoPilotPlugin(UASInterface* uas, QObject* parent) : { Q_ASSERT(uas); - qmlRegisterType("QGroundControl.Controllers", 1, 0, "FlightModesComponentController"); - qmlRegisterType("QGroundControl.Controllers", 1, 0, "AirframeComponentController"); - _parameterFacts = new PX4ParameterLoader(this, uas, this); Q_CHECK_PTR(_parameterFacts); diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.cc b/src/AutoPilotPlugins/PX4/SensorsComponent.cc index 1f1c30afa..ef7bfd2c5 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.cc +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.cc @@ -110,11 +110,7 @@ QWidget* SensorsComponent::setupWidget(void) const QGCQmlWidgetHolder* holder = new QGCQmlWidgetHolder(); Q_CHECK_PTR(holder); - holder->setAutoPilot(_autopilot); - - SensorsComponentController* controller = new SensorsComponentController(_autopilot, holder); - holder->setContextPropertyObject("controller", controller); - + holder->setAutoPilot(_autopilot); holder->setSource(QUrl::fromUserInput("qrc:/qml/SensorsComponent.qml")); return holder; diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.qml b/src/AutoPilotPlugins/PX4/SensorsComponent.qml index cad799897..b4fe62a35 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.qml +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.qml @@ -31,91 +31,101 @@ import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 import QGroundControl.ScreenTools 1.0 +import QGroundControl.Controllers 1.0 QGCView { id: rootQGCView viewComponent: view + // Help text which is shown both in the status text area prior to pressing a cal button and in the + // pre-calibration dialog. + + readonly property string compassHelp: "For Compass calibration you will need to rotate your vehicle through a number of positions. For this calibration is is best " + + "to be connected to your vehicle via radio instead of USB since the USB cable will likely get in the way." + readonly property string gyroHelp: "For Gyroscope calibration you will need to place your vehicle right side up on solid surface and leave it still." + readonly property string accelHelp: "For Accelerometer calibration you will need to place your vehicle on all six sides and hold it still there for a few seconds." + readonly property string airspeedHelp: "For Airspeed calibration you will need to keep your airspeed sensor out of any wind and then blow across the sensor." + + property var controller + + // Used to pass what type of calibration is being performed to the preCalibrationDialog + property string preCalibrationDialogType + + // Used to pass help text to the preCalibrationDialog dialog + property string preCalibrationDialogHelp + + readonly property int rotationColumnWidth: 200 + readonly property var rotations: [ + "ROTATION_NONE", + "ROTATION_YAW_45", + "ROTATION_YAW_90", + "ROTATION_YAW_135", + "ROTATION_YAW_180", + "ROTATION_YAW_225", + "ROTATION_YAW_270", + "ROTATION_YAW_315", + "ROTATION_ROLL_180", + "ROTATION_ROLL_180_YAW_45", + "ROTATION_ROLL_180_YAW_90", + "ROTATION_ROLL_180_YAW_135", + "ROTATION_PITCH_180", + "ROTATION_ROLL_180_YAW_225", + "ROTATION_ROLL_180_YAW_270", + "ROTATION_ROLL_180_YAW_315", + "ROTATION_ROLL_90", + "ROTATION_ROLL_90_YAW_45", + "ROTATION_ROLL_90_YAW_90", + "ROTATION_ROLL_90_YAW_135", + "ROTATION_ROLL_270", + "ROTATION_ROLL_270_YAW_45", + "ROTATION_ROLL_270_YAW_90", + "ROTATION_ROLL_270_YAW_135", + "ROTATION_PITCH_90", + "ROTATION_PITCH_270", + "ROTATION_ROLL_270_YAW_270" + ] + Component { id: preCalibrationDialogComponent QGCViewDialog { id: preCalibrationDialog - Fact { id: sys_autostart; name: "SYS_AUTOSTART" } - function accept() { - sys_autostart.value = 0 - customConfigDialog.hideDialog() - } - - QGCLabel { - anchors.fill: parent - wrapMode: Text.WordWrap - text: "Your vehicle is using a custom airframe configuration. " + - "This configuration can only be modified through the Parameter Editor.\n\n" + - "If you want to Reset your airframe configuration and select a standard configuration, click 'Reset' above." + if (preCalibrationDialogType == "gyro") { + controller.calibrateGyro() + } else if (preCalibrationDialogType == "accel") { + controller.calibrateAccel() + } else if (preCalibrationDialogType == "compass") { + controller.calibrateCompass() + } else if (preCalibrationDialogType == "airspeed") { + controller.calibrateAirspeed() + } + preCalibrationDialog.hideDialog() } - Rectangle { - property string calibrationType - - id: boardRotationOverlay - width: 300 - height: boardRotationOverlayColumn.height + 11 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - color: qgcPal.window - border.width: 1 - border.color: qgcPal.text - visible: false - z: overlay.z + 1 - - Column { - id: boardRotationOverlayColumn - anchors.topMargin: 10 - anchors.top: parent.top - width: parent.width - spacing: 10 - Column { - anchors.leftMargin: 10 - anchors.rightMargin: 10 - anchors.left: parent.left - anchors.right: parent.right - spacing: 10 - - QGCLabel { - width: parent.width - wrapMode: Text.WordWrap - text: "Please check and/or update board rotation before calibrating" - } - - FactComboBox { - width: rotationColumnWidth - model: rotations - fact: Fact { name: "SENS_BOARD_ROT" } - } - } + Column { + anchors.fill: parent + spacing: 10 - QGCButton { - x: 1 - width: parent.width - 2 - primary: true - text: "OK" + QGCLabel { + width: parent.width + wrapMode: Text.WordWrap + text: preCalibrationDialogHelp + } - onClicked: { - boardRotationOverlay.visible = false - overlay.visible = false + QGCLabel { + width: parent.width + wrapMode: Text.WordWrap + visible: preCalibrationDialogType != "airspeed" + text: "Please check and/or update board rotation before calibrating" + } - if (boardRotationOverlay.calibrationType == "gyro") { - controller.calibrateGyro() - } else if (boardRotationOverlay.calibrationType == "accel") { - controller.calibrateAccel() - } else if (boardRotationOverlay.calibrationType == "compass") { - controller.calibrateCompass() - } - } - } + FactComboBox { + width: rotationColumnWidth + model: rotations + visible: preCalibrationDialogType != "airspeed" + fact: Fact { name: "SENS_BOARD_ROT"; onFactMissing: showMissingFactOverlay(name) } } } } @@ -124,42 +134,44 @@ QGCView { Component { id: view - // FIXME: Need to convert QGCViewPanel to FactPanel QGCViewPanel { - anchors.fill: parent + id: viewPanel + + Connections { + target: rootQGCView + + onCompleted: { + rootQGCView.controller = viewPanel.controller + } + } + + SensorsComponentController { + id: controller + factPanel: viewPanel + statusLog: statusTextArea + progressBar: progressBar + compassButton: compassButton + gyroButton: gyroButton + accelButton: accelButton + airspeedButton: airspeedButton + cancelButton: cancelButton + orientationCalAreaHelpText: orientationCalAreaHelpText + + onResetStatusTextArea: statusTextArea.text = statusTextAreaDefaultText + + onSetCompassRotations: showCompassRotationOverlay() + + onWaitingForCancelChanged: { + if (controller.waitingForCancel) { + showMessage( + } else { + hideDialog() + } + } + } QGCPalette { id: qgcPal; colorGroupEnabled: enabled } - readonly property int rotationColumnWidth: 200 - readonly property var rotations: [ - "ROTATION_NONE", - "ROTATION_YAW_45", - "ROTATION_YAW_90", - "ROTATION_YAW_135", - "ROTATION_YAW_180", - "ROTATION_YAW_225", - "ROTATION_YAW_270", - "ROTATION_YAW_315", - "ROTATION_ROLL_180", - "ROTATION_ROLL_180_YAW_45", - "ROTATION_ROLL_180_YAW_90", - "ROTATION_ROLL_180_YAW_135", - "ROTATION_PITCH_180", - "ROTATION_ROLL_180_YAW_225", - "ROTATION_ROLL_180_YAW_270", - "ROTATION_ROLL_180_YAW_315", - "ROTATION_ROLL_90", - "ROTATION_ROLL_90_YAW_45", - "ROTATION_ROLL_90_YAW_90", - "ROTATION_ROLL_90_YAW_135", - "ROTATION_ROLL_270", - "ROTATION_ROLL_270_YAW_45", - "ROTATION_ROLL_270_YAW_90", - "ROTATION_ROLL_270_YAW_135", - "ROTATION_PITCH_90", - "ROTATION_PITCH_270", - "ROTATION_ROLL_270_YAW_270" - ] readonly property string statusTextAreaDefaultText: "For Compass calibration you will need to rotate your vehicle through a number of positions. For this calibration is is best " + "to be connected to your vehicle via radio instead of USB since the USB cable will likely get in the way.\n\n" + @@ -181,33 +193,6 @@ QGCView { color: qgcPal.window - // We use this bogus loader just so we can get an onLoaded signal to hook to in order to - // finish controller initialization. - Component { - id: loadSignal; - Item { } - } - Loader { - sourceComponent: loadSignal - onLoaded: { - controller.statusLog = statusTextArea - controller.progressBar = progressBar - controller.compassButton = compassButton - controller.gyroButton = gyroButton - controller.accelButton = accelButton - controller.airspeedButton = airspeedButton - controller.cancelButton = cancelButton - controller.orientationCalAreaHelpText = orientationCalAreaHelpText - } - } - - Connections { - target: controller - - onResetStatusTextArea: statusTextArea.text = statusTextAreaDefaultText - onSetCompassRotations: showCompassRotationOverlay() - } - Rectangle { id: overlay anchors.fill: parent @@ -383,7 +368,11 @@ QGCView { text: "Compass" indicatorGreen: fact.value != 0 - onClicked: showBoardRotationOverlay("compass") + onClicked: { + preCalibrationDialogType = "compass" + preCalibrationDialogHelp = compassHelp + showDialog(preCalibrationDialogComponent, "Calibrate Compass", 50, StandardButton.Cancel | StandardButton.Ok) + } } IndicatorButton { @@ -394,7 +383,11 @@ QGCView { text: "Gyroscope" indicatorGreen: fact.value != 0 - onClicked: showBoardRotationOverlay("gyro") + onClicked: { + preCalibrationDialogType = "gyro" + preCalibrationDialogHelp = gyroHelp + showDialog(preCalibrationDialogComponent, "Calibrate Gyro", 50, StandardButton.Cancel | StandardButton.Ok) + } } IndicatorButton { @@ -405,7 +398,11 @@ QGCView { text: "Accelerometer" indicatorGreen: fact.value != 0 - onClicked: showBoardRotationOverlay("accel") + onClicked: { + preCalibrationDialogType = "accel" + preCalibrationDialogHelp = accelHelp + showDialog(preCalibrationDialogComponent, "Calibrate Accelerometer", 50, StandardButton.Cancel | StandardButton.Ok) + } } IndicatorButton { @@ -416,7 +413,12 @@ QGCView { text: "Airspeed" visible: controller.fixedWing indicatorGreen: fact.value != 0 - onClicked: controller.calibrateAirspeed() + + onClicked: { + preCalibrationDialogType = "airspeed" + preCalibrationDialogHelp = airspeedHelp + showDialog(preCalibrationDialogComponent, "Calibrate Airspeed", 50, StandardButton.Cancel | StandardButton.Ok) + } } QGCButton { diff --git a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc index c8e258f59..e170e904e 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc +++ b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc @@ -32,8 +32,7 @@ #include #include -SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilot, QObject* parent) : - QObject(parent), +SensorsComponentController::SensorsComponentController(void) : _statusLog(NULL), _progressBar(NULL), _compassButton(NULL), @@ -67,15 +66,8 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo _orientationCalLeftSideRotate(false), _orientationCalNoseDownSideRotate(false), _unknownFirmwareVersion(false), - _waitingForCancel(false), - _autopilot(autopilot) + _waitingForCancel(false) { - Q_ASSERT(_autopilot); - Q_ASSERT(_autopilot->pluginReady()); - - _uas = _autopilot->uas(); - Q_ASSERT(_uas); - // Mag rotation parameters are optional _showCompass0 = _autopilot->parameterExists("CAL_MAG0_ROT") && _autopilot->getParameterFact("CAL_MAG0_ROT")->value().toInt() >= 0; diff --git a/src/AutoPilotPlugins/PX4/SensorsComponentController.h b/src/AutoPilotPlugins/PX4/SensorsComponentController.h index dd5c62c78..fac472619 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponentController.h +++ b/src/AutoPilotPlugins/PX4/SensorsComponentController.h @@ -31,15 +31,15 @@ #include #include "UASInterface.h" -#include "AutoPilotPlugin.h" +#include "FactPanelController.h" /// Sensors Component MVC Controller for SensorsComponent.qml. -class SensorsComponentController : public QObject +class SensorsComponentController : public FactPanelController { Q_OBJECT public: - SensorsComponentController(AutoPilotPlugin* autopilot, QObject* parent = NULL); + SensorsComponentController(void); Q_PROPERTY(bool fixedWing READ fixedWing CONSTANT) @@ -167,9 +167,6 @@ private: bool _unknownFirmwareVersion; bool _waitingForCancel; - - AutoPilotPlugin* _autopilot; - UASInterface* _uas; }; #endif diff --git a/src/FactSystem/FactControls/FactPanel.qml b/src/FactSystem/FactControls/FactPanel.qml index dde0acf93..f941f82bb 100644 --- a/src/FactSystem/FactControls/FactPanel.qml +++ b/src/FactSystem/FactControls/FactPanel.qml @@ -31,7 +31,11 @@ import QGroundControl.FactSystem 1.0 import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 -Item { +Rectangle { + color: __qgcPal.window + + QGCPalette { id: __qgcPal; colorGroupEnabled: true } + property string __missingFacts: "" function showMissingFactOverlay(missingFactName) { @@ -43,8 +47,6 @@ Item { } Rectangle { - QGCPalette { id: __qgcPal; colorGroupEnabled: true } - id: __missingFactOverlay anchors.fill: parent z: 9999 diff --git a/src/FactSystem/FactControls/FactPanelController.cc b/src/FactSystem/FactControls/FactPanelController.cc index ddebadd4a..25df92b12 100644 --- a/src/FactSystem/FactControls/FactPanelController.cc +++ b/src/FactSystem/FactControls/FactPanelController.cc @@ -33,10 +33,10 @@ FactPanelController::FactPanelController(void) : _autopilot(NULL), _factPanel(NULL) { - UASInterface* uas = UASManager::instance()->getActiveUAS(); - Q_ASSERT(uas); + _uas = UASManager::instance()->getActiveUAS(); + Q_ASSERT(_uas); - _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(uas); + _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uas); Q_ASSERT(_autopilot); Q_ASSERT(_autopilot->pluginReady()); diff --git a/src/FactSystem/FactControls/FactPanelController.h b/src/FactSystem/FactControls/FactPanelController.h index 094114320..9d21b712b 100644 --- a/src/FactSystem/FactControls/FactPanelController.h +++ b/src/FactSystem/FactControls/FactPanelController.h @@ -56,6 +56,7 @@ protected: /// Report a missing fact to the FactPanel Qml element void _reportMissingFact(const QString& missingFact); + UASInterface* _uas; AutoPilotPlugin* _autopilot; private slots: diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 67ae49eb5..ff533442c 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -62,6 +62,9 @@ #include "ViewWidgetController.h" #include "ParameterEditorController.h" #include "CustomCommandWidgetController.h" +#include "FlightModesComponentController.h" +#include "AirframeComponentController.h" +#include "SensorsComponentController.h" #include "ScreenTools.h" #include "MavManager.h" @@ -310,13 +313,20 @@ void QGCApplication::_initCommon(void) // setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); // Register our Qml objects + qmlRegisterType("QGroundControl.Palette", 1, 0, "QGCPalette"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); qmlRegisterType("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "FlightModesComponentController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "AirframeComponentController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "SensorsComponentController"); + //-- Create QML Singleton Interfaces qmlRegisterSingletonType("QGroundControl.ScreenTools", 1, 0, "ScreenTools", screenToolsSingletonFactory); qmlRegisterSingletonType("QGroundControl.MavManager", 1, 0, "MavManager", mavManagerSingletonFactory); + //-- Register Waypoint Interface qmlRegisterInterface("Waypoint"); } diff --git a/src/QmlControls/QGCViewDialog.qml b/src/QmlControls/QGCViewDialog.qml index f65b9d612..24a6da7b9 100644 --- a/src/QmlControls/QGCViewDialog.qml +++ b/src/QmlControls/QGCViewDialog.qml @@ -30,8 +30,11 @@ import QtQuick.Controls 1.3 import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 -Rectangle { - QGCPalette { id: qgcPal; colorGroupEnabled: enabled } +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 + +FactPanel { + QGCPalette { id: __qgcPal; colorGroupEnabled: enabled } signal hideDialog @@ -43,5 +46,5 @@ Rectangle { hideDialog() } - color: qgcPal.windowShadeDark + color: __qgcPal.windowShadeDark } diff --git a/src/QmlControls/QGCViewPanel.qml b/src/QmlControls/QGCViewPanel.qml index de4a49bc4..7cc4e75a9 100644 --- a/src/QmlControls/QGCViewPanel.qml +++ b/src/QmlControls/QGCViewPanel.qml @@ -30,12 +30,15 @@ import QtQuick.Controls 1.3 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 -Rectangle { - property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: enabled } +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 + +FactPanel { + QGCPalette { id: __qgcPal; colorGroupEnabled: enabled } signal showDialog(Component component, string title, int charWidth, int buttons) signal hideDialog signal showMessage(string title, string message, int buttons) - color: qgcPal.window + color: __qgcPal.window } -- 2.22.0