SafetyComponent.qml 29.5 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/>.

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

dogmaphobic's avatar
dogmaphobic committed
24
import QtQuick 2.5
Don Gagne's avatar
Don Gagne committed
25 26
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
dogmaphobic's avatar
dogmaphobic committed
27 28
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
29

Don Gagne's avatar
Don Gagne committed
30
import QGroundControl.FactSystem 1.0
31
import QGroundControl.FactControls 1.0
32
import QGroundControl.Palette 1.0
Don Gagne's avatar
Don Gagne committed
33
import QGroundControl.Controls 1.0
34
import QGroundControl.ScreenTools 1.0
Don Gagne's avatar
Don Gagne committed
35

Don Gagne's avatar
Don Gagne committed
36

dogmaphobic's avatar
dogmaphobic committed
37
QGCView {
Don Gagne's avatar
Don Gagne committed
38 39 40
    id:             _safetyView
    viewPanel:      panel
    anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
41

dogmaphobic's avatar
dogmaphobic committed
42
    FactPanelController { id: controller; factPanel: panel }
Don Gagne's avatar
Don Gagne committed
43

dogmaphobic's avatar
dogmaphobic committed
44
    QGCPalette { id: palette; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
45

46
    property real _margins:         ScreenTools.defaultFontPixelHeight
47 48
    property real _middleRowWidth:  ScreenTools.defaultFontPixelWidth * 20
    property real _editFieldWidth:  ScreenTools.defaultFontPixelWidth * 14
Don Gagne's avatar
Don Gagne committed
49

Don Gagne's avatar
Don Gagne committed
50 51 52 53
    property Fact _fenceAction:     controller.getParameterFact(-1, "GF_ACTION")
    property Fact _fenceRadius:     controller.getParameterFact(-1, "GF_MAX_HOR_DIST")
    property Fact _fenceAlt:        controller.getParameterFact(-1, "GF_MAX_VER_DIST")
    property Fact _rtlLandDelay:    controller.getParameterFact(-1, "RTL_LAND_DELAY")
54 55
    property Fact _lowBattAction:   controller.getParameterFact(-1, "COM_LOW_BAT_ACT")
    property Fact _rcLossAction:    controller.getParameterFact(-1, "NAV_RCL_ACT")
56
    property Fact _dlLossAction:    controller.getParameterFact(-1, "NAV_DLL_ACT")
57
    property Fact _disarmLandDelay: controller.getParameterFact(-1, "COM_DISARM_LAND")
58
    property Fact _landSpeedMC:     controller.getParameterFact(-1, "MPC_LAND_SPEED", false)
dogmaphobic's avatar
dogmaphobic committed
59 60 61 62

    QGCViewPanel {
        id:             panel
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
63
        QGCFlickable {
64
            clip:                                       true
65
            anchors.fill:   parent
66 67
            contentHeight:                              mainCol.height
            flickableDirection:                         Flickable.VerticalFlick
68
            Column {
69 70
                id:                                     mainCol
                spacing:                                _margins
71
                anchors.horizontalCenter:               parent.horizontalCenter
72 73 74 75
                /*
                   **** Low Battery ****
                */
                Item { width: 1; height: _margins * 0.5; }
76
                QGCLabel {
77
                    text:                               qsTr("Low Battery Failsafe Trigger")
78
                    font.family:                        ScreenTools.demiboldFontFamily
79 80
                }
                Rectangle {
81 82 83
                    color:                              palette.windowShade
                    width:                              rtlSettings.width
                    height:                             lowBattRow.height + _margins * 2
84
                    Row {
85 86 87 88 89 90 91
                        id:                             lowBattRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        Image {
                            height:                     ScreenTools.defaultFontPixelWidth * 6
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
92
                            sourceSize.width:           width
93 94 95 96
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
                            source:                     qgcPal.globalTheme === QGCPalette.Light ? "/qmlimages/LowBatteryLight.svg" : "/qmlimages/LowBattery.svg"
                            anchors.verticalCenter:     parent.verticalCenter
97
                        }
98 99 100 101 102
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            Row {
103
                                visible:                !controller.fixedWing
104 105 106
                                QGCLabel {
                                    anchors.baseline:   lowBattCombo.baseline
                                    width:              _middleRowWidth
107
                                    text:               qsTr("Failsafe Action:")
108 109 110 111 112
                                }
                                FactComboBox {
                                    id:                 lowBattCombo
                                    width:              _editFieldWidth
                                    fact:               _lowBattAction
113
                                    indexModel:         false
114 115 116 117 118 119
                                }
                            }
                            Row {
                                QGCLabel {
                                    anchors.baseline:   batLowLevelField.baseline
                                    width:              _middleRowWidth
120
                                    text:               qsTr("Battery Warn Level:")
121 122 123
                                }
                                FactTextField {
                                    id:                 batLowLevelField
124
                                    fact:               controller.getParameterFact(-1, "BAT_LOW_THR")
125 126 127 128
                                    showUnits:          true
                                    width:              _editFieldWidth
                                }
                            }
129 130
                            Row {
                                QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
131
                                    anchors.baseline:   batCritLevelField.baseline
132 133 134 135 136 137 138 139 140 141
                                    width:              _middleRowWidth
                                    text:               qsTr("Battery Failsafe Level:")
                                }
                                FactTextField {
                                    id:                 batCritLevelField
                                    fact:               controller.getParameterFact(-1, "BAT_CRIT_THR")
                                    showUnits:          true
                                    width:              _editFieldWidth
                                }
                            }
142
                        }
143 144 145 146 147 148
                    }
                }
                /*
                   **** RC Loss ****
                */
                QGCLabel {
149
                    text:                               qsTr("RC Loss Failsafe Trigger")
150
                    font.family:                        ScreenTools.demiboldFontFamily
151 152 153 154 155 156 157 158 159 160 161 162 163
                }
                Rectangle {
                    color:                              palette.windowShade
                    width:                              rtlSettings.width
                    height:                             rcLossRow.height + _margins * 2
                    Row {
                        id:                             rcLossRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        Image {
                            height:                     ScreenTools.defaultFontPixelWidth * 6
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
164
                            sourceSize.width:           width
165 166 167 168
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
                            source:                     qgcPal.globalTheme === QGCPalette.Light ? "/qmlimages/RCLossLight.svg" : "/qmlimages/RCLoss.svg"
                            anchors.verticalCenter:     parent.verticalCenter
169
                        }
170
                        Item { width: _margins * 0.5; height: 1; }
171
                        Column {
172 173 174 175 176 177
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            Row {
                                QGCLabel {
                                    anchors.baseline:   rcLossCombo.baseline
                                    width:              _middleRowWidth
178
                                    text:               qsTr("Failsafe Action:")
179 180 181 182 183
                                }
                                FactComboBox {
                                    id:                 rcLossCombo
                                    width:              _editFieldWidth
                                    fact:               _rcLossAction
184
                                    indexModel:         false
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                                }
                            }
                            Row {
                                QGCLabel {
                                    anchors.baseline:   rcLossField.baseline
                                    width:              _middleRowWidth
                                    text:               qsTr("RC Loss Timeout:")
                                }
                                FactTextField {
                                    id:                 rcLossField
                                    fact:               controller.getParameterFact(-1, "COM_RC_LOSS_T")
                                    showUnits:          true
                                    width:              _editFieldWidth
                                }
                            }
200 201 202 203 204 205 206
                        }
                    }
                }
                /*
                   **** Data Link Loss ****
                */
                QGCLabel {
207
                    text:                               qsTr("Data Link Loss Failsafe Trigger")
208
                    font.family:                        ScreenTools.demiboldFontFamily
209 210 211 212 213 214 215 216 217 218 219 220 221
                }
                Rectangle {
                    color:                              palette.windowShade
                    width:                              rtlSettings.width
                    height:                             dlLossRow.height + _margins * 2
                    Row {
                        id:                             dlLossRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        Image {
                            height:                     ScreenTools.defaultFontPixelWidth * 6
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
222
                            sourceSize.width:           width
223 224 225 226 227 228 229 230 231
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
                            source:                     qgcPal.globalTheme === QGCPalette.Light ? "/qmlimages/DatalinkLossLight.svg" : "/qmlimages/DatalinkLoss.svg"
                            anchors.verticalCenter:     parent.verticalCenter
                        }
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
232 233
                            Row {
                                QGCLabel {
234
                                    anchors.baseline:   dlLossCombo.baseline
235
                                    width:              _middleRowWidth
236
                                    text:               qsTr("Failsafe Action:")
237 238 239 240 241 242 243 244 245 246 247 248 249
                                }
                                FactComboBox {
                                    id:                 dlLossCombo
                                    width:              _editFieldWidth
                                    fact:               _dlLossAction
                                    indexModel:         false
                                }
                            }
                            Row {
                                QGCLabel {
                                    anchors.baseline:   dlLossField.baseline
                                    width:              _middleRowWidth
                                    text:               qsTr("Data Link Loss Timeout:")
250 251
                                }
                                FactTextField {
252 253
                                    id:                 dlLossField
                                    fact:               controller.getParameterFact(-1, "COM_DL_LOSS_T")
254
                                    showUnits:          true
255
                                    width:              _editFieldWidth
256 257 258 259 260 261 262 263 264
                                }
                            }
                        }
                    }
                }
                /*
                   **** Geofence ****
                */
                QGCLabel {
265
                    text:                               qsTr("Geofence Failsafe Trigger")
266
                    font.family:                        ScreenTools.demiboldFontFamily
267 268 269 270 271 272 273 274 275 276 277 278 279
                }
                Rectangle {
                    color:                              palette.windowShade
                    width:                              rtlSettings.width
                    height:                             geofenceRow.height + _margins * 2
                    Row {
                        id:                             geofenceRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        Image {
                            height:                     ScreenTools.defaultFontPixelWidth * 8
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
280
                            sourceSize.width:           width
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
                            source:                     qgcPal.globalTheme === QGCPalette.Light ? "/qmlimages/GeoFenceLight.svg" : "/qmlimages/GeoFence.svg"
                            anchors.verticalCenter:     parent.verticalCenter
                        }
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            Row {
                                QGCLabel {
                                    id:                 fenceActionLabel
                                    anchors.baseline:   fenceActionCombo.baseline
                                    text:               qsTr("Action on breach:")
                                    width:              _middleRowWidth
                                }
                                FactComboBox {
                                    id:                 fenceActionCombo
                                    width:              _editFieldWidth
                                    fact:               _fenceAction
301
                                    indexModel:         false
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
                                }
                            }
                            Row {
                                QGCCheckBox {
                                    id:                 fenceRadiusCheckBox
                                    anchors.baseline:   fenceRadiusField.baseline
                                    text:               qsTr("Max radius:")
                                    checked:            _fenceRadius.value >= 0
                                    onClicked:          _fenceRadius.value = checked ? 100 : -1
                                    width:              _middleRowWidth
                                }
                                FactTextField {
                                    id:                 fenceRadiusField
                                    showUnits:          true
                                    fact:               _fenceRadius
                                    enabled:            fenceRadiusCheckBox.checked
                                    width:              _editFieldWidth
                                }
                            }
                            Row {
                                QGCCheckBox {
                                    id:                 fenceAltMaxCheckBox
                                    anchors.baseline:   fenceAltMaxField.baseline
                                    text:               qsTr("Max altitude:")
                                    checked:            _fenceAlt.value >= 0
                                    onClicked:          _fenceAlt.value = checked ? 100 : -1
                                    width:              _middleRowWidth
                                }
                                FactTextField {
                                    id:                 fenceAltMaxField
                                    showUnits:          true
                                    fact:               _fenceAlt
                                    enabled:            fenceAltMaxCheckBox.checked
                                    width:              _editFieldWidth
                                }
                            }
                        }
                    }
                }
                /*
                   **** Return Home Settings ****
                */
                QGCLabel {
                    id:                                 rtlLabel
                    text:                               qsTr("Return Home Settings")
347
                    font.family:                        ScreenTools.demiboldFontFamily
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
                }
                Rectangle {
                    id:                                 rtlSettings
                    color:                              palette.windowShade
                    width:                              rtlRow.width  + _margins * 2
                    height:                             rtlRow.height + _margins * 2
                    Row {
                        id:                             rtlRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        QGCColoredImage {
                            id:                         icon
                            color:                      palette.text
                            height:                     ScreenTools.defaultFontPixelWidth * 10
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
364
                            sourceSize.width:           width
365 366
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
367
                            source:                     controller.fixedWing ? "/qmlimages/ReturnToHomeAltitude.svg" : "/qmlimages/ReturnToHomeAltitudeCopter.svg"
368 369 370 371 372
                            anchors.verticalCenter:     parent.verticalCenter
                        }
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
                            spacing:                    _margins * 0.5
373 374 375 376
                            Row {
                                QGCLabel {
                                    id:                 climbLabel
                                    anchors.baseline:   climbField.baseline
377
                                    width:              _middleRowWidth
378 379 380 381 382 383
                                    text:               qsTr("Climb to altitude of:")
                                }
                                FactTextField {
                                    id:                 climbField
                                    fact:               controller.getParameterFact(-1, "RTL_RETURN_ALT")
                                    showUnits:          true
384
                                    width:              _editFieldWidth
385 386
                                }
                            }
387
                            Item { width: 1; height: _margins * 0.5; }
388
                            QGCLabel {
389 390
                                id:                     returnHomeLabel
                                text:                   "Return home, then:"
391 392
                            }
                            Row {
393
                                Item { height: 1; width: _margins; }
394 395 396 397
                                Column {
                                    spacing:            _margins * 0.5
                                    ExclusiveGroup { id: homeLoiterGroup }
                                    QGCRadioButton {
398 399 400 401 402
                                        id:             homeLandRadio
                                        checked:        _rtlLandDelay.value === 0
                                        exclusiveGroup: homeLoiterGroup
                                        text:           "Land immediately"
                                        onClicked:      _rtlLandDelay.value = 0
403 404
                                    }
                                    QGCRadioButton {
405 406 407 408 409
                                        id:             homeLoiterNoLandRadio
                                        checked:        _rtlLandDelay.value < 0
                                        exclusiveGroup: homeLoiterGroup
                                        text:           "Loiter and do not land"
                                        onClicked:      _rtlLandDelay.value = -1
410 411
                                    }
                                    QGCRadioButton {
412 413 414 415 416
                                        id:             homeLoiterLandRadio
                                        checked:        _rtlLandDelay.value > 0
                                        exclusiveGroup: homeLoiterGroup
                                        text:           qsTr("Loiter and land after specified time")
                                        onClicked:      _rtlLandDelay.value = 60
417 418 419
                                    }
                                }
                            }
420
                            Item { width: 1; height: _margins * 0.5; }
421 422 423
                            Row {
                                QGCLabel {
                                    text:               qsTr("Loiter Time")
424
                                    width:              _middleRowWidth
425 426 427 428 429 430 431 432 433
                                    anchors.baseline:   landDelayField.baseline
                                    color:              palette.text
                                    enabled:            homeLoiterLandRadio.checked === true
                                }
                                FactTextField {
                                    id:                 landDelayField
                                    fact:               controller.getParameterFact(-1, "RTL_LAND_DELAY")
                                    showUnits:          true
                                    enabled:            homeLoiterLandRadio.checked === true
434
                                    width:              _editFieldWidth
435 436 437 438 439
                                }
                            }
                            Row {
                                QGCLabel {
                                    text:               qsTr("Loiter Altitude")
440
                                    width:              _middleRowWidth
441 442
                                    anchors.baseline:   descendField.baseline
                                    color:              palette.text
443
                                    enabled:            homeLoiterLandRadio.checked === true || homeLoiterNoLandRadio.checked === true
444 445 446 447
                                }
                                FactTextField {
                                    id:                 descendField
                                    fact:               controller.getParameterFact(-1, "RTL_DESCEND_ALT")
448
                                    enabled:            homeLoiterLandRadio.checked === true || homeLoiterNoLandRadio.checked === true
449
                                    showUnits:          true
450
                                    width:              _editFieldWidth
451 452 453 454 455
                                }
                            }
                        }
                    }
                }
