QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GuidedActionsController.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtLocation
5import QtPositioning
6import QtQuick.Layouts
7
8import QGroundControl
9import QGroundControl.Controls
10import QGroundControl.FlightMap
11import QGroundControl.Logging
12
13/// This provides the smarts behind the guided mode commands, minus the user interface. This way you can change UI
14/// without affecting the underlying functionality.
15Item {
16 id: _root
17
18 property var missionController
19 property var confirmDialog
20 property var guidedValueSlider
21 property var fwdFlightGotoMapCircle
22 property var orbitMapCircle
23
24 readonly property string emergencyStopTitle: qsTr("EMERGENCY STOP")
25 readonly property string armTitle: qsTr("Arm")
26 readonly property string mvArmTitle: qsTr("Arm (MV)")
27 readonly property string forceArmTitle: qsTr("Force Arm")
28 readonly property string disarmTitle: qsTr("Disarm")
29 readonly property string mvDisarmTitle: qsTr("Disarm (MV)")
30 readonly property string rtlTitle: qsTr("Return")
31 readonly property string takeoffTitle: qsTr("Takeoff")
32 readonly property string landTitle: qsTr("Land")
33 readonly property string startMissionTitle: qsTr("Start Mission")
34 readonly property string mvStartMissionTitle: qsTr("Start Mission (MV)")
35 readonly property string continueMissionTitle: qsTr("Continue Mission")
36 readonly property string resumeMissionUploadFailTitle: qsTr("Resume FAILED")
37 readonly property string pauseTitle: qsTr("Pause")
38 readonly property string mvPauseTitle: qsTr("Pause (MV)")
39 readonly property string changeAltTitle: qsTr("Change Altitude")
40 readonly property string changeLoiterRadiusTitle: qsTr("Change Loiter Radius")
41 readonly property string changeCruiseSpeedTitle: qsTr("Change Max Ground Speed")
42 readonly property string changeAirspeedTitle: qsTr("Change Airspeed")
43 readonly property string orbitTitle: qsTr("Orbit")
44 readonly property string landAbortTitle: qsTr("Land Abort")
45 readonly property string setWaypointTitle: qsTr("Set Waypoint")
46 readonly property string gotoTitle: qsTr("Go To Location")
47 readonly property string roiTitle: qsTr("ROI")
48 readonly property string setHomeTitle: qsTr("Set Home")
49 readonly property string setEstimatorOriginTitle: qsTr("Set Estimator Origin")
50 readonly property string setFlightMode: qsTr("Set Flight Mode")
51 readonly property string changeHeadingTitle: qsTr("Change Heading")
52
53 readonly property string armMessage: qsTr("Arm the vehicle.")
54 readonly property string mvArmMessage: qsTr("Arm selected vehicles.")
55 readonly property string forceArmMessage: qsTr("WARNING: This will force arming of the vehicle bypassing any safety checks.")
56 readonly property string disarmMessage: qsTr("Disarm the vehicle")
57 readonly property string mvDisarmMessage: qsTr("Disarm selected vehicles.")
58 readonly property string emergencyStopMessage: qsTr("WARNING: THIS WILL STOP ALL MOTORS. IF VEHICLE IS CURRENTLY IN THE AIR IT WILL CRASH.")
59 readonly property string takeoffMessage: qsTr("Takeoff and hold position")
60 readonly property string startMissionMessage: qsTr("Takeoff and start the current mission")
61 readonly property string mvStartMissionMessage: qsTr("Takeoff and start the current mission for selected vehicles")
62 readonly property string continueMissionMessage: qsTr("Continue the mission from the current waypoint")
63 readonly property string resumeMissionUploadFailMessage: qsTr("Upload of resume mission failed. Confirm to retry upload")
64 readonly property string landMessage: qsTr("Land the vehicle at the current position")
65 readonly property string rtlMessage: qsTr("Return to the launch position of the vehicle")
66 readonly property string changeAltMessage: qsTr("Change the altitude of the vehicle up or down")
67 readonly property string changeLoiterRadiusMessage: qsTr("Change the forward flight loiter radius")
68 readonly property string changeCruiseSpeedMessage: qsTr("Change the maximum horizontal cruise speed")
69 readonly property string changeAirspeedMessage: qsTr("Change the equivalent airspeed setpoint")
70 readonly property string gotoMessage: qsTr("Move the vehicle to the specified location")
71 property string setWaypointMessage: qsTr("Adjust current waypoint to %1").arg(_actionData)
72 readonly property string orbitMessage: qsTr("Orbit the vehicle around the specified location")
73 readonly property string landAbortMessage: qsTr("Abort the landing sequence")
74 readonly property string pauseMessage: qsTr("Pause at current position")
75 readonly property string mvPauseMessage: qsTr("Pause selected vehicles at their current position")
76 readonly property string roiMessage: qsTr("Make the specified location a Region Of Interest")
77 readonly property string setHomeMessage: qsTr("Set vehicle home as the specified location. This will affect Return to Home position")
78 readonly property string setEstimatorOriginMessage: qsTr("Make the specified location the estimator origin")
79 readonly property string setFlightModeMessage: qsTr("Set the vehicle flight mode to %1").arg(_actionData)
80 readonly property string changeHeadingMessage: qsTr("Set the vehicle heading towards the specified location")
81
82 readonly property int actionRTL: 1
83 readonly property int actionLand: 2
84 readonly property int actionTakeoff: 3
85 readonly property int actionArm: 4
86 readonly property int actionDisarm: 5
87 readonly property int actionEmergencyStop: 6
88 readonly property int actionChangeAlt: 7
89 readonly property int actionGoto: 8
90 readonly property int actionSetWaypoint: 9
91 readonly property int actionOrbit: 10
92 readonly property int actionLandAbort: 11
93 readonly property int actionStartMission: 12
94 readonly property int actionContinueMission: 13
95 readonly property int actionResumeMission: 14
96 readonly property int _actionUnused: 15
97 readonly property int actionResumeMissionUploadFail: 16
98 readonly property int actionPause: 17
99 readonly property int actionMVPause: 18
100 readonly property int actionMVStartMission: 19
101 readonly property int actionROI: 20
102 readonly property int actionForceArm: 21
103 readonly property int actionChangeSpeed: 22
104 readonly property int actionSetHome: 24
105 readonly property int actionSetEstimatorOrigin: 25
106 readonly property int actionSetFlightMode: 26
107 readonly property int actionChangeHeading: 27
108 readonly property int actionMVArm: 28
109 readonly property int actionMVDisarm: 29
110 readonly property int actionChangeLoiterRadius: 30
111
112 readonly property int customActionStart: 10000 // Custom actions ids should start here so that they don't collide with the built in actions
113
114 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
115 property var _flyViewSettings: QGroundControl.settingsManager.flyViewSettings
116 property var _unitsConversion: QGroundControl.unitsConversion
117 property var _readiness: _activeVehicle ? _activeVehicle.readiness : null
118
119 // Whether the vehicle would accept the action. Applicable actions which are not ready are shown disabled.
120 property bool armReady: _readiness ? _readiness.canArm : false
121 property bool takeoffReady: _readiness ? _readiness.canTakeoff : false
122 property bool startMissionReady: _readiness ? _readiness.canStartMission : false
123
124 // Takeoff and Land share a tool strip slot: Takeoff while on the ground, Land once underway
125 readonly property bool takeoffLandSlotShowsLand: _vehicleUnderway
126
127 property bool showEmergencyStop: !_hideEmergencyStop && _vehicleArmed && _vehicleAirborne
128 property bool showArm: _guidedActionsEnabled && !_vehicleArmed
129 property bool showForceArm: _guidedActionsEnabled && !_vehicleArmed && _flyViewSettings.allowForceArm.rawValue
130 property bool showDisarm: _vehicleArmed && !_vehicleAirborne
131 property bool showRTL: _guidedActionsEnabled && _activeVehicle && _vehicleArmed && _activeVehicle.supports.guidedMode && _activeVehicle.rtlFlightMode !== "" && _vehicleUnderway && !_vehicleInRTLMode
132 property bool showTakeoff: _guidedActionsEnabled && _activeVehicle && (_activeVehicle.supports.guidedTakeoffWithAltitude || _activeVehicle.supports.guidedTakeoffWithoutAltitude) && !_vehicleUnderway
133 property bool showLand: _guidedActionsEnabled && _activeVehicle && _activeVehicle.supports.guidedMode && _vehicleArmed && !_activeVehicle.fixedWing && !_vehicleInLandMode
134 property bool showStartMission: _guidedActionsEnabled && _missionAvailable && !_missionActive && !_vehicleUnderway
135 property bool showContinueMission: _guidedActionsEnabled && _missionAvailable && !_missionActive && _vehicleArmed && _vehicleUnderway && (_currentMissionIndex < _visualItemsCount - 1)
136 property bool showPause: _guidedActionsEnabled && _activeVehicle && _vehicleArmed && _activeVehicle.supports.pauseVehicle && _vehicleUnderway && !_vehiclePaused && !_fixedWingOnApproach
137 property bool showChangeAlt: _guidedActionsEnabled && _activeVehicle && _vehicleUnderway && _activeVehicle.supports.guidedMode && _vehicleArmed && !_missionActive
138 property bool showChangeLoiterRadius: _guidedActionsEnabled && _activeVehicle && _vehicleUnderway && _activeVehicle.supports.guidedMode && _vehicleArmed && !_missionActive && _vehicleInFwdFlight && fwdFlightGotoMapCircle.visible
139 property bool showChangeSpeed: _guidedActionsEnabled && _activeVehicle && _vehicleUnderway && _activeVehicle.supports.guidedMode && _vehicleArmed && !_missionActive && _speedLimitsAvailable
140 property bool showOrbit: _guidedActionsEnabled && _activeVehicle && _vehicleUnderway && __orbitSupported && !_missionActive && _activeVehicle.homePosition.isValid && !isNaN(_activeVehicle.homePosition.altitude)
141 property bool showROI: _guidedActionsEnabled && _vehicleUnderway && __roiSupported
142 property bool showLandAbort: _guidedActionsEnabled && _vehicleUnderway && _fixedWingOnApproach
143 property bool showGotoLocation: _guidedActionsEnabled && _vehicleUnderway
144 property bool showSetHome: _guidedActionsEnabled
145 property bool showSetEstimatorOrigin: _activeVehicle && !(_activeVehicle.sensorsPresentBits & MAVLinkEnums.MAV_SYS_STATUS_SENSOR_GPS)
146 property bool showChangeHeading: _guidedActionsEnabled && _vehicleUnderway
147
148 property string changeSpeedTitle: _vehicleInFwdFlight ? changeAirspeedTitle : changeCruiseSpeedTitle
149 property string changeSpeedMessage: _vehicleInFwdFlight ? changeAirspeedMessage : changeCruiseSpeedMessage
150
151 // Note: The '_visualItemsCount - 2' is a hack to not trigger resume mission when a mission ends with an RTL item
152 property bool showResumeMission: _activeVehicle && !_vehicleArmed && _vehicleWasUnderway && _missionAvailable && _resumeMissionIndex > 0 && (_resumeMissionIndex < _visualItemsCount - 2)
153
154 property bool guidedUIVisible: confirmDialog.visible
155
156 property var _corePlugin: QGroundControl.corePlugin
157 property var _corePluginOptions: QGroundControl.corePlugin.options
158 property bool _guidedActionsEnabled: (!ScreenTools.isDebug && _corePluginOptions.guidedActionsRequireRCRSSI && _activeVehicle) ? _rcRSSIAvailable : _activeVehicle
159 property string _flightMode: _activeVehicle ? _activeVehicle.flightMode : ""
160 property bool _missionAvailable: missionController.containsItems
161 property bool _missionActive: _activeVehicle ? _vehicleArmed && (_vehicleInLandMode || _vehicleInRTLMode || _vehicleInMissionMode) : false
162 property bool _vehicleArmed: _activeVehicle ? _activeVehicle.armed : false
163 property bool _vehicleUnderway: _activeVehicle ? _activeVehicle.underway : false
164 // Rover/Sub are underway whenever armed but accept a normal disarm, so only airborne vehicles need emergency stop
165 property bool _vehicleAirborne: _activeVehicle ? _activeVehicle.airborne : false
166 property bool _vehicleLanding: _activeVehicle ? _activeVehicle.landing : false
167 property bool _vehiclePaused: false
168 property bool _vehicleInMissionMode: false
169 property bool _vehicleInRTLMode: false
170 property bool _vehicleInLandMode: false
171 property int _visualItemsCount: missionController.visualItems ? missionController.visualItems.count : 0
172 property int _currentMissionIndex: missionController.currentMissionIndex
173 property int _resumeMissionIndex: missionController.resumeMissionIndex
174 property bool _hideEmergencyStop: !_corePluginOptions.flyView.guidedBarShowEmergencyStop
175 property bool _hideOrbit: !_corePluginOptions.flyView.guidedBarShowOrbit
176 property bool _hideROI: !_corePluginOptions.flyView.guidedBarShowROI
177 property bool _vehicleWasUnderway: false
178 property bool _rcRSSIAvailable: _activeVehicle ? _activeVehicle.rcRSSI.rawValue > 0 && _activeVehicle.rcRSSI.rawValue <= 100 : false
179 property bool _fixedWingOnApproach: _activeVehicle ? _activeVehicle.fixedWing && _vehicleLanding : false
180 property bool _vehicleInFwdFlight: _activeVehicle ? _activeVehicle.inFwdFlight : false
181 property bool _speedLimitsAvailable: _activeVehicle && ((_vehicleInFwdFlight && _activeVehicle.haveFWSpeedLimits) || (!_vehicleInFwdFlight && _activeVehicle.haveMRSpeedLimits))
182
183 // You can turn on log output for GuidedActionsController by turning on GuidedActionsControllerLog category
184 property bool __guidedModeSupported: _activeVehicle ? _activeVehicle.supports.guidedMode : false
185 property bool __pauseVehicleSupported: _activeVehicle ? _activeVehicle.supports.pauseVehicle : false
186 property bool __roiSupported: _activeVehicle ? !_hideROI && _activeVehicle.supports.roiMode : false
187 property bool __orbitSupported: _activeVehicle ? !_hideOrbit && _activeVehicle.supports.orbitMode : false
188 property bool __flightMode: _flightMode
189
190 // Allow custom builds to add custom actions by overriding CustomGuidedActionsController.qml
191 CustomGuidedActionsController {
192 id: customController
193 }
194 property var _customController: customController
195
196 function _isGuidedActionsControllerLogEnabled() {
197 return QGCLoggingCategoryManager.isCategoryEnabled("GuidedActionsControllerLog")
198 }
199
200 function _outputState() {
201 if (_isGuidedActionsControllerLogEnabled()) {
202 console.log(qsTr("_activeVehicle(%1) _vehicleArmed(%2) guidedModeSupported(%3) _vehicleUnderway(%4) _vehicleWasUnderway(%5) _vehicleInRTLMode(%6) pauseVehicleSupported(%7) _vehiclePaused(%8) _flightMode(%9) _visualItemsCount(%10) roiSupported(%11) orbitSupported(%12) _missionActive(%13) _hideROI(%14) _hideOrbit(%15)").arg(_activeVehicle ? 1 : 0).arg(_vehicleArmed ? 1 : 0).arg(__guidedModeSupported ? 1 : 0).arg(_vehicleUnderway ? 1 : 0).arg(_vehicleWasUnderway ? 1 : 0).arg(_vehicleInRTLMode ? 1 : 0).arg(__pauseVehicleSupported ? 1 : 0).arg(_vehiclePaused ? 1 : 0).arg(_flightMode).arg(_visualItemsCount).arg(__roiSupported).arg(__orbitSupported).arg(_missionActive).arg(_hideROI).arg(_hideOrbit))
203 }
204 }
205
206 function setupSlider(actionCode) {
207 if (actionCode === actionTakeoff) {
208 guidedValueSlider.setupSlider(
209 GuidedValueSlider.SliderType.Takeoff,
210 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_activeVehicle.minimumTakeoffAltitudeMeters()),
211 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_flyViewSettings.guidedMaximumAltitude.rawValue),
212 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_activeVehicle.minimumTakeoffAltitudeMeters()),
213 qsTr("Height (rel)"))
214 } else if (actionCode === actionChangeSpeed) {
215 if (_vehicleInFwdFlight) {
216 guidedValueSlider.setupSlider(
217 GuidedValueSlider.SliderType.Speed,
218 _unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.minimumEquivalentAirspeed()).toFixed(1),
219 _unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumEquivalentAirspeed()).toFixed(1),
220 _unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.airSpeed.rawValue),
221 qsTr("Airspeed"))
222 } else if (!_vehicleInFwdFlight && _activeVehicle.haveMRSpeedLimits) {
223 guidedValueSlider.setupSlider(
224 GuidedValueSlider.SliderType.Speed,
225 _unitsConversion.metersSecondToAppSettingsSpeedUnits(0.1).toFixed(1),
226 _unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumHorizontalSpeedMultirotorMetersSecond()).toFixed(1),
227 _unitsConversion.metersSecondToAppSettingsSpeedUnits(_activeVehicle.maximumHorizontalSpeedMultirotorMetersSecond()/2).toFixed(1),
228 qsTr("Speed"))
229 } else {
230 console.error("setupSlider called for inapproproate change speed action", _vehicleInFwdFlight, _activeVehicle.haveMRSpeedLimits)
231 }
232 } else if (actionCode === actionChangeAlt || actionCode === actionOrbit || actionCode === actionGoto || actionCode === actionPause) {
233 guidedValueSlider.setupSlider(
234 GuidedValueSlider.SliderType.Altitude,
235 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_flyViewSettings.guidedMinimumAltitude.rawValue),
236 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_flyViewSettings.guidedMaximumAltitude.rawValue),
237 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_activeVehicle.altitudeRelative.rawValue),
238 qsTr("Alt (rel)"))
239 } else if (actionCode === actionROI) {
240 // ROI targets a point on the ground by default, so start at 0 above home
241 guidedValueSlider.setupSlider(
242 GuidedValueSlider.SliderType.Altitude,
243 0,
244 _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_flyViewSettings.guidedMaximumAltitude.rawValue),
245 0,
246 qsTr("Alt (rel)"))
247 }
248 }
249
250 on_ActiveVehicleChanged: _outputState()
251
252 Component.onCompleted: _outputState()
253 on_VehicleArmedChanged: _outputState()
254 on_VehicleInRTLModeChanged: _outputState()
255 on_VehiclePausedChanged: _outputState()
256 on__FlightModeChanged: _outputState()
257 on__GuidedModeSupportedChanged: _outputState()
258 on__PauseVehicleSupportedChanged: _outputState()
259 on__RoiSupportedChanged: _outputState()
260 on__OrbitSupportedChanged: _outputState()
261 on_VisualItemsCountChanged: _outputState()
262 on_MissionActiveChanged: _outputState()
263
264 on_CurrentMissionIndexChanged: {
265 if (_isGuidedActionsControllerLogEnabled()) {
266 console.log("_currentMissionIndex", _currentMissionIndex)
267 }
268 }
269 on_ResumeMissionIndexChanged: {
270 if (_isGuidedActionsControllerLogEnabled()) {
271 console.log("_resumeMissionIndex", _resumeMissionIndex)
272 }
273 }
274 onShowResumeMissionChanged: {
275 if (_isGuidedActionsControllerLogEnabled()) {
276 console.log("showResumeMission", showResumeMission)
277 }
278 _outputState()
279 }
280 onShowStartMissionChanged: {
281 if (_isGuidedActionsControllerLogEnabled()) {
282 console.log("showStartMission", showStartMission)
283 }
284 _outputState()
285 _startMissionPopupIfAvailable()
286 }
287 onStartMissionReadyChanged: _startMissionPopupIfAvailable()
288
289 function _startMissionPopupIfAvailable() {
290 if (showStartMission && startMissionReady &&
291 _flyViewSettings.enableAutomaticMissionPopups.rawValue) {
292 confirmAction(actionStartMission)
293 }
294 }
295 onShowContinueMissionChanged: {
296 if (_isGuidedActionsControllerLogEnabled()) {
297 console.log("showContinueMission", showContinueMission)
298 }
299 _outputState()
300 if (showContinueMission &&
301 _flyViewSettings.enableAutomaticMissionPopups.rawValue) {
302 confirmAction(actionContinueMission)
303 }
304 }
305 onShowRTLChanged: {
306 if (_isGuidedActionsControllerLogEnabled()) {
307 console.log("showRTL", showRTL)
308 }
309 _outputState()
310 }
311 onShowChangeAltChanged: {
312 if (_isGuidedActionsControllerLogEnabled()) {
313 console.log("showChangeAlt", showChangeAlt)
314 }
315 _outputState()
316 }
317 onShowROIChanged: {
318 if (_isGuidedActionsControllerLogEnabled()) {
319 console.log("showROI", showROI)
320 }
321 _outputState()
322 }
323 onShowOrbitChanged: {
324 if (_isGuidedActionsControllerLogEnabled()) {
325 console.log("showOrbit", showOrbit)
326 }
327 _outputState()
328 }
329 onShowGotoLocationChanged: {
330 if (_isGuidedActionsControllerLogEnabled()) {
331 console.log("showGotoLocation", showGotoLocation)
332 }
333 _outputState()
334 }
335 onShowLandAbortChanged: {
336 if (showLandAbort) {
337 confirmAction(actionLandAbort)
338 }
339 }
340
341 on_VehicleUnderwayChanged: {
342 _outputState()
343 if (!_vehicleUnderway) {
344 // We use _vehicleWasUnderway to help trigger Resume Mission only if the vehicle actually moved and came back down.
345 // Otherwise it may trigger during the Start Mission sequence due to signal ordering or armed and resume mission index.
346 _vehicleWasUnderway = true
347 }
348 }
349
350 property var _actionData
351
352 on_FlightModeChanged: {
353 _vehiclePaused = _activeVehicle ? _flightMode === _activeVehicle.pauseFlightMode : false
354 _vehicleInRTLMode = _activeVehicle ? _flightMode === _activeVehicle.rtlFlightMode || _flightMode === _activeVehicle.smartRTLFlightMode : false
355 _vehicleInLandMode = _activeVehicle ? _flightMode === _activeVehicle.landFlightMode : false
356 _vehicleInMissionMode = _activeVehicle ? _flightMode === _activeVehicle.missionFlightMode : false // Must be last to get correct signalling for showStartMission popups
357 }
358
359 Connections {
360 target: missionController
361 function onResumeMissionUploadFail() { confirmAction(actionResumeMissionUploadFail) }
362 }
363
364 Connections {
365 target: mainWindow
366 function onArmVehicleRequest() { armVehicleRequest() }
367 function onForceArmVehicleRequest() { forceArmVehicleRequest() }
368 function onDisarmVehicleRequest() { disarmVehicleRequest() }
369 }
370
371 Connections {
372 target: _unitsConversion
373
374 function onUnitsChanged() {
375 // Slider range and value were captured in the previous units
376 if (_activeVehicle && guidedValueSlider.visible) {
377 setupSlider(confirmDialog.action)
378 }
379 }
380 }
381
382 function armVehicleRequest() {
383 confirmAction(actionArm)
384 }
385
386 function forceArmVehicleRequest() {
387 confirmAction(actionForceArm)
388 }
389
390 function disarmVehicleRequest() {
391 if (showEmergencyStop) {
392 confirmAction(actionEmergencyStop)
393 } else {
394 confirmAction(actionDisarm)
395 }
396
397 }
398
399 function closeAll() {
400 confirmDialog.visible = false
401 guidedValueSlider.visible = false
402 }
403
404 // Called when an action is about to be executed in order to confirm
405 function confirmAction(actionCode, actionData, mapIndicator) {
406 var showImmediate = true
407
408 // Cancel any previously pending action, notifying its map indicator if it differs from the incoming one
409 confirmDialog.confirmCancelled(mapIndicator)
410
411 confirmDialog.action = actionCode
412 confirmDialog.actionData = actionData
413 confirmDialog.mapIndicator = mapIndicator
414 confirmDialog.optionText = ""
415 _actionData = actionData
416
417 setupSlider(actionCode)
418
419 switch (actionCode) {
420 case actionArm:
421 if (_vehicleUnderway || !_guidedActionsEnabled) {
422 return
423 }
424 confirmDialog.title = armTitle
425 confirmDialog.message = armMessage
426 confirmDialog.hideTrigger = Qt.binding(function() { return !showArm || !armReady })
427 break;
428 case actionMVArm:
429 confirmDialog.title = mvArmTitle
430 confirmDialog.message = mvArmMessage
431 break;
432 case actionForceArm:
433 confirmDialog.title = forceArmTitle
434 confirmDialog.message = forceArmMessage
435 confirmDialog.hideTrigger = Qt.binding(function() { return !showForceArm })
436 break;
437 case actionDisarm:
438 if (_vehicleAirborne) {
439 return
440 }
441 confirmDialog.title = disarmTitle
442 confirmDialog.message = disarmMessage
443 confirmDialog.hideTrigger = Qt.binding(function() { return !showDisarm })
444 break;
445 case actionMVDisarm:
446 confirmDialog.title = mvDisarmTitle
447 confirmDialog.message = mvDisarmMessage
448 break;
449 case actionEmergencyStop:
450 confirmDialog.title = emergencyStopTitle
451 confirmDialog.message = emergencyStopMessage
452 confirmDialog.hideTrigger = Qt.binding(function() { return !showEmergencyStop })
453 break;
454 case actionTakeoff:
455 confirmDialog.title = takeoffTitle
456 confirmDialog.message = takeoffMessage
457 confirmDialog.hideTrigger = Qt.binding(function() { return !showTakeoff || !takeoffReady })
458 guidedValueSlider.visible = _activeVehicle.supports.guidedTakeoffWithAltitude
459 break;
460 case actionStartMission:
461 showImmediate = false
462 confirmDialog.title = startMissionTitle
463 confirmDialog.message = startMissionMessage
464 confirmDialog.hideTrigger = Qt.binding(function() { return !showStartMission || !startMissionReady })
465 break;
466 case actionMVStartMission:
467 confirmDialog.title = mvStartMissionTitle
468 confirmDialog.message = mvStartMissionMessage
469 break;
470 case actionContinueMission:
471 showImmediate = false
472 confirmDialog.title = continueMissionTitle
473 confirmDialog.message = continueMissionMessage
474 confirmDialog.hideTrigger = Qt.binding(function() { return !showContinueMission })
475 break;
476 case actionResumeMission:
477 // Resume Mission is handled in mission end dialog
478 return
479 case actionResumeMissionUploadFail:
480 confirmDialog.title = resumeMissionUploadFailTitle
481 confirmDialog.message = resumeMissionUploadFailMessage
482 confirmDialog.hideTrigger = Qt.binding(function() { return !showResumeMission })
483 break;
484 case actionLand:
485 confirmDialog.title = landTitle
486 confirmDialog.message = landMessage
487 confirmDialog.hideTrigger = Qt.binding(function() { return !showLand })
488 break;
489 case actionRTL:
490 confirmDialog.title = rtlTitle
491 confirmDialog.message = rtlMessage
492 if (_activeVehicle.supports.smartRTL) {
493 confirmDialog.optionText = qsTr("Smart RTL")
494 confirmDialog.optionChecked = false
495 }
496 confirmDialog.hideTrigger = Qt.binding(function() { return !showRTL })
497 break;
498 case actionChangeAlt:
499 confirmDialog.title = changeAltTitle
500 confirmDialog.message = changeAltMessage
501 confirmDialog.hideTrigger = Qt.binding(function() { return !showChangeAlt })
502 guidedValueSlider.visible = true
503 break;
504 case actionChangeLoiterRadius:
505 confirmDialog.title = changeLoiterRadiusTitle
506 confirmDialog.message = changeLoiterRadiusMessage
507 confirmDialog.hideTrigger = Qt.binding(function() { return !showChangeLoiterRadius })
508 confirmDialog.mapIndicator = fwdFlightGotoMapCircle
509 fwdFlightGotoMapCircle.startLoiterRadiusEdit()
510 break
511 case actionGoto:
512 confirmDialog.title = gotoTitle
513 confirmDialog.message = gotoMessage
514 confirmDialog.hideTrigger = Qt.binding(function() { return !showGotoLocation })
515 break;
516 case actionSetWaypoint:
517 confirmDialog.title = setWaypointTitle
518 confirmDialog.message = setWaypointMessage
519 break;
520 case actionOrbit:
521 confirmDialog.title = orbitTitle
522 confirmDialog.message = orbitMessage
523 confirmDialog.hideTrigger = Qt.binding(function() { return !showOrbit })
524 guidedValueSlider.visible = true
525 break;
526 case actionLandAbort:
527 confirmDialog.title = landAbortTitle
528 confirmDialog.message = landAbortMessage
529 confirmDialog.hideTrigger = Qt.binding(function() { return !showLandAbort })
530 break;
531 case actionPause:
532 confirmDialog.title = pauseTitle
533 confirmDialog.message = pauseMessage
534 confirmDialog.hideTrigger = Qt.binding(function() { return !showPause })
535 guidedValueSlider.visible = true
536 break;
537 case actionMVPause:
538 confirmDialog.title = mvPauseTitle
539 confirmDialog.message = mvPauseMessage
540 break;
541 case actionROI:
542 confirmDialog.title = roiTitle
543 confirmDialog.message = roiMessage
544 confirmDialog.hideTrigger = Qt.binding(function() { return !showROI })
545 guidedValueSlider.visible = true
546 break;
547 case actionChangeSpeed:
548 confirmDialog.title = changeSpeedTitle
549 confirmDialog.message = changeSpeedMessage
550 guidedValueSlider.visible = true
551 break
552 case actionSetHome:
553 confirmDialog.title = setHomeTitle
554 confirmDialog.message = setHomeMessage
555 confirmDialog.hideTrigger = Qt.binding(function() { return !showSetHome })
556 break
557 case actionSetEstimatorOrigin:
558 confirmDialog.title = setEstimatorOriginTitle
559 confirmDialog.message = setEstimatorOriginMessage
560 break
561 case actionSetFlightMode:
562 confirmDialog.title = setFlightMode
563 confirmDialog.message = setFlightModeMessage
564 break
565 case actionChangeHeading:
566 confirmDialog.title = changeHeadingTitle
567 confirmDialog.message = changeHeadingMessage
568 break
569 default:
570 if (!customController.customConfirmAction(actionCode, actionData, mapIndicator, confirmDialog)) {
571 console.warn("Unknown actionCode", actionCode)
572 return
573 }
574 }
575 confirmDialog.show(showImmediate)
576 }
577
578 // Executes the specified action
579 // Returns false if the action failed and any associated map indicator should be restored
580 function executeAction(actionCode, actionData, sliderOutputValue, optionChecked) {
581 var i;
582 var selectedVehicles;
583 switch (actionCode) {
584 case actionRTL:
585 _activeVehicle.guidedModeRTL(optionChecked)
586 break
587 case actionLand:
588 _activeVehicle.guidedModeLand()
589 break
590 case actionTakeoff:
591 if (_activeVehicle.supports.guidedTakeoffWithAltitude) {
592 var valueInMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue)
593 _activeVehicle.guidedModeTakeoff(valueInMeters)
594 } else {
595 _activeVehicle.startTakeoff()
596 }
597 break
598 case actionResumeMission:
599 case actionResumeMissionUploadFail:
600 missionController.resumeMission(missionController.resumeMissionIndex)
601 break
602 case actionStartMission:
603 case actionContinueMission:
604 _activeVehicle.startMission()
605 break
606 case actionMVStartMission:
607 selectedVehicles = QGroundControl.multiVehicleManager.selectedVehicles
608 for (i = 0; i < selectedVehicles.count; i++) {
609 var vehicle = selectedVehicles.get(i)
610 if (vehicle.armed === true){
611 vehicle.startMission()
612 }
613 }
614 break
615 case actionArm:
616 _activeVehicle.armed = true
617 break
618 case actionMVArm:
619 selectedVehicles = QGroundControl.multiVehicleManager.selectedVehicles
620 for (i = 0; i < selectedVehicles.count; i++) {
621 selectedVehicles.get(i).armed = true
622 }
623 break
624 case actionForceArm:
625 _activeVehicle.forceArm()
626 break
627 case actionDisarm:
628 _activeVehicle.armed = false
629 break
630 case actionMVDisarm:
631 selectedVehicles = QGroundControl.multiVehicleManager.selectedVehicles
632 for (i = 0; i < selectedVehicles.count; i++) {
633 selectedVehicles.get(i).armed = false
634 }
635 break
636 case actionEmergencyStop:
637 _activeVehicle.emergencyStop()
638 break
639 case actionChangeAlt:
640 var valueInMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue)
641 var altitudeChangeInMeters = valueInMeters - _activeVehicle.altitudeRelative.rawValue
642 _activeVehicle.guidedModeChangeAltitude(altitudeChangeInMeters, false /* pauseVehicle */)
643 break
644 case actionChangeLoiterRadius:
645 if (!_activeVehicle.guidedModeGotoLocation(
646 fwdFlightGotoMapCircle.coordinate,
647 (fwdFlightGotoMapCircle.clockwiseRotation ? 1 : -1) *
648 Math.abs(fwdFlightGotoMapCircle.radius.rawValue)
649 )) {
650 return false
651 }
652 break
653 case actionGoto:
654 if (!_activeVehicle.guidedModeGotoLocation(
655 actionData,
656 _vehicleInFwdFlight /* forwardFlightLoiterRadius */
657 ? _flyViewSettings.forwardFlightGoToLocationLoiterRad.rawValue
658 : 0
659 )) {
660 return false
661 }
662 break
663 case actionSetWaypoint:
664 _activeVehicle.setCurrentMissionSequence(actionData)
665 break
666 case actionOrbit:
667 var valueInMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue)
668 _activeVehicle.guidedModeOrbit(orbitMapCircle.center, orbitMapCircle.radius() * (orbitMapCircle.clockwiseRotation ? 1 : -1), _activeVehicle.homePosition.altitude + valueInMeters)
669 break
670 case actionLandAbort:
671 _activeVehicle.abortLanding(50) // hardcoded climbOutAltitude: ArduPilot Plane climbs to 50m above home, PX4 ignores it
672 break
673 case actionPause:
674 var valueInMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue)
675 var altitudeChangeInMeters = valueInMeters - _activeVehicle.altitudeRelative.rawValue
676 _activeVehicle.guidedModeChangeAltitude(altitudeChangeInMeters, true /* pauseVehicle */)
677 break
678 case actionMVPause:
679 selectedVehicles = QGroundControl.multiVehicleManager.selectedVehicles
680 for (i = 0; i < selectedVehicles.count; i++) {
681 selectedVehicles.get(i).pauseVehicle()
682 }
683 break
684 case actionROI: {
685 const roiRelativeAltitudeMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue)
686 if (!_activeVehicle.guidedModeROI(actionData, roiRelativeAltitudeMeters)) {
687 return false
688 }
689 break
690 }
691 case actionChangeSpeed:
692 if (_activeVehicle) {
693 // We need to convert back to m/s as that is what mavlink standard uses for MAV_CMD_DO_CHANGE_SPEED
694 var metersSecondSpeed = _unitsConversion.appSettingsSpeedUnitsToMetersSecond(sliderOutputValue)
695 if (_vehicleInFwdFlight) {
696 _activeVehicle.guidedModeChangeEquivalentAirspeedMetersSecond(metersSecondSpeed)
697 } else {
698 _activeVehicle.guidedModeChangeGroundSpeedMetersSecond(metersSecondSpeed)
699 }
700 }
701 break
702 case actionSetHome:
703 _activeVehicle.doSetHome(actionData)
704 break
705 case actionSetEstimatorOrigin:
706 _activeVehicle.setEstimatorOrigin(actionData)
707 break
708 case actionSetFlightMode:
709 _activeVehicle.flightMode = actionData
710 break
711 case actionChangeHeading:
712 _activeVehicle.guidedModeChangeHeading(actionData)
713 break
714 default:
715 if (!customController.customExecuteAction(actionCode, actionData, sliderOutputValue, optionChecked)) {
716 console.warn(qsTr("Internal error: unknown actionCode"), actionCode)
717 return false
718 }
719 break
720 }
721 return true
722 }
723}