QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SensorsVehicleView.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick3D
3
4import QGroundControl
5import QGroundControl.Controls
6
7import "PX4SensorsPose.js" as Pose
8
9/// The vehicle in 3D on the side given. When the side changes it tips once, by the shortest turn, onto the new side. While
10/// rotating it then turns about the vertical. When live it follows roll, pitch and heading instead.
11View3D {
12 id: control
13
14 property string side: "level"
15 property bool rotating: false
16 /// "multiRotor", "fixedWing", "vtol", "rover" or anything else for a flat board
17 property string vehicleKind: ""
18 property bool live: false
19 /// Degrees, used when live
20 property real roll: 0
21 property real pitch: 0
22 property real heading: 0
23
24 // When live the vehicle stays put and the ground is below the furthest it can reach in any attitude
25 readonly property real _ground: live ? Math.hypot(vehicleModel.halfSize[0], vehicleModel.halfSize[1], vehicleModel.halfSize[2]) + 4 :
26 Math.max(vehicleModel.halfSize[0], vehicleModel.halfSize[1], vehicleModel.halfSize[2])
27
28 property var _from: Pose.sidePose("level")
29 property var _to: Pose.sidePose("level")
30 property real _swing: 1
31 property var _pose: Pose.slerp(_from, _to, _swing)
32 readonly property var _shownPose: live ? Pose.attitudePose(roll, pitch, heading) : _pose
33
34 onSideChanged: {
35 _from = _pose
36 _swing = 0
37 _to = Pose.tipTarget(_from, side)
38 swingAnimation.restart()
39 }
40
41 Component.onCompleted: {
42 _from = Pose.sidePose(side)
43 _to = _from
44 }
45
46 QGCPalette { id: qgcPal }
47
48 NumberAnimation {
49 id: swingAnimation
50 target: control
51 property: "_swing"
52 from: 0
53 to: 1
54 duration: 900
55 easing.type: Easing.InOutCubic
56 }
57
58 NumberAnimation {
59 target: spin
60 property: "eulerRotation.y"
61 from: 0
62 to: 360
63 duration: 4000
64 loops: Animation.Infinite
65 running: control.rotating && control._swing >= 1
66 onRunningChanged: {
67 if (!running) {
68 spin.eulerRotation.y = 0
69 }
70 }
71 }
72
73 environment: SceneEnvironment {
74 backgroundMode: SceneEnvironment.Transparent
75 antialiasingMode: SceneEnvironment.MSAA
76 antialiasingQuality: SceneEnvironment.High
77 }
78
79 // Further back when live, to fit the wider disc and the vehicle in any attitude
80 PerspectiveCamera {
81 position: control.live ? Qt.vector3d(0, 300, 859) : Qt.vector3d(0, 185, 560)
82 eulerRotation.x: -21
83 fieldOfView: 32
84 }
85
86 DirectionalLight {
87 eulerRotation: Qt.vector3d(-45, -30, 0)
88 brightness: 1.3
89 }
90
91 DirectionalLight {
92 eulerRotation: Qt.vector3d(30, 150, 0)
93 brightness: 0.5
94 }
95
96 Node {
97 y: control.live ? 20 : 0
98 eulerRotation.y: -30
99
100 // When live the disc is wider, so the north arrow on its rim stays clear of the vehicle
101 Model {
102 source: "#Cylinder"
103 y: -control._ground - 1
104 scale: control.live ? Qt.vector3d(3.4, 0.01, 3.4) : Qt.vector3d(2.4, 0.01, 2.4)
105 materials: PrincipledMaterial {
106 baseColor: qgcPal.borderSubtle
107 roughness: 1
108 }
109 }
110
111 // Points north, heading 0, which the live pose turns the nose (-z) towards. Sits on top of the disc, which has a
112 // radius of 170 when live. The cone's base is at its origin, so its tip, 36 further on, is on the rim.
113 Model {
114 visible: control.live
115 source: "#Cone"
116 y: -control._ground
117 z: -134
118 eulerRotation.x: -90
119 scale: Qt.vector3d(0.28, 0.36, 0.01)
120 materials: PrincipledMaterial {
121 baseColor: qgcPal.colorRed
122 lighting: PrincipledMaterial.NoLighting
123 }
124 }
125
126 Node {
127 id: spin
128
129 SensorsVehicleModel {
130 id: vehicleModel
131 kind: control.vehicleKind
132 rotation: Qt.quaternion(control._shownPose[0], control._shownPose[1], control._shownPose[2], control._shownPose[3])
133 y: control.live ? 0 : Pose.restHeight(control._shownPose, halfSize) - control._ground
134 }
135 }
136 }
137}