QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SensorsLiveCard.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6import QGroundControl.FlightMap
7
8/// Live attitude of the vehicle and the sensors it has, to check the autopilot orientation and the compass against.
9/// devices is PX4SensorsRows.hardwareDevices, deviceName(param) returns the description of a device ID parameter.
10ConfigRowsPanel {
11 id: control
12
13 property var vehicle: null
14 /// "multiRotor", "fixedWing", "vtol", "rover" or anything else for a flat board
15 property string vehicleKind: ""
16 property var devices: []
17 property var deviceName: function (param) { return "" }
18
19 QGCPalette { id: qgcPal }
20
21 // Formats after rounding, so a small negative value shows 0 rather than -0. A wrapped heading shows 360 as 0.
22 function _degrees(value, decimals, wrap) {
23 if (!isFinite(value)) {
24 return "--"
25 }
26 let rounded = Number(value.toFixed(decimals))
27 if (wrap && rounded >= 360) {
28 rounded -= 360
29 }
30 if (rounded === 0) {
31 rounded = 0
32 }
33 return rounded.toFixed(decimals) + "°"
34 }
35
36 QGCLabel {
37 text: qsTr("Live orientation")
38 font.bold: true
39 }
40
41 // Qt Quick 3D needs a GPU renderer. Without one the attitude indicator is shown instead.
42 Loader {
43 objectName: "sensors_attitude"
44 Layout.fillWidth: true
45 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight * 12
46 sourceComponent: {
47 switch (GraphicsInfo.api) {
48 case GraphicsInfo.Unknown:
49 return null
50 case GraphicsInfo.Software:
51 return attitudeIndicator
52 }
53 return vehicleView
54 }
55 }
56
57 Component {
58 id: vehicleView
59
60 SensorsVehicleView {
61 live: true
62 vehicleKind: control.vehicleKind
63 roll: control.vehicle ? control.vehicle.roll.rawValue : 0
64 pitch: control.vehicle ? control.vehicle.pitch.rawValue : 0
65 heading: control.vehicle ? control.vehicle.heading.rawValue : 0
66 }
67 }
68
69 Component {
70 id: attitudeIndicator
71
72 Item {
73 QGCAttitudeWidget {
74 anchors.centerIn: parent
75 size: parent.height
76 vehicle: control.vehicle
77 }
78 }
79 }
80
81 RowLayout {
82 Layout.fillWidth: true
83 spacing: ScreenTools.defaultFontPixelWidth
84
85 Repeater {
86 model: [
87 { caption: qsTr("Roll"), value: control._degrees(control.vehicle ? control.vehicle.roll.rawValue : NaN, 1) },
88 { caption: qsTr("Pitch"), value: control._degrees(control.vehicle ? control.vehicle.pitch.rawValue : NaN, 1) },
89 { caption: qsTr("Heading"), value: control._degrees(control.vehicle ? control.vehicle.heading.rawValue : NaN, 0, true) }
90 ]
91
92 // Equal fixed widths and right aligned values, so changing values do not move anything
93 QGCCaptionCell {
94 Layout.fillWidth: true
95 Layout.preferredWidth: 1
96 caption: modelData.caption
97
98 required property var modelData
99
100 QGCLabel {
101 Layout.fillWidth: true
102 horizontalAlignment: Text.AlignRight
103 text: modelData.value
104 font.family: ScreenTools.fixedFontFamily
105 }
106 }
107 }
108 }
109
110 Rectangle {
111 Layout.fillWidth: true
112 implicitHeight: 1
113 color: qgcPal.borderSubtle
114 visible: control.devices.length > 0
115 }
116
117 ColumnLayout {
118 Layout.fillWidth: true
119 spacing: ScreenTools.defaultFontPixelHeight * 0.25
120 visible: control.devices.length > 0
121
122 Repeater {
123 model: control.devices
124
125 RowLayout {
126 Layout.fillWidth: true
127
128 required property var modelData
129
130 QGCLabel {
131 Layout.fillWidth: true
132 text: modelData.label
133 color: qgcPal.textSecondary
134 }
135
136 QGCLabel {
137 text: control.deviceName(modelData.param)
138 font.family: ScreenTools.fixedFontFamily
139 }
140 }
141 }
142 }
143
144 ConfigNote {
145 text: qsTr("Tilt and turn the vehicle: the model should follow. If it moves the wrong way, change the autopilot rotation.")
146 }
147}