PX4AdvancedFlightModes.qml 19.2 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick                  2.3
import QtQuick.Controls         1.2
13
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed
14
import QtQuick.Dialogs          1.2
15
import QtQuick.Layouts          1.2
Don Gagne's avatar
Don Gagne committed
16 17 18 19 20 21 22 23

import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0

Don Gagne's avatar
Don Gagne committed
24 25 26 27
/// PX4 Advanced Flight Mode configuration
Item {
    id: root

Don Gagne's avatar
Don Gagne committed
28
    readonly property bool _shortText: ScreenTools.isTinyScreen
Don Gagne's avatar
Don Gagne committed
29 30 31

    // User visible strings

32
    readonly property string title:                     qsTr("FLIGHT MODES")
33

Don Gagne's avatar
Don Gagne committed
34 35 36 37 38 39 40
    property string topHelpText: ScreenTools.isTinyScreen ?
                                     qsTr("Assign Flight Modes to radio control channels and adjust the thresholds for triggering them.") :
                                     (qsTr("Assign Flight Modes to radio control channels and adjust the thresholds for triggering them. ") +
                                      qsTr("You can assign multiple flight modes to a single channel. ") +
                                      qsTr("Turn your radio control on to test switch settings. ") +
                                      qsTr("The following channels: ") + controller.reservedChannels +
                                      qsTr(" are not available for Flight Modes since they are already in use for other functions."))
Don Gagne's avatar
Don Gagne committed
41

42 43 44 45 46 47
    readonly property string fwManualModeName:          qsTr("Manual/Main")
    readonly property string mrManualModeName:          qsTr("Stabilized/Main")
    readonly property string fwManualModeDescription:   qsTr("The pilot has full control of the aircraft, no assistance is provided. ") +
                                                        qsTr("The Main mode switch must always be assigned to a channel in order to fly")
    readonly property string mrManualModeDescription:   qsTr("The pilot has full control of the aircraft, only attitude is stabilized. ") +
                                                        qsTr("The Main mode switch must always be assigned to a channel in order to fly")
Don Gagne's avatar
Don Gagne committed
48

49
    readonly property string assistModeName:            qsTr("Assist")
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
50
    readonly property string assistModeDescription:     qsTr("If Position Control is placed on a separate channel from the Main mode channel, an additional 'Assist' mode is added to the Main switch. ") +
51
                                                        qsTr("In order for the Attitude Control/Position Control switch to be active, the Main switch must be in Assist mode.")
Don Gagne's avatar
Don Gagne committed
52

53
    readonly property string autoModeName:              qsTr("Auto")
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
54
    readonly property string autoModeDescription:       qsTr("If Loiter is placed on a separate channel from the Main mode channel, an additional 'Auto' mode is added to the Main switch. ") +
55
                                                        qsTr("In order for the Mission/Loiter switch to be active, the Main switch must be in Auto mode.")
Don Gagne's avatar
Don Gagne committed
56

57 58
    readonly property string fwAcroModeName:            qsTr("Stabilized")
    readonly property string mrAcroModeName:            qsTr("Acro")
59
    readonly property string fwAcroModeDescription:     qsTr("Roll/pitch angles and rudder deflection are controlled. ")
60
    readonly property string mrAcroModeDescription:     qsTr("The angular rates are controlled, but not the attitude. ")
61

Daniel Agar's avatar
Daniel Agar committed
62
    readonly property string altCtlModeName:            qsTr("Altitude")
63 64 65 66
    readonly property string fwAltCtlModeDescription:   qsTr("Roll stick controls banking, pitch stick altitude ") +
                                                        qsTr("Throttle stick controls speed. ") +
                                                        qsTr("With no stick inputs the plane holds heading, but drifts off in wind. ")
    readonly property string mrAltCtlModeDescription:   qsTr("Same as Stablized mode except that Throttle controls climb/sink rate. Centered Throttle holds altitude steady. ")
Don Gagne's avatar
Don Gagne committed
67

68 69 70 71 72 73
    readonly property string posCtlModeName:            qsTr("Position Control")
    readonly property string fwPosCtlModeDescription:   qsTr("Roll stick controls banking, pitch stick controls altitude. ") +
                                                        qsTr("Throttle stick controls speed.") +
                                                        qsTr("With no stick inputs the plane flies a straight line, even in wind. ")
    readonly property string mrPosCtlModeDescription:   qsTr("Roll and Pitch sticks control sideways and forward speed ") +
                                                        qsTr("Throttle stick controls climb / sink rade. ")
Don Gagne's avatar
Don Gagne committed
74

Daniel Agar's avatar
Daniel Agar committed
75
    readonly property string missionModeName:           qsTr("Mission")
76
    readonly property string missionModeDescription:    qsTr("The aircraft obeys the programmed mission sent by QGroundControl. ")
Don Gagne's avatar
Don Gagne committed
77

Daniel Agar's avatar
Daniel Agar committed
78
    readonly property string loiterModeName:            qsTr("Hold")
79 80
    readonly property string fwLoiterModeDescription:   qsTr("The aircraft flies in a circle around the current position at the current altitude. ")
    readonly property string mrLoiterModeDescription:   qsTr("The multirotor hovers at the current position and altitude. ")
Don Gagne's avatar
Don Gagne committed
81

82
    readonly property string returnModeName:            qsTr("Return")
83
    readonly property string returnModeDescription:     qsTr("The vehicle returns to the launch position, loiters and then lands. ")
Don Gagne's avatar
Don Gagne committed
84

85 86
    readonly property string offboardModeName:          qsTr("Offboard")
    readonly property string offboardModeDescription:   qsTr("All flight control aspects are controlled by an offboard system.")
Don Gagne's avatar
Don Gagne committed
87 88 89

    readonly property real modeSpacing: ScreenTools.defaultFontPixelHeight / 3

Don Gagne's avatar
Don Gagne committed
90
    PX4AdvancedFlightModesController {
Don Gagne's avatar
Don Gagne committed
91 92
        id:         controller
        onModeRowsChanged: recalcModePositions()
Don Gagne's avatar
Don Gagne committed
93 94
    }

Don Gagne's avatar
Don Gagne committed
95 96 97
    Timer {
        interval:   200
        running:    true
Don Gagne's avatar
Don Gagne committed
98

99
        onTriggered: {
100
            recalcModePositions()
101
        }
Don Gagne's avatar
Don Gagne committed
102
    }
Don Gagne's avatar
Don Gagne committed
103

Don Gagne's avatar
Don Gagne committed
104 105 106
    function recalcModePositions() {
        var spacing = ScreenTools.defaultFontPixelHeight / 2
        var nextY = manualMode.y + manualMode.height + spacing
Don Gagne's avatar
Don Gagne committed
107

Don Gagne's avatar
Don Gagne committed
108 109 110 111 112 113
        for (var index = 0; index < 9; index++) {
            if (controller.assistModeRow == index) {
                if (controller.assistModeVisible) {
                    assistMode.y = nextY
                    assistMode.z = 9 - index
                    nextY += assistMode.height + spacing
Don Gagne's avatar
Don Gagne committed
114
                }
Don Gagne's avatar
Don Gagne committed
115 116 117 118 119
            } else if (controller.autoModeRow == index) {
                if (controller.autoModeVisible) {
                    autoMode.y = nextY
                    autoMode.z = 9 - index
                    nextY += autoMode.height  + spacing
Don Gagne's avatar
Don Gagne committed
120
                }
Don Gagne's avatar
Don Gagne committed
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
            } else if (controller.acroModeRow == index) {
                acroMode.y = nextY
                acroMode.z = 9 - index
                nextY += acroMode.height + spacing
            } else if (controller.altCtlModeRow == index) {
                altCtlMode.y = nextY
                altCtlMode.z = 9 - index
                nextY += altCtlMode.height + spacing
            } else if (controller.posCtlModeRow == index) {
                posCtlMode.y = nextY
                posCtlMode.z = 9 - index
                nextY += posCtlMode.height + spacing
            } else if (controller.loiterModeRow == index) {
                loiterMode.y = nextY
                loiterMode.z = 9 - index
                nextY += loiterMode.height + spacing
            } else if (controller.missionModeRow == index) {
                missionMode.y = nextY
                missionMode.z = 9 - index
                nextY += missionMode.height + spacing
            } else if (controller.returnModeRow == index) {
                returnMode.y = nextY
                returnMode.z = 9 - index
                nextY += returnMode.height + spacing
            } else if (controller.offboardModeRow == index) {
                offboardMode.y = nextY
                offboardMode.z = 9 - index
                nextY += offboardMode.height + spacing
Don Gagne's avatar
Don Gagne committed
149
            }
Don Gagne's avatar
Don Gagne committed
150
        }
Don Gagne's avatar
Don Gagne committed
151

Don Gagne's avatar
Don Gagne committed
152 153
        scrollItem.height = nextY
    }
Don Gagne's avatar
Don Gagne committed
154

Don Gagne's avatar
Don Gagne committed
155 156
    Component {
        id: joystickEnabledDialogComponent
Don Gagne's avatar
Don Gagne committed
157

Don Gagne's avatar
Don Gagne committed
158
        QGCViewMessage {
159
            message: qsTr("Flight Mode Config is disabled since you have a Joystick enabled.")
160
        }
Don Gagne's avatar
Don Gagne committed
161 162 163 164 165 166
    }

    ScrollView {
        id:                         scroll
        anchors.fill:               parent
        horizontalScrollBarPolicy:  Qt.ScrollBarAlwaysOff
167

Don Gagne's avatar
Don Gagne committed
168 169 170
        Item {
            id:     scrollItem
            width:  scroll.viewport.width
Don Gagne's avatar
Don Gagne committed
171

Don Gagne's avatar
Don Gagne committed
172
            Item {
Don Gagne's avatar
Don Gagne committed
173 174 175 176 177 178 179 180 181 182
                id:             helpApplyRow
                width:          parent.width
                height:         Math.max(helpText.contentHeight, applyButton.y + applyButton.height)

                QGCLabel {
                    id:                     helpText
                    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                    anchors.left:           parent.left
                    anchors.right:          buttonColumn.left
                    text:                   topHelpText
183
                    font.pointSize:         ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
184 185 186 187 188 189 190 191 192 193
                    wrapMode:               Text.WordWrap
                }

                Column {
                    id:                     buttonColumn
                    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                    anchors.right:          parent.right
                    spacing:                ScreenTools.defaultFontPixelHeight / 4

                    QGCButton {
194
                        text: qsTr("Use Single Channel Mode Selection")
Don Gagne's avatar
Don Gagne committed
195 196 197 198 199
                        visible: controller.parameterExists(-1, "RC_MAP_FLTMODE")
                        onClicked: {
                            controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 0
                            controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 5
                        }
200 201 202 203
                    }

                    QGCButton {
                        id:                     applyButton
204
                        text:                   qsTr("Generate Thresholds")
205 206
                        onClicked: controller.generateThresholds()
                    }
Don Gagne's avatar
Don Gagne committed
207
                }
Don Gagne's avatar
Don Gagne committed
208
            }
Don Gagne's avatar
Don Gagne committed
209

Don Gagne's avatar
Don Gagne committed
210 211 212 213 214 215
            Item {
                id:             lastSpacer
                anchors.top:    helpApplyRow.bottom
                height:         ScreenTools.defaultFontPixelHeight
                width:          10
            }
Don Gagne's avatar
Don Gagne committed
216

Don Gagne's avatar
Don Gagne committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230
            ModeSwitchDisplay {
                id:                     manualMode
                anchors.top:            lastSpacer.bottom
                flightModeName:         controller.fixedWing ? fwManualModeName : mrManualModeName
                flightModeDescription:  controller.fixedWing ? fwManualModeDescription : mrManualModeDescription
                rcValue:                controller.manualModeRcValue
                modeChannelIndex:       controller.manualModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.manualModeSelected
                thresholdValue:         controller.manualModeThreshold
                thresholdDragEnabled:   false

                onModeChannelIndexSelected: controller.manualModeChannelIndex = index
            }
Don Gagne's avatar
Don Gagne committed
231

Don Gagne's avatar
Don Gagne committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
            ModeSwitchDisplay {
                id:                     assistMode
                visible:                controller.assistModeVisible
                flightModeName:         assistModeName
                flightModeDescription:  assistModeDescription
                rcValue:                controller.assistModeRcValue
                modeChannelIndex:       controller.assistModeChannelIndex
                modeChannelEnabled:     false
                modeSelected:           controller.assistModeSelected
                thresholdValue:         controller.assistModeThreshold
                thresholdDragEnabled:   true

                onThresholdValueChanged: controller.assistModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
248

Don Gagne's avatar
Don Gagne committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
            ModeSwitchDisplay {
                id:                     autoMode
                visible:                controller.autoModeVisible
                flightModeName:         autoModeName
                flightModeDescription:  autoModeDescription
                rcValue:                controller.autoModeRcValue
                modeChannelIndex:       controller.autoModeChannelIndex
                modeChannelEnabled:     false
                modeSelected:           controller.autoModeSelected
                thresholdValue:         controller.autoModeThreshold
                thresholdDragEnabled:   true

                onThresholdValueChanged: controller.autoModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
265

Don Gagne's avatar
Don Gagne committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
            ModeSwitchDisplay {
                id:                     acroMode
                flightModeName:         controller.fixedWing ? fwAcroModeName : mrAcroModeName
                flightModeDescription:  controller.fixedWing ? fwAcroModeDescription : mrAcroModeDescription
                rcValue:                controller.acroModeRcValue
                modeChannelIndex:       controller.acroModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.acroModeSelected
                thresholdValue:         controller.acroModeThreshold
                thresholdDragEnabled:   true

                onModeChannelIndexSelected:  controller.acroModeChannelIndex = index
                onThresholdValueChanged:    controller.acroModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
282

Don Gagne's avatar
Don Gagne committed
283 284 285 286 287 288 289 290 291 292
            ModeSwitchDisplay {
                id:                     altCtlMode
                flightModeName:         altCtlModeName
                flightModeDescription:  controller.fixedWing ? fwAltCtlModeDescription : mrAltCtlModeDescription
                rcValue:                controller.altCtlModeRcValue
                modeChannelIndex:       controller.altCtlModeChannelIndex
                modeChannelEnabled:     false
                modeSelected:           controller.altCtlModeSelected
                thresholdValue:         controller.altCtlModeThreshold
                thresholdDragEnabled:   !controller.assistModeVisible
Don Gagne's avatar
Don Gagne committed
293

Don Gagne's avatar
Don Gagne committed
294
                onThresholdValueChanged:    controller.altCtlModeThreshold = thresholdValue
Don Gagne's avatar
Don Gagne committed
295

Don Gagne's avatar
Don Gagne committed
296 297
                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
298

Don Gagne's avatar
Don Gagne committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
            ModeSwitchDisplay {
                id:                     posCtlMode
                flightModeName:         posCtlModeName
                flightModeDescription:  controller.fixedWing ? fwPosCtlModeDescription : mrPosCtlModeDescription
                rcValue:                controller.posCtlModeRcValue
                modeChannelIndex:       controller.posCtlModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.posCtlModeSelected
                thresholdValue:         controller.posCtlModeThreshold
                thresholdDragEnabled:   true

                onModeChannelIndexSelected:  controller.posCtlModeChannelIndex = index
                onThresholdValueChanged:    controller.posCtlModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
315

Don Gagne's avatar
Don Gagne committed
316 317 318 319 320 321 322 323 324 325
            ModeSwitchDisplay {
                id:                     missionMode
                flightModeName:         missionModeName
                flightModeDescription:  missionModeDescription
                rcValue:                controller.missionModeRcValue
                modeChannelIndex:       controller.missionModeChannelIndex
                modeChannelEnabled:     false
                modeSelected:           controller.missionModeSelected
                thresholdValue:         controller.missionModeThreshold
                thresholdDragEnabled:   !controller.autoModeVisible
Don Gagne's avatar
Don Gagne committed
326

Don Gagne's avatar
Don Gagne committed
327
                onThresholdValueChanged: controller.missionModeThreshold = thresholdValue
Don Gagne's avatar
Don Gagne committed
328

Don Gagne's avatar
Don Gagne committed
329 330
                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
331

Don Gagne's avatar
Don Gagne committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
            ModeSwitchDisplay {
                id:                     loiterMode
                flightModeName:         loiterModeName
                flightModeDescription:  controller.fixedWing ? fwLoiterModeDescription : mrLoiterModeDescription
                rcValue:                controller.loiterModeRcValue
                modeChannelIndex:       controller.loiterModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.loiterModeSelected
                thresholdValue:         controller.loiterModeThreshold
                thresholdDragEnabled:   true

                onModeChannelIndexSelected:  controller.loiterModeChannelIndex = index
                onThresholdValueChanged:    controller.loiterModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
348

Don Gagne's avatar
Don Gagne committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
            ModeSwitchDisplay {
                id:                     returnMode
                flightModeName:         returnModeName
                flightModeDescription:  returnModeDescription
                rcValue:                controller.returnModeRcValue
                modeChannelIndex:       controller.returnModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.returnModeSelected
                thresholdValue:         controller.returnModeThreshold
                thresholdDragEnabled:   true

                onModeChannelIndexSelected:  controller.returnModeChannelIndex = index
                onThresholdValueChanged:    controller.returnModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
Don Gagne's avatar
Don Gagne committed
365

Don Gagne's avatar
Don Gagne committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
            ModeSwitchDisplay {
                id:                     offboardMode
                flightModeName:         offboardModeName
                flightModeDescription:  offboardModeDescription
                rcValue:                controller.offboardModeRcValue
                modeChannelIndex:       controller.offboardModeChannelIndex
                modeChannelEnabled:     true
                modeSelected:           controller.offboardModeSelected
                thresholdValue:         controller.offboardModeThreshold
                thresholdDragEnabled:   true

                onModeChannelIndexSelected:  controller.offboardModeChannelIndex = index
                onThresholdValueChanged:    controller.offboardModeThreshold = thresholdValue

                Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
            }
        } // Item
    } // Scroll View
} // Item