FlightModesComponent.qml 21.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

 QGroundControl Open Source Ground Control Station

 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

 This file is part of the QGROUNDCONTROL project

 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

 ======================================================================*/

Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
import QtQuick.Layouts          1.1

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

QGCView {
    id:         rootQGCView
    viewPanel:  panel

    readonly property int monitorThresholdCharWidth: 8  // Character width of Monitor and Threshold labels

    // User visible strings

45
    property string topHelpText:                        "Assign Flight Modes to radio control channels and adjust the thresholds for triggering them. " +
Don Gagne's avatar
Don Gagne committed
46
                                                        "You can assign multiple flight modes to a single channel. " +
47 48 49
                                                        "Turn your radio control on to test switch settings. " +
                                                        "The following channels: " + controller.reservedChannels +
                                                        " are not available for Flight Modes since they are already in use for other functions."
Don Gagne's avatar
Don Gagne committed
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


    readonly property string fwManualModeName:          "Manual/Main"
    readonly property string mrManualModeName:          "Stabilized/Main"
    readonly property string fwManualModeDescription:   "The pilot has full control of the aircraft, no assistance is provided. " +
                                                        "The Main mode switch must always be assigned to a channel in order to fly"
    readonly property string mrManualModeDescription:   "Centering roll/pitch stick will return the multirotor to a level attitude, but it will continue drifting in the direction it was previously sent. " +
                                                        "Altitude is controlled fully by pilot using the Throttle stick. " +
                                                        "The Main mode switch must always be assigned to a channel in order to fly"

    readonly property string assistModeName:            "Assist"
    readonly property string assistModeDescription:     "If Position Control is placed on a seperate channel from the Main mode channel, an additional 'Assist' mode is added to the Main switch. " +
                                                        "In order for the Attitude Control/Position Control switch to be active, the Main switch must be in Assist mode."

    readonly property string autoModeName:              "Auto"
    readonly property string autoModeDescription:       "If Loiter is placed on a seperate channel from the Main mode channel, an additional 'Auto' mode is added to the Main switch. " +
                                                        "In order for the Mission/Loiter switch to be active, the Main switch must be in Auto mode."

    readonly property string fwAcroModeName:            "Stabilized"
    readonly property string mrAcroModeName:            "Acro"
    readonly property string fwAcroModeDescription:     "Need Stablized description"
    readonly property string mrAcroModeDescription:     "Need Acro mode description"

    readonly property string fwAltCtlModeName:          "Attitude Control"
    readonly property string mrAltCtlModeName:          "Altitude Control"
    readonly property string fwAltCtlModeDescription:   "Aileron and Elevator sticks affect roll and pitch according to the Attitude Control settings. " +
                                                        "Altitude is not maintained automatically. " +
                                                        "Rudder is controlled fully by the pilot."
    readonly property string mrAltCtlModeDescription:   "Same as Stablized mode except that Throttle controls climb/sink rate. Centered throttle holds altitude steady."

    readonly property string posCtlModeName:            "Position Control"
    readonly property string fwPosCtlModeDescription:   "Throttle controls speed, pitch controls climb/sink rate, roll controls yaw rate. " +
                                                        "Roll and Pitch centered gives level, straight-line flight. " +
                                                        "Position Control and Attitude Control must always be on the same channel."
    readonly property string mrPosCtlModeDescription:   "Roll and Pitch control left-right and front-back speed over ground respectively. " +
                                                        "When roll and pitch are centered, the multirotor will hold position. " +
                                                        "Yaw controls yaw rate as in Stablized mode. " +
                                                        "Throttle controls climb/sink rate. Centered throttle holds altitude steady. " +
                                                        "Position Control and Attitude Control must always be on the same channel."

    readonly property string missionModeName:           "Mission"
    readonly property string missionModeDescription:    "The aircraft obeys the programmed mission sent by QGroundControl. " +
                                                        "If no mission was sent, aircraft will loiter at current position instead."

    readonly property string loiterModeName:            "Loiter"
    readonly property string fwLoiterModeDescription:   "The aircraft flies in a circle around the current position at the current altitude. " +
                                                        "Loiter and Mission must always be on the same channel."
    readonly property string mrLoiterModeDescription:   "The multirotor hovers in a fixed position at the current position and altitude. " +
                                                        "Loiter and Mission must always be on the same channel."

    readonly property string returnModeName:            "Return"
    readonly property string fwReturnModeDescription:   "The aircraft returns to the home position and loiters above it." +
                                                        "The settings which control this sequence can be found under Setup - Safety."
    readonly property string mrReturnModeDescription:   "The multirotor returns to the home position, loiters and then lands. " +
                                                        "The settings which control this sequence can be found under Setup - Safety."

    readonly property string offboardModeName:          "Offboard"
    readonly property string offboardModeDescription:   "Offboard description"

    readonly property real modeSpacing: ScreenTools.defaultFontPixelHeight / 3

    QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled }

    FlightModesComponentController {
        id:         controller
        factPanel:  panel

        onModeRowsChanged: recalcModePositions()
Don Gagne's avatar
Don Gagne committed
118 119
    }

