From 9fa4c40b69e7775d4195842a4d7693be4f3c0b57 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 5 Mar 2016 11:47:38 -0800 Subject: [PATCH] Simple flight mode config --- qgroundcontrol.pro | 6 +- qgroundcontrol.qrc | 4 +- .../PX4/FlightModesComponent.cc | 20 +- .../PX4/FlightModesComponentSummary.qml | 86 ++-- ...mponent.qml => PX4AdvancedFlightModes.qml} | 415 +++++++++--------- ...cc => PX4AdvancedFlightModesController.cc} | 116 ++--- ...r.h => PX4AdvancedFlightModesController.h} | 8 +- .../PX4/PX4AutoPilotPlugin.cc | 2 +- src/AutoPilotPlugins/PX4/PX4FlightModes.qml | 67 +++ .../PX4/PX4SimpleFlightModes.qml | 140 ++++++ .../PX4/PX4SimpleFlightModesController.cc | 73 +++ .../PX4/PX4SimpleFlightModesController.h | 62 +++ src/FactSystem/ParameterLoader.cc | 2 +- .../PX4/PX4ParameterFactMetaData.xml | 201 +++++---- src/QGCApplication.cc | 6 +- src/VehicleSetup/VehicleComponent.cc | 6 +- 16 files changed, 821 insertions(+), 393 deletions(-) rename src/AutoPilotPlugins/PX4/{FlightModesComponent.qml => PX4AdvancedFlightModes.qml} (51%) rename src/AutoPilotPlugins/PX4/{FlightModesComponentController.cc => PX4AdvancedFlightModesController.cc} (85%) rename src/AutoPilotPlugins/PX4/{FlightModesComponentController.h => PX4AdvancedFlightModesController.h} (98%) create mode 100644 src/AutoPilotPlugins/PX4/PX4FlightModes.qml create mode 100644 src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml create mode 100644 src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc create mode 100644 src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 021380372..222329fda 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -590,7 +590,8 @@ HEADERS+= \ src/AutoPilotPlugins/PX4/AirframeComponentAirframes.h \ src/AutoPilotPlugins/PX4/AirframeComponentController.h \ src/AutoPilotPlugins/PX4/FlightModesComponent.h \ - src/AutoPilotPlugins/PX4/FlightModesComponentController.h \ + src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.h \ + src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h \ src/AutoPilotPlugins/PX4/PowerComponent.h \ src/AutoPilotPlugins/PX4/PowerComponentController.h \ src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h \ @@ -646,7 +647,8 @@ SOURCES += \ src/AutoPilotPlugins/PX4/AirframeComponentAirframes.cc \ src/AutoPilotPlugins/PX4/AirframeComponentController.cc \ src/AutoPilotPlugins/PX4/FlightModesComponent.cc \ - src/AutoPilotPlugins/PX4/FlightModesComponentController.cc \ + src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.cc \ + src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc \ src/AutoPilotPlugins/PX4/PowerComponent.cc \ src/AutoPilotPlugins/PX4/PowerComponentController.cc \ src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc \ diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index d5c8c2f5e..e553d7f62 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -14,7 +14,9 @@ src/ViewWidgets/LogDownload.qml src/VehicleSetup/FirmwareUpgrade.qml src/FlightDisplay/FlightDisplayView.qml - src/AutoPilotPlugins/PX4/FlightModesComponent.qml + src/AutoPilotPlugins/PX4/PX4FlightModes.qml + src/AutoPilotPlugins/PX4/PX4AdvancedFlightModes.qml + src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml src/AutoPilotPlugins/APM/APMFlightModesComponent.qml src/AutoPilotPlugins/APM/APMFlightModesComponentSummary.qml diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponent.cc b/src/AutoPilotPlugins/PX4/FlightModesComponent.cc index 5825147a2..fcf7aa9dc 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponent.cc +++ b/src/AutoPilotPlugins/PX4/FlightModesComponent.cc @@ -63,18 +63,30 @@ bool FlightModesComponent::requiresSetup(void) const bool FlightModesComponent::setupComplete(void) const { - return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 || - _autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0; + if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) { + return true; + } + + if (_autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0 || + (_autopilot->parameterExists(FactSystem::defaultComponentId, "RC_MAP_FLTMODE") && _autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_FLTMODE")->rawValue().toInt() != 0)) { + return true; + } + + return false; } QStringList FlightModesComponent::setupCompleteChangedTriggerList(void) const { - return QStringList("RC_MAP_MODE_SW"); + QStringList list; + + list << QStringLiteral("RC_MAP_MODE_SW") << QStringLiteral("RC_MAP_FLTMODE"); + + return list; } QUrl FlightModesComponent::setupSource(void) const { - return QUrl::fromUserInput("qrc:/qml/FlightModesComponent.qml"); + return QUrl::fromUserInput("qrc:/qml/PX4FlightModes.qml"); } QUrl FlightModesComponent::summaryQmlSource(void) const diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml b/src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml index 87b392db2..13630c372 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml +++ b/src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml @@ -1,10 +1,11 @@ -import QtQuick 2.2 +import QtQuick 2.2 import QtQuick.Controls 1.2 -import QGroundControl.FactSystem 1.0 -import QGroundControl.FactControls 1.0 -import QGroundControl.Controls 1.0 -import QGroundControl.Palette 1.0 +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.ScreenTools 1.0 FactPanel { id: panel @@ -14,33 +15,68 @@ FactPanel { QGCPalette { id: qgcPal; colorGroupEnabled: enabled } FactPanelController { id: controller; factPanel: panel } - property Fact modeSwFact: controller.getParameterFact(-1, "RC_MAP_MODE_SW") - property Fact posCtlSwFact: controller.getParameterFact(-1, "RC_MAP_POSCTL_SW") - property Fact loiterSwFact: controller.getParameterFact(-1, "RC_MAP_LOITER_SW") - property Fact returnSwFact: controller.getParameterFact(-1, "RC_MAP_RETURN_SW") + property Fact _nullFact + property Fact _rcMapFltmode: controller.parameterExists(-1, "RC_MAP_FLTMODE") ? controller.getParameterFact(-1, "RC_MAP_FLTMODE") : _nullFact + property Fact _rcMapModeSw: controller.getParameterFact(-1, "RC_MAP_MODE_SW") + property bool _simpleMode: _rcMapFltmode.value > 0 || _rcMapModeSw.value == 0 - Column { + + Loader { anchors.fill: parent - anchors.margins: 8 + sourceComponent: _simpleMode ? simple : advanced + } - VehicleSummaryRow { - labelText: "Mode switch:" - valueText: modeSwFact ? (modeSwFact.value === 0 ? "Setup required" : modeSwFact.valueString) : "" - } + Component { + id: simple - VehicleSummaryRow { - labelText: "Position Ctl switch:" - valueText: posCtlSwFact ? (posCtlSwFact.value === 0 ? "Disabled" : posCtlSwFact.valueString) : "" - } + Column { + anchors.margins: 8 - VehicleSummaryRow { - labelText: "Loiter switch:" - valueText: loiterSwFact ? (loiterSwFact.value === 0 ? "Disabled" : loiterSwFact.valueString) : "" + VehicleSummaryRow { + labelText: "Mode switch:" + valueText: _rcMapFltmode.value === 0 ? "Setup required" : _rcMapFltmode.enumStringValue + } + + Repeater { + model: 6 + + VehicleSummaryRow { + labelText: "Flight Mode " + (index + 1) + ":" + valueText: controller.getParameterFact(-1, "COM_FLTMODE" + (index + 1)).enumStringValue + } + } } + } + + Component { + id: advanced + + Column { + anchors.margins: 8 + + property Fact posCtlSwFact: controller.getParameterFact(-1, "RC_MAP_POSCTL_SW") + property Fact loiterSwFact: controller.getParameterFact(-1, "RC_MAP_LOITER_SW") + property Fact returnSwFact: controller.getParameterFact(-1, "RC_MAP_RETURN_SW") + + VehicleSummaryRow { + labelText: "Mode switch:" + valueText: _rcMapModeSw.value === 0 ? "Setup required" : _rcMapModeSw.valueString + } + + VehicleSummaryRow { + labelText: "Position Ctl switch:" + valueText: posCtlSwFact.value === 0 ? "Disabled" : posCtlSwFact.valueString + } + + VehicleSummaryRow { + labelText: "Loiter switch:" + valueText: loiterSwFact.value === 0 ? "Disabled" : loiterSwFact.valueString + } - VehicleSummaryRow { - labelText: "Return switch:" - valueText: returnSwFact ? (returnSwFact.value === 0 ? "Disabled" : returnSwFact.valueString) : "" + VehicleSummaryRow { + labelText: "Return switch:" + valueText: returnSwFact.value === 0 ? "Disabled" : returnSwFact.valueString + } } } } diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModes.qml similarity index 51% rename from src/AutoPilotPlugins/PX4/FlightModesComponent.qml rename to src/AutoPilotPlugins/PX4/PX4AdvancedFlightModes.qml index d63a3edcf..ee673b5a8 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml +++ b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModes.qml @@ -34,9 +34,13 @@ import QGroundControl.Controls 1.0 import QGroundControl.Controllers 1.0 import QGroundControl.ScreenTools 1.0 -QGCView { - id: qgcView - viewPanel: panel +/// PX4 Advanced Flight Mode configuration +Item { + id: root + + // The following properties must be pushed in from the Loader + //property var qgcView - QGCView control + //property var qgcViewPanel - QGCViewPanel control readonly property int monitorThresholdCharWidth: 8 // Character width of Monitor and Threshold labels @@ -120,13 +124,11 @@ QGCView { readonly property real modeSpacing: ScreenTools.defaultFontPixelHeight / 3 - property Fact rcInMode: controller.getParameterFact(-1, "COM_RC_IN_MODE") - QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled } - FlightModesComponentController { + PX4AdvancedFlightModesController { id: controller - factPanel: panel + factPanel: qgcViewPanel onModeRowsChanged: recalcModePositions() } @@ -137,9 +139,6 @@ QGCView { onTriggered: { recalcModePositions() - if (rcInMode.value == 1) { - showDialog(joystickEnabledDialogComponent, title, qgcView.showDialogDefaultWidth, 0) - } } } @@ -194,225 +193,233 @@ QGCView { scrollItem.height = nextY } - QGCViewPanel { - id: panel - anchors.fill: parent + Component { + id: joystickEnabledDialogComponent - Component { - id: joystickEnabledDialogComponent - - QGCViewMessage { - message: "Flight Mode Config is disabled since you have a Joystick enabled." - } + QGCViewMessage { + message: "Flight Mode Config is disabled since you have a Joystick enabled." } + } + + ScrollView { + id: scroll + anchors.fill: parent + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff - ScrollView { - id: scroll - anchors.fill: parent - horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + Item { + id: scrollItem + width: scroll.viewport.width Item { - id: scrollItem - width: scroll.viewport.width - - Item { - id: helpApplyRow - width: parent.width - height: Math.max(helpText.contentHeight, applyButton.height) - - QGCLabel { - id: helpText - anchors.rightMargin: ScreenTools.defaultFontPixelWidth - anchors.left: parent.left - anchors.right: applyButton.left - text: topHelpText - font.pixelSize: ScreenTools.defaultFontPixelSize - wrapMode: Text.WordWrap + id: helpApplyRow + width: parent.width + height: Math.max(helpText.contentHeight, applyButton.y + applyButton.height) + + QGCLabel { + id: helpText + anchors.rightMargin: ScreenTools.defaultFontPixelWidth + anchors.left: parent.left + anchors.right: buttonColumn.left + text: topHelpText + font.pixelSize: ScreenTools.defaultFontPixelSize + wrapMode: Text.WordWrap + } + + Column { + id: buttonColumn + anchors.rightMargin: ScreenTools.defaultFontPixelWidth + anchors.right: parent.right + spacing: ScreenTools.defaultFontPixelHeight / 4 + + QGCButton { + text: "Use Simple Flight Modes" + visible: controller.parameterExists(-1, "RC_MAP_FLTMODE") + onClicked: { + controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 0 + controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 5 + } } QGCButton { id: applyButton - anchors.rightMargin: ScreenTools.defaultFontPixelWidth - anchors.right: parent.right text: "Generate Thresholds" - onClicked: controller.generateThresholds() } } + } - Item { - id: lastSpacer - anchors.top: helpApplyRow.bottom - height: ScreenTools.defaultFontPixelHeight - width: 10 - } + Item { + id: lastSpacer + anchors.top: helpApplyRow.bottom + height: ScreenTools.defaultFontPixelHeight + width: 10 + } - ModeSwitchDisplay { - id: manualMode - anchors.top: lastSpacer.bottom - flightModeName: controller.fixedWing ? fwManualModeName : mrManualModeName - flightModeDescription: controller.fixedWing ? fwManualModeDescription : mrManualModeDescription - rcValue: controller.manualModeRcValue - modeChannelIndex: controller.manualModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.manualModeSelected - thresholdValue: controller.manualModeThreshold - thresholdDragEnabled: false - - onModeChannelIndexSelected: controller.manualModeChannelIndex = index - } + ModeSwitchDisplay { + id: manualMode + anchors.top: lastSpacer.bottom + flightModeName: controller.fixedWing ? fwManualModeName : mrManualModeName + flightModeDescription: controller.fixedWing ? fwManualModeDescription : mrManualModeDescription + rcValue: controller.manualModeRcValue + modeChannelIndex: controller.manualModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.manualModeSelected + thresholdValue: controller.manualModeThreshold + thresholdDragEnabled: false + + onModeChannelIndexSelected: controller.manualModeChannelIndex = index + } - ModeSwitchDisplay { - id: assistMode - visible: controller.assistModeVisible - flightModeName: assistModeName - flightModeDescription: assistModeDescription - rcValue: controller.assistModeRcValue - modeChannelIndex: controller.assistModeChannelIndex - modeChannelEnabled: false - modeSelected: controller.assistModeSelected - thresholdValue: controller.assistModeThreshold - thresholdDragEnabled: true - - onThresholdValueChanged: controller.assistModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: assistMode + visible: controller.assistModeVisible + flightModeName: assistModeName + flightModeDescription: assistModeDescription + rcValue: controller.assistModeRcValue + modeChannelIndex: controller.assistModeChannelIndex + modeChannelEnabled: false + modeSelected: controller.assistModeSelected + thresholdValue: controller.assistModeThreshold + thresholdDragEnabled: true + + onThresholdValueChanged: controller.assistModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: autoMode - visible: controller.autoModeVisible - flightModeName: autoModeName - flightModeDescription: autoModeDescription - rcValue: controller.autoModeRcValue - modeChannelIndex: controller.autoModeChannelIndex - modeChannelEnabled: false - modeSelected: controller.autoModeSelected - thresholdValue: controller.autoModeThreshold - thresholdDragEnabled: true - - onThresholdValueChanged: controller.autoModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: autoMode + visible: controller.autoModeVisible + flightModeName: autoModeName + flightModeDescription: autoModeDescription + rcValue: controller.autoModeRcValue + modeChannelIndex: controller.autoModeChannelIndex + modeChannelEnabled: false + modeSelected: controller.autoModeSelected + thresholdValue: controller.autoModeThreshold + thresholdDragEnabled: true + + onThresholdValueChanged: controller.autoModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: acroMode - flightModeName: controller.fixedWing ? fwAcroModeName : mrAcroModeName - flightModeDescription: controller.fixedWing ? fwAcroModeDescription : mrAcroModeDescription - rcValue: controller.acroModeRcValue - modeChannelIndex: controller.acroModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.acroModeSelected - thresholdValue: controller.acroModeThreshold - thresholdDragEnabled: true - - onModeChannelIndexSelected: controller.acroModeChannelIndex = index - onThresholdValueChanged: controller.acroModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: acroMode + flightModeName: controller.fixedWing ? fwAcroModeName : mrAcroModeName + flightModeDescription: controller.fixedWing ? fwAcroModeDescription : mrAcroModeDescription + rcValue: controller.acroModeRcValue + modeChannelIndex: controller.acroModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.acroModeSelected + thresholdValue: controller.acroModeThreshold + thresholdDragEnabled: true + + onModeChannelIndexSelected: controller.acroModeChannelIndex = index + onThresholdValueChanged: controller.acroModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: altCtlMode - flightModeName: altCtlModeName - flightModeDescription: controller.fixedWing ? fwAltCtlModeDescription : mrAltCtlModeDescription - rcValue: controller.altCtlModeRcValue - modeChannelIndex: controller.altCtlModeChannelIndex - modeChannelEnabled: false - modeSelected: controller.altCtlModeSelected - thresholdValue: controller.altCtlModeThreshold - thresholdDragEnabled: !controller.assistModeVisible + ModeSwitchDisplay { + id: altCtlMode + flightModeName: altCtlModeName + flightModeDescription: controller.fixedWing ? fwAltCtlModeDescription : mrAltCtlModeDescription + rcValue: controller.altCtlModeRcValue + modeChannelIndex: controller.altCtlModeChannelIndex + modeChannelEnabled: false + modeSelected: controller.altCtlModeSelected + thresholdValue: controller.altCtlModeThreshold + thresholdDragEnabled: !controller.assistModeVisible - onThresholdValueChanged: controller.altCtlModeThreshold = thresholdValue + onThresholdValueChanged: controller.altCtlModeThreshold = thresholdValue - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: posCtlMode - flightModeName: posCtlModeName - flightModeDescription: controller.fixedWing ? fwPosCtlModeDescription : mrPosCtlModeDescription - rcValue: controller.posCtlModeRcValue - modeChannelIndex: controller.posCtlModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.posCtlModeSelected - thresholdValue: controller.posCtlModeThreshold - thresholdDragEnabled: true - - onModeChannelIndexSelected: controller.posCtlModeChannelIndex = index - onThresholdValueChanged: controller.posCtlModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: posCtlMode + flightModeName: posCtlModeName + flightModeDescription: controller.fixedWing ? fwPosCtlModeDescription : mrPosCtlModeDescription + rcValue: controller.posCtlModeRcValue + modeChannelIndex: controller.posCtlModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.posCtlModeSelected + thresholdValue: controller.posCtlModeThreshold + thresholdDragEnabled: true + + onModeChannelIndexSelected: controller.posCtlModeChannelIndex = index + onThresholdValueChanged: controller.posCtlModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: missionMode - flightModeName: missionModeName - flightModeDescription: missionModeDescription - rcValue: controller.missionModeRcValue - modeChannelIndex: controller.missionModeChannelIndex - modeChannelEnabled: false - modeSelected: controller.missionModeSelected - thresholdValue: controller.missionModeThreshold - thresholdDragEnabled: !controller.autoModeVisible + ModeSwitchDisplay { + id: missionMode + flightModeName: missionModeName + flightModeDescription: missionModeDescription + rcValue: controller.missionModeRcValue + modeChannelIndex: controller.missionModeChannelIndex + modeChannelEnabled: false + modeSelected: controller.missionModeSelected + thresholdValue: controller.missionModeThreshold + thresholdDragEnabled: !controller.autoModeVisible - onThresholdValueChanged: controller.missionModeThreshold = thresholdValue + onThresholdValueChanged: controller.missionModeThreshold = thresholdValue - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: loiterMode - flightModeName: loiterModeName - flightModeDescription: controller.fixedWing ? fwLoiterModeDescription : mrLoiterModeDescription - rcValue: controller.loiterModeRcValue - modeChannelIndex: controller.loiterModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.loiterModeSelected - thresholdValue: controller.loiterModeThreshold - thresholdDragEnabled: true - - onModeChannelIndexSelected: controller.loiterModeChannelIndex = index - onThresholdValueChanged: controller.loiterModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: loiterMode + flightModeName: loiterModeName + flightModeDescription: controller.fixedWing ? fwLoiterModeDescription : mrLoiterModeDescription + rcValue: controller.loiterModeRcValue + modeChannelIndex: controller.loiterModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.loiterModeSelected + thresholdValue: controller.loiterModeThreshold + thresholdDragEnabled: true + + onModeChannelIndexSelected: controller.loiterModeChannelIndex = index + onThresholdValueChanged: controller.loiterModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: returnMode - flightModeName: returnModeName - flightModeDescription: returnModeDescription - rcValue: controller.returnModeRcValue - modeChannelIndex: controller.returnModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.returnModeSelected - thresholdValue: controller.returnModeThreshold - thresholdDragEnabled: true - - onModeChannelIndexSelected: controller.returnModeChannelIndex = index - onThresholdValueChanged: controller.returnModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } + ModeSwitchDisplay { + id: returnMode + flightModeName: returnModeName + flightModeDescription: returnModeDescription + rcValue: controller.returnModeRcValue + modeChannelIndex: controller.returnModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.returnModeSelected + thresholdValue: controller.returnModeThreshold + thresholdDragEnabled: true + + onModeChannelIndexSelected: controller.returnModeChannelIndex = index + onThresholdValueChanged: controller.returnModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } - ModeSwitchDisplay { - id: offboardMode - flightModeName: offboardModeName - flightModeDescription: offboardModeDescription - rcValue: controller.offboardModeRcValue - modeChannelIndex: controller.offboardModeChannelIndex - modeChannelEnabled: true - modeSelected: controller.offboardModeSelected - thresholdValue: controller.offboardModeThreshold - thresholdDragEnabled: true - - onModeChannelIndexSelected: controller.offboardModeChannelIndex = index - onThresholdValueChanged: controller.offboardModeThreshold = thresholdValue - - Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } - } - } // Item - } // Scroll View - } // QGCViewPanel -} // QGCView + ModeSwitchDisplay { + id: offboardMode + flightModeName: offboardModeName + flightModeDescription: offboardModeDescription + rcValue: controller.offboardModeRcValue + modeChannelIndex: controller.offboardModeChannelIndex + modeChannelEnabled: true + modeSelected: controller.offboardModeSelected + thresholdValue: controller.offboardModeThreshold + thresholdDragEnabled: true + + onModeChannelIndexSelected: controller.offboardModeChannelIndex = index + onThresholdValueChanged: controller.offboardModeThreshold = thresholdValue + + Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } + } + } // Item + } // Scroll View +} // Item diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponentController.cc b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.cc similarity index 85% rename from src/AutoPilotPlugins/PX4/FlightModesComponentController.cc rename to src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.cc index f38602cec..4eb989df7 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponentController.cc +++ b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.cc @@ -24,14 +24,14 @@ /// @file /// @author Don Gagne -#include "FlightModesComponentController.h" +#include "PX4AdvancedFlightModesController.h" #include "QGCMAVLink.h" #include "AutoPilotPluginManager.h" #include #include -FlightModesComponentController::FlightModesComponentController(void) : +PX4AdvancedFlightModesController::PX4AdvancedFlightModesController(void) : _validConfiguration(false), _channelCount(18), _manualModeSelected(false), @@ -55,10 +55,10 @@ FlightModesComponentController::FlightModesComponentController(void) : _init(); _validateConfiguration(); - connect(_vehicle, &Vehicle::rcChannelsChanged, this, &FlightModesComponentController::_rcChannelsChanged); + connect(_vehicle, &Vehicle::rcChannelsChanged, this, &PX4AdvancedFlightModesController::_rcChannelsChanged); } -void FlightModesComponentController::_init(void) +void PX4AdvancedFlightModesController::_init(void) { // FIXME: What about VTOL? That confuses the whole Flight Mode naming scheme _fixedWing = _vehicle->vehicleType() == MAV_TYPE_FIXED_WING; @@ -151,7 +151,7 @@ void FlightModesComponentController::_init(void) /// This will look for parameter settings which would cause the config to not run correctly. /// It will set _validConfiguration and _configurationErrors as needed. -void FlightModesComponentController::_validateConfiguration(void) +void PX4AdvancedFlightModesController::_validateConfiguration(void) { _validConfiguration = true; @@ -205,7 +205,7 @@ void FlightModesComponentController::_validateConfiguration(void) } /// Connected to Vehicle::rcChannelsChanged signal -void FlightModesComponentController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) +void PX4AdvancedFlightModesController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) { for (int channel=0; channelrawValue().toInt(); @@ -275,12 +275,12 @@ double FlightModesComponentController::altCtlModeRcValue(void) } } -double FlightModesComponentController::posCtlModeRcValue(void) +double PX4AdvancedFlightModesController::posCtlModeRcValue(void) { return _switchLiveRange("RC_MAP_POSCTL_SW"); } -double FlightModesComponentController::missionModeRcValue(void) +double PX4AdvancedFlightModesController::missionModeRcValue(void) { int returnSwitchChannel = getParameterFact(-1, "RC_MAP_RETURN_SW")->rawValue().toInt(); int loiterSwitchChannel = getParameterFact(-1, "RC_MAP_LOITER_SW")->rawValue().toInt(); @@ -302,22 +302,22 @@ double FlightModesComponentController::missionModeRcValue(void) return _switchLiveRange(switchChannelParam); } -double FlightModesComponentController::loiterModeRcValue(void) +double PX4AdvancedFlightModesController::loiterModeRcValue(void) { return _switchLiveRange("RC_MAP_LOITER_SW"); } -double FlightModesComponentController::returnModeRcValue(void) +double PX4AdvancedFlightModesController::returnModeRcValue(void) { return _switchLiveRange("RC_MAP_RETURN_SW"); } -double FlightModesComponentController::offboardModeRcValue(void) +double PX4AdvancedFlightModesController::offboardModeRcValue(void) { return _switchLiveRange("RC_MAP_OFFB_SW"); } -void FlightModesComponentController::_recalcModeSelections(void) +void PX4AdvancedFlightModesController::_recalcModeSelections(void) { _manualModeSelected = false; _assistModeSelected = false; @@ -377,7 +377,7 @@ void FlightModesComponentController::_recalcModeSelections(void) emit modesSelectedChanged(); } -void FlightModesComponentController::_recalcModeRows(void) +void PX4AdvancedFlightModesController::_recalcModeRows(void) { int modeSwitchChannel = getParameterFact(-1, "RC_MAP_MODE_SW")->rawValue().toInt(); int acroSwitchChannel = getParameterFact(-1, "RC_MAP_ACRO_SW")->rawValue().toInt(); @@ -467,140 +467,140 @@ void FlightModesComponentController::_recalcModeRows(void) emit modeRowsChanged(); } -double FlightModesComponentController::manualModeThreshold(void) +double PX4AdvancedFlightModesController::manualModeThreshold(void) { return 0.0; } -double FlightModesComponentController::assistModeThreshold(void) +double PX4AdvancedFlightModesController::assistModeThreshold(void) { return getParameterFact(-1, "RC_ASSIST_TH")->rawValue().toDouble(); } -double FlightModesComponentController::autoModeThreshold(void) +double PX4AdvancedFlightModesController::autoModeThreshold(void) { return getParameterFact(-1, "RC_AUTO_TH")->rawValue().toDouble(); } -double FlightModesComponentController::acroModeThreshold(void) +double PX4AdvancedFlightModesController::acroModeThreshold(void) { return getParameterFact(-1, "RC_ACRO_TH")->rawValue().toDouble(); } -double FlightModesComponentController::altCtlModeThreshold(void) +double PX4AdvancedFlightModesController::altCtlModeThreshold(void) { return _assistModeVisible ? 0.0 : getParameterFact(-1, "RC_ASSIST_TH")->rawValue().toDouble(); } -double FlightModesComponentController::posCtlModeThreshold(void) +double PX4AdvancedFlightModesController::posCtlModeThreshold(void) { return getParameterFact(-1, "RC_POSCTL_TH")->rawValue().toDouble(); } -double FlightModesComponentController::missionModeThreshold(void) +double PX4AdvancedFlightModesController::missionModeThreshold(void) { return _autoModeVisible ? 0.0 : getParameterFact(-1, "RC_AUTO_TH")->rawValue().toDouble(); } -double FlightModesComponentController::loiterModeThreshold(void) +double PX4AdvancedFlightModesController::loiterModeThreshold(void) { return getParameterFact(-1, "RC_LOITER_TH")->rawValue().toDouble(); } -double FlightModesComponentController::returnModeThreshold(void) +double PX4AdvancedFlightModesController::returnModeThreshold(void) { return getParameterFact(-1, "RC_RETURN_TH")->rawValue().toDouble(); } -double FlightModesComponentController::offboardModeThreshold(void) +double PX4AdvancedFlightModesController::offboardModeThreshold(void) { return getParameterFact(-1, "RC_OFFB_TH")->rawValue().toDouble(); } -void FlightModesComponentController::setAssistModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setAssistModeThreshold(double threshold) { getParameterFact(-1, "RC_ASSIST_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setAutoModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setAutoModeThreshold(double threshold) { getParameterFact(-1, "RC_AUTO_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setAcroModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setAcroModeThreshold(double threshold) { getParameterFact(-1, "RC_ACRO_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setAltCtlModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setAltCtlModeThreshold(double threshold) { setAssistModeThreshold(threshold); } -void FlightModesComponentController::setPosCtlModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setPosCtlModeThreshold(double threshold) { getParameterFact(-1, "RC_POSCTL_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setMissionModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setMissionModeThreshold(double threshold) { setAutoModeThreshold(threshold); } -void FlightModesComponentController::setLoiterModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setLoiterModeThreshold(double threshold) { getParameterFact(-1, "RC_LOITER_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setReturnModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setReturnModeThreshold(double threshold) { getParameterFact(-1, "RC_RETURN_TH")->setRawValue(threshold); _recalcModeSelections(); } -void FlightModesComponentController::setOffboardModeThreshold(double threshold) +void PX4AdvancedFlightModesController::setOffboardModeThreshold(double threshold) { getParameterFact(-1, "RC_OFFB_TH")->setRawValue(threshold); _recalcModeSelections(); } -int FlightModesComponentController::_channelToChannelIndex(int channel) +int PX4AdvancedFlightModesController::_channelToChannelIndex(int channel) { return _channelListModelChannel.lastIndexOf(channel); } -int FlightModesComponentController::_channelToChannelIndex(const QString& channelParam) +int PX4AdvancedFlightModesController::_channelToChannelIndex(const QString& channelParam) { return _channelToChannelIndex(getParameterFact(-1, channelParam)->rawValue().toInt()); } -int FlightModesComponentController::manualModeChannelIndex(void) +int PX4AdvancedFlightModesController::manualModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_MODE_SW"); } -int FlightModesComponentController::assistModeChannelIndex(void) +int PX4AdvancedFlightModesController::assistModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_MODE_SW"); } -int FlightModesComponentController::autoModeChannelIndex(void) +int PX4AdvancedFlightModesController::autoModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_MODE_SW"); } -int FlightModesComponentController::acroModeChannelIndex(void) +int PX4AdvancedFlightModesController::acroModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_ACRO_SW"); } -int FlightModesComponentController::altCtlModeChannelIndex(void) +int PX4AdvancedFlightModesController::altCtlModeChannelIndex(void) { int posCtlSwitchChannel = getParameterFact(-1, "RC_MAP_POSCTL_SW")->rawValue().toInt(); @@ -611,17 +611,17 @@ int FlightModesComponentController::altCtlModeChannelIndex(void) } } -int FlightModesComponentController::posCtlModeChannelIndex(void) +int PX4AdvancedFlightModesController::posCtlModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_POSCTL_SW"); } -int FlightModesComponentController::loiterModeChannelIndex(void) +int PX4AdvancedFlightModesController::loiterModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_LOITER_SW"); } -int FlightModesComponentController::missionModeChannelIndex(void) +int PX4AdvancedFlightModesController::missionModeChannelIndex(void) { int loiterSwitchChannel = getParameterFact(-1, "RC_MAP_LOITER_SW")->rawValue().toInt(); @@ -632,22 +632,22 @@ int FlightModesComponentController::missionModeChannelIndex(void) } } -int FlightModesComponentController::returnModeChannelIndex(void) +int PX4AdvancedFlightModesController::returnModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_RETURN_SW"); } -int FlightModesComponentController::offboardModeChannelIndex(void) +int PX4AdvancedFlightModesController::offboardModeChannelIndex(void) { return _channelToChannelIndex("RC_MAP_OFFB_SW"); } -int FlightModesComponentController::_channelIndexToChannel(int index) +int PX4AdvancedFlightModesController::_channelIndexToChannel(int index) { return _channelListModelChannel[index]; } -void FlightModesComponentController::setManualModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setManualModeChannelIndex(int index) { getParameterFact(-1, "RC_MAP_MODE_SW")->setRawValue(_channelIndexToChannel(index)); @@ -657,7 +657,7 @@ void FlightModesComponentController::setManualModeChannelIndex(int index) } -void FlightModesComponentController::setAcroModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setAcroModeChannelIndex(int index) { getParameterFact(-1, "RC_MAP_ACRO_SW")->setRawValue(_channelIndexToChannel(index)); @@ -665,7 +665,7 @@ void FlightModesComponentController::setAcroModeChannelIndex(int index) _recalcModeRows(); } -void FlightModesComponentController::setPosCtlModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setPosCtlModeChannelIndex(int index) { int channel = _channelIndexToChannel(index); @@ -687,7 +687,7 @@ void FlightModesComponentController::setPosCtlModeChannelIndex(int index) } -void FlightModesComponentController::setLoiterModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setLoiterModeChannelIndex(int index) { int channel = _channelIndexToChannel(index); @@ -709,7 +709,7 @@ void FlightModesComponentController::setLoiterModeChannelIndex(int index) } -void FlightModesComponentController::setReturnModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setReturnModeChannelIndex(int index) { getParameterFact(-1, "RC_MAP_RETURN_SW")->setRawValue(_channelIndexToChannel(index)); _recalcModeSelections(); @@ -718,7 +718,7 @@ void FlightModesComponentController::setReturnModeChannelIndex(int index) } -void FlightModesComponentController::setOffboardModeChannelIndex(int index) +void PX4AdvancedFlightModesController::setOffboardModeChannelIndex(int index) { getParameterFact(-1, "RC_MAP_OFFB_SW")->setRawValue(_channelIndexToChannel(index)); _recalcModeSelections(); @@ -727,7 +727,7 @@ void FlightModesComponentController::setOffboardModeChannelIndex(int index) } -void FlightModesComponentController::generateThresholds(void) +void PX4AdvancedFlightModesController::generateThresholds(void) { // Reset all thresholds to 0.0 diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponentController.h b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.h similarity index 98% rename from src/AutoPilotPlugins/PX4/FlightModesComponentController.h rename to src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.h index 9070de31c..e4c990c16 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponentController.h +++ b/src/AutoPilotPlugins/PX4/PX4AdvancedFlightModesController.h @@ -24,8 +24,8 @@ /// @file /// @author Don Gagne -#ifndef FLIGHTMODESCOMPONENTCONTROLLER_H -#define FLIGHTMODESCOMPONENTCONTROLLER_H +#ifndef PX4AdvancedFlightModesController_H +#define PX4AdvancedFlightModesController_H #include #include @@ -37,12 +37,12 @@ #include "FactPanelController.h" /// MVC Controller for FlightModesComponent.qml. -class FlightModesComponentController : public FactPanelController +class PX4AdvancedFlightModesController : public FactPanelController { Q_OBJECT public: - FlightModesComponentController(void); + PX4AdvancedFlightModesController(void); Q_PROPERTY(bool validConfiguration MEMBER _validConfiguration CONSTANT) Q_PROPERTY(QString configurationErrors MEMBER _configurationErrors CONSTANT) diff --git a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc index 15f3ab58a..bff3721ba 100644 --- a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc +++ b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc @@ -24,7 +24,7 @@ #include "PX4AutoPilotPlugin.h" #include "AutoPilotPluginManager.h" #include "PX4AirframeLoader.h" -#include "FlightModesComponentController.h" +#include "PX4AdvancedFlightModesController.h" #include "AirframeComponentController.h" #include "UAS.h" #include "FirmwarePlugin/PX4/PX4ParameterMetaData.h" // FIXME: Hack diff --git a/src/AutoPilotPlugins/PX4/PX4FlightModes.qml b/src/AutoPilotPlugins/PX4/PX4FlightModes.qml new file mode 100644 index 000000000..1ef817ddd --- /dev/null +++ b/src/AutoPilotPlugins/PX4/PX4FlightModes.qml @@ -0,0 +1,67 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 +import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.1 + +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.Controllers 1.0 +import QGroundControl.ScreenTools 1.0 + +/// PX4 Flight Mode configuration. This control will load either the Simple or Advanced Flight Mode config +/// based on current parameter settings. +QGCView { + id: rootQGCView + viewPanel: panel + + property Fact _nullFact + property Fact _rcMapFltmode: controller.parameterExists(-1, "RC_MAP_FLTMODE") ? controller.getParameterFact(-1, "RC_MAP_FLTMODE") : _nullFact + property Fact _rcMapModeSw: controller.getParameterFact(-1, "RC_MAP_MODE_SW") + property bool _simpleMode: _rcMapFltmode.value > 0 || _rcMapModeSw.value == 0 + + QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled } + + FactPanelController { + id: controller + factPanel: panel + } + + QGCViewPanel { + id: panel + anchors.fill: parent + + Loader { + anchors.fill: parent + source: _simpleMode ? "qrc:/qml/PX4SimpleFlightModes.qml" : "qrc:/qml/PX4AdvancedFlightModes.qml" + + property var qgcView: rootQGCView + property var qgcViewPanel: panel + } + } // QGCViewPanel +} // QGCView diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml new file mode 100644 index 000000000..45df98829 --- /dev/null +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml @@ -0,0 +1,140 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +import QtQuick 2.5 +import QtQuick.Controls 1.2 + +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.Controllers 1.0 +import QGroundControl.ScreenTools 1.0 + +Item { + id: root + + // The following properties must be pushed in from the Loader + //property var qgcView - QGCView control + //property var qgcViewPanel - QGCViewPanel control + + property real _margins: ScreenTools.defaultFontPixelHeight / 2 + + QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled } + + PX4SimpleFlightModesController { + id: controller + factPanel: qgcViewPanel + } + + QGCFlickable { + anchors.fill: parent + clip: true + contentWidth: contentColumn.width + contentHeight: contentColumn.height + + Column { + id: contentColumn + spacing: _margins + + QGCLabel { + id: flightModeLabel + text: "Flight Mode Settings" + font.weight: Font.DemiBold + } + + Item { + height: modeChannelCombo.height + width: modeChannelCombo.x + modeChannelCombo.width + + QGCLabel { + id: modeChannelLabel + anchors.baseline: modeChannelCombo.baseline + text: "Flight mode channel:" + } + + FactComboBox { + id: modeChannelCombo + anchors.leftMargin: _margins + anchors.left: modeChannelLabel.right + width: ScreenTools.defaultFontPixelWidth * 15 + fact: controller.getParameterFact(-1, "RC_MAP_FLTMODE") + indexModel: false + } + } + + Rectangle { + id: flightModeSettings + width: flightModeColumn.width + (_margins * 2) + height: flightModeColumn.height + ScreenTools.defaultFontPixelHeight + color: qgcPal.windowShade + + Column { + id: flightModeColumn + anchors.margins: ScreenTools.defaultFontPixelWidth + anchors.left: parent.left + anchors.top: parent.top + spacing: ScreenTools.defaultFontPixelHeight + + Repeater { + model: 6 + + Row { + spacing: ScreenTools.defaultFontPixelWidth + + property int index: modelData + 1 + property var pwmStrings: [ "PWM 0 - 1230", "PWM 1231 - 1360", "PWM 1361 - 1490", "PWM 1491 - 1620", "PWM 1621 - 1749", "PWM 1750 +"] + + + QGCLabel { + anchors.baseline: modeCombo.baseline + text: "Flight Mode " + index + ":" + color: controller.activeFlightMode == index ? "yellow" : qgcPal.text + } + + FactComboBox { + id: modeCombo + width: ScreenTools.defaultFontPixelWidth * 20 + fact: controller.getParameterFact(-1, "COM_FLTMODE" + index) + indexModel: false + } + + QGCLabel { + anchors.baseline: modeCombo.baseline + text: pwmStrings[modelData] + } + } + } // Repeater - Flight Modes + } // Column - Flight Modes + } // Rectangle - Flight Modes + + QGCButton { + text: "Use Advanced Flight Modes" + onClicked: { + controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 5 + controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 0 + } + } + } // Column + } // QGCFlickable +} // QGCView diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc new file mode 100644 index 000000000..ffc4ee6e5 --- /dev/null +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc @@ -0,0 +1,73 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "PX4SimpleFlightModesController.h" +#include "QGCMAVLink.h" +#include "AutoPilotPluginManager.h" + +#include +#include + +PX4SimpleFlightModesController::PX4SimpleFlightModesController(void) + : _activeFlightMode(0) + , _channelCount(Vehicle::cMaxRcChannels) + +{ + QStringList usedParams; + usedParams << QStringLiteral("COM_FLTMODE1") << QStringLiteral("COM_FLTMODE2") << QStringLiteral("COM_FLTMODE3") + << QStringLiteral("COM_FLTMODE4") << QStringLiteral("COM_FLTMODE5") << QStringLiteral("COM_FLTMODE6") + << QStringLiteral("RC_MAP_FLTMODE"); + if (!_allParametersExists(FactSystem::defaultComponentId, usedParams)) { + return; + } + + connect(_vehicle, &Vehicle::rcChannelsChanged, this, &PX4SimpleFlightModesController::_rcChannelsChanged); +} + +/// Connected to Vehicle::rcChannelsChanged signal +void PX4SimpleFlightModesController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) +{ + int flightModeChannel = getParameterFact(-1, "RC_MAP_FLTMODE")->rawValue().toInt() - 1; + + if (flightModeChannel < 0 || flightModeChannel > channelCount) { + return; + } + + _activeFlightMode = 0; + int channelValue = pwmValues[flightModeChannel]; + if (channelValue != -1) { + bool found = false; + int rgThreshold[] = { 1230, 1360, 1490, 1620, 1749 }; + for (int i=0; i<5; i++) { + if (channelValue <= rgThreshold[i]) { + _activeFlightMode = i + 1; + found = true; + break; + } + } + if (!found) { + _activeFlightMode = 6; + } + } + emit activeFlightModeChanged(_activeFlightMode); +} diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h new file mode 100644 index 000000000..1a5c8ed49 --- /dev/null +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h @@ -0,0 +1,62 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef PX4SimpleFlightModesController_H +#define PX4SimpleFlightModesController_H + +#include +#include +#include +#include + +#include "UASInterface.h" +#include "AutoPilotPlugin.h" +#include "FactPanelController.h" +#include "Vehicle.h" + +/// MVC Controller for PX4SimpleFlightModes.qml +class PX4SimpleFlightModesController : public FactPanelController +{ + Q_OBJECT + +public: + PX4SimpleFlightModesController(void); + + Q_PROPERTY(int activeFlightMode READ activeFlightMode NOTIFY activeFlightModeChanged) + Q_PROPERTY(int channelCount MEMBER _channelCount CONSTANT) + + int activeFlightMode(void) const { return _activeFlightMode; } + +signals: + void activeFlightModeChanged(int activeFlightMode); + void channelOptionEnabledChanged(void); + +private slots: + void _rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]); + +private: + int _activeFlightMode; + int _channelCount; +}; + +#endif diff --git a/src/FactSystem/ParameterLoader.cc b/src/FactSystem/ParameterLoader.cc index 5ac6e522a..87f90a0d3 100644 --- a/src/FactSystem/ParameterLoader.cc +++ b/src/FactSystem/ParameterLoader.cc @@ -44,7 +44,7 @@ QGC_LOGGING_CATEGORY(ParameterLoaderVerboseLog, "ParameterLoaderVerboseLog") Fact ParameterLoader::_defaultFact; -const char* ParameterLoader::_cachedMetaDataFilePrefix = "ParamaterFactMetaData"; +const char* ParameterLoader::_cachedMetaDataFilePrefix = "ParameterFactMetaData"; ParameterLoader::ParameterLoader(Vehicle* vehicle) : QObject(vehicle) diff --git a/src/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml b/src/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml index 28225ce59..88d3d61b1 100644 --- a/src/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml +++ b/src/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml @@ -2,8 +2,7 @@ 3 1 - 1 - + 1 Speed controller bandwidth Speed controller bandwidth, in Hz. Higher values result in faster speed and current rise times, but may result in overshoot and higher current consumption. For fixed-wing aircraft, this value should be less than 50 Hz; for multirotors, values up to 100 Hz may provide improvements in responsiveness. @@ -3583,6 +3582,33 @@ replay messages for logging + + Single channel flight mode selection + If this parameter is non-zero, flight modes are only selected by this channel and are assigned to six slots. + 0 + 18 + + RC Channel 11 + RC Channel 10 + RC Channel 13 + RC Channel 12 + RC Channel 15 + RC Channel 14 + RC Channel 17 + RC Channel 16 + RC Channel 18 + RC Channel 1 + Unassigned + RC Channel 3 + RC Channel 2 + RC Channel 5 + RC Channel 4 + RC Channel 7 + RC Channel 6 + RC Channel 9 + RC Channel 8 + + Mode switch channel mapping This is the main flight mode selector. The channel index (starting from 1 for channel 1) indicates which channel should be used for deciding about the main mode. A value of zero indicates the switch is not assigned. @@ -4775,121 +4801,118 @@ Maps the change of airspeed error to the acceleration setpoint RV_YAW_P - - COM_FLTMODE_CH - - + First flightmode slot (1000-1160) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED - + Second flightmode slot (1160-1320) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED - + Third flightmode slot (1320-1480) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED - + Fourth flightmode slot (1480-1640) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED - + Fift flightmode slot (1640-1800) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED - + Sixt flightmode slot (1800-2000) If the main switch channel is in this range the selected flight mode will be applied. - AUTO / TAKEOFF - RATTITUDE - AUTO / LAND - MANUAL - Unassigned - POSITION CONTROL - ALTITUDE CONTROL - AUTO / PAUSE - AUTO / MISSION - ACRO - RETURN TO LAUNCH - STABILIZED - OFFBOARD + AUTO / LAND + AUTO / TAKEOFF + ALTITUDE CONTROL + MANUAL + AUTO / MISSION + POSITION CONTROL + Unassigned + AUTO / PAUSE + OFFBOARD + ACRO + RATTITUDE + RETURN TO LAUNCH + STABILIZED diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a79e10def..42816fbe3 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -61,7 +61,8 @@ #include "ViewWidgetController.h" #include "ParameterEditorController.h" #include "CustomCommandWidgetController.h" -#include "FlightModesComponentController.h" +#include "PX4AdvancedFlightModesController.h" +#include "PX4SimpleFlightModesController.h" #include "APMFlightModesComponentController.h" #include "AirframeComponentController.h" #include "SensorsComponentController.h" @@ -434,7 +435,8 @@ void QGCApplication::_initCommon(void) qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "APMFlightModesComponentController"); - qmlRegisterType ("QGroundControl.Controllers", 1, 0, "FlightModesComponentController"); + qmlRegisterType ("QGroundControl.Controllers", 1, 0, "PX4AdvancedFlightModesController"); + qmlRegisterType ("QGroundControl.Controllers", 1, 0, "PX4SimpleFlightModesController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "APMAirframeComponentController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "AirframeComponentController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "APMSensorsComponentController"); diff --git a/src/VehicleSetup/VehicleComponent.cc b/src/VehicleSetup/VehicleComponent.cc index de7a4835a..433169263 100644 --- a/src/VehicleSetup/VehicleComponent.cc +++ b/src/VehicleSetup/VehicleComponent.cc @@ -62,8 +62,10 @@ void VehicleComponent::setupTriggerSignals(void) { // Watch for changed on trigger list params foreach (const QString ¶mName, setupCompleteChangedTriggerList()) { - Fact* fact = _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName); - connect(fact, &Fact::valueChanged, this, &VehicleComponent::_triggerUpdated); + if (_autopilot->parameterExists(FactSystem::defaultComponentId, paramName)) { + Fact* fact = _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName); + connect(fact, &Fact::valueChanged, this, &VehicleComponent::_triggerUpdated); + } } } -- 2.22.0