From b0e79c0b7d94682cdc4281ada89216cf84ef921d Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Thu, 20 Aug 2020 16:20:35 -0700 Subject: [PATCH] Support unlimited compasses, plus all sort of other ui fixup --- src/AutoPilotPlugins/PX4/SensorsSetup.qml | 249 ++++++++++++---------- 1 file changed, 132 insertions(+), 117 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/SensorsSetup.qml b/src/AutoPilotPlugins/PX4/SensorsSetup.qml index 817f53f13..f834d1682 100644 --- a/src/AutoPilotPlugins/PX4/SensorsSetup.qml +++ b/src/AutoPilotPlugins/PX4/SensorsSetup.qml @@ -41,10 +41,10 @@ Item { readonly property string boardRotationText: qsTr("If the orientation is in the direction of flight, select ROTATION_NONE.") readonly property string compassRotationText: qsTr("If the orientation is in the direction of flight, select ROTATION_NONE.") - readonly property string compassHelp: qsTr("For Compass calibration you will need to rotate your vehicle through a number of positions.\n\nClick Ok to start calibration.") - readonly property string gyroHelp: qsTr("For Gyroscope calibration you will need to place your vehicle on a surface and leave it still.\n\nClick Ok to start calibration.") - readonly property string accelHelp: qsTr("For Accelerometer calibration you will need to place your vehicle on all six sides on a perfectly level surface and hold it still in each orientation for a few seconds.\n\nClick Ok to start calibration.") - readonly property string levelHelp: qsTr("To level the horizon you need to place the vehicle in its level flight position and press OK.") + readonly property string compassHelp: qsTr("For Compass calibration you will need to rotate your vehicle through a number of positions.") + readonly property string gyroHelp: qsTr("For Gyroscope calibration you will need to place your vehicle on a surface and leave it still.") + readonly property string accelHelp: qsTr("For Accelerometer calibration you will need to place your vehicle on all six sides on a perfectly level surface and hold it still in each orientation for a few seconds.") + readonly property string levelHelp: qsTr("To level the horizon you need to place the vehicle in its level flight position and leave still.") readonly property string airspeedHelp: qsTr("For Airspeed calibration you will need to keep your airspeed sensor out of any wind and then blow across the sensor. Do not touch the sensor or obstruct any holes during the calibration.") readonly property string statusTextAreaDefaultText: qsTr("Start the individual calibration steps by clicking one of the buttons to the left.") @@ -55,7 +55,6 @@ Item { // Used to pass help text to the preCalibrationDialog dialog property string preCalibrationDialogHelp - readonly property int rotationColumnWidth: ScreenTools.defaultFontPixelWidth * 30 readonly property var rotations: [ "ROTATION_NONE", "ROTATION_YAW_45", @@ -110,9 +109,75 @@ Item { property bool showCompass1Rot: cal_mag1_id.value > 0 && cal_mag1_rot.value >= 0 property bool showCompass2Rot: cal_mag2_id.value > 0 && cal_mag2_rot.value >= 0 - property bool _sensorsHaveFixedOrientation: QGroundControl.corePlugin.options.sensorsHaveFixedOrientation - property bool _wifiReliableForCalibration: QGroundControl.corePlugin.options.wifiReliableForCalibration - property int _buttonWidth: ScreenTools.defaultFontPixelWidth * 15 + property bool _sensorsHaveFixedOrientation: QGroundControl.corePlugin.options.sensorsHaveFixedOrientation + property bool _wifiReliableForCalibration: QGroundControl.corePlugin.options.wifiReliableForCalibration + property int _buttonWidth: ScreenTools.defaultFontPixelWidth * 15 + property string _calMagIdParamFormat: "CAL_MAG#_ID" + property string _calMagRotParamFormat: "CAL_MAG#_ROT" + property bool _allMagsDisabled: controller.parameterExists(-1, "SYS_HAS_MAG") ? controller.getParameterFact(-1, "SYS_HAS_MAG").value === 0 : false + property bool _boardOrientationChangeAllowed: !_sensorsHaveFixedOrientation && setOrientationsDialogShowBoardOrientation + property bool _compassOrientationChangeAllowed: !_sensorsHaveFixedOrientation + property int _arbitrarilyLargeMaxMagIndex: 50 + + function currentMagParamCount() { + if (_allMagsDisabled) { + return 0 + } else { + for (var index=0; index<_arbitrarilyLargeMaxMagIndex; index++) { + var magIdParam = _calMagIdParamFormat.replace("#", index) + if (!controller.parameterExists(-1, magIdParam)) { + return index + } + } + console.warn("SensorSetup.qml:currentMagParamCount internal error") + return -1 + } + } + + function currentExternalMagCount() { + if (_allMagsDisabled) { + return 0 + } else { + var externalMagCount = 0 + for (var index=0; index<_arbitrarilyLargeMaxMagIndex; index++) { + var magIdParam = _calMagIdParamFormat.replace("#", index) + if (controller.parameterExists(-1, magIdParam)) { + var calMagIdFact = controller.getParameterFact(-1, magIdParam) + var calMagRotFact = controller.getParameterFact(-1, _calMagRotParamFormat.replace("#", index)) + if (calMagIdFact.value > 0 && calMagRotFact.value >= 0) { + externalMagCount++ + } + } else { + return externalMagCount + } + } + console.warn("SensorSetup.qml:currentExternalMagCount internal error") + return 0 + } + } + + function orientationsButtonVisible() { + if (_sensorsHaveFixedOrientation || !showSetOrientations) { + return false + } else if (_boardOrientationChangeAllowed) { + return true + } else if (_compassOrientationChangeAllowed && !_allMagsDisabled) { + for (var index=0; index<_arbitrarilyLargeMaxMagIndex; index++) { + var magIdParam = _calMagIdParamFormat.replace("#", index) + if (controller.parameterExists(-1, magIdParam)) { + var calMagIdFact = controller.parameterExists(-1, magIdParam) + var calMagRotFact = controller.parameterExists(-1, _calMagRotParamFormat.replace("#", index)) + if (calMagIdFact.value > 0 && calMagRotFact.value >= 0) { + // Only external compasses can set orientation + return true + } + } + } + return false + } else { + return false + } + } SensorsComponentController { id: controller @@ -130,7 +195,9 @@ Item { onResetStatusTextArea: statusLog.text = statusTextAreaDefaultText onMagCalComplete: { - setOrientationsDialogShowBoardOrientation = false + setOrientationsButton.visible = orientationsButtonVisible() + setOrientationsDialogShowBoardOrientation = false + setOrientationsDialogShowReboot = true mainWindow.showComponentDialog(setOrientationsDialogComponent, qsTr("Compass Calibration Complete"), mainWindow.showDialogDefaultWidth, StandardButton.Ok) } @@ -191,43 +258,49 @@ Item { anchors.fill: parent spacing: ScreenTools.defaultFontPixelHeight + QGCLabel { + width: parent.width + wrapMode: Text.WordWrap + text: preCalibrationDialogHelp + } + + QGCLabel { + id: boardRotationHelp + width: parent.width + wrapMode: Text.WordWrap + visible: !_sensorsHaveFixedOrientation && (preCalibrationDialogType == "accel" || preCalibrationDialogType == "compass") + text: qsTr("Set autopilot orientation before calibrating.") + } + Column { - width: parent.width - spacing: 5 - visible: !_sensorsHaveFixedOrientation + width: parent.width + visible: boardRotationHelp.visible + QGCLabel { text: qsTr("Autopilot Orientation") } + + FactComboBox { + sizeToContents: true + model: rotations + fact: sens_board_rot + } QGCLabel { - id: boardRotationHelp width: parent.width wrapMode: Text.WordWrap - visible: (preCalibrationDialogType != "airspeed") && (preCalibrationDialogType != "gyro") - text: qsTr("Set autopilot orientation before calibrating.") - } - - Column { - visible: boardRotationHelp.visible - - QGCLabel { text: qsTr("Autopilot Orientation:") } - - FactComboBox { - id: boardRotationCombo - width: rotationColumnWidth; - model: rotations - fact: sens_board_rot - } + text: qsTr("ROTATION_NONE indicates component points in direction of flight.") } } QGCLabel { width: parent.width wrapMode: Text.WordWrap - text: preCalibrationDialogHelp + text: qsTr("Click Ok to start calibration.") } } } } - property bool setOrientationsDialogShowBoardOrientation: true + property bool setOrientationsDialogShowBoardOrientation: true + property bool setOrientationsDialogShowReboot: true Component { id: setOrientationsDialogComponent @@ -251,13 +324,13 @@ Item { QGCLabel { width: parent.width wrapMode: Text.WordWrap - text: _sensorsHaveFixedOrientation ? - qsTr("Make sure to reboot the vehicle prior to flight.") : - qsTr("Set your compass orientations below and the make sure to reboot the vehicle prior to flight.") + text: qsTr("Reboot the vehicle prior to flight.") + visible: setOrientationsDialogShowReboot } QGCButton { - text: qsTr("Reboot Vehicle") + text: qsTr("Reboot Vehicle") + visible: setOrientationsDialogShowReboot onClicked: { controller.vehicle.rebootVehicle() hideDialog() @@ -267,104 +340,46 @@ Item { QGCLabel { width: parent.width wrapMode: Text.WordWrap - text: boardRotationText - visible: !_sensorsHaveFixedOrientation + text: qsTr("Adjust orientations as needed.\n\nROTATION_NONE indicates component points in direction of flight.") + visible: _boardOrientationChangeAllowed || (_compassOrientationChangeAllowed && currentExternalMagCount() !== 0) + + Component.onCompleted: console.log(_boardOrientationChangeAllowed, _compassOrientationChangeAllowed, currentExternalMagCount()) } Column { - visible: setOrientationsDialogShowBoardOrientation + visible: _boardOrientationChangeAllowed QGCLabel { - text: qsTr("Autopilot Orientation:") + text: qsTr("Autopilot Orientation") } FactComboBox { - id: boardRotationCombo - width: rotationColumnWidth; - model: rotations - fact: sens_board_rot - } - } - - // Compass 0 rotation - Column { - visible: !_sensorsHaveFixedOrientation - - Component { - id: compass0ComponentLabel2 - - QGCLabel { - text: qsTr("External Compass Orientation:") - } - } - - Component { - id: compass0ComponentCombo2 - - FactComboBox { - id: compass0RotationCombo - width: rotationColumnWidth - model: rotations - fact: cal_mag0_rot - } + sizeToContents: true + model: rotations + fact: sens_board_rot } - - Loader { sourceComponent: showCompass0Rot ? compass0ComponentLabel2 : null } - Loader { sourceComponent: showCompass0Rot ? compass0ComponentCombo2 : null } } - // Compass 1 rotation - Column { - visible: !_sensorsHaveFixedOrientation + Repeater { + model: _compassOrientationChangeAllowed ? currentMagParamCount() : 0 - Component { - id: compass1ComponentLabel2 + Column { + // id > = signals compass available, rot < 0 signals internal compass + visible: calMagIdFact.value > 0 && calMagRotFact.value >= 0 - QGCLabel { - text: qsTr("External Compass 1 Orientation:") - } - } - - Component { - id: compass1ComponentCombo2 - - FactComboBox { - id: compass1RotationCombo - width: rotationColumnWidth - model: rotations - fact: cal_mag1_rot - } - } - - Loader { sourceComponent: showCompass1Rot ? compass1ComponentLabel2 : null } - Loader { sourceComponent: showCompass1Rot ? compass1ComponentCombo2 : null } - } - - // Compass 2 rotation - Column { - visible: !_sensorsHaveFixedOrientation - spacing: ScreenTools.defaultFontPixelWidth - - Component { - id: compass2ComponentLabel2 + property Fact calMagIdFact: controller.getParameterFact(-1, _calMagIdParamFormat.replace("#", index)) + property Fact calMagRotFact: controller.getParameterFact(-1, _calMagRotParamFormat.replace("#", index)) QGCLabel { - text: qsTr("Compass 2 Orientation") + text: qsTr("Mag %1 Orientation").arg(index) } - } - - Component { - id: compass2ComponentCombo2 FactComboBox { - id: compass1RotationCombo - width: rotationColumnWidth - model: rotations - fact: cal_mag2_rot + sizeToContents: true + model: rotations + fact: parent.calMagRotFact } } - Loader { sourceComponent: showCompass2Rot ? compass2ComponentLabel2 : null } - Loader { sourceComponent: showCompass2Rot ? compass2ComponentCombo2 : null } } } // Column } // QGCFlickable @@ -383,12 +398,11 @@ Item { spacing: ScreenTools.defaultFontPixelHeight / 2 IndicatorButton { - property bool _hasMag: controller.parameterExists(-1, "SYS_HAS_MAG") ? controller.getParameterFact(-1, "SYS_HAS_MAG").value !== 0 : true id: compassButton width: _buttonWidth text: qsTr("Compass") indicatorGreen: cal_mag0_id.value !== 0 - visible: _hasMag && QGroundControl.corePlugin.options.showSensorCalibrationCompass && showSensorCalibrationCompass + visible: !_allMagsDisabled && QGroundControl.corePlugin.options.showSensorCalibrationCompass && showSensorCalibrationCompass onClicked: { preCalibrationDialogType = "compass" @@ -478,11 +492,12 @@ Item { QGCButton { id: setOrientationsButton width: _buttonWidth - text: qsTr("Set Orientations") - visible: !_sensorsHaveFixedOrientation && showSetOrientations + text: qsTr("Orientations") + visible: orientationsButtonVisible() onClicked: { - setOrientationsDialogShowBoardOrientation = true + setOrientationsDialogShowBoardOrientation = true + setOrientationsDialogShowReboot = false mainWindow.showComponentDialog(setOrientationsDialogComponent, qsTr("Set Orientations"), mainWindow.showDialogDefaultWidth, StandardButton.Ok) } } -- 2.22.0