Don Gagne's avatar
Don Gagne committed
120 121 122
    Timer {
        interval:   200
        running:    true
Don Gagne's avatar
Don Gagne committed
123

Don Gagne's avatar
Don Gagne committed
124 125
        onTriggered: recalcModePositions()
    }
Don Gagne's avatar
Don Gagne committed
126

Don Gagne's avatar
Don Gagne committed
127 128 129
    function recalcModePositions() {
        var spacing = ScreenTools.defaultFontPixelHeight / 2
        var nextY = manualMode.y + manualMode.height + spacing
Don Gagne's avatar
Don Gagne committed
130

Don Gagne's avatar
Don Gagne committed
131 132 133 134 135 136
        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
137
                }
Don Gagne's avatar
Don Gagne committed
138 139 140 141 142
            } 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
143
                }
Don Gagne's avatar
Don Gagne committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            } 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
172
            }
Don Gagne's avatar
Don Gagne committed
173
        }
Don Gagne's avatar
Don Gagne committed
174

Don Gagne's avatar
Don Gagne committed
175 176
        scrollItem.height = nextY
    }
Don Gagne's avatar
Don Gagne committed
177

Don Gagne's avatar
Don Gagne committed
178 179 180
    QGCViewPanel {
        id:             panel
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
181

Don Gagne's avatar
Don Gagne committed
182 183 184 185
        ScrollView {
            id:                         scroll
            anchors.fill:               parent
            horizontalScrollBarPolicy:  Qt.ScrollBarAlwaysOff
Don Gagne's avatar
Don Gagne committed
186

Don Gagne's avatar
Don Gagne committed
187 188 189
            Item {
                id:     scrollItem
                width:  scroll.viewport.width
Don Gagne's avatar
Don Gagne committed
190

Don Gagne's avatar
Don Gagne committed
191 192 193 194 195
                QGCLabel {
                    id:             header
                    width:          parent.width
                    font.pixelSize: ScreenTools.largeFontPixelSize
                    text:           "FLIGHT MODES CONFIG"
Don Gagne's avatar
Don Gagne committed
196 197
                }

Don Gagne's avatar
Don Gagne committed
198 199 200 201 202
                Item {
                    id:             headingSpacer
                    anchors.top:    header.bottom
                    height:         20
                    width:          20
Don Gagne's avatar
Don Gagne committed
203 204
                }

Don Gagne's avatar
Don Gagne committed
205 206 207 208 209 210 211
                QGCLabel {
                    anchors.top:            headingSpacer.bottom
                    anchors.left:           parent.left
                    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                    anchors.right:          applyButton.left
                    text:                   topHelpText
                    wrapMode:               Text.WordWrap
212
                }
Don Gagne's avatar
Don Gagne committed
213

Don Gagne's avatar
Don Gagne committed
214 215 216 217 218 219
                QGCButton {
                    id:                     applyButton
                    anchors.top:            headingSpacer.bottom
                    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                    anchors.right:          parent.right
                    text:                   "Generate Thresholds"
Don Gagne's avatar
Don Gagne committed
220

Don Gagne's avatar
Don Gagne committed
221
                    onClicked: controller.generateThresholds()
Don Gagne's avatar
Don Gagne committed
222 223
                }

Don Gagne's avatar
Don Gagne committed
224 225 226 227 228
                Item {
                    id:             lastSpacer
                    anchors.top:    applyButton.bottom
                    height:         20
                    width:          10
Don Gagne's avatar
Don Gagne committed
229
                }
Don Gagne's avatar
Don Gagne committed
230

Don Gagne's avatar
Don Gagne committed
231 232 233 234 235 236 237 238 239 240 241 242 243
                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

                    onModeChannelIndexChanged: controller.manualModeChannelIndex = modeChannelIndex
Don Gagne's avatar
Don Gagne committed
244
                }
Don Gagne's avatar
Don Gagne committed
245

Don Gagne's avatar
Don Gagne committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
                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
261 262
                }

Don Gagne's avatar
Don Gagne committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
                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
278 279
                }

