Skip to content

Commit

Permalink
Fix altitude slider and guidedactions for speed action:
Browse files Browse the repository at this point in the history
There were some errors where fixed wing would not show the action,
also unit conversion support for speed was added
  • Loading branch information
Davidsastresas authored and DonLakeFlyer committed Nov 17, 2023
1 parent 4c1f6c7 commit 8bffc3f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/FlightDisplay/GuidedActionsController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,24 @@ Item {
function setupSlider(actionCode) {
// generic defaults
guidedValueSlider.configureAsLinearSlider()
guidedValueSlider.setIsSpeedSlider(false)

if (actionCode === actionTakeoff) {
guidedValueSlider.setMinVal(_activeVehicle.minimumTakeoffAltitude())
guidedValueSlider.setValue(_activeVehicle ? _activeVehicle.minimumTakeoffAltitude() : 0)
guidedValueSlider.setDisplayText("Height")
} else if (actionCode === actionChangeSpeed) {
if (_activeVehicle.vtolInFwdFlight) {
guidedValueSlider.setIsSpeedSlider(true)
if (_fixedWing) {
guidedValueSlider.setDisplayText("Set Airspeed")
guidedValueSlider.setMinVal(_activeVehicle.minimumEquivalentAirspeed())
guidedValueSlider.setMaxVal(_activeVehicle.maximumEquivalentAirspeed())
guidedValueSlider.setValue(_activeVehicle.airSpeedSetpoint.rawValue)
} else {
guidedValueSlider.setMinVal(QGroundControl.unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.minimumEquivalentAirspeed()).toFixed(1))
guidedValueSlider.setMaxVal(QGroundControl.unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumEquivalentAirspeed()).toFixed(1))
guidedValueSlider.setValue(_activeVehicle.airSpeed.value)
} else if (!_fixedWing && _activeVehicle.haveMRSpeedLimits) {
guidedValueSlider.setDisplayText("Set Speed")
guidedValueSlider.setMinVal(0.1)
guidedValueSlider.setMaxVal(_activeVehicle.maximumHorizontalSpeedMultirotor())
guidedValueSlider.setValue(_activeVehicle.maximumHorizontalSpeedMultirotor()/2)
guidedValueSlider.setMinVal(QGroundControl.unitsConversion.metersSecondToAppSettingsSpeedUnits(0.1).toFixed(1))
guidedValueSlider.setMaxVal(QGroundControl.unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumHorizontalSpeedMultirotor()).toFixed(1))
guidedValueSlider.setValue(QGroundControl.unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumHorizontalSpeedMultirotor()/2).toFixed(1))
}
} else if (actionCode === actionChangeAlt || actionCode === actionOrbit || actionCode === actionGoto || actionCode === actionPause) {
guidedValueSlider.setDisplayText("New Alt(rel)")
Expand Down Expand Up @@ -599,10 +601,12 @@ Item {
break
case actionChangeSpeed:
if (_activeVehicle) {
// We need to convert back to m/s as that is what mavlink standard uses for MAV_CMD_DO_CHANGE_SPEED
var metersSecondSpeed = QGroundControl.unitsConversion.appSettingsSpeedUnitsToMetersSecond(sliderOutputValue).toFixed(1)
if (_activeVehicle.vtolInFwdFlight || _activeVehicle.fixedWing) {
_activeVehicle.guidedModeChangeEquivalentAirspeed(sliderOutputValue)
_activeVehicle.guidedModeChangeEquivalentAirspeed(metersSecondSpeed)
} else {
_activeVehicle.guidedModeChangeGroundSpeed(sliderOutputValue)
_activeVehicle.guidedModeChangeGroundSpeed(metersSecondSpeed)
}
}
break
Expand Down
15 changes: 13 additions & 2 deletions src/FlightDisplay/GuidedValueSlider.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Rectangle {
property real _sliderCenterValue: _vehicleAltitude
property string _displayText: ""
property bool _altSlider: true
property bool _speedSlider: false

property var sliderValue : valueSlider.value

Expand Down Expand Up @@ -75,6 +76,10 @@ Rectangle {
_displayText = text
}

function setIsSpeedSlider(isSpeed) {
_speedSlider = isSpeed
}

function getOutputValue() {
if (_altSlider) {
return valueField.newValue - _sliderCenterValue
Expand All @@ -101,7 +106,8 @@ Rectangle {
QGCLabel {
id: valueField
anchors.horizontalCenter: parent.horizontalCenter
text: newValueAppUnits + " " + QGroundControl.unitsConversion.appSettingsHorizontalDistanceUnitsString
text: newValueAppUnits + " " + (_speedSlider ? QGroundControl.unitsConversion.appSettingsSpeedUnitsString
: QGroundControl.unitsConversion.appSettingsHorizontalDistanceUnitsString)

property real newValue
property string newValueAppUnits
Expand All @@ -120,7 +126,12 @@ Rectangle {
function updateLinear(value) {
// value is between -1 and 1
newValue = _sliderMinVal + (value + 1) * 0.5 * (_sliderMaxVal - _sliderMinVal)
newValueAppUnits = QGroundControl.unitsConversion.metersToAppSettingsHorizontalDistanceUnits(newValue).toFixed(1)
if (_speedSlider) {
// Already working in converted units
newValueAppUnits = newValue.toFixed(1)
} else {
newValueAppUnits = QGroundControl.unitsConversion.metersToAppSettingsHorizontalDistanceUnits(newValue).toFixed(1)
}
}

function getSliderValueFromOutputLinear(val) {
Expand Down

0 comments on commit 8bffc3f

Please sign in to comment.