Skip to content

Commit b9f6bc4

Browse files
authored
Merge pull request #8785 from mavlink/VirtualJoystickReverse
Rework reverse/center throttle support. Fix right stick centering bug.
2 parents 4d76c8b + eec06e4 commit b9f6bc4

File tree

9 files changed

+78
-69
lines changed

9 files changed

+78
-69
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Note: This file only contains high level features or important fixes.
77
## 4.0.7 - Not yet released
88

99
* Fix video page sizing
10+
* Virtual Joystick: Fix right stick centering. Fix/add support for rover/sub reverse throttle support.
1011
* Fix display of multiple ADSB vehicles
1112

1213
### 4.0.6 - Stable

src/FlightDisplay/FlightDisplayView.qml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,17 @@ Item {
544544
z: _mapAndVideo.z + 5
545545
width: parent.width - (_flightVideoPipControl.width / 2)
546546
height: Math.min(mainWindow.height * 0.25, ScreenTools.defaultFontPixelWidth * 16)
547-
visible: (_virtualJoystick ? _virtualJoystick.value : false) && !QGroundControl.videoManager.fullScreen && !(activeVehicle ? activeVehicle.highLatencyLink : false)
547+
visible: _virtualJoystickEnabled && !QGroundControl.videoManager.fullScreen && !(activeVehicle ? activeVehicle.highLatencyLink : false)
548548
anchors.bottom: _flightVideoPipControl.top
549549
anchors.bottomMargin: ScreenTools.defaultFontPixelHeight * 2
550550
anchors.horizontalCenter: flightDisplayViewWidgets.horizontalCenter
551551
source: "qrc:/qml/VirtualJoystick.qml"
552-
active: (_virtualJoystick ? _virtualJoystick.value : false) && !(activeVehicle ? activeVehicle.highLatencyLink : false)
552+
active: _virtualJoystickEnabled && !(activeVehicle ? activeVehicle.highLatencyLink : false)
553553

554-
property bool useLightColors: isBackgroundDark
555-
// The default behaviour is not centralized throttle
556-
property bool centralizeThrottle: _virtualJoystickCentralized ? _virtualJoystickCentralized.value : false
554+
property bool useLightColors: isBackgroundDark
555+
property bool autoCenterThrottle: QGroundControl.settingsManager.appSettings.virtualJoystickAutoCenterThrottle.rawValue
557556

558-
property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
559-
property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
557+
property bool _virtualJoystickEnabled: QGroundControl.settingsManager.appSettings.virtualJoystick.rawValue
560558
}
561559

562560
ToolStrip {

src/FlightDisplay/FlightDisplayViewWidgets.qml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ Item {
9595
target: QGroundControl.settingsManager.appSettings.virtualJoystick
9696
onValueChanged: _setInstrumentWidget()
9797
}
98-
Connections {
99-
target: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
100-
onValueChanged: _setInstrumentWidget()
101-
}
10298

10399
Connections {
104100
target: QGroundControl.settingsManager.appSettings.showLargeCompass

src/FlightDisplay/VirtualJoystick.qml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ import QGroundControl.Palette 1.0
1717
import QGroundControl.Vehicle 1.0
1818

1919
Item {
20-
//property bool useLightColors - Must be passed in from loaded
21-
//property bool centralizeThrottle - Must be passed in from loaded
20+
// The following properties must be passed in from the Loader
21+
// property bool useLightColors
22+
// property bool autoCenterThrottle - true: throttle will snap back to center when released
23+
24+
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
25+
2226
Timer {
2327
interval: 40 // 25Hz, same as real joystick rate
2428
running: QGroundControl.settingsManager.appSettings.virtualJoystick.value && activeVehicle
2529
repeat: true
2630
onTriggered: {
2731
if (activeVehicle) {
28-
activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis)
32+
activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, -rightStick.yAxis, leftStick.xAxis, leftStick.yAxis)
2933
}
3034
}
3135
}
@@ -38,8 +42,8 @@ Item {
3842
anchors.bottom: parent.bottom
3943
width: parent.height
4044
height: parent.height
41-
yAxisThrottle: true
42-
yAxisThrottleCentered: centralizeThrottle
45+
yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && !_activeVehicle.sub
46+
yAxisReCenter: autoCenterThrottle
4347
lightColors: useLightColors
4448
}
4549

src/QmlControls/JoystickThumbPad.qml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ import QGroundControl.ScreenTools 1.0
77
Item {
88
id: _joyRoot
99

10-
property alias lightColors: mapPal.lightColors ///< true: use light colors from QGCMapPalette for drawing
11-
property real xAxis: 0 ///< Value range [-1,1], negative values left stick, positive values right stick
12-
property real yAxis: 0 ///< Value range [-1,1], negative values up stick, positive values down stick
13-
property bool yAxisThrottle: false ///< true: yAxis used for throttle, range [1,0], positive value are stick up
14-
property bool yAxisThrottleCentered: false ///< false: center yAxis in throttle for reverser and forward
15-
property real xPositionDelta: 0 ///< Amount to move the control on x axis
16-
property real yPositionDelta: 0 ///< Amount to move the control on y axis
17-
property bool springYToCenter:true ///< true: Spring Y to center on release
10+
property alias lightColors: mapPal.lightColors ///< true: use light colors from QGCMapPalette for drawing
11+
property real xAxis: 0 ///< Value range [-1,1], negative values left stick, positive values right stick
12+
property real yAxis: 0 ///< Value range [-1,1], negative values down stick, positive values up stick
13+
property bool yAxisPositiveRangeOnly: false ///< true: value range [0,1], false: value range [-1,1]
14+
property bool yAxisReCenter: true ///< true: snaps back to center on release, false: stays at current position on release
15+
property real xPositionDelta: 0 ///< Amount to move the control on x axis
16+
property real yPositionDelta: 0 ///< Amount to move the control on y axis
1817

1918
property real _centerXY: width / 2
2019
property bool _processTouchPoints: false
2120
property real stickPositionX: _centerXY
22-
property real stickPositionY: yAxisThrottleCentered ? _centerXY : height
21+
property real stickPositionY: yAxisReCenter ? _centerXY : height
2322

2423
QGCMapPalette { id: mapPal }
2524

26-
onWidthChanged: calculateXAxis()
27-
onStickPositionXChanged: calculateXAxis()
28-
onHeightChanged: calculateYAxis()
29-
onStickPositionYChanged: calculateYAxis()
25+
onWidthChanged: calculateXAxis()
26+
onStickPositionXChanged: calculateXAxis()
27+
onHeightChanged: calculateYAxis()
28+
onStickPositionYChanged: calculateYAxis()
29+
onYAxisPositiveRangeOnlyChanged: calculateYAxis()
3030

3131
function calculateXAxis() {
3232
if(!_joyRoot.visible) {
@@ -42,13 +42,13 @@ Item {
4242
if(!_joyRoot.visible) {
4343
return;
4444
}
45-
var yAxisTemp = stickPositionY / height
46-
yAxisTemp *= 2.0
47-
yAxisTemp -= 1.0
48-
if (yAxisThrottle) {
49-
yAxisTemp = ((yAxisTemp * -1.0) / 2.0) + 0.5
45+
var fullRange = yAxisPositiveRangeOnly ? 1 : 2
46+
var pctUp = 1.0 - (stickPositionY / height)
47+
var rangeUp = pctUp * fullRange
48+
if (!yAxisPositiveRangeOnly) {
49+
rangeUp -= 1
5050
}
51-
yAxis = yAxisTemp
51+
yAxis = rangeUp
5252
}
5353

5454
function reCenter() {
@@ -58,17 +58,17 @@ Item {
5858
xPositionDelta = 0
5959
yPositionDelta = 0
6060

61-
// Center sticks
61+
// Re-Center sticks as needed
6262
stickPositionX = _centerXY
63-
if (yAxisThrottleCentered) {
63+
if (yAxisReCenter) {
6464
stickPositionY = _centerXY
6565
}
6666
}
6767

6868
function thumbDown(touchPoints) {
6969
// Position the control around the initial thumb position
7070
xPositionDelta = touchPoints[0].x - _centerXY
71-
if (yAxisThrottle) {
71+
if (yAxisPositiveRangeOnly) {
7272
yPositionDelta = touchPoints[0].y - stickPositionY
7373
} else {
7474
yPositionDelta = touchPoints[0].y - _centerXY
@@ -94,7 +94,7 @@ Item {
9494

9595
QGCColoredImage {
9696
color: lightColors ? "white" : "black"
97-
visible: yAxisThrottle
97+
visible: yAxisPositiveRangeOnly
9898
height: ScreenTools.defaultFontPixelHeight
9999
width: height
100100
sourceSize.height: height
@@ -108,7 +108,7 @@ Item {
108108

109109
QGCColoredImage {
110110
color: lightColors ? "white" : "black"
111-
visible: yAxisThrottle
111+
visible: yAxisPositiveRangeOnly
112112
height: ScreenTools.defaultFontPixelHeight
113113
width: height
114114
sourceSize.height: height
@@ -122,7 +122,7 @@ Item {
122122

123123
QGCColoredImage {
124124
color: lightColors ? "white" : "black"
125-
visible: yAxisThrottle
125+
visible: yAxisPositiveRangeOnly
126126
height: ScreenTools.defaultFontPixelHeight
127127
width: height
128128
sourceSize.height: height
@@ -136,7 +136,7 @@ Item {
136136

137137
QGCColoredImage {
138138
color: lightColors ? "white" : "black"
139-
visible: yAxisThrottle
139+
visible: yAxisPositiveRangeOnly
140140
height: ScreenTools.defaultFontPixelHeight
141141
width: height
142142
sourceSize.height: height
@@ -200,9 +200,6 @@ Item {
200200
maximumTouchPoints: 1
201201
touchPoints: [ TouchPoint { id: touchPoint } ]
202202
onPressed: _joyRoot.thumbDown(touchPoints)
203-
onReleased: {
204-
if(springYToCenter)
205-
_joyRoot.reCenter()
206-
}
203+
onReleased: _joyRoot.reCenter()
207204
}
208205
}

src/Settings/App.SettingsGroup.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
"defaultValue": false
112112
},
113113
{
114-
"name": "virtualJoystickCentralized",
115-
"shortDescription": "Set virtual joystick to be centralize throttle (spring-loaded).",
116-
"longDescription": "If this option is enabled the virtual joystick throttle stick will be centralized.",
114+
"name": "virtualJoystickAutoCenterThrottle",
115+
"shortDescription": "Auto-Center Throttle",
116+
"longDescription": "If enabled the throttle stick will snap back to center when released.",
117117
"type": "bool",
118118
"defaultValue": false
119119
},

src/Settings/AppSettings.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ DECLARE_SETTINGGROUP(App, "")
3939
qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
4040
QGCPalette::setGlobalTheme(indoorPalette()->rawValue().toBool() ? QGCPalette::Dark : QGCPalette::Light);
4141

42+
// virtualJoystickCentralized -> virtualJoystickAutoCenterThrottle
43+
QSettings settings;
44+
settings.beginGroup(_settingsGroup);
45+
QString deprecatedVirtualJoystickCentralizedKey("virtualJoystickCentralized");
46+
if (settings.contains(deprecatedVirtualJoystickCentralizedKey)) {
47+
settings.setValue(virtualJoystickAutoCenterThrottleName, settings.value(deprecatedVirtualJoystickCentralizedKey));
48+
settings.remove(deprecatedVirtualJoystickCentralizedKey);
49+
}
50+
4251
// Instantiate savePath so we can check for override and setup default path if needed
4352

4453
SettingsFact* savePathFact = qobject_cast<SettingsFact*>(savePath());
@@ -85,7 +94,7 @@ DECLARE_SETTINGSFACT(AppSettings, telemetrySaveNotArmed)
8594
DECLARE_SETTINGSFACT(AppSettings, audioMuted)
8695
DECLARE_SETTINGSFACT(AppSettings, checkInternet)
8796
DECLARE_SETTINGSFACT(AppSettings, virtualJoystick)
88-
DECLARE_SETTINGSFACT(AppSettings, virtualJoystickCentralized)
97+
DECLARE_SETTINGSFACT(AppSettings, virtualJoystickAutoCenterThrottle)
8998
DECLARE_SETTINGSFACT(AppSettings, appFontPointSize)
9099
DECLARE_SETTINGSFACT(AppSettings, showLargeCompass)
91100
DECLARE_SETTINGSFACT(AppSettings, savePath)

src/Settings/AppSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AppSettings : public SettingsGroup
3939
DEFINE_SETTINGFACT(audioMuted)
4040
DEFINE_SETTINGFACT(checkInternet)
4141
DEFINE_SETTINGFACT(virtualJoystick)
42-
DEFINE_SETTINGFACT(virtualJoystickCentralized)
42+
DEFINE_SETTINGFACT(virtualJoystickAutoCenterThrottle)
4343
DEFINE_SETTINGFACT(appFontPointSize)
4444
DEFINE_SETTINGFACT(indoorPalette)
4545
DEFINE_SETTINGFACT(showLargeCompass)

src/ui/preferences/GeneralSettings.qml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ Rectangle {
3030
anchors.fill: parent
3131
anchors.margins: ScreenTools.defaultFontPixelWidth
3232

33-
property Fact _percentRemainingAnnounce: QGroundControl.settingsManager.appSettings.batteryPercentRemainingAnnounce
34-
property Fact _savePath: QGroundControl.settingsManager.appSettings.savePath
35-
property Fact _appFontPointSize: QGroundControl.settingsManager.appSettings.appFontPointSize
36-
property Fact _userBrandImageIndoor: QGroundControl.settingsManager.brandImageSettings.userBrandImageIndoor
37-
property Fact _userBrandImageOutdoor: QGroundControl.settingsManager.brandImageSettings.userBrandImageOutdoor
33+
property Fact _percentRemainingAnnounce: QGroundControl.settingsManager.appSettings.batteryPercentRemainingAnnounce
34+
property Fact _savePath: QGroundControl.settingsManager.appSettings.savePath
35+
property Fact _appFontPointSize: QGroundControl.settingsManager.appSettings.appFontPointSize
36+
property Fact _userBrandImageIndoor: QGroundControl.settingsManager.brandImageSettings.userBrandImageIndoor
37+
property Fact _userBrandImageOutdoor: QGroundControl.settingsManager.brandImageSettings.userBrandImageOutdoor
38+
property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
39+
property Fact _virtualJoystickAutoCenterThrottle: QGroundControl.settingsManager.appSettings.virtualJoystickAutoCenterThrottle
40+
3841
property real _labelWidth: ScreenTools.defaultFontPixelWidth * 20
3942
property real _comboFieldWidth: ScreenTools.defaultFontPixelWidth * 30
4043
property real _valueFieldWidth: ScreenTools.defaultFontPixelWidth * 10
@@ -512,22 +515,23 @@ Rectangle {
512515
property Fact _showLogReplayStatusBar: QGroundControl.settingsManager.flyViewSettings.showLogReplayStatusBar
513516
}
514517

515-
FactCheckBox {
516-
text: qsTr("Virtual Joystick")
517-
visible: _virtualJoystick.visible
518-
fact: _virtualJoystick
519-
520-
property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
521-
}
518+
RowLayout {
519+
spacing: ScreenTools.defaultFontPixelWidth
522520

523-
FactCheckBox {
524-
text: qsTr("Auto-Center throttle")
525-
visible: _virtualJoystickCentralized.visible && activeVehicle && (activeVehicle.sub || activeVehicle.rover)
526-
fact: _virtualJoystickCentralized
527-
Layout.leftMargin: _margins
521+
FactCheckBox {
522+
text: qsTr("Virtual Joystick")
523+
visible: _virtualJoystick.visible
524+
fact: _virtualJoystick
525+
}
528526

529-
property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
527+
FactCheckBox {
528+
text: qsTr("Auto-Center Throttle")
529+
visible: _virtualJoystickAutoCenterThrottle.visible
530+
enabled: _virtualJoystick.rawValue
531+
fact: _virtualJoystickAutoCenterThrottle
532+
}
530533
}
534+
531535
FactCheckBox {
532536
text: qsTr("Use Vertical Instrument Panel")
533537
visible: _alternateInstrumentPanel.visible

0 commit comments

Comments
 (0)