456 457 458
                /*
                   **** Land Mode Settings ****
                */
459
                QGCLabel {
460
                    text:                               qsTr("Land Mode Settings")
461
                    font.family:                        ScreenTools.demiboldFontFamily
462 463
                }
                Rectangle {
464 465 466
                    color:                              palette.windowShade
                    width:                              rtlSettings.width
                    height:                             landModeRow.height + _margins * 2
467
                    Row {
468 469 470
                        id:                             landModeRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
471
                        Item {
472 473
                            width:                      _margins * 0.5
                            height:                     1
474 475
                        }
                        QGCColoredImage {
476
                            color:                      palette.text
dogmaphobic's avatar
dogmaphobic committed
477
                            height:                     ScreenTools.defaultFontPixelWidth * 13
478
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
479
                            sourceSize.width:           width
480 481
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
482
                            source:                     controller.fixedWing ? "/qmlimages/LandMode.svg" : "/qmlimages/LandModeCopter.svg"
483
                            anchors.verticalCenter:     parent.verticalCenter
484 485
                        }
                        Item {
486 487
                            width:                      _margins * 0.5
                            height:                     1
488 489 490 491 492
                        }
                        Column {
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            Row {
Lorenz Meier's avatar
Lorenz Meier committed
493
                                visible:                _landSpeedMC !== -1
494 495
                                QGCLabel {
                                    anchors.baseline:   landVelField.baseline
496 497
                                    width:              _middleRowWidth
                                    text:               qsTr("Landing Velocity:")
498 499 500
                                }
                                FactTextField {
                                    id:                 landVelField
Lorenz Meier's avatar
Lorenz Meier committed
501
                                    fact:               _landSpeedMC
502
                                    showUnits:          true
503
                                    width:              _editFieldWidth
504 505 506
                                }
                            }
                            Row {
507 508
                                QGCCheckBox {
                                    id:                 disarmDelayCheckBox
509 510
                                    anchors.baseline:   disarmField.baseline
                                    text:               qsTr("Disarm After:")
511 512 513
                                    checked:            _disarmLandDelay.value > 0
                                    onClicked:          _disarmLandDelay.value = checked ? 2 : 0
                                    width:              _middleRowWidth
514 515 516 517
                                }
                                FactTextField {
                                    id:                 disarmField
                                    showUnits:          true
518 519
                                    fact:               _disarmLandDelay
                                    enabled:            disarmDelayCheckBox.checked
520
                                    width:              _editFieldWidth
521 522 523 524 525
                                }
                            }
                        }
                    }
                }
526
                Item { width: 1; height: _margins * 0.5; }
Don Gagne's avatar
Don Gagne committed
527
            }
528 529 530
        }
    }
}
531