Don Gagne's avatar
Don Gagne committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
                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

                    onModeChannelIndexChanged:  controller.acroModeChannelIndex = modeChannelIndex
                    onThresholdValueChanged:    controller.acroModeThreshold = thresholdValue

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

Don Gagne's avatar
Don Gagne committed
297 298 299 300 301 302 303 304 305 306
                ModeSwitchDisplay {
                    id:                     altCtlMode
                    flightModeName:         controller.fixedWing ? fwAltCtlModeName : mrAltCtlModeName
                    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
307

Don Gagne's avatar
Don Gagne committed
308
                    onThresholdValueChanged:    controller.altCtlModeThreshold = thresholdValue
Don Gagne's avatar
Don Gagne committed
309

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

Don Gagne's avatar
Don Gagne committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
                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

                    onModeChannelIndexChanged:  controller.posCtlModeChannelIndex = modeChannelIndex
                    onThresholdValueChanged:    controller.posCtlModeThreshold = thresholdValue

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

Don Gagne's avatar
Don Gagne committed
330 331 332 333 334 335 336 337 338 339
                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
340

Don Gagne's avatar
Don Gagne committed
341
                    onThresholdValueChanged: controller.missionModeThreshold = thresholdValue
Don Gagne's avatar
Don Gagne committed
342

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

Don Gagne's avatar
Don Gagne committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
                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

                    onModeChannelIndexChanged:  controller.loiterModeChannelIndex = modeChannelIndex
                    onThresholdValueChanged:    controller.loiterModeThreshold = thresholdValue

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

Don Gagne's avatar
Don Gagne committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
                ModeSwitchDisplay {
                    id:                     returnMode
                    flightModeName:         returnModeName
                    flightModeDescription:  controller.fixedWing ? fwReturnModeDescription : mrReturnModeDescription
                    rcValue:                controller.returnModeRcValue
                    modeChannelIndex:       controller.returnModeChannelIndex
                    modeChannelEnabled:     true
                    modeSelected:           controller.returnModeSelected
                    thresholdValue:         controller.returnModeThreshold
                    thresholdDragEnabled:   true

                    onModeChannelIndexChanged:  controller.returnModeChannelIndex = modeChannelIndex
                    onThresholdValueChanged:    controller.returnModeThreshold = thresholdValue

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

Don Gagne's avatar
Don Gagne committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
                ModeSwitchDisplay {
                    id:                     offboardMode
                    flightModeName:         offboardModeName
                    flightModeDescription:  offboardModeDescription
                    rcValue:                controller.offboardModeRcValue
                    modeChannelIndex:       controller.offboardModeChannelIndex
                    modeChannelEnabled:     true
                    modeSelected:           controller.offboardModeSelected
                    thresholdValue:         controller.offboardModeThreshold
                    thresholdDragEnabled:   true

                    onModeChannelIndexChanged:  controller.offboardModeChannelIndex = modeChannelIndex
                    onThresholdValueChanged:    controller.offboardModeThreshold = thresholdValue

                    Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } }
Don Gagne's avatar
Don Gagne committed
395
                }
Don Gagne's avatar
Don Gagne committed
396 397 398 399
            } // Item
        } // Scroll View
    } // QGCViewPanel
} // QGCView