QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
OnScreenGimbalController.qml
Go to the documentation of this file.
1import QtQuick
2
3import QGroundControl
4import QGroundControl.Controls
5
6Item {
7 id: rootItem
8 anchors.fill: parent
9
10 property var screenX
11 property var screenY
12 property var screenXrateInitCoocked
13 property var screenYrateInitCoocked
14
15 property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
16 property var gimbalController: activeVehicle ? activeVehicle.gimbalController : undefined
17 property var activeGimbal: gimbalController ? gimbalController.activeGimbal : undefined
18 property bool gimbalAvailable: activeGimbal != undefined
19 property var gimbalControllerSettings: QGroundControl.settingsManager.gimbalControllerSettings
20 property bool cameraTrackingEnabled: false // Used to ignore clicks when camera tracking operation is active, otherwise it would collide with these gimbal controls
21 property bool shouldProcessClicks: gimbalControllerSettings.EnableOnScreenControl.value && activeGimbal && !cameraTrackingEnabled ? true : false
22
23 function clickControl() {
24 if (!shouldProcessClicks) {
25 return
26 }
27 // If click and slide control, return, it uses press and release
28 if (!gimbalControllerSettings.ControlType.rawValue == 0) {
29 return
30 }
31 clickAndPoint(x, y)
32 }
33
34 // Sends a +-(0-1) xy value to vehicle.gimbalController.gimbalOnScreenControl
35 function clickAndPoint() {
36 if (rootItem.gimbalAvailable) {
37 var xCoocked = ( (screenX / parent.width) * 2) - 1
38 var yCoocked = -( (screenY / parent.height) * 2) + 1
39 // console.log("X global: " + x + " Y global: " + y)
40 // console.log("X coocked: " + xCoocked + " Y coocked: " + yCoocked)
41 gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, true, false, false)
42 } else {
43 // We should never be here
44 console.log("gimbal not available")
45 }
46 }
47
48 function pressControl() {
49 if (!shouldProcessClicks) {
50 return
51 }
52 // If click and point control return, that is handled exclusively on clickAndPoint()
53 if (!gimbalControllerSettings.ControlType.rawValue == 1) {
54 return
55 }
56 sendRateTimer.start()
57 screenXrateInitCoocked = ( ( screenX / parent.width) * 2) - 1
58 screenYrateInitCoocked = -( ( screenY / parent.height) * 2) + 1
59 }
60
61 function releaseControl() {
62 if (!shouldProcessClicks) {
63 return
64 }
65 // If click and point control return, that is handled exclusively on clickAndPoint()
66 if (!gimbalControllerSettings.ControlType.rawValue == 1) {
67 return
68 }
69 sendRateTimer.stop()
70 screenXrateInitCoocked = null
71 screenYrateInitCoocked = null
72 }
73
74 Timer {
75 id: sendRateTimer
76 interval: 100
77 repeat: true
78 onTriggered: {
79 if (rootItem.gimbalAvailable) {
80 var xCoocked = ( ( screenX / parent.width) * 2) - 1
81 var yCoocked = -( ( screenY / parent.height) * 2) + 1
82 xCoocked -= screenXrateInitCoocked
83 yCoocked -= screenYrateInitCoocked
84 gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, false, true, true)
85 } else {
86 console.log("gimbal not available")
87 }
88 }
89 }
90}