Commit 524b8548 authored by Don Gagne's avatar Don Gagne

Virtual joystick support

parent 7661b921
......@@ -258,6 +258,7 @@ HEADERS += \
src/QGCFileDialog.h \
src/QGCGeo.h \
src/QGCLoggingCategory.h \
src/QGCMapPalette.h \
src/QGCMessageBox.h \
src/QGCPalette.h \
src/QGCQmlWidgetHolder.h \
......@@ -371,6 +372,7 @@ SOURCES += \
src/QGCDockWidget.cc \
src/QGCFileDialog.cc \
src/QGCLoggingCategory.cc \
src/QGCMapPalette.cc \
src/QGCPalette.cc \
src/QGCQmlWidgetHolder.cpp \
src/QGCQuickWidget.cc \
......
......@@ -32,6 +32,7 @@
<file alias="QGroundControl/Controls/DropButton.qml">src/QmlControls/DropButton.qml</file>
<file alias="QGroundControl/Controls/ExclusiveGroupItem.qml">src/QmlControls/ExclusiveGroupItem.qml</file>
<file alias="QGroundControl/Controls/IndicatorButton.qml">src/QmlControls/IndicatorButton.qml</file>
<file alias="QGroundControl/Controls/JoystickThumbPad.qml">src/QmlControls/JoystickThumbPad.qml</file>
<file alias="QGroundControl/Controls/MainToolBar.qml">src/ui/toolbar/MainToolBar.qml</file>
<file alias="QGroundControl/Controls/MainToolBarIndicators.qml">src/ui/toolbar/MainToolBarIndicators.qml</file>
<file alias="QGroundControl/Controls/MissionItemEditor.qml">src/QmlControls/MissionItemEditor.qml</file>
......
......@@ -21,7 +21,7 @@ This file is part of the QGROUNDCONTROL project
======================================================================*/
import QtQuick 2.4
import QtQuick 2.5
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.2
......@@ -216,4 +216,117 @@ Item {
height: availableHeight
}
Item {
id: multiTouchItem
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: thumbAreaHeight
visible: QGroundControl.virtualTabletJoystick
readonly property real thumbAreaHeight: parent.height / 4
QGCMapPalette { id: mapPal; lightColors: !isBackgroundDark }
Component.onCompleted: console.log("test", mapPal)
MultiPointTouchArea {
anchors.fill: parent
maximumTouchPoints: 2
property var leftRect: Qt.rect(0, 0, parent.thumbAreaHeight, parent.thumbAreaHeight)
property var rightRect: Qt.rect(parent.width - parent.thumbAreaHeight, 0, parent.thumbAreaHeight, parent.thumbAreaHeight)
function pointInRect(rect, point) {
return point.x >= rect.x &&
point.y >= rect.y &&
point.x <= rect.x + rect.width &&
point.y <= rect.y + rect.height
}
function newTouchPoints(touchPoints)
{
var point1Location = 0
var point2Location = 0
var point1
if (touchPoints.length > 0) {
point1 = touchPoints[0]
if (pointInRect(leftRect, point1)) {
point1Location = -1
} else if (pointInRect(rightRect, point1)) {
point1Location = 1
}
}
var point2
if (touchPoints.length == 2) {
point2 = touchPoints[1]
if (pointInRect(leftRect, point2)) {
point2Location = -1
} else if (pointInRect(rightRect, point2)) {
point2Location = 1
}
}
// Make sure points are not both in the same rect
if (point1Location != point2Location) {
if (point1Location != 0) {
if (point1Location == -1) {
leftStick.stickPosition = point1
} else {
rightStick.stickPosition = Qt.point(point1.x - (multiTouchItem.width - multiTouchItem.thumbAreaHeight), point1.y)
}
}
if (point2Location != 0) {
if (point2Location == -1) {
rightStick.stickPosition = Qt.point(point2.x - (multiTouchItem.width - multiTouchItem.thumbAreaHeight), point2.y)
} else {
leftStick.stickPosition = point2
}
}
}
}
onPressed: newTouchPoints(touchPoints)
onTouchUpdated: newTouchPoints(touchPoints)
onReleased: {
leftStick.reCenter()
rightStick.reCenter()
}
}
Timer {
interval: 10
running: QGroundControl.virtualTabletJoystick
repeat: true
onTriggered: {
if (_activeVehicle) {
_activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis)
}
}
}
JoystickThumbPad {
id: leftStick
anchors.left: parent.left
anchors.bottom: parent.bottom
width: parent.thumbAreaHeight
height: parent.thumbAreaHeight
yAxisThrottle: true
lightColors: !isBackgroundDark
}
JoystickThumbPad {
id: rightStick
anchors.right: parent.right
anchors.bottom: parent.bottom
width: parent.thumbAreaHeight
height: parent.thumbAreaHeight
lightColors: !isBackgroundDark
}
}
}
......@@ -39,6 +39,7 @@
QGCQuickWidget::QGCQuickWidget(QWidget* parent) :
QQuickWidget(parent)
{
setAttribute(Qt::WA_AcceptTouchEvents);
rootContext()->engine()->addImportPath("qrc:/qml");
rootContext()->setContextProperty("multiVehicleManager", qgcApp()->toolbox()->multiVehicleManager());
rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager());
......
import QtQuick 2.5
import QtQuick.Controls 1.2
import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
Rectangle {
radius: width / 2
border.color: mapPal.thumbJoystick
border.width: 2
color: "transparent"
property alias lightColors: mapPal.lightColors /// true: use light colors from QGCMapPalette for drawing
property var stickPosition: Qt.point(0, 0)
property real xAxis: 0 /// Value range [-1,1], negative values left stick, positive values right stick
property real yAxis: 0 /// Value range [-1,1], negative values up stick, positive values down stick
property bool yAxisThrottle: false /// true: yAxis used for throttle, range [1,0], positive value are stick up
property bool _stickCenteredOnce: false
QGCMapPalette { id: mapPal }
onWidthChanged: {
if (!_stickCenteredOnce && width != 0) {
reCenter()
}
}
onStickPositionChanged: {
var xAxisTemp = stickPosition.x / width
xAxisTemp *= 2.0
xAxisTemp -= 1.0
xAxis = xAxisTemp
var yAxisTemp = stickPosition.y / width
yAxisTemp *= 2.0
yAxisTemp -= 1.0
if (yAxisThrottle) {
yAxisTemp = ((yAxisTemp * -1.0) / 2.0) + 0.5
}
yAxis = yAxisTemp
}
function reCenter()
{
stickPosition = Qt.point(width / 2, width / 2)
}
Column {
QGCLabel { text: xAxis }
QGCLabel { text: yAxis }
}
Rectangle {
anchors.margins: parent.width / 4
anchors.fill: parent
radius: width / 2
border.color: mapPal.thumbJoystick
border.width: 2
color: "transparent"
}
Rectangle {
width: hatWidth
height: hatWidth
radius: hatWidthHalf
color: mapPal.thumbJoystick
x: stickPosition.x - hatWidthHalf
y: stickPosition.y - hatWidthHalf
readonly property real hatWidth: ScreenTools.defaultFontPixelHeight
readonly property real hatWidthHalf: ScreenTools.defaultFontPixelHeight / 2
}
}
Module QGroundControl.Controls
QGCLabel 1.0 QGCLabel.qml
QGCButton 1.0 QGCButton.qml
QGCRadioButton 1.0 QGCRadioButton.qml
QGCCheckBox 1.0 QGCCheckBox.qml
QGCTextField 1.0 QGCTextField.qml
QGCComboBox 1.0 QGCComboBox.qml
QGCColoredImage 1.0 QGCColoredImage.qml
QGCToolBarButton 1.0 QGCToolBarButton.qml
QGCMovableItem 1.0 QGCMovableItem.qml
SubMenuButton 1.0 SubMenuButton.qml
IndicatorButton 1.0 IndicatorButton.qml
DropButton 1.0 DropButton.qml
RoundButton 1.0 RoundButton.qml
VehicleRotationCal 1.0 VehicleRotationCal.qml
VehicleSummaryRow 1.0 VehicleSummaryRow.qml
ViewWidget 1.0 ViewWidget.qml
ExclusiveGroupItem 1.0 ExclusiveGroupItem.qml
ClickableColor 1.0 ClickableColor.qml
DropButton 1.0 DropButton.qml
ExclusiveGroupItem 1.0 ExclusiveGroupItem.qml
IndicatorButton 1.0 IndicatorButton.qml
JoystickThumbPad 1.0 JoystickThumbPad.qml
MainToolBar 1.0 MainToolBar.qml
MissionItemEditor 1.0 MissionItemEditor.qml
MissionItemIndexLabel 1.0 MissionItemIndexLabel.qml
ModeSwitchDisplay 1.0 ModeSwitchDisplay.qml
ParameterEditor 1.0 ParameterEditor.qml
ParameterEditorDialog 1.0 ParameterEditorDialog.qml
ModeSwitchDisplay 1.0 ModeSwitchDisplay.qml
QGCView 1.0 QGCView.qml
QGCViewPanel 1.0 QGCViewPanel.qml
QGCViewDialog 1.0 QGCViewDialog.qml
QGCViewMessage 1.0 QGCViewMessage.qml
MissionItemIndexLabel 1.0 MissionItemIndexLabel.qml
MissionItemEditor 1.0 MissionItemEditor.qml
MainToolBar 1.0 MainToolBar.qml
SignalStrength 1.0 SignalStrength.qml
ClickableColor 1.0 ClickableColor.qml
QGCButton 1.0 QGCButton.qml
QGCCheckBox 1.0 QGCCheckBox.qml
QGCColoredImage 1.0 QGCColoredImage.qml
QGCComboBox 1.0 QGCComboBox.qml
QGCLabel 1.0 QGCLabel.qml
QGCMovableItem 1.0 QGCMovableItem.qml
QGCRadioButton 1.0 QGCRadioButton.qml
QGCTextField 1.0 QGCTextField.qml
QGCToolBarButton 1.0 QGCToolBarButton.qml
QGCView 1.0 QGCView.qml
QGCViewDialog 1.0 QGCViewDialog.qml
QGCViewMessage 1.0 QGCViewMessage.qml
QGCViewPanel 1.0 QGCViewPanel.qml
RoundButton 1.0 RoundButton.qml
SignalStrength 1.0 SignalStrength.qml
SubMenuButton 1.0 SubMenuButton.qml
VehicleRotationCal 1.0 VehicleRotationCal.qml
VehicleSummaryRow 1.0 VehicleSummaryRow.qml
ViewWidget 1.0 ViewWidget.qml
......@@ -1074,3 +1074,8 @@ void Vehicle::_remoteControlRSSIChanged(uint8_t rssi)
emit rcRSSIChanged(_rcRSSI);
}
}
void Vehicle::virtualTabletJoystickValue(double roll, double pitch, double yaw, double thrust)
{
_uas->setExternalControlSetpoint(roll, pitch, yaw, thrust, 0, JoystickModeRC);
}
......@@ -124,13 +124,14 @@ public:
// Called when the message drop-down is invoked to clear current count
Q_INVOKABLE void resetMessages();
Q_INVOKABLE void virtualTabletJoystickValue(double roll, double pitch, double yaw, double thrust);
// Property accessors
QGeoCoordinate coordinate(void) { return _coordinate; }
bool coordinateValid(void) { return _coordinateValid; }
QmlObjectListModel* missionItemsModel(void);
typedef enum {
JoystickModeRC, ///< Joystick emulates an RC Transmitter
JoystickModeAttitude,
......
......@@ -1508,7 +1508,6 @@ void UAS::executeCommand(MAV_CMD command, int confirmation, float param1, float
* Set the manual control commands.
* This can only be done if the system has manual inputs enabled and is armed.
*/
#ifndef __mobile__
void UAS::setExternalControlSetpoint(float roll, float pitch, float yaw, float thrust, quint16 buttons, int joystickMode)
{
if (!_vehicle) {
......@@ -1690,7 +1689,6 @@ void UAS::setExternalControlSetpoint(float roll, float pitch, float yaw, float t
emit attitudeThrustSetPointChanged(this, roll, pitch, yaw, thrust, QGC::groundTimeMilliseconds());
}
}
#endif
#ifndef __mobile__
void UAS::setManual6DOFControlCommands(double x, double y, double z, double roll, double pitch, double yaw)
......
......@@ -555,9 +555,7 @@ public slots:
void stopLowBattAlarm();
/** @brief Set the values for the manual control of the vehicle */
#ifndef __mobile__
void setExternalControlSetpoint(float roll, float pitch, float yaw, float thrust, quint16 buttons, int joystickMode);
#endif
/** @brief Set the values for the 6dof manual control of the vehicle */
#ifndef __mobile__
......
......@@ -234,10 +234,9 @@ Rectangle {
//-----------------------------------------------------------------
//-- Virtual joystick settings
QGCCheckBox {
text: "Thumb Joystick (WIP - be careful!)"
text: "Virtual Joystick"
checked: QGroundControl.virtualTabletJoystick
onClicked: QGroundControl.virtualTabletJoystick = checked
visible: ScreenTools.isMobile
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment