Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
c0393e63
Commit
c0393e63
authored
9 years ago
by
Don Gagne
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2660 from DonLakeFlyer/VirtualJoystick
Virtual joystick improvments
parents
a0b03086
b946e889
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
116 deletions
+97
-116
FlightDisplayView.qml
src/FlightDisplay/FlightDisplayView.qml
+24
-97
JoystickThumbPad.qml
src/QmlControls/JoystickThumbPad.qml
+60
-19
MockLink.cc
src/comm/MockLink.cc
+12
-0
MockLink.h
src/comm/MockLink.h
+1
-0
No files found.
src/FlightDisplay/FlightDisplayView.qml
View file @
c0393e63
...
...
@@ -220,83 +220,6 @@ Item {
QGCMapPalette
{
id
:
mapPal
;
lightColors
:
!
isBackgroundDark
}
MultiPointTouchArea
{
anchors.fill
:
parent
touchPoints
:
[
TouchPoint
{
id
:
point1
},
TouchPoint
{
id
:
point2
}
]
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
}
}
var
leftStickSet
=
false
var
rightStickSet
=
false
// Make sure points are not both in the same rect
if
(
point1Location
!=
point2Location
)
{
if
(
point1Location
!=
0
)
{
if
(
point1Location
==
-
1
)
{
leftStick
.
stickPosition
=
point1
leftStickSet
=
true
}
else
{
rightStick
.
stickPosition
=
Qt
.
point
(
point1
.
x
-
(
multiTouchItem
.
width
-
multiTouchItem
.
thumbAreaHeight
),
point1
.
y
)
rightStickSet
=
true
}
}
if
(
point2Location
!=
0
)
{
if
(
point2Location
==
-
1
)
{
leftStick
.
stickPosition
=
point2
leftStickSet
=
true
}
else
{
rightStick
.
stickPosition
=
Qt
.
point
(
point2
.
x
-
(
multiTouchItem
.
width
-
multiTouchItem
.
thumbAreaHeight
),
point2
.
y
)
rightStickSet
=
true
}
}
}
if
(
!
leftStickSet
)
{
leftStick
.
reCenter
()
}
if
(
!
rightStickSet
)
{
rightStick
.
reCenter
()
}
}
onTouchUpdated
:
newTouchPoints
(
touchPoints
)
}
Timer
{
interval
:
40
// 25Hz, same as real joystick rate
running
:
QGroundControl
.
virtualTabletJoystick
&&
_activeVehicle
...
...
@@ -310,6 +233,8 @@ Item {
JoystickThumbPad
{
id
:
leftStick
anchors.leftMargin
:
xPositionDelta
anchors.bottomMargin
:
-
yPositionDelta
anchors.left
:
parent
.
left
anchors.bottom
:
parent
.
bottom
width
:
parent
.
thumbAreaHeight
...
...
@@ -320,6 +245,8 @@ Item {
JoystickThumbPad
{
id
:
rightStick
anchors.rightMargin
:
-
xPositionDelta
anchors.bottomMargin
:
-
yPositionDelta
anchors.right
:
parent
.
right
anchors.bottom
:
parent
.
bottom
width
:
parent
.
thumbAreaHeight
...
...
This diff is collapsed.
Click to expand it.
src/QmlControls/JoystickThumbPad.qml
View file @
c0393e63
...
...
@@ -7,29 +7,30 @@ import QGroundControl.ScreenTools 1.0
Item
{
id
:
_joyRoot
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
alias
lightColors
:
mapPal
.
lightColors
///< true: use light colors from QGCMapPalette for drawing
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
real
xPositionDelta
:
0
///< Amount to move the control on x axis
property
real
yPositionDelta
:
0
///< Anount to move the control on y axis
property
real
_centerXY
:
width
/
2
property
bool
_processTouchPoints
:
false
property
bool
_stickCenteredOnce
:
false
property
real
stickPositionX
:
_centerXY
property
real
stickPositionY
:
_centerXY
QGCMapPalette
{
id
:
mapPal
}
onWidthChanged
:
{
if
(
!
_stickCenteredOnce
&&
width
!=
0
)
{
reCenter
()
}
}
onStickPositionChanged
:
{
var
xAxisTemp
=
stickPosition
.
x
/
width
onStickPositionXChanged
:
{
var
xAxisTemp
=
stickPositionX
/
width
xAxisTemp
*=
2.0
xAxisTemp
-=
1.0
xAxis
=
xAxisTemp
}
var
yAxisTemp
=
stickPosition
.
y
/
width
onStickPositionYChanged
:
{
var
yAxisTemp
=
stickPositionY
/
width
yAxisTemp
*=
2.0
yAxisTemp
-=
1.0
if
(
yAxisThrottle
)
{
...
...
@@ -40,11 +41,26 @@ Item {
function
reCenter
()
{
stickPosition
=
Qt
.
point
(
width
/
2
,
width
/
2
)
_processTouchPoints
=
false
// Move control back to original position
xPositionDelta
=
0
yPositionDelta
=
0
// Center sticks
stickPositionX
=
_centerXY
stickPositionY
=
_centerXY
}
function
thumbDown
(
touchPoints
)
{
// Center the control around the initial thumb position
xPositionDelta
=
touchPoints
[
0
].
x
-
_centerXY
yPositionDelta
=
touchPoints
[
0
].
y
-
_centerXY
// We need to wait until we move the control to the right position before we process touch points
_processTouchPoints
=
true
}
/*
Keep in for debugging
//
Keep in for debugging
Column {
QGCLabel { text: xAxis }
QGCLabel { text: yAxis }
...
...
@@ -72,10 +88,35 @@ Item {
height
:
hatWidth
radius
:
hatWidthHalf
color
:
mapPal
.
thumbJoystick
x
:
stickPosition
.
x
-
hatWidthHalf
y
:
stickPosition
.
y
-
hatWidthHalf
x
:
stickPosition
X
-
hatWidthHalf
y
:
stickPosition
Y
-
hatWidthHalf
readonly
property
real
hatWidth
:
ScreenTools
.
defaultFontPixelHeight
readonly
property
real
hatWidthHalf
:
ScreenTools
.
defaultFontPixelHeight
/
2
}
Connections
{
target
:
touchPoint
onXChanged
:
{
if
(
_processTouchPoints
)
{
_joyRoot
.
stickPositionX
=
Math
.
max
(
Math
.
min
(
touchPoint
.
x
,
_joyRoot
.
width
),
0
)
}
}
onYChanged
:
{
if
(
_processTouchPoints
)
{
_joyRoot
.
stickPositionY
=
Math
.
max
(
Math
.
min
(
touchPoint
.
y
,
_joyRoot
.
height
),
0
)
}
}
}
MultiPointTouchArea
{
anchors.fill
:
parent
minimumTouchPoints
:
1
maximumTouchPoints
:
1
touchPoints
:
[
TouchPoint
{
id
:
touchPoint
}
]
onPressed
:
_joyRoot
.
thumbDown
(
touchPoints
)
onReleased
:
_joyRoot
.
reCenter
()
}
}
This diff is collapsed.
Click to expand it.
src/comm/MockLink.cc
View file @
c0393e63
...
...
@@ -390,6 +390,10 @@ void MockLink::_handleIncomingMavlinkBytes(const uint8_t* bytes, int cBytes)
_handleCommandLong
(
msg
);
break
;
case
MAVLINK_MSG_ID_MANUAL_CONTROL
:
_handleManualControl
(
msg
);
break
;
default:
break
;
}
...
...
@@ -413,6 +417,14 @@ void MockLink::_handleSetMode(const mavlink_message_t& msg)
_mavCustomMode
=
request
.
custom_mode
;
}
void
MockLink
::
_handleManualControl
(
const
mavlink_message_t
&
msg
)
{
mavlink_manual_control_t
manualControl
;
mavlink_msg_manual_control_decode
(
&
msg
,
&
manualControl
);
qDebug
()
<<
"MANUAL_CONTROL"
<<
manualControl
.
x
<<
manualControl
.
y
<<
manualControl
.
z
<<
manualControl
.
r
;
}
void
MockLink
::
_setParamFloatUnionIntoMap
(
int
componentId
,
const
QString
&
paramName
,
float
paramFloat
)
{
mavlink_param_union_t
valueUnion
;
...
...
This diff is collapsed.
Click to expand it.
src/comm/MockLink.h
View file @
c0393e63
...
...
@@ -187,6 +187,7 @@ private:
void
_handleParamRequestRead
(
const
mavlink_message_t
&
msg
);
void
_handleFTP
(
const
mavlink_message_t
&
msg
);
void
_handleCommandLong
(
const
mavlink_message_t
&
msg
);
void
_handleManualControl
(
const
mavlink_message_t
&
msg
);
float
_floatUnionForParam
(
int
componentId
,
const
QString
&
paramName
);
void
_setParamFloatUnionIntoMap
(
int
componentId
,
const
QString
&
paramName
,
float
paramFloat
);
void
_sendHomePosition
(
void
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment