diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index ea3fb45a45c..236d10d83ef 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -122,6 +122,8 @@ class FirmwarePlugin : public QObject /// Returns the flight mode to use when the operator wants to take back control from autonomouse flight. virtual QString takeControlFlightMode(void) const { return QString(); } + virtual QString vtolTakeoffFlightMode(void) const { return QString(); } + /// Returns whether the vehicle is in guided mode or not. virtual bool isGuidedMode(const Vehicle* vehicle) const; diff --git a/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h b/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h index 4a3d86e3470..17267027a88 100644 --- a/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h +++ b/src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h @@ -42,6 +42,7 @@ class PX4FirmwarePlugin : public FirmwarePlugin QString takeControlFlightMode (void) const override { return _manualFlightMode; } QString gotoFlightMode (void) const override { return _holdFlightMode; } QString followFlightMode (void) const override { return _followMeFlightMode; }; + QString vtolTakeoffFlightMode (void) const override { return _vtolTakeoffFlightMode; } void pauseVehicle (Vehicle* vehicle) override; void guidedModeRTL (Vehicle* vehicle, bool smartRTL) override; void guidedModeLand (Vehicle* vehicle) override; diff --git a/src/FlightDisplay/GuidedActionsController.qml b/src/FlightDisplay/GuidedActionsController.qml index dd1caa4bc9d..f87e6215d7b 100644 --- a/src/FlightDisplay/GuidedActionsController.qml +++ b/src/FlightDisplay/GuidedActionsController.qml @@ -173,6 +173,7 @@ Item { property var vtolTakeoffLoiterCoordinate: null signal showVtolTakeoffLoiter + signal vtolTakeoffExecuted signal actionCancelled function _outputState() { @@ -185,7 +186,7 @@ Item { // generic defaults guidedValueSlider.configureAsLinearSlider() - if (actionCode === actionTakeoff) { + if (actionCode === actionTakeoff || actionCode === actionVtolTakeoff) { guidedValueSlider.setMinVal(_activeVehicle.minimumTakeoffAltitude()) guidedValueSlider.setValue(_activeVehicle ? _activeVehicle.minimumTakeoffAltitude() : 0) guidedValueSlider.setDisplayText("Height") @@ -504,8 +505,7 @@ Item { confirmDialog.title = takeoffTitle confirmDialog.message = takeoffMessage confirmDialog.hideTrigger = Qt.binding(function() { return !showTakeoff }) - altitudeSlider.setToMinimumTakeoff() - altitudeSlider.visible = true + guidedValueSlider.visible = true showVtolTakeoffLoiter() break; @@ -598,7 +598,8 @@ Item { } } case actionVtolTakeoff: - _activeVehicle.guidedModeVtolTakeoff(actionAltitudeChange, vtolTakeoffLoiterCoordinate.latitude, vtolTakeoffLoiterCoordinate.longitude) + _activeVehicle.guidedModeVtolTakeoff(sliderOutputValue, vtolTakeoffLoiterCoordinate.latitude, vtolTakeoffLoiterCoordinate.longitude) + vtolTakeoffExecuted() break default: console.warn(qsTr("Internal error: unknown actionCode"), actionCode) diff --git a/src/FlightDisplay/VtolTakeoffPreview.qml b/src/FlightDisplay/VtolTakeoffPreview.qml index 10ffb805124..4e2b573327c 100644 --- a/src/FlightDisplay/VtolTakeoffPreview.qml +++ b/src/FlightDisplay/VtolTakeoffPreview.qml @@ -26,6 +26,17 @@ Item { property var distHomeToLoiter : activeVehicle ? activeVehicle.loiterRadiusMeters * 3 : 0 + function destroyVisuals() + { + if ( _loiterComponent) { + _loiterComponent.destroy() + } + + if (_lineComponent) { + _lineComponent.destroy() + } + } + Component { id: lineComponent @@ -141,9 +152,8 @@ Item { target: (activeVehicle && activeVehicle.vtol) ? activeVehicle : null onVtolInFwdFlightChanged: { - if (_loiterComponent && activeVehicle.vtolInFwdFlight) { - _loiterComponent.destroy() - _lineComponent.destroy() + if (activeVehicle.vtolInFwdFlight) { + destroyVisuals() } } @@ -152,16 +162,16 @@ Item { if (success) { vtLoiterCircle.interactive = false } else { - if (_loiterComponent) { - _loiterComponent.destroy() - } - - if (_lineComponent) { - _lineComponent.destroy() - } + destroyVisuals() } } + onFlightModeChanged: { + if (_takeoff_executed && activeVehicle.flightMode !== activeVehicle.vtolTakeoffFlightMode) { + // this happens if a user aborts the vtol takeoff by changing flight mode + destroyVisuals() + } + } } Connections { @@ -179,17 +189,13 @@ Item { _takeoff_executed = false } + onVtolTakeoffExecuted: { + _takeoff_executed = true + } + onActionCancelled: { if (!_takeoff_executed) { - if (_loiterComponent) { - _loiterComponent.destroy() - } - - if (_lineComponent) { - _lineComponent.destroy() - } - - _guidedActionsController.vtolTakeoffLoiterCoordinate = QtPositioning.coordinate() + destroyVisuals() } } } diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 2681f2ae480..41d859d8092 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -3561,6 +3561,11 @@ QString Vehicle::followFlightMode() const return _firmwarePlugin->followFlightMode(); } +QString Vehicle::vtolTakeoffFlightMode() const +{ + return _firmwarePlugin->vtolTakeoffFlightMode(); +} + QString Vehicle::vehicleImageOpaque() const { if(_firmwarePlugin) diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 074b95c86a6..606b72be68d 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -220,6 +220,7 @@ class Vehicle : public FactGroup Q_PROPERTY(QString landFlightMode READ landFlightMode CONSTANT) Q_PROPERTY(QString takeControlFlightMode READ takeControlFlightMode CONSTANT) Q_PROPERTY(QString followFlightMode READ followFlightMode CONSTANT) + Q_PROPERTY(QString vtolTakeoffFlightMode READ vtolTakeoffFlightMode CONSTANT) Q_PROPERTY(QString firmwareTypeString READ firmwareTypeString NOTIFY firmwareTypeChanged) Q_PROPERTY(QString vehicleTypeString READ vehicleTypeString NOTIFY vehicleTypeChanged) Q_PROPERTY(QString vehicleImageOpaque READ vehicleImageOpaque CONSTANT) @@ -603,6 +604,7 @@ class Vehicle : public FactGroup QString landFlightMode () const; QString takeControlFlightMode () const; QString followFlightMode () const; + QString vtolTakeoffFlightMode () const; double defaultCruiseSpeed () const { return _defaultCruiseSpeed; } double defaultHoverSpeed () const { return _defaultHoverSpeed; } QString firmwareTypeString () const;