Commit 9fa4c40b authored by Don Gagne's avatar Don Gagne

Simple flight mode config

parent ed475329
......@@ -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 \
......
......@@ -14,7 +14,9 @@
<file alias="LogDownload.qml">src/ViewWidgets/LogDownload.qml</file>
<file alias="FirmwareUpgrade.qml">src/VehicleSetup/FirmwareUpgrade.qml</file>
<file alias="FlightDisplayView.qml">src/FlightDisplay/FlightDisplayView.qml</file>
<file alias="FlightModesComponent.qml">src/AutoPilotPlugins/PX4/FlightModesComponent.qml</file>
<file alias="PX4FlightModes.qml">src/AutoPilotPlugins/PX4/PX4FlightModes.qml</file>
<file alias="PX4AdvancedFlightModes.qml">src/AutoPilotPlugins/PX4/PX4AdvancedFlightModes.qml</file>
<file alias="PX4SimpleFlightModes.qml">src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml</file>
<file alias="FlightModesComponentSummary.qml">src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml</file>
<file alias="APMFlightModesComponent.qml">src/AutoPilotPlugins/APM/APMFlightModesComponent.qml</file>
<file alias="APMFlightModesComponentSummary.qml">src/AutoPilotPlugins/APM/APMFlightModesComponentSummary.qml</file>
......
......@@ -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
......
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
}
}
}
}
......@@ -24,8 +24,8 @@
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef FLIGHTMODESCOMPONENTCONTROLLER_H
#define FLIGHTMODESCOMPONENTCONTROLLER_H
#ifndef PX4AdvancedFlightModesController_H
#define PX4AdvancedFlightModesController_H
#include <QObject>
#include <QQuickItem>
......@@ -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)
......
......@@ -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
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
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
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
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
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
#include "PX4SimpleFlightModesController.h"
#include "QGCMAVLink.h"
#include "AutoPilotPluginManager.h"
#include <QVariant>
#include <QQmlProperty>
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);
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef PX4SimpleFlightModesController_H
#define PX4SimpleFlightModesController_H
#include <QObject>
#include <QQuickItem>
#include <QList>
#include <QStringList>
#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
......@@ -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)
......
......@@ -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<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
qmlRegisterType<APMFlightModesComponentController> ("QGroundControl.Controllers", 1, 0, "APMFlightModesComponentController");
qmlRegisterType<FlightModesComponentController> ("QGroundControl.Controllers", 1, 0, "FlightModesComponentController");
qmlRegisterType<PX4AdvancedFlightModesController> ("QGroundControl.Controllers", 1, 0, "PX4AdvancedFlightModesController");
qmlRegisterType<PX4SimpleFlightModesController> ("QGroundControl.Controllers", 1, 0, "PX4SimpleFlightModesController");
qmlRegisterType<APMAirframeComponentController> ("QGroundControl.Controllers", 1, 0, "APMAirframeComponentController");
qmlRegisterType<AirframeComponentController> ("QGroundControl.Controllers", 1, 0, "AirframeComponentController");
qmlRegisterType<APMSensorsComponentController> ("QGroundControl.Controllers", 1, 0, "APMSensorsComponentController");
......
......@@ -62,8 +62,10 @@ void VehicleComponent::setupTriggerSignals(void)
{
// Watch for changed on trigger list params
foreach (const QString &paramName, 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);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment