Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/FlightDisplay/VehicleWarnings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ import QtQuick
import QGroundControl
import QGroundControl.ScreenTools
import QGroundControl.Controls
import QGroundControl.FactSystem

Rectangle {
anchors.margins: -ScreenTools.defaultFontPixelHeight
height: warningsCol.height
width: warningsCol.width
color: Qt.rgba(1, 1, 1, 0.5)
radius: ScreenTools.defaultFontPixelWidth / 2
visible: _noGPSLockVisible || _prearmErrorVisible
visible: _noGPSLockVisible || _prearmErrorVisible || (_showAltitudeWarning && (_vehicleAltitudeBelowMin || _vehicleAltitudeAboveMax || !_terrainDataAvailable.value))

property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property bool _noGPSLockVisible: _activeVehicle && _activeVehicle.requiresGpsFix && !_activeVehicle.coordinate.isValid
property bool _prearmErrorVisible: _activeVehicle && !_activeVehicle.armed && _activeVehicle.prearmError && !_activeVehicle.healthAndArmingCheckReport.supported
property bool _prearmErrorVisible: _activeVehicle && !_activeVehicle.armed && _activeVehicle.prearmError

property Fact _altitudeWarnThresholdEnabled: QGroundControl.settingsManager.flyViewSettings.altitudeWarnThresholdEnabled
property Fact _altitudeWarnMinAGL: QGroundControl.settingsManager.flyViewSettings.altitudeWarnMinAGL
property Fact _altitudeWarnMaxAGL: QGroundControl.settingsManager.flyViewSettings.altitudeWarnMaxAGL
property Fact _altitudeAboveTerrain: _activeVehicle ? _activeVehicle.altitudeAboveTerr : null
property Fact _terrainDataAvailable: _activeVehicle ? _activeVehicle.terrainDataAvailable : null
property bool _vehicleAltitudeBelowMin: _altitudeAboveTerrain ? (_altitudeAboveTerrain.value < _altitudeWarnMinAGL.value) : false
property bool _vehicleAltitudeAboveMax: _altitudeAboveTerrain ? (_altitudeAboveTerrain.value > _altitudeWarnMaxAGL.value) : false
property bool _showAltitudeWarning: _activeVehicle && _activeVehicle.flying && !_activeVehicle.landing && _altitudeWarnThresholdEnabled.value

Column {
id: warningsCol
Expand All @@ -45,6 +55,30 @@ Rectangle {
text: _activeVehicle ? _activeVehicle.prearmError : ""
}

QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
visible: _showAltitudeWarning && _terrainDataAvailable.value && _vehicleAltitudeBelowMin
color: "black"
font.pointSize: ScreenTools.largeFontPointSize
text: visible ? qsTr("Altitude below minimum threshold of %1 %2 above terrain: (%3 %4)").arg(_altitudeWarnMinAGL.value).arg(_altitudeWarnMinAGL.units).arg(_altitudeAboveTerrain.value.toFixed(2)).arg(_altitudeAboveTerrain.units) : ""
}

QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
visible: _showAltitudeWarning && _terrainDataAvailable.value && _vehicleAltitudeAboveMax
color: "black"
font.pointSize: ScreenTools.largeFontPointSize
text: visible ? qsTr("Altitude above maximum threshold of %1 %2 above terrain: (%3 %4)").arg(_altitudeWarnMaxAGL.value).arg(_altitudeWarnMaxAGL.units).arg(_altitudeAboveTerrain.value.toFixed(2)).arg(_altitudeAboveTerrain.units) : ""
}

QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
visible: _showAltitudeWarning && !_terrainDataAvailable.value
color: "black"
font.pointSize: ScreenTools.largeFontPointSize
text: qsTr("Terrain data not available at vehicle pos, altitude warning thresholds are disabled")
}

QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
visible: _prearmErrorVisible
Expand Down
27 changes: 27 additions & 0 deletions src/Settings/FlyView.SettingsGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@
"min": 3,
"max": 60,
"default": 10
},
{
"name": "altitudeWarnThresholdEnabled",
"shortDesc": "Altitude warning threshold enabled",
"longDesc": "If this option is enabled, warn user if drone flies above or below altitude threshold.",
"type": "bool",
"default": false
},
{
"name": "altitudeWarnMinAGL",
"shortDesc": "Minimum altitude AGL for warning",
"longDesc": "Minimum altitude warning threshold in meters above ground level.",
"type": "double",
"default": 2.0,
"min": 0.0,
"units": "m",
"decimalPlaces": 1
},
{
"name": "altitudeWarnMaxAGL",
"shortDesc": "Minimum altitude AGL for warning",
"longDesc": "Minimum altitude warning threshold in meters above ground level.",
"type": "double",
"default": 121.92,
"min": 0.0,
"units": "m",
"decimalPlaces": 1
}
]
}
3 changes: 3 additions & 0 deletions src/Settings/FlyViewSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ DECLARE_SETTINGSFACT(FlyViewSettings, updateHomePosition)
DECLARE_SETTINGSFACT(FlyViewSettings, instrumentQmlFile2)
DECLARE_SETTINGSFACT(FlyViewSettings, requestControlAllowTakeover)
DECLARE_SETTINGSFACT(FlyViewSettings, requestControlTimeout)
DECLARE_SETTINGSFACT(FlyViewSettings, altitudeWarnThresholdEnabled)
DECLARE_SETTINGSFACT(FlyViewSettings, altitudeWarnMinAGL)
DECLARE_SETTINGSFACT(FlyViewSettings, altitudeWarnMaxAGL)
3 changes: 3 additions & 0 deletions src/Settings/FlyViewSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ class FlyViewSettings : public SettingsGroup
DEFINE_SETTINGFACT(instrumentQmlFile2)
DEFINE_SETTINGFACT(requestControlAllowTakeover)
DEFINE_SETTINGFACT(requestControlTimeout)
DEFINE_SETTINGFACT(altitudeWarnThresholdEnabled)
DEFINE_SETTINGFACT(altitudeWarnMinAGL)
DEFINE_SETTINGFACT(altitudeWarnMaxAGL)
};
28 changes: 28 additions & 0 deletions src/UI/AppSettings/FlyViewSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ SettingsPage {
}
}

SettingsGroupLayout {
Layout.fillWidth: true
heading: qsTr("Altitude above ground level warning threshold")

FactCheckBoxSlider {
Layout.fillWidth: true
text: qsTr("Altitude warning enabled")
visible: fact.visible
fact: _flyViewSettings.altitudeWarnThresholdEnabled
}

LabelledFactTextField {
Layout.fillWidth: true
label: qsTr("Minimum Altitude")
fact: _flyViewSettings.altitudeWarnMinAGL
visible: fact.visible
enabled: _flyViewSettings.altitudeWarnThresholdEnabled.value
}

LabelledFactTextField {
Layout.fillWidth: true
label: qsTr("Maximum Altitude")
fact: _flyViewSettings.altitudeWarnMaxAGL
visible: fact.visible
enabled: _flyViewSettings.altitudeWarnThresholdEnabled.value
}
}

