From e3367e35880942fd210a4f0f763c4524473ac27c Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Fri, 7 Apr 2017 12:06:48 -0700 Subject: [PATCH] New Arm/Disarm toolbar indicator --- qgroundcontrol.qrc | 1 + .../APM/ArduCopterFirmwarePlugin.h | 1 + .../APM/ArduPlaneFirmwarePlugin.h | 1 + src/FirmwarePlugin/FirmwarePlugin.cc | 7 ++++ src/FirmwarePlugin/FirmwarePlugin.h | 3 ++ src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h | 1 + src/FlightDisplay/FlightDisplayView.qml | 4 +- src/FlightDisplay/GuidedActionsController.qml | 10 ++++- src/Vehicle/Vehicle.cc | 27 ++++++++++-- src/Vehicle/Vehicle.h | 4 ++ src/ui/MainWindowInner.qml | 4 ++ src/ui/toolbar/ArmedIndicator.qml | 42 +++++++++++++++++++ src/ui/toolbar/MainToolBar.qml | 2 + 13 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 src/ui/toolbar/ArmedIndicator.qml diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 79aa71152..510c5efcc 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -3,6 +3,7 @@ src/FactSystem/FactSystemTest.qml + src/ui/toolbar/ArmedIndicator.qml src/ui/toolbar/BatteryIndicator.qml src/ui/toolbar/GPSIndicator.qml src/ui/toolbar/MessageIndicator.qml diff --git a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h index ea33ee76d..8b771c110 100644 --- a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h @@ -76,6 +76,7 @@ public: QString landFlightMode(void) const override { return QString("Land"); } QString takeControlFlightMode(void) const override { return QString("Stablize"); } bool vehicleYawsToNextWaypointInMission(const Vehicle* vehicle) const final; + QString autoDisarmParameter(Vehicle* vehicle) final { Q_UNUSED(vehicle); return QStringLiteral("DISARM_DELAY"); } private: static bool _remapParamNameIntialized; diff --git a/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h index dfa434081..7a012e16b 100644 --- a/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h @@ -59,6 +59,7 @@ public: QString offlineEditingParamFile(Vehicle* vehicle) final { Q_UNUSED(vehicle); return QStringLiteral(":/FirmwarePlugin/APM/Plane.OfflineEditing.params"); } const FirmwarePlugin::remapParamNameMajorVersionMap_t& paramNameRemapMajorVersionMap(void) const final { return _remapParamName; } int remapParamNameHigestMinorVersionNumber(int majorVersionNumber) const final; + QString autoDisarmParameter(Vehicle* vehicle) final { Q_UNUSED(vehicle); return QStringLiteral("LAND_DISARMDELAY"); } private: static bool _remapParamNameIntialized; diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 0bb2acc1d..c89b9c947 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -336,6 +336,7 @@ const QVariantList &FirmwarePlugin::toolBarIndicators(const Vehicle* vehicle) _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/RCRSSIIndicator.qml"))); _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/BatteryIndicator.qml"))); _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ModeIndicator.qml"))); + _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ArmedIndicator.qml"))); } return _toolBarIndicatorList; } @@ -445,3 +446,9 @@ void FirmwarePlugin::batteryConsumptionData(Vehicle* vehicle, int& mAhBattery, d hoverAmps = 0; cruiseAmps = 0; } + +QString FirmwarePlugin::autoDisarmParameter(Vehicle* vehicle) +{ + Q_UNUSED(vehicle); + return QString(); +} diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index 034bcfedb..20ede0740 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -282,6 +282,9 @@ public: /// @param[out] cruiseAmps Current draw in amps during cruise virtual void batteryConsumptionData(Vehicle* vehicle, int& mAhBattery, double& hoverAmps, double& cruiseAmps) const; + // Returns the parameter which control auto-dismar. Assume == 0 means no auto disarm + virtual QString autoDisarmParameter(Vehicle* vehicle); + // FIXME: Hack workaround for non pluginize FollowMe support static const char* px4FollowMeFlightMode; diff --git a/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h b/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h index c75bb8dcf..7778c2551 100644 --- a/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h +++ b/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h @@ -67,6 +67,7 @@ public: QString brandImageIndoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); } QString brandImageOutdoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); } bool vehicleYawsToNextWaypointInMission(const Vehicle* vehicle) const override; + QString autoDisarmParameter (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral("COM_DISARM_LAND"); } protected: typedef struct { diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 347edf223..3d8164b96 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -34,6 +34,8 @@ QGCView { QGCPalette { id: qgcPal; colorGroupEnabled: enabled } + property alias guidedController: guidedActionsController + property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle @@ -444,7 +446,7 @@ QGCView { } GuidedActionsController { - id: guidedController + id: guidedActionsController missionController: flyMissionController z: _flightVideoPipControl.z + 1 diff --git a/src/FlightDisplay/GuidedActionsController.qml b/src/FlightDisplay/GuidedActionsController.qml index ce73f713c..35d9e03b5 100644 --- a/src/FlightDisplay/GuidedActionsController.qml +++ b/src/FlightDisplay/GuidedActionsController.qml @@ -46,8 +46,8 @@ Item { readonly property string setWaypointTitle: qsTr("Set Waypoint") readonly property string gotoTitle: qsTr("Goto Location") - readonly property string armMessage: qsTr("arm") - readonly property string disarmMessage: qsTr("disarm") + readonly property string armMessage: qsTr("Arm the vehicle.") + readonly property string disarmMessage: qsTr("Disarm the vehicle") readonly property string emergencyStopMessage: qsTr("WARNING: This still stop all motors. If vehicle is currently in air it will crash.") readonly property string takeoffMessage: qsTr("Takeoff from ground and hold position.") readonly property string startMissionMessage: qsTr("Start the mission which is currently displayed above. If the vehicle is on the ground it will takeoff.") @@ -109,10 +109,16 @@ Item { _actionData = actionData switch (actionCode) { case actionArm: + if (_activeVehicle.flying) { + return + } title = armTitle message = armMessage break; case actionDisarm: + if (_activeVehicle.flying) { + return + } title = disarmTitle message = disarmMessage break; diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 2bed10ccc..f0daf4379 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -1647,10 +1647,8 @@ void Vehicle::_startMissionRequest(void) void Vehicle::_parametersReady(bool parametersReady) { if (parametersReady) { + _setupAutoDisarmSignalling(); _startMissionRequest(); - } - - if (parametersReady) { setJoystickEnabled(_joystickEnabled); } } @@ -2413,6 +2411,29 @@ bool Vehicle::vehicleYawsToNextWaypointInMission(void) const return _firmwarePlugin->vehicleYawsToNextWaypointInMission(this); } +void Vehicle::_setupAutoDisarmSignalling(void) +{ + QString param = _firmwarePlugin->autoDisarmParameter(this); + + if (!param.isEmpty() && _parameterManager->parameterExists(FactSystem::defaultComponentId, param)) { + Fact* fact = _parameterManager->getParameter(FactSystem::defaultComponentId,param); + connect(fact, &Fact::rawValueChanged, this, &Vehicle::autoDisarmChanged); + emit autoDisarmChanged(); + } +} + +bool Vehicle::autoDisarm(void) +{ + QString param = _firmwarePlugin->autoDisarmParameter(this); + + if (!param.isEmpty() && _parameterManager->parameterExists(FactSystem::defaultComponentId, param)) { + Fact* fact = _parameterManager->getParameter(FactSystem::defaultComponentId,param); + return fact->rawValue().toDouble() > 0; + } + + return false; +} + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 3021a662c..4b9d4b2fb 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -240,6 +240,7 @@ public: Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) Q_PROPERTY(QGeoCoordinate homePosition READ homePosition NOTIFY homePositionChanged) Q_PROPERTY(bool armed READ armed WRITE setArmed NOTIFY armedChanged) + Q_PROPERTY(bool autoDisarm READ autoDisarm NOTIFY autoDisarmChanged) Q_PROPERTY(bool flightModeSetAvailable READ flightModeSetAvailable CONSTANT) Q_PROPERTY(QStringList flightModes READ flightModes CONSTANT) Q_PROPERTY(QString flightMode READ flightMode WRITE setFlightMode NOTIFY flightModeChanged) @@ -588,6 +589,7 @@ public: unsigned int telemetryTXBuffer () { return _telemetryTXBuffer; } unsigned int telemetryLNoise () { return _telemetryLNoise; } unsigned int telemetryRNoise () { return _telemetryRNoise; } + bool autoDisarm (); Fact* roll (void) { return &_rollFact; } Fact* heading (void) { return &_headingFact; } @@ -717,6 +719,7 @@ signals: void telemetryTXBufferChanged (unsigned int value); void telemetryLNoiseChanged (unsigned int value); void telemetryRNoiseChanged (unsigned int value); + void autoDisarmChanged (void); void firmwareMajorVersionChanged(int major); void firmwareMinorVersionChanged(int minor); @@ -825,6 +828,7 @@ private: void _updatePriorityLink(void); void _commonInit(void); void _startMissionRequest(void); + void _setupAutoDisarmSignalling(void); int _id; ///< Mavlink system id int _defaultComponentId; diff --git a/src/ui/MainWindowInner.qml b/src/ui/MainWindowInner.qml index a044a712c..3a7ebe1f6 100644 --- a/src/ui/MainWindowInner.qml +++ b/src/ui/MainWindowInner.qml @@ -265,12 +265,16 @@ Item { anchors.top: parent.top opacity: planToolBar.visible ? 0 : 1 z: QGroundControl.zOrderTopMost + Component.onCompleted: ScreenTools.availableHeight = parent.height - toolBar.height onShowSettingsView: mainWindow.showSettingsView() onShowSetupView: mainWindow.showSetupView() onShowPlanView: mainWindow.showPlanView() onShowFlyView: mainWindow.showFlyView() onShowAnalyzeView: mainWindow.showAnalyzeView() + onArmVehicle: flightView.guidedController.confirmAction(flightView.guidedController.actionArm) + onDisarmVehicle: flightView.guidedController.confirmAction(flightView.guidedController.actionDisarm) + //-- Entire tool bar area disable on cammand MouseArea { id: toolbarBlocker diff --git a/src/ui/toolbar/ArmedIndicator.qml b/src/ui/toolbar/ArmedIndicator.qml new file mode 100644 index 000000000..9428825e5 --- /dev/null +++ b/src/ui/toolbar/ArmedIndicator.qml @@ -0,0 +1,42 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.2 + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.MultiVehicleManager 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Palette 1.0 + +//------------------------------------------------------------------------- +//-- Armed Indicator +QGCLabel { + anchors.top: parent.top + anchors.bottom: parent.bottom + verticalAlignment: Text.AlignVCenter + text: _armed ? qsTr("Armed") : qsTr("Disarmed") + font.pointSize: ScreenTools.mediumFontPointSize + color: qgcPal.buttonText + visible: !_autoDisarm || _fixedWing + + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property bool _autoDisarm: _activeVehicle ? _activeVehicle.autoDisarm : false + property bool _fixedWing: _activeVehicle ? _activeVehicle.fixedWing : false + property bool _armed: _activeVehicle ? _activeVehicle.armed : false + + QGCPalette { id: qgcPal } + + QGCMouseArea { + fillItem: parent + onClicked: _armed ? toolBar.disarmVehicle() : toolBar.armVehicle() + } +} diff --git a/src/ui/toolbar/MainToolBar.qml b/src/ui/toolbar/MainToolBar.qml index bd51817ef..03101ddca 100644 --- a/src/ui/toolbar/MainToolBar.qml +++ b/src/ui/toolbar/MainToolBar.qml @@ -31,6 +31,8 @@ Rectangle { signal showPlanView signal showFlyView signal showAnalyzeView + signal armVehicle + signal disarmVehicle function checkSettingsButton() { settingsButton.checked = true -- 2.22.0