QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorComponent.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtQuick.Layouts
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FactControls
9import QGroundControl.AutoPilotPlugins.PX4
10
11SetupPage {
12 id: actuatorPage
13 pageComponent: pageComponent
14 showAdvanced: true
15
16 property var actuators: globals.activeVehicle.actuators
17
18 property var _showAdvanced: advanced
19 readonly property real _margins: ScreenTools.defaultFontPixelHeight
20
21 Component {
22 id: pageComponent
23
24 Row {
25 spacing: ScreenTools.defaultFontPixelWidth * 4
26 property var _leftColumnWidth: Math.max(actuatorTesting.implicitWidth, mixerUi.implicitWidth) + (_margins * 2)
27
28 ColumnLayout {
29 spacing: ScreenTools.defaultFontPixelHeight
30 implicitWidth: _leftColumnWidth
31
32 // mixer ui
33 RowLayout {
34 width: _leftColumnWidth
35 visible: actuators.mixer.groups.count > 0
36 QGCLabel {
37 text: qsTr("Geometry") + (actuators.mixer.title ? ": " + actuators.mixer.title : "")
38 font.pointSize: ScreenTools.mediumFontPointSize
39 Layout.fillWidth: true
40 }
41 QGCLabel {
42 text: "<a href='"+actuators.mixer.helpUrl+"'>?</a>"
43 font.pointSize: ScreenTools.mediumFontPointSize
44 visible: actuators.mixer.helpUrl
45 textFormat: Text.RichText
46 onLinkActivated: (link) => {
47 Qt.openUrlExternally(link);
48 }
49 }
50 }
51
52 Rectangle {
53 implicitWidth: _leftColumnWidth
54 implicitHeight: mixerUi.height + (_margins * 2)
55 color: qgcPal.windowCard
56 visible: actuators.mixer.groups.count > 0
57
58 Column {
59 id: mixerUi
60 spacing: _margins
61 anchors {
62 left: parent.left
63 leftMargin: _margins
64 verticalCenter: parent.verticalCenter
65 }
66 enabled: !safetySwitch.checked && !actuators.motorAssignmentActive
67 Repeater {
68 model: actuators.mixer.groups
69 ColumnLayout {
70 property var mixerGroup: object
71
72 RowLayout {
73 QGCLabel {
74 text: mixerGroup.label
75 font.bold: true
76 rightPadding: ScreenTools.defaultFontPixelWidth * 3
77 }
78 ActuatorFact {
79 property var countParam: mixerGroup.countParam
80 visible: countParam != null
81 fact: countParam ? countParam.fact : null
82 }
83 }
84
85 GridLayout {
86 rows: 1 + mixerGroup.channels.count
87 columns: 1 + mixerGroup.channelConfigs.count
88
89 QGCLabel {
90 text: ""
91 }
92
93 // param config labels
94 Repeater {
95 model: mixerGroup.channelConfigs
96 QGCLabel {
97 text: object.label
98 visible: object.visible && (_showAdvanced || !object.advanced)
99 Layout.row: 0
100 Layout.column: 1 + index
101 }
102 }
103 // param instances
104 Repeater {
105 model: mixerGroup.channels
106 QGCLabel {
107 text: object.label + ":"
108 Layout.row: 1 + index
109 Layout.column: 0
110 }
111 }
112 Repeater {
113 model: mixerGroup.channels
114 Repeater {
115 property var channel: object
116 property var channelIndex: index
117
118 model: object.configInstances
119
120 ActuatorFact {
121 fact: object.fact
122 Layout.row: 1 + channelIndex
123 Layout.column: 1 + index
124 visible: object.config.visible && (_showAdvanced || !object.config.advanced) && object.visible
125 enabled: object.enabled
126 }
127 }
128 }
129 }
130
131 // extra group config params
132 Repeater {
133 model: mixerGroup.configParams
134
135 RowLayout {
136 spacing: ScreenTools.defaultFontPixelWidth
137 QGCLabel {
138 text: object.label + ":"
139 visible: _showAdvanced || !object.advanced
140 }
141 ActuatorFact {
142 fact: object.fact
143 visible: _showAdvanced || !object.advanced
144 }
145 }
146 }
147 }
148 }
149 }
150 }
151
152 // actuator image
153 Image {
154 id: actuatorImage
155 source: "image://actuators/geometry"+refreshFlag
156 sourceSize.width: imageSize
157 sourceSize.height: imageSize
158 Layout.preferredWidth: imageSize
159 Layout.preferredHeight: imageSize
160 Layout.alignment: Qt.AlignHCenter
161 visible: actuators.isMultirotor
162 cache: false
163
164 property var refreshFlag: actuators.imageRefreshFlag
165 readonly property real imageSize: 9 * ScreenTools.defaultFontPixelHeight
166
167 MouseArea {
168 anchors.fill: parent
169 onClicked: (mouse) => {
170 if (mouse.button == Qt.LeftButton) {
171 actuators.imageClicked(Qt.size(width, height), mouse.x, mouse.y);
172 }
173 }
174 }
175 }
176
177 // actuator testing
178 QGCLabel {
179 text: qsTr("Actuator Testing")
180 font.pointSize: ScreenTools.mediumFontPointSize
181 }
182
183 Rectangle {
184 implicitWidth: _leftColumnWidth
185 implicitHeight: actuatorTesting.height + (_margins * 2)
186 color: qgcPal.windowCard
187
188 Column {
189 id: actuatorTesting
190 spacing: _margins
191 anchors {
192 left: parent.left
193 leftMargin: _margins
194 verticalCenter: parent.verticalCenter
195 }
196
197 QGCLabel {
198 text: qsTr("Configure some outputs in order to test them.")
199 visible: actuators.actuatorTest.actuators.count == 0
200 }
201
202 Row {
203 spacing: ScreenTools.defaultFontPixelWidth
204 visible: actuators.actuatorTest.actuators.count > 0
205
206 Switch {
207 id: safetySwitch
208 enabled: !actuators.motorAssignmentActive && !actuators.actuatorTest.hadFailure
209 Connections {
210 target: actuators.actuatorTest
211 onHadFailureChanged: {
212 if (actuators.actuatorTest.hadFailure) {
213 safetySwitch.checked = false;
214 safetySwitch.switchUpdated();
215 }
216 }
217 }
218 onClicked: {
219 switchUpdated();
220 }
221 function switchUpdated() {
222 if (!checked) {
223 for (var channelIdx=0; channelIdx<sliderRepeater.count; channelIdx++) {
224 sliderRepeater.itemAt(channelIdx).stop();
225 }
226 if (allMotorsLoader.item != null)
227 allMotorsLoader.item.stop();
228 }
229 actuators.actuatorTest.setActive(checked);
230 }
231 }
232
233 QGCLabel {
234 color: qgcPal.warningText
235 text: safetySwitch.checked ? qsTr("Careful: Actuator sliders are enabled") : qsTr("Propellers are removed - Enable sliders")
236 }
237 } // Row
238
239 Row {
240 spacing: ScreenTools.defaultFontPixelWidth * 2
241 enabled: safetySwitch.checked
242
243 // (optional) slider for all motors
244 Loader {
245 id: allMotorsLoader
246 sourceComponent: actuators.actuatorTest.allMotorsActuator ? allMotorsComponent : null
247 Layout.alignment: Qt.AlignTop
248 }
249 Component {
250 id: allMotorsComponent
251 ActuatorSlider {
252 channel: actuators.actuatorTest.allMotorsActuator
253 rightPadding: ScreenTools.defaultFontPixelWidth * 3
254 onActuatorValueChanged: (value, sliderValue) => {
255 stopTimer();
256 for (var channelIdx=0; channelIdx<sliderRepeater.count; channelIdx++) {
257 var channelSlider = sliderRepeater.itemAt(channelIdx);
258 if (channelSlider.channel.isMotor) {
259 channelSlider.value = sliderValue;
260 }
261 }
262 }
263 }
264 }
265
266 // all channels
267 Repeater {
268 id: sliderRepeater
269 model: actuators.actuatorTest.actuators
270
271 ActuatorSlider {
272 channel: object
273 onActuatorValueChanged: (value) =>{
274 if (isNaN(value)) {
275 actuators.actuatorTest.stopControl(index);
276 stop();
277 } else {
278 actuators.actuatorTest.setChannelTo(index, value);
279 }
280 }
281 }
282 } // Repeater
283 } // Row
284
285 // actuator actions
286 Column {
287 visible: actuators.actuatorActions.count > 0
288 enabled: !safetySwitch.checked && !actuators.motorAssignmentActive
289 Row {
290 spacing: ScreenTools.defaultFontPixelWidth * 2
291 Repeater {
292 model: actuators.actuatorActions
293
294 QGCButton {
295 property var actionGroup: object
296 text: actionGroup.label
297 onClicked: actionMenu.popup()
298 QGCMenu {
299 id: actionMenu
300
301 Instantiator {
302 model: actionGroup.actions
303 QGCMenuItem {
304 text: object.label
305 onTriggered: object.trigger()
306 }
307 onObjectAdded: (index, object) => actionMenu.insertItem(index, object)
308 onObjectRemoved: (index, object) => actionMenu.removeItem(object)
309 }
310 }
311 }
312 }
313 }
314
315 } // Column
316
317 } // Column
318 } // Rectangle
319 }
320
321 // Right column
322 Column {
323 QGCLabel {
324 text: qsTr("Actuator Outputs")
325 font.pointSize: ScreenTools.mediumFontPointSize
326 bottomPadding: ScreenTools.defaultFontPixelHeight
327 }
328 QGCLabel {
329 text: qsTr("One or more actuator still needs to be assigned to an output.")
330 visible: actuators.hasUnsetRequiredFunctions
331 color: qgcPal.errorText
332 bottomPadding: ScreenTools.defaultFontPixelHeight
333 }
334
335
336 // actuator output selection tabs
337 QGCGroupBox {
338 showDividers: false
339 contentSpacing: 0
340
341 onCurrentIndexChanged: actuators.selectActuatorOutput(currentIndex)
342
343 Repeater {
344 model: actuators.actuatorOutputs
345 QGCGroupBoxTab { title: object.label }
346 }
347
348 // actuator outputs
349 Item {
350 id: selActuatorOutput
351 implicitWidth: actuatorGroupColumn.width
352 implicitHeight: actuatorGroupColumn.height
353
354 property var actuatorOutput: actuators.selectedActuatorOutput
355
356 Column {
357 id: actuatorGroupColumn
358 spacing: _margins
359 anchors.centerIn: parent
360
361 // Motor assignment
362 Row {
363 visible: actuators.isMultirotor
364 enabled: !safetySwitch.checked
365 anchors.right: parent.right
366 spacing: _margins
367 QGCButton {
368 text: qsTr("Identify & Assign Motors")
369 visible: !actuators.motorAssignmentActive && selActuatorOutput.actuatorOutput.groupsVisible
370 enabled: actuators.motorAssignmentEnabled
371 onClicked: {
372 var success = actuators.initMotorAssignment()
373 if (success) {
374 motorAssignmentConfirmDialog.open()
375 } else {
376 motorAssignmentFailureDialog.open()
377 }
378 }
379 MessageDialog {
380 id: motorAssignmentConfirmDialog
381 visible: false
382 //icon: StandardIcon.Warning
383 buttons: MessageDialog.Yes | MessageDialog.No
384 title: qsTr("Motor Order Identification and Assignment")
385 text: actuators.motorAssignmentMessage
386 onButtonClicked: function (button, role) {
387 switch (button) {
388 case MessageDialog.Yes:
389 actuators.startMotorAssignment()
390 break;
391 }
392 }
393 }
394 MessageDialog {
395 id: motorAssignmentFailureDialog
396 visible: false
397 //icon: StandardIcon.Critical
398 buttons: MessageDialog.Ok
399 title: qsTr("Error")
400 text: actuators.motorAssignmentMessage
401 }
402 }
403 QGCButton {
404 text: qsTr("Spin Motor Again")
405 visible: actuators.motorAssignmentActive
406 onClicked: {
407 actuators.spinCurrentMotor()
408 }
409 }
410 QGCButton {
411 text: qsTr("Abort")
412 visible: actuators.motorAssignmentActive
413 onClicked: {
414 actuators.abortMotorAssignment()
415 }
416 }
417 }
418
419 Column {
420 enabled: !safetySwitch.checked && !actuators.motorAssignmentActive
421 spacing: _margins
422
423 RowLayout {
424 property var enableParam: selActuatorOutput.actuatorOutput.enableParam
425 QGCLabel {
426 visible: parent.enableParam != null
427 text: parent.enableParam ? parent.enableParam.label + ":" : ""
428 }
429 ActuatorFact {
430 visible: parent.enableParam != null
431 fact: parent.enableParam ? parent.enableParam.fact : null
432 }
433 }
434
435
436 Repeater {
437 model: selActuatorOutput.actuatorOutput.subgroups
438
439 ColumnLayout {
440 property var subgroup: object
441 visible: selActuatorOutput.actuatorOutput.groupsVisible
442
443 RowLayout {
444 visible: subgroup.label != ""
445 QGCLabel {
446 text: subgroup.label
447 font.bold: true
448 rightPadding: ScreenTools.defaultFontPixelWidth * 3
449 }
450 ActuatorFact {
451 property var primaryParam: subgroup.primaryParam
452 visible: primaryParam != null
453 fact: primaryParam ? primaryParam.fact : null
454 }
455 }
456
457 GridLayout {
458 rows: 1 + subgroup.channels.count
459 columns: 1 + subgroup.channelConfigs.count
460
461 QGCLabel {
462 text: ""
463 }
464
465 // param config labels
466 Repeater {
467 model: subgroup.channelConfigs
468 QGCLabel {
469 text: object.label
470 visible: object.visible && (_showAdvanced || !object.advanced)
471 Layout.row: 0
472 Layout.column: 1 + index
473 }
474 }
475 // param instances
476 Repeater {
477 model: subgroup.channels
478 QGCLabel {
479 text: object.label + ":"
480 Layout.row: 1 + index
481 Layout.column: 0
482 }
483 }
484 Repeater {
485 model: subgroup.channels
486 Repeater {
487 property var channel: object
488 property var channelIndex: index
489 model: object.configInstances
490 ActuatorFact {
491 fact: object.fact
492 Layout.row: 1 + channelIndex
493 Layout.column: 1 + index
494 visible: object.config.visible && (_showAdvanced || !object.config.advanced)
495 }
496 }
497 }
498 }
499
500 // extra subgroup config params
501 Repeater {
502 model: subgroup.configParams
503
504 RowLayout {
505 QGCLabel {
506 text: object.label + ":"
507 }
508 ActuatorFact {
509 fact: object.fact
510 }
511 }
512 }
513
514 }
515 } // subgroup Repeater
516
517 // extra actuator config params
518 Repeater {
519 model: selActuatorOutput.actuatorOutput.configParams
520
521 RowLayout {
522 QGCLabel {
523 text: object.label + ":"
524 }
525 ActuatorFact {
526 fact: object.fact
527 }
528 }
529 }
530
531 // notes
532 Repeater {
533 model: selActuatorOutput.actuatorOutput.notes
534 ColumnLayout {
535 spacing: ScreenTools.defaultFontPixelHeight
536 QGCLabel {
537 text: modelData
538 color: qgcPal.warningText
539 }
540 }
541 }
542 }
543 }
544 } // Item
545 }
546 } // Column
547 } // Row
548
549 }
550}