SettingsGroupLayout {
Layout.fillWidth: true
heading: qsTr("Guided Commands")
Expand Down
6 changes: 6 additions & 0 deletions src/Vehicle/FactGroups/VehicleFact.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
"decimalPlaces": 1,
"units": "m"
},
{
"name": "terrainDataAvailable",
"shortDesc": "Terrain Data Available",
"type": "bool",
"defaultValue": false
},
{
"name": "flightDistance",
"shortDesc": "Flight Distance",
Expand Down
1 change: 1 addition & 0 deletions src/Vehicle/FactGroups/VehicleFactGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ VehicleFactGroup::VehicleFactGroup(QObject *parent)
_addFact(&_altitudeRelativeFact);
_addFact(&_altitudeAMSLFact);
_addFact(&_altitudeAboveTerrFact);
_addFact(&_terrainDataAvailableFact);
_addFact(&_altitudeTuningFact);
_addFact(&_altitudeTuningSetpointFact);
_addFact(&_xTrackErrorFact);
Expand Down
3 changes: 3 additions & 0 deletions src/Vehicle/FactGroups/VehicleFactGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class VehicleFactGroup : public FactGroup
Q_PROPERTY(Fact *altitudeRelative READ altitudeRelative CONSTANT)
Q_PROPERTY(Fact *altitudeAMSL READ altitudeAMSL CONSTANT)
Q_PROPERTY(Fact *altitudeAboveTerr READ altitudeAboveTerr CONSTANT)
Q_PROPERTY(Fact *terrainDataAvailable READ terrainDataAvailable CONSTANT)
Q_PROPERTY(Fact *altitudeTuning READ altitudeTuning CONSTANT)
Q_PROPERTY(Fact *altitudeTuningSetpoint READ altitudeTuningSetpoint CONSTANT)
Q_PROPERTY(Fact *xTrackError READ xTrackError CONSTANT)
Expand Down Expand Up @@ -61,6 +62,7 @@ class VehicleFactGroup : public FactGroup
Fact *altitudeRelative() { return &_altitudeRelativeFact; }
Fact *altitudeAMSL() { return &_altitudeAMSLFact; }
Fact *altitudeAboveTerr() { return &_altitudeAboveTerrFact; }
Fact *terrainDataAvailable() { return &_terrainDataAvailableFact; }
Fact *altitudeTuning() { return &_altitudeTuningFact; }
Fact *altitudeTuningSetpoint() { return &_altitudeTuningSetpointFact; }
Fact *xTrackError() { return &_xTrackErrorFact; }
Expand Down Expand Up @@ -105,6 +107,7 @@ class VehicleFactGroup : public FactGroup
Fact _altitudeRelativeFact = Fact(0, QStringLiteral("altitudeRelative"), FactMetaData::valueTypeDouble);
Fact _altitudeAMSLFact = Fact(0, QStringLiteral("altitudeAMSL"), FactMetaData::valueTypeDouble);
Fact _altitudeAboveTerrFact = Fact(0, QStringLiteral("altitudeAboveTerr"), FactMetaData::valueTypeDouble);
Fact _terrainDataAvailableFact = Fact(0, QStringLiteral("terrainDataAvailable"), FactMetaData::valueTypeBool);
Fact _altitudeTuningFact = Fact(0, QStringLiteral("altitudeTuning"), FactMetaData::valueTypeDouble);
Fact _altitudeTuningSetpointFact = Fact(0, QStringLiteral("altitudeTuningSetpoint"), FactMetaData::valueTypeDouble);
Fact _xTrackErrorFact = Fact(0, QStringLiteral("xTrackError"), FactMetaData::valueTypeDouble);
Expand Down
14 changes: 11 additions & 3 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3766,11 +3766,19 @@ void Vehicle::_updateAltAboveTerrain()
void Vehicle::_altitudeAboveTerrainReceived(bool success, QList<double> heights)
{
if (!success) {
qCDebug(VehicleLog) << "_altitudeAboveTerrainReceived: terrain data not available for vehicle coordinate";
qCDebug(VehicleLog) << "terrain data not available for vehicle coordinate";
if (_coordinate.isValid() &&
SettingsManager::instance()->flyViewSettings()->altitudeWarnThresholdEnabled()->rawValue().toBool() && _flying) {
_terrainDataAvailableFact.setRawValue(false);
}
_altitudeAboveTerrFact.setRawValue(qQNaN()); // Reset the altitude above terrain fact to NaN
} else {
if (!_terrainDataAvailableFact.rawValue().toBool()) {
_terrainDataAvailableFact.setRawValue(true);
}
// Query was succesful, save the data.
double terrainAltitude = heights[0];
double altitudeAboveTerrain = altitudeAMSL()->rawValue().toDouble() - terrainAltitude;
const double terrainAltitude = heights[0];
const double altitudeAboveTerrain = altitudeAMSL()->rawValue().toDouble() - terrainAltitude;
_altitudeAboveTerrFact.setRawValue(altitudeAboveTerrain);
}
// Clean up
Expand Down
Loading