Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBapst committed Mar 21, 2022
1 parent db8e7fa commit fc7783a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/FirmwarePlugin/FirmwarePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/FlightDisplay/GuidedActionsController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Item {
property var vtolTakeoffLoiterCoordinate: null

signal showVtolTakeoffLoiter
signal vtolTakeoffExecuted
signal actionCancelled

function _outputState() {
Expand All @@ -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")
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
44 changes: 25 additions & 19 deletions src/FlightDisplay/VtolTakeoffPreview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -141,9 +152,8 @@ Item {
target: (activeVehicle && activeVehicle.vtol) ? activeVehicle : null

onVtolInFwdFlightChanged: {
if (_loiterComponent && activeVehicle.vtolInFwdFlight) {
_loiterComponent.destroy()
_lineComponent.destroy()
if (activeVehicle.vtolInFwdFlight) {
destroyVisuals()
}
}

Expand All @@ -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 {
Expand All @@ -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()
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,11 @@ QString Vehicle::followFlightMode() const
return _firmwarePlugin->followFlightMode();
}

QString Vehicle::vtolTakeoffFlightMode() const
{
return _firmwarePlugin->vtolTakeoffFlightMode();
}

QString Vehicle::vehicleImageOpaque() const
{
if(_firmwarePlugin)
Expand Down
2 changes: 2 additions & 0 deletions src/Vehicle/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fc7783a

Please sign in to comment.