This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
forked from zhangh94/MAQSS_GCS
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ControlPanel.qml
163 lines (145 loc) · 5.22 KB
/
ControlPanel.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import XbeeInterfaceClass 1.0
import "js_resources/Transforms.js" as Transforms
import "js_resources/Coordinates.js" as Coordinates
Rectangle {
id: controlPanelBox
property int controlPanelPadding: 25
property int buttonHeight: controlPanelBox.height/5
property int buttonWidth: controlPanelBox.width/2
property bool captureState: false
property var searchChunkMessages: []
// States for capturing/waiting to change CaptureButton behavior and appearance
states: [
State {
name: "Capturing"; when: captureButton.checked
PropertyChanges { target: controlPanelBox; captureState: true}
PropertyChanges { target: captureButton; text: qsTr("Capturing")}
},
State {
name: "Waiting";
PropertyChanges { target: controlPanelBox; captureState: false }
PropertyChanges { target: captureButton; text: qsTr("Set Mission") }
PropertyChanges { target: captureButton; checked: false }
}
]
// Text input for field_angle
TextField {
id: headingInput
color: "black"
anchors {
bottom: controlPanelBox.bottom
bottomMargin: controlPanelPadding
left: controlPanelBox.left
leftMargin: 0
}
height: buttonHeight
width: buttonWidth
placeholderText: qsTr("Enter Angle (deg)")
onEditingFinished: {
mainPage.field_angle = parseFloat(text)
focus = false
mapContainer.update()
}
}
// Button to start/stop comms
Button {
id: commsButton
state: "Stopped"
anchors {
left: captureButton.left
bottom: captureButton.top
bottomMargin: controlPanelPadding/2
}
width: buttonWidth
height: buttonHeight
text: qsTr("Comms OFF")
highlighted: false
checkable: true
states: State {
name: "Started"; when: commsButton.checked
PropertyChanges {target:commsButton; text: qsTr("Comms ON")}
}
onClicked: {
if (commsButton.state === "Started") {
XbeeInterface.startComms();
}
else {
XbeeInterface.stopComms()
}
}
}
// Button to transition into mission capture mode
Button {
id: captureButton
state: "Waiting"
anchors {
left: controlPanelBox.left
leftMargin: 0
bottom: headingInput.top
bottomMargin: controlPanelPadding/2
}
width: buttonWidth
height: buttonHeight
text: qsTr("Set Mission")
highlighted: false
checkable: true
}
// Switch to toggle mission start (send search chunks off to vehicles)
Switch {
id: startSwitch
width: buttonWidth * 0.5
height: buttonHeight
scale: parent.width/parent.height * 1.5
anchors.right: controlPanelBox.right
anchors.rightMargin: padding
anchors.verticalCenter: captureButton.verticalCenter
states: State {
name: "Started"; when: startSwitch.checked === true
PropertyChanges { target: switchText; text: qsTr("Stop")}
}
Text {
id: switchText
anchors.bottom: parent.top
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Start")
}
// Evaluate state when clicked
onClicked: {
var ndx;
// Start state, allocate search Chunks and send msg off to vehicles
if (startSwitch.state === "Started") {
captureButton.checkable = false
vehicleStatusBox.roleCheckable = false;
console.log("Started")
startSignal(mainPage)
currentMsg = "Starting Mission -- Transmitting"
messageBox.write(currentMsg)
// run function to allocate quadcopters to closest point
var msg = Coordinates.allocateSearchChunks(mainPage.searchChunkCoords, mainPage.vehicleCoords, mainPage.field_angle)
// Write msg to Quads here
for (ndx = 0; ndx < msg.length; ndx++) {
if (!quadcopters[ndx].role) { // if role = 0 ("Quick")
console.log("Role: ", quadcopters[ndx].role, "at ndx: ", ndx);
XbeeInterface.writeMsg(msg[ndx]);
XbeeInterface.writeMsg("NEWMSG,START,Q" + quadcopters[ndx].idNumber);
}
}
}
// stop state, send STOP signal to all vehicles
else {
captureButton.checkable = true
vehicleStatusBox.roleCheckable = true;
currentMsg = "Halting Mission"
messageBox.write(currentMsg)
for (ndx = 0; ndx < quadcopters.length; ndx++) {
if (!quadcopters[ndx].role) { // if role = 0 ("Quick")
XbeeInterface.writeMsg("NEWMSG,STOP,Q" + quadcopters[ndx].idNumber);
}
}
}
}
}
}