APMCameraComponent.qml 26.3 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9 10


11 12
import QtQuick              2.3
import QtQuick.Controls     1.2
Don Gagne's avatar
Don Gagne committed
13 14 15 16 17 18 19

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

20 21 22
SetupPage {
    id:             cameraPage
    pageComponent:  cameraPageComponent
Don Gagne's avatar
Don Gagne committed
23 24

    Component {
25 26 27 28 29 30
        id: cameraPageComponent

        Column {
            spacing:    _margins
            width:      availableWidth

31
            FactPanelController { id: controller; }
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

            QGCPalette { id: palette; colorGroupEnabled: true }

            property Fact _mountRetractX:       controller.getParameterFact(-1, "MNT_RETRACT_X")
            property Fact _mountRetractY:       controller.getParameterFact(-1, "MNT_RETRACT_Y")
            property Fact _mountRetractZ:       controller.getParameterFact(-1, "MNT_RETRACT_Z")

            property Fact _mountNeutralX:       controller.getParameterFact(-1, "MNT_NEUTRAL_X")
            property Fact _mountNeutralY:       controller.getParameterFact(-1, "MNT_NEUTRAL_Y")
            property Fact _mountNeutralZ:       controller.getParameterFact(-1, "MNT_NEUTRAL_Z")

            property Fact _mountRCInTilt:       controller.getParameterFact(-1, "MNT_RC_IN_TILT")
            property Fact _mountStabTilt:       controller.getParameterFact(-1, "MNT_STAB_TILT")
            property Fact _mountAngMinTilt:     controller.getParameterFact(-1, "MNT_ANGMIN_TIL")
            property Fact _mountAngMaxTilt:     controller.getParameterFact(-1, "MNT_ANGMAX_TIL")

            property Fact _mountRCInRoll:       controller.getParameterFact(-1, "MNT_RC_IN_ROLL")
            property Fact _mountStabRoll:       controller.getParameterFact(-1, "MNT_STAB_ROLL")
            property Fact _mountAngMinRoll:     controller.getParameterFact(-1, "MNT_ANGMIN_ROL")
            property Fact _mountAngMaxRoll:     controller.getParameterFact(-1, "MNT_ANGMAX_ROL")

            property Fact _mountRCInPan:        controller.getParameterFact(-1, "MNT_RC_IN_PAN")
            property Fact _mountStabPan:        controller.getParameterFact(-1, "MNT_STAB_PAN")
            property Fact _mountAngMinPan:      controller.getParameterFact(-1, "MNT_ANGMIN_PAN")
            property Fact _mountAngMaxPan:      controller.getParameterFact(-1, "MNT_ANGMAX_PAN")

58 59 60 61 62 63 64 65 66 67
            property Fact _rc5Function:         controller.getParameterFact(-1, "SERVO5_FUNCTION")
            property Fact _rc6Function:         controller.getParameterFact(-1, "SERVO6_FUNCTION")
            property Fact _rc7Function:         controller.getParameterFact(-1, "SERVO7_FUNCTION")
            property Fact _rc8Function:         controller.getParameterFact(-1, "SERVO8_FUNCTION")
            property Fact _rc9Function:         controller.getParameterFact(-1, "SERVO9_FUNCTION")
            property Fact _rc10Function:        controller.getParameterFact(-1, "SERVO10_FUNCTION")
            property Fact _rc11Function:        controller.getParameterFact(-1, "SERVO11_FUNCTION")
            property Fact _rc12Function:        controller.getParameterFact(-1, "SERVO12_FUNCTION")
            property Fact _rc13Function:        controller.getParameterFact(-1, "SERVO13_FUNCTION")
            property Fact _rc14Function:        controller.getParameterFact(-1, "SERVO14_FUNCTION")
68 69 70 71 72

            property bool _tiltEnabled:         false
            property bool _panEnabled:          false
            property bool _rollEnabled:         false

73 74
            property bool _servoReverseIsBool:  controller.parameterExists(-1, "RC5_REVERSED")

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
            // Gimbal Settings not available on older firmware
            property bool _showGimbaLSettings:  controller.parameterExists(-1, "MNT_DEFLT_MODE")

            readonly property real  _margins:                       ScreenTools.defaultFontPixelHeight
            readonly property int   _rcFunctionDisabled:            0
            readonly property int   _rcFunctionMountPan:            6
            readonly property int   _rcFunctionMountTilt:           7
            readonly property int   _rcFunctionMountRoll:           8
            readonly property int   _firstGimbalOutChannel:         5
            readonly property int   _lastGimbalOutChannel:          14
            readonly property int   _mountDefaultModeRCTargetting:  3

            Component.onCompleted: {
                if (_showGimbaLSettings) {
                    gimbalSettingsLoader.sourceComponent = gimbalSettings
Don Gagne's avatar
Don Gagne committed
90
                }
91 92
                calcGimbalOutValues()
            }
Don Gagne's avatar
Don Gagne committed
93

94
            function setGimbalSettingsServoInfo(loader, channel) {
95
                var rcPrefix = "SERVO" + channel + "_"
Don Gagne's avatar
Don Gagne committed
96

97 98 99
                loader.gimbalOutIndex = channel - 4
                loader.servoPWMMinFact = controller.getParameterFact(-1, rcPrefix + "MIN")
                loader.servoPWMMaxFact = controller.getParameterFact(-1, rcPrefix + "MAX")
Don Gagne's avatar
Don Gagne committed
100
                loader.servoReverseFact = controller.getParameterFact(-1, rcPrefix + "REVERSED")
101
            }
Don Gagne's avatar
Don Gagne committed
102

103
            /// Gimbal output channels are stored in SERVO#_FUNCTION parameters. We need to loop through those
104 105 106 107 108 109 110 111 112
            /// to find them and setup the ui accordindly.
            function calcGimbalOutValues() {
                gimbalDirectionTiltLoader.gimbalOutIndex = 0
                gimbalDirectionPanLoader.gimbalOutIndex = 0
                gimbalDirectionRollLoader.gimbalOutIndex = 0
                _tiltEnabled = false
                _panEnabled = false
                _rollEnabled = false
                for (var channel=_firstGimbalOutChannel; channel<=_lastGimbalOutChannel; channel++) {
113
                    var functionFact = controller.getParameterFact(-1, "SERVO" + channel + "_FUNCTION")
114 115 116 117 118 119 120 121 122 123
                    if (functionFact.value == _rcFunctionMountTilt) {
                        _tiltEnabled = true
                        setGimbalSettingsServoInfo(gimbalDirectionTiltLoader, channel)
                    } else if (functionFact.value == _rcFunctionMountPan) {
                        _panEnabled = true
                        setGimbalSettingsServoInfo(gimbalDirectionPanLoader, channel)
                    } else if (functionFact.value == _rcFunctionMountRoll) {
                        _rollEnabled = true
                        setGimbalSettingsServoInfo(gimbalDirectionRollLoader, channel)
                    }
Don Gagne's avatar
Don Gagne committed
124
                }
125 126
            }

127 128 129
            function setRCFunction(channel, rcFunction) {
                // First clear any previous settings for this function
                for (var index=_firstGimbalOutChannel; index<=_lastGimbalOutChannel; index++) {
130
                    var functionFact = controller.getParameterFact(-1, "SERVO" + index + "_FUNCTION")
131 132 133
                    if (functionFact.value != _rcFunctionDisabled && functionFact.value == rcFunction) {
                        functionFact.value = _rcFunctionDisabled
                    }
134 135
                }

136 137
                // Now set the function into the new channel
                if (channel != 0) {
138
                    var functionFact = controller.getParameterFact(-1, "SERVO" + channel + "_FUNCTION")
139
                    functionFact.value = rcFunction
140
                }
141
            }
142

143
            // Whenever any SERVO#_FUNCTION parameters changes we need to go looking for gimbal output channels again
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
            Connections { target: _rc5Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc6Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc7Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc8Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc9Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc10Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc11Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc12Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc13Function; onValueChanged: calcGimbalOutValues() }
            Connections { target: _rc14Function; onValueChanged: calcGimbalOutValues() }

            // Whenever an MNT_RC_IN_* setting is changed make sure to turn on RC targeting
            Connections {
                target:         _mountRCInPan
                onValueChanged: _mountDefaultMode.value = _mountDefaultModeRCTargetting
            }
160

161 162 163 164
            Connections {
                target:         _mountRCInRoll
                onValueChanged: _mountDefaultMode.value = _mountDefaultModeRCTargetting
            }
165

166 167 168 169
            Connections {
                target:         _mountRCInTilt
                onValueChanged: _mountDefaultMode.value = _mountDefaultModeRCTargetting
            }
170

171 172
            ListModel {
                id: gimbalOutModel
173 174
                // It appears that QGCComboBox can't handle models that don't have a initial item
                // after onModelChanged
175
                ListElement { text: qsTr("Disabled"); value: 0 }
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195

                function update(number) {
                    // Not enough channels
                    if(number < 6) {
                        return
                    }
                    for(var i = 5; i <= number; i++) {
                        var text = qsTr("Channel ") + i
                        append({"text": text, "value": i})
                    }
                }

                Component.onCompleted: {
                    // Number of main outputs
                    var baseValue = 8
                    // Extra outputs
                    // http://ardupilot.org/copter/docs/parameters.html#brd-pwm-count-auxiliary-pin-config
                    var brd_pwm_count_value = controller.getParameterFact(-1, "BRD_PWM_COUNT").value
                    update(8 + (brd_pwm_count_value == 7 ? 3 : brd_pwm_count_value))
                }
196
            }
Don Gagne's avatar
Don Gagne committed
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211
            Component {
                id: gimbalDirectionSettings

                // The following properties must be set in the Loader
                //      property string directionTitle
                //      property bool directionEnabled
                //      property int gimbalOutIndex
                //      property Fact mountRcInFact
                //      property Fact mountStabFact
                //      property Fact mountAngMinFact
                //      property Fact mountAngMaxFact
                //      property Fact servoPWMMinFact
                //      property Fact servoPWMMaxFact
                //      property Fact servoReverseFact
212
                //      property bool servoReverseIsBool
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                //      property int rcFunction

                Item {
                    width:  rectangle.x + rectangle.width
                    height: rectangle.y + rectangle.height

                    QGCLabel {
                        id:         directionLabel
                        text:       qsTr("Gimbal ") + directionTitle
                        font.family: ScreenTools.demiboldFontFamily
                    }

                    Rectangle {
                        id:                 rectangle
                        anchors.topMargin:  _margins / 2
                        anchors.left:       parent.left
                        anchors.top:        directionLabel.bottom
                        width:              mountAngMaxField.x + mountAngMaxField.width + _margins
                        height:             servoPWMMaxField.y + servoPWMMaxField.height + _margins
                        color:              palette.windowShade

                        FactCheckBox {
                            id:                 mountStabCheckBox
                            anchors.topMargin:  _margins
                            anchors.left:       servoReverseCheckBox.left
                            anchors.top:        parent.top
                            text:               qsTr("Stabilize")
                            fact:               mountStabFact
                            checkedValue:       1
                            uncheckedValue:     0
                            enabled:            directionEnabled
                        }

                        FactCheckBox {
                            id:                 servoReverseCheckBox
                            anchors.margins:    _margins
                            anchors.top:        mountStabCheckBox.bottom
                            anchors.right:       parent.right
                            text:               qsTr("Servo reverse")
252 253
                            checkedValue:       _servoReverseIsBool ? 1 : -1
                            uncheckedValue:     _servoReverseIsBool ? 0 : 1
254 255
                            fact:               servoReverseFact
                            enabled:            directionEnabled
256 257

                            property bool _servoReverseIsBool: servoReverseIsBool
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
                        }

                        QGCLabel {
                            id:                 gimbalOutLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   gimbalOutCombo.baseline
                            text:               qsTr("Output channel:")
                        }

                        QGCComboBox {
                            id:                 gimbalOutCombo
                            anchors.margins:    _margins
                            anchors.top:        parent.top
                            anchors.left:       gimbalOutLabel.right
                            width:              mountAngMinField.width
                            model:              gimbalOutModel
275
                            textRole:           "text"
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
                            currentIndex:       gimbalOutIndex

                            onActivated: setRCFunction(gimbalOutModel.get(index).value, rcFunction)
                        }

                        QGCLabel {
                            id:                 mountRcInLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   mountRcInCombo.baseline
                            text:               qsTr("Input channel:")
                            enabled:            directionEnabled
                        }

                        FactComboBox {
                            id:                 mountRcInCombo
                            anchors.topMargin:  _margins / 2
                            anchors.top:        gimbalOutCombo.bottom
                            anchors.left:       gimbalOutCombo.left
                            width:              mountAngMinField.width
                            fact:               mountRcInFact
                            indexModel:         false
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 mountAngLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   mountAngMinField.baseline
                            text:               qsTr("Gimbal angle limits:")
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 mountAngMinLabel
                            anchors.margins:    _margins
                            anchors.left:       mountAngLabel.right
                            anchors.baseline:   mountAngMinField.baseline
                            text:               qsTr("min")
                            enabled:            directionEnabled
                        }

                        FactTextField {
                            id:                 mountAngMinField
                            anchors.margins:    _margins
                            anchors.top:        mountRcInCombo.bottom
                            anchors.left:       mountAngMinLabel.right
                            fact:               mountAngMinFact
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 mountAngMaxLabel
                            anchors.margins:    _margins
                            anchors.left:       mountAngMinField.right
                            anchors.baseline:   mountAngMinField.baseline
                            text:               qsTr("max")
                            enabled:            directionEnabled
                        }

                        FactTextField {
                            id:                 mountAngMaxField
                            anchors.leftMargin: _margins
                            anchors.top:        mountAngMinField.top
                            anchors.left:       mountAngMaxLabel.right
                            fact:               mountAngMaxFact
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 servoPWMLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   servoPWMMinField.baseline
                            text:               qsTr("Servo PWM limits:")
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 servoPWMMinLabel
                            anchors.left:       mountAngMinLabel.left
                            anchors.baseline:   servoPWMMinField.baseline
                            text:               qsTr("min")
                            enabled:            directionEnabled
                        }

                        FactTextField {
                            id:                 servoPWMMinField
                            anchors.topMargin:  _margins / 2
                            anchors.leftMargin: _margins
                            anchors.top:        mountAngMaxField.bottom
                            anchors.left:       servoPWMMinLabel.right
                            fact:               servoPWMMinFact
                            enabled:            directionEnabled
                        }

                        QGCLabel {
                            id:                 servoPWMMaxLabel
                            anchors.margins:    _margins
                            anchors.left:       servoPWMMinField.right
                            anchors.baseline:   servoPWMMinField.baseline
                            text:               qsTr("max")
                            enabled:            directionEnabled
                        }

                        FactTextField {
                            id:                 servoPWMMaxField
                            anchors.leftMargin: _margins
                            anchors.top:        servoPWMMinField.top
                            anchors.left:       servoPWMMaxLabel.right
                            fact:               servoPWMMaxFact
                            enabled:            directionEnabled
                        }
                    } // Rectangle
                } // Item
            } // Component - gimbalDirectionSettings

            Component {
                id: gimbalSettings

                Item {
                    width:  rectangle.x + rectangle.width
                    height: rectangle.y + rectangle.height

                    property Fact _mountDefaultMode:    controller.getParameterFact(-1, "MNT_DEFLT_MODE")
                    property Fact _mountType:           controller.getParameterFact(-1, "MNT_TYPE")

                    QGCLabel {
                        id:             settingsLabel
                        text:           qsTr("Gimbal Settings")
                        font.family:    ScreenTools.demiboldFontFamily
                    }

                    Rectangle {
                        id:                 rectangle
                        anchors.topMargin:  _margins / 2
                        anchors.top:        settingsLabel.bottom
                        width:              gimbalModeCombo.x + gimbalModeCombo.width + _margins
                        height:             gimbalModeCombo.y + gimbalModeCombo.height + _margins
                        color:              palette.windowShade

                        QGCLabel {
                            id:                 gimbalTypeLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   gimbalTypeCombo.baseline
                            text:               qsTr("Type:")
                        }

                        FactComboBox {
                            id:                 gimbalTypeCombo
                            anchors.topMargin:  _margins
                            anchors.top:        parent.top
                            anchors.left:       gimbalModeCombo.left
                            width:              gimbalModeCombo.width
                            fact:               _mountType
                            indexModel:         false
                        }

                        QGCLabel {
                            id:                     rebootLabel
                            anchors.topMargin:      _margins / 2
                            anchors.leftMargin:     _margins
                            anchors.rightMargin:    _margins
                            anchors.left:           parent.left
                            anchors.right:          parent.right
                            anchors.top:            gimbalTypeCombo.bottom
                            wrapMode:               Text.WordWrap
                            text:                   qsTr("Gimbal Type changes takes affect next reboot of autopilot")
                        }

                        QGCLabel {
                            id:                 gimbalModeLabel
                            anchors.margins:    _margins
                            anchors.left:       parent.left
                            anchors.baseline:   gimbalModeCombo.baseline
                            text:               qsTr("Default Mode:")
                        }

                        FactComboBox {
                            id:                 gimbalModeCombo
                            anchors.margins:    _margins
                            anchors.top:        rebootLabel.bottom
                            anchors.left:       gimbalModeLabel.right
                            width:              ScreenTools.defaultFontPixelWidth * 15
                            fact:               _mountDefaultMode
                            indexModel:         false
                        }
                    } // Rectangle
                } // Item
            } // Component - gimbalSettings
Don Gagne's avatar
Don Gagne committed
468 469 470 471 472

            Loader {
                id:                 gimbalDirectionTiltLoader
                sourceComponent:    gimbalDirectionSettings

473
                property string directionTitle:     qsTr("Tilt")
Don Gagne's avatar
Don Gagne committed
474 475 476 477 478 479 480 481 482
                property bool   directionEnabled:   _tiltEnabled
                property int    gimbalOutIndex:     0
                property Fact   mountRcInFact:      _mountRCInTilt
                property Fact   mountStabFact:      _mountStabTilt
                property Fact   mountAngMinFact:    _mountAngMinTilt
                property Fact   mountAngMaxFact:    _mountAngMaxTilt
                property Fact   servoPWMMinFact:    Fact { }
                property Fact   servoPWMMaxFact:    Fact { }
                property Fact   servoReverseFact:   Fact { }
483
                property bool   servoReverseIsBool: _servoReverseIsBool
Don Gagne's avatar
Don Gagne committed
484 485 486 487 488 489 490
                property int    rcFunction:         _rcFunctionMountTilt
            }

            Loader {
                id:                 gimbalDirectionRollLoader
                sourceComponent:    gimbalDirectionSettings

491
                property string directionTitle:     qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
492 493 494 495 496 497 498 499 500
                property bool   directionEnabled:   _rollEnabled
                property int    gimbalOutIndex:     0
                property Fact   mountRcInFact:      _mountRCInRoll
                property Fact   mountStabFact:      _mountStabRoll
                property Fact   mountAngMinFact:    _mountAngMinRoll
                property Fact   mountAngMaxFact:    _mountAngMaxRoll
                property Fact   servoPWMMinFact:    Fact { }
                property Fact   servoPWMMaxFact:    Fact { }
                property Fact   servoReverseFact:   Fact { }
501
                property bool   servoReverseIsBool: _servoReverseIsBool
Don Gagne's avatar
Don Gagne committed
502 503 504 505 506 507 508
                property int    rcFunction:         _rcFunctionMountRoll
            }

            Loader {
                id:                 gimbalDirectionPanLoader
                sourceComponent:    gimbalDirectionSettings

509
                property string directionTitle:     qsTr("Pan")
Don Gagne's avatar
Don Gagne committed
510 511 512 513 514 515 516 517 518
                property bool   directionEnabled:   _panEnabled
                property int    gimbalOutIndex:     0
                property Fact   mountRcInFact:      _mountRCInPan
                property Fact   mountStabFact:      _mountStabPan
                property Fact   mountAngMinFact:    _mountAngMinPan
                property Fact   mountAngMaxFact:    _mountAngMaxPan
                property Fact   servoPWMMinFact:    Fact { }
                property Fact   servoPWMMaxFact:    Fact { }
                property Fact   servoReverseFact:   Fact { }
519
                property bool   servoReverseIsBool: _servoReverseIsBool
Don Gagne's avatar
Don Gagne committed
520 521 522
                property int    rcFunction:         _rcFunctionMountPan
            }

523
            Loader {
524
                id: gimbalSettingsLoader
Don Gagne's avatar
Don Gagne committed
525
            }
526 527 528
        } // Column
    } // Component
} // SetupPage