CustomFlyView.qml 35.3 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/****************************************************************************
 *
 * (c) 2009-2019 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 * @file
 *   @author Gus Grubba <gus@auterion.com>
 */

import QtQuick                  2.11
import QtQuick.Controls         2.4
import QtQuick.Layouts          1.11
import QtQuick.Dialogs          1.3
import QtPositioning            5.2

import QGroundControl                       1.0
import QGroundControl.Controllers           1.0
import QGroundControl.Controls              1.0
import QGroundControl.FlightMap             1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.Palette               1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Vehicle               1.0
import QGroundControl.QGCPositionManager    1.0
import QGroundControl.Airspace              1.0

import CustomQuickInterface                 1.0
import Custom.Widgets                       1.0

Item {
    anchors.fill:                           parent
    visible:                                !QGroundControl.videoManager.fullScreen

    readonly property string scaleState:    "topMode"
    readonly property string noGPS:         qsTr("NO GPS")
    readonly property real   indicatorValueWidth:   ScreenTools.defaultFontPixelWidth * 7

    property real   _indicatorDiameter:     ScreenTools.defaultFontPixelWidth * 18
    property real   _indicatorsHeight:      ScreenTools.defaultFontPixelHeight
    property var    _sepColor:              qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(0,0,0,0.5) : Qt.rgba(1,1,1,0.5)
    property color  _indicatorsColor:       qgcPal.text

    property bool   _communicationLost:     activeVehicle ? activeVehicle.connectionLost : false
    property bool   _isVehicleGps:          activeVehicle && activeVehicle.gps && activeVehicle.gps.count.rawValue > 1 && activeVehicle.gps.hdop.rawValue < 1.4
    property var    _dynamicCameras:        activeVehicle ? activeVehicle.dynamicCameras : null
    property bool   _isCamera:              _dynamicCameras ? _dynamicCameras.cameras.count > 0 : false
    property int    _curCameraIndex:        _dynamicCameras ? _dynamicCameras.currentCamera : 0
    property var    _camera:                _isCamera ? _dynamicCameras.cameras.get(_curCameraIndex) : null
    property bool   _cameraPresent:         _camera && _camera.cameraMode !== QGCCameraControl.CAM_MODE_UNDEFINED
    property var    _flightPermit:          QGroundControl.airmapSupported ? QGroundControl.airspaceManager.flightPlan.flightPermitStatus : null
53
    property bool   _hasGimbal:             activeVehicle && activeVehicle.gimbalData
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 118 119 120 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

    property bool   _airspaceIndicatorVisible: QGroundControl.airmapSupported && mainIsMap && _flightPermit && _flightPermit !== AirspaceFlightPlanProvider.PermitNone

    property string _altitude:              activeVehicle ? (isNaN(activeVehicle.altitudeRelative.value) ? "0.0" : activeVehicle.altitudeRelative.value.toFixed(1)) + ' ' + activeVehicle.altitudeRelative.units : "0.0"
    property string _distanceStr:           isNaN(_distance) ? "0" : _distance.toFixed(0) + ' ' + (activeVehicle ? activeVehicle.altitudeRelative.units : "")
    property real   _heading:               activeVehicle   ? activeVehicle.heading.rawValue : 0

    property real   _distance:              0.0
    property string _messageTitle:          ""
    property string _messageText:           ""

    function secondsToHHMMSS(timeS) {
        var sec_num = parseInt(timeS, 10);
        var hours   = Math.floor(sec_num / 3600);
        var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
        var seconds = sec_num - (hours * 3600) - (minutes * 60);
        if (hours   < 10) {hours   = "0"+hours;}
        if (minutes < 10) {minutes = "0"+minutes;}
        if (seconds < 10) {seconds = "0"+seconds;}
        return hours+':'+minutes+':'+seconds;
    }

    Timer {
        id:        connectionTimer
        interval:  5000
        running:   false;
        repeat:    false;
        onTriggered: {
            //-- Vehicle is gone
            if(activeVehicle) {
                //-- Let video stream close
                QGroundControl.settingsManager.videoSettings.rtspTimeout.rawValue = 1
                if(!activeVehicle.armed) {
                    //-- If it wasn't already set to auto-disconnect
                    if(!activeVehicle.autoDisconnect) {
                        //-- Vehicle is not armed. Close connection and tell user.
                        activeVehicle.disconnectInactiveVehicle()
                        connectionLostDisarmedDialog.open()
                    }
                } else {
                    //-- Vehicle is armed. Show doom dialog.
                    connectionLostArmed.open()
                }
            }
        }
    }

    Connections {
        target: QGroundControl.qgcPositionManger
        onGcsPositionChanged: {
            if (activeVehicle && gcsPosition.latitude && Math.abs(gcsPosition.latitude)  > 0.001 && gcsPosition.longitude && Math.abs(gcsPosition.longitude)  > 0.001) {
                var gcs = QtPositioning.coordinate(gcsPosition.latitude, gcsPosition.longitude)
                var veh = activeVehicle.coordinate;
                _distance = QGroundControl.metersToAppSettingsDistanceUnits(gcs.distanceTo(veh));
                //-- Ignore absurd values
                if(_distance > 99999)
                    _distance = 0;
                if(_distance < 0)
                    _distance = 0;
            } else {
                _distance = 0;
            }
        }
    }

    Connections {
        target: QGroundControl.multiVehicleManager.activeVehicle
        onConnectionLostChanged: {
            if(!_communicationLost) {
                //-- Communication regained
                connectionTimer.stop();
                if(connectionLostArmed.visible) {
                    connectionLostArmed.close()
                }
                //-- Reset stream timeout
                QGroundControl.settingsManager.videoSettings.rtspTimeout.rawValue = 60
            } else {
                if(activeVehicle && !activeVehicle.autoDisconnect) {
                    //-- Communication lost
                    connectionTimer.start();
                }
            }
        }
    }

    Connections {
        target: QGroundControl.multiVehicleManager
        onVehicleAdded: {
            //-- Dismiss comm lost dialog if open
            connectionLostDisarmedDialog.close()
        }
    }
146
    //-------------------------------------------------------------------------
147 148 149 150 151 152 153 154 155
    MessageDialog {
        id:                 connectionLostDisarmedDialog
        title:              qsTr("Communication Lost")
        text:               qsTr("Connection to vehicle has been lost and closed.")
        standardButtons:    StandardButton.Ok
        onAccepted: {
            connectionLostDisarmedDialog.close()
        }
    }
156
    //-------------------------------------------------------------------------
157 158 159 160 161 162 163 164 165
    //-- Heading Indicator
    Rectangle {
        id:             compassBar
        height:         ScreenTools.defaultFontPixelHeight * 1.5
        width:          ScreenTools.defaultFontPixelWidth  * 50
        color:          "#DEDEDE"
        radius:         2
        clip:           true
        anchors.top:    parent.top
166
        anchors.topMargin: ScreenTools.defaultFontPixelHeight * (_airspaceIndicatorVisible ? 3 : 1)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        anchors.horizontalCenter: parent.horizontalCenter
        visible:        !mainIsMap
        Repeater {
            model: 720
            visible:    !mainIsMap
            QGCLabel {
                function _normalize(degrees) {
                    var a = degrees % 360
                    if (a < 0) a += 360
                    return a
                }
                property int _startAngle: modelData + 180 + _heading
                property int _angle: _normalize(_startAngle)
                anchors.verticalCenter: parent.verticalCenter
                x:              visible ? ((modelData * (compassBar.width / 360)) - (width * 0.5)) : 0
                visible:        _angle % 45 == 0
                color:          "#75505565"
                font.pointSize: ScreenTools.smallFontPointSize
            text: {
                    switch(_angle) {
                    case 0:     return "N"
                    case 45:    return "NE"
                    case 90:    return "E"
                    case 135:   return "SE"
                    case 180:   return "S"
                    case 225:   return "SW"
                    case 270:   return "W"
                    case 315:   return "NW"
                    }
                    return ""
                }
            }
        }
    }
    Rectangle {
        id:                         headingIndicator
        height:                     ScreenTools.defaultFontPixelHeight
        width:                      ScreenTools.defaultFontPixelWidth * 4
        color:                      qgcPal.windowShadeDark
        visible:                    !mainIsMap
        anchors.bottom:             compassBar.top
        anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * -0.1
        anchors.horizontalCenter:   parent.horizontalCenter
        QGCLabel {
            text:                   _heading
            color:                  qgcPal.text
            font.pointSize:         ScreenTools.smallFontPointSize
            anchors.centerIn:       parent
        }
    }
    Image {
        height:                     _indicatorsHeight
        width:                      height
        source:                     "/custom/img/compass_pointer.svg"
        visible:                    !mainIsMap
        fillMode:                   Image.PreserveAspectFit
        sourceSize.height:          height
        anchors.top:                compassBar.bottom
        anchors.topMargin:          ScreenTools.defaultFontPixelHeight * -0.5
        anchors.horizontalCenter:   parent.horizontalCenter
    }
228
    //-------------------------------------------------------------------------
229 230 231 232 233 234 235 236
    //-- Camera Control
    Loader {
        id:                     camControlLoader
        visible:                !mainIsMap && _cameraPresent && _camera.paramComplete
        source:                 visible ? "/custom/CustomCameraControl.qml" : ""
        anchors.right:          parent.right
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.top:            parent.top
237
        anchors.topMargin:      ScreenTools.defaultFontPixelHeight
238
    }
239
    //-------------------------------------------------------------------------
240 241 242 243 244 245 246 247 248 249
    //-- Map Scale
    MapScale {
        id:                     mapScale
        anchors.left:           parent.left
        anchors.top:            parent.top
        anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.5
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth  * 16
        mapControl:             mainWindow.flightDisplayMap
        visible:                rootBackground.visible && mainIsMap
    }
250
    //-------------------------------------------------------------------------
251 252 253
    //-- Vehicle Indicator
    Rectangle {
        id:                     vehicleIndicator
254
        color:                  qgcPal.window
255 256 257
        width:                  vehicleStatusGrid.width  + (ScreenTools.defaultFontPixelWidth  * 3)
        height:                 vehicleStatusGrid.height + (ScreenTools.defaultFontPixelHeight * 1.5)
        radius:                 2
Yasen's avatar
Yasen committed
258
        anchors.bottom:         parent.bottom
259 260 261
        anchors.bottomMargin:   ScreenTools.defaultFontPixelWidth
        anchors.right:          attitudeIndicator.visible ? attitudeIndicator.left : parent.right
        anchors.rightMargin:    attitudeIndicator.visible ? -ScreenTools.defaultFontPixelWidth : ScreenTools.defaultFontPixelWidth
262 263 264 265 266 267 268

        readonly property bool  _showGps: CustomQuickInterface.showAttitudeWidget


        GridLayout {
            id:                     vehicleStatusGrid
            columnSpacing:          ScreenTools.defaultFontPixelWidth  * 1.5
269 270 271
            rowSpacing:             ScreenTools.defaultFontPixelHeight * 0.5
            columns:                7
            anchors.centerIn:       parent
272

273 274
            //-- Latitude
            QGCLabel {
275 276 277 278
                height:                 _indicatorsHeight
                width:                  height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text
279 280
                text:                   "Lat:"
                visible:                vehicleIndicator._showGps
281
            }
282 283 284 285 286 287 288 289
            QGCLabel {
                id:                     firstLabel
                text:                   activeVehicle ? activeVehicle.gps.lat.value.toFixed(activeVehicle.gps.lat.decimalPlaces) : "-"
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    Text.AlignLeft
290
                visible:                vehicleIndicator._showGps
291 292 293
            }
            //-- Longitude
            QGCLabel {
294 295 296 297
                height:                 _indicatorsHeight
                width:                  height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text
298 299
                text:                   "Lon:"
                visible:                vehicleIndicator._showGps
300 301
            }
            QGCLabel {
302
                text:                   activeVehicle ? activeVehicle.gps.lon.value.toFixed(activeVehicle.gps.lon.decimalPlaces) : "-"
303 304 305 306
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
307
                horizontalAlignment:    firstLabel.horizontalAlignment
308
                visible:                vehicleIndicator._showGps
309
            }
310 311
            //-- HDOP
            QGCLabel {
312 313 314 315
                height:                 _indicatorsHeight
                width:                  height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text
316
                text:                   "HDOP:"
317
                visible:                vehicleIndicator._showGps
318 319
            }
            QGCLabel {
320
                text:                   activeVehicle ? activeVehicle.gps.hdop.value.toFixed(activeVehicle.gps.hdop.decimalPlaces) : "-"
321 322 323 324
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
325
                horizontalAlignment:    firstLabel.horizontalAlignment
326
                visible:                vehicleIndicator._showGps
327
            }
328

329 330
            //-- Compass
            Item {
331
                Layout.rowSpan:         3
332
                Layout.column:          6
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
                Layout.minimumWidth:    mainIsMap ? parent.height * 1.25 : 0
                Layout.fillHeight:      true
                Layout.fillWidth:       true
                //-- Large circle
                Rectangle {
                    height:             mainIsMap ? parent.height : 0
                    width:              mainIsMap ? height : 0
                    radius:             height * 0.5
                    border.color:       qgcPal.text
                    border.width:       1
                    color:              Qt.rgba(0,0,0,0)
                    anchors.centerIn:   parent
                    visible:            mainIsMap
                }
                //-- North Label
                Rectangle {
                    height:             mainIsMap ? ScreenTools.defaultFontPixelHeight * 0.75 : 0
                    width:              mainIsMap ? ScreenTools.defaultFontPixelWidth  * 2 : 0
                    radius:             ScreenTools.defaultFontPixelWidth  * 0.25
                    color:              qgcPal.windowShade
                    visible:            mainIsMap
                    anchors.top:        parent.top
                    anchors.topMargin:  ScreenTools.defaultFontPixelHeight * -0.25
                    anchors.horizontalCenter: parent.horizontalCenter
                    QGCLabel {
                        text:               "N"
                        color:              qgcPal.text
                        font.pointSize:     ScreenTools.smallFontPointSize
                        anchors.centerIn:   parent
                    }
                }
                //-- Needle
                Image {
                    id:                 compassNeedle
                    anchors.centerIn:   parent
                    height:             mainIsMap ? parent.height * 0.75 : 0
                    width:              height
                    source:             "/custom/img/compass_needle.svg"
                    fillMode:           Image.PreserveAspectFit
                    visible:            mainIsMap
                    sourceSize.height:  height
                    transform: [
                        Rotation {
                            origin.x:   compassNeedle.width  / 2
                            origin.y:   compassNeedle.height / 2
                            angle:      _heading
                        }]
                }
                //-- Heading
                Rectangle {
                    height:             mainIsMap ? ScreenTools.defaultFontPixelHeight * 0.75 : 0
                    width:              mainIsMap ? ScreenTools.defaultFontPixelWidth  * 3.5 : 0
                    radius:             ScreenTools.defaultFontPixelWidth  * 0.25
                    color:              qgcPal.windowShade
                    visible:            mainIsMap
                    anchors.bottom:         parent.bottom
                    anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * -0.25
                    anchors.horizontalCenter: parent.horizontalCenter
                    QGCLabel {
                        text:               _heading
                        color:              qgcPal.text
                        font.pointSize:     ScreenTools.smallFontPointSize
                        anchors.centerIn:   parent
                    }
                }
            }
            //-- Second Row
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
            //-- Chronometer
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/chronometer.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text
            }
            QGCLabel {
                text: {
                        if(activeVehicle)
                            return secondsToHHMMSS(activeVehicle.getFact("flightTime").value)
                    return "00:00:00"
                }
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    firstLabel.horizontalAlignment
            }
            //-- Ground Speed
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/horizontal_speed.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text
            }
            QGCLabel {
                text:                   activeVehicle ? activeVehicle.groundSpeed.value.toFixed(1) + ' ' + activeVehicle.groundSpeed.units : "0.0"
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    firstLabel.horizontalAlignment
            }
            //-- Vertical Speed
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/vertical_speed.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text

            }
            QGCLabel {
                text:                   activeVehicle ? activeVehicle.climbRate.value.toFixed(1) + ' ' + activeVehicle.climbRate.units : "0.0"
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    firstLabel.horizontalAlignment
            }
            //-- Third Row
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
            //-- Odometer
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/odometer.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text

            }
            QGCLabel {
                text:                   activeVehicle ? ('00000' + activeVehicle.flightDistance.value.toFixed(0)).slice(-5) + ' ' + activeVehicle.flightDistance.units : "00000"
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
477
                horizontalAlignment:    firstLabel.horizontalAlignment
478
            }
479
            //-- Altitude
480 481 482 483 484 485 486 487 488
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/altitude.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text

489 490 491 492 493 494 495 496 497 498
            }
            QGCLabel {
                text:                   _altitude
                color:                  _indicatorsColor
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    firstLabel.horizontalAlignment
            }
            //-- Distance
499 500 501 502 503 504 505 506 507
            QGCColoredImage {
                height:                 _indicatorsHeight
                width:                  height
                source:                 "/custom/img/distance.svg"
                fillMode:               Image.PreserveAspectFit
                sourceSize.height:      height
                Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
                color:                  qgcPal.text

508 509 510 511 512 513 514 515 516
            }
            QGCLabel {
                text:                   _distance ? _distanceStr : noGPS
                color:                  _distance ? _indicatorsColor : qgcPal.colorOrange
                font.pointSize:         ScreenTools.smallFontPointSize
                Layout.fillWidth:       true
                Layout.minimumWidth:    indicatorValueWidth
                horizontalAlignment:    firstLabel.horizontalAlignment
            }
517 518 519
        }
        MouseArea {
            anchors.fill:       parent
520
            onDoubleClicked:    CustomQuickInterface.showAttitudeWidget = !CustomQuickInterface.showAttitudeWidget
521 522
        }
    }
523
    //-------------------------------------------------------------------------
524 525
    //-- Attitude Indicator
    Rectangle {
526
        color:                  qgcPal.window
527 528
        width:                  attitudeIndicator.width * 0.5
        height:                 vehicleIndicator.height
529
        visible:                CustomQuickInterface.showAttitudeWidget
530 531 532 533 534 535 536 537 538 539 540 541 542
        anchors.top:            vehicleIndicator.top
        anchors.left:           vehicleIndicator.right
    }
    Rectangle {
        id:                     attitudeIndicator
        anchors.bottom:         vehicleIndicator.bottom
        anchors.bottomMargin:   ScreenTools.defaultFontPixelWidth * -0.5
        anchors.right:  parent.right
        anchors.rightMargin:  ScreenTools.defaultFontPixelWidth
        height:                 ScreenTools.defaultFontPixelHeight * 6
        width:                  height
        radius:                 height * 0.5
        color:                  qgcPal.windowShade
543
        visible:                CustomQuickInterface.showAttitudeWidget
544 545 546 547 548 549 550
            CustomAttitudeWidget {
            size:               parent.height * 0.95
            vehicle:            activeVehicle
                showHeading:        false
            anchors.centerIn:   parent
        }
    }
551
    //-------------------------------------------------------------------------
552 553 554 555 556
    //-- Multi Vehicle Selector
    Row {
        id:                     multiVehicleSelector
        spacing:                ScreenTools.defaultFontPixelWidth
        anchors.bottom:         parent.bottom
557
        anchors.bottomMargin:   ScreenTools.defaultFontPixelWidth * 1.5
Yasen's avatar
Yasen committed
558
        anchors.right:          vehicleIndicator.left
559 560 561 562 563 564 565 566
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
        Repeater {
            model:              QGroundControl.multiVehicleManager.vehicles.count
            CustomVehicleButton {
                property var _vehicle: QGroundControl.multiVehicleManager.vehicles.get(modelData)
                vehicle:        _vehicle
                checked:        (_vehicle && activeVehicle) ? _vehicle.id === activeVehicle.id : false
567 568 569
                onClicked: {
                    QGroundControl.multiVehicleManager.activeVehicle = _vehicle
                }
570 571 572
            }
        }
    }
573
    //-------------------------------------------------------------------------
Gus Grubba's avatar
Gus Grubba committed
574
    //-- Gimbal Control
575
    Rectangle {
Gus Grubba's avatar
Gus Grubba committed
576
        id:                     gimbalControl
577
        visible:                camControlLoader.visible && CustomQuickInterface.showGimbalControl && _hasGimbal
578
        anchors.bottom:         camControlLoader.bottom
Gus Grubba's avatar
Gus Grubba committed
579
        anchors.right:          camControlLoader.left
580
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth * (QGroundControl.videoManager.hasThermal ? -1 : 1)
Gus Grubba's avatar
Gus Grubba committed
581 582
        height:                 parent.width * 0.125
        width:                  height
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
        color:                  Qt.rgba(1,1,1,0.25)
        radius:                 width * 0.5

        property real _currentPitch:    0
        property real _currentYaw:      0
        property real time_last_seconds:0
        property real _lastHackedYaw:   0
        property real speedMultiplier:  5

        property real maxRate:          20
        property real exponentialFactor:0.6
        property real kPFactor:         3

        property real reportedYawDeg:   activeVehicle ? activeVehicle.gimbalYaw   : NaN
        property real reportedPitchDeg: activeVehicle ? activeVehicle.gimbalPitch : NaN

Gus Grubba's avatar
Gus Grubba committed
599 600 601 602 603 604
        Timer {
            interval:   100  //-- 10Hz
            running:    gimbalControl.visible && activeVehicle
            repeat:     true
            onTriggered: {
                if (activeVehicle) {
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
                    var yaw = gimbalControl._currentYaw
                    var oldYaw = yaw;
                    var pitch = gimbalControl._currentPitch
                    var oldPitch = pitch;
                    var pitch_stick = (stick.yAxis * 2.0 - 1.0)
                    if(_camera && _camera.vendor === "NextVision") {
                        var time_current_seconds = ((new Date()).getTime())/1000.0
                        if(gimbalControl.time_last_seconds === 0.0)
                            gimbalControl.time_last_seconds = time_current_seconds
                        var pitch_angle = gimbalControl._currentPitch
                        // Preparing stick input with exponential curve and maximum rate
                        var pitch_expo = (1 - gimbalControl.exponentialFactor) * pitch_stick + gimbalControl.exponentialFactor * pitch_stick * pitch_stick * pitch_stick
                        var pitch_rate = pitch_stick * gimbalControl.maxRate
                        var pitch_angle_reported = gimbalControl.reportedPitchDeg
                        // Integrate the angular rate to an angle time abstracted
                        pitch_angle += pitch_rate * (time_current_seconds - gimbalControl.time_last_seconds)
                        // Control the angle quicker by driving the gimbal internal angle controller into saturation
                        var pitch_angle_error = pitch_angle - pitch_angle_reported
                        pitch_angle_error = Math.round(pitch_angle_error)
                        var pitch_setpoint = pitch_angle + pitch_angle_error * gimbalControl.kPFactor
                        //console.info("error: " + pitch_angle_error + "; angle_state: " + pitch_angle)
                        pitch = pitch_setpoint
                        yaw += stick.xAxis * gimbalControl.speedMultiplier
628

629
                        yaw = clamp(yaw, -180, 180)
630 631 632
                        pitch = clamp(pitch, -90, 45)
                        pitch_angle = clamp(pitch_angle, -90, 45)

633 634 635 636 637 638 639
                        //console.info("P: " + pitch + "; Y: " + yaw)
                        activeVehicle.gimbalControlValue(pitch, yaw);
                        gimbalControl._currentYaw = yaw
                        gimbalControl._currentPitch = pitch_angle
                        gimbalControl.time_last_seconds = time_current_seconds
                    } else {
                        yaw += stick.xAxis * gimbalControl.speedMultiplier
640
                        var hackedYaw = yaw + (stick.xAxis * gimbalControl.speedMultiplier * 50)
641 642 643 644 645 646 647 648 649 650
                        pitch += pitch_stick * gimbalControl.speedMultiplier
                        hackedYaw = clamp(hackedYaw, -180, 180)
                        yaw = clamp(yaw, -180, 180)
                        pitch = clamp(pitch, -90, 90)
                        if(gimbalControl._lastHackedYaw !== hackedYaw || gimbalControl.hackedYaw !== oldYaw || pitch !== oldPitch) {
                            activeVehicle.gimbalControlValue(pitch, hackedYaw)
                            gimbalControl._lastHackedYaw = hackedYaw
                            gimbalControl._currentPitch = pitch
                            gimbalControl._currentYaw = yaw
                        }
Gus Grubba's avatar
Gus Grubba committed
651 652 653
                    }
                }
            }
654 655 656
            function clamp(num, min, max) {
                return Math.min(Math.max(num, min), max);
            }
Gus Grubba's avatar
Gus Grubba committed
657 658 659 660
        }
        JoystickThumbPad {
            id:                     stick
            anchors.fill:           parent
661 662
            lightColors:            qgcPal.globalTheme === QGCPalette.Light
            yAxisThrottle:          true
Gus Grubba's avatar
Gus Grubba committed
663
            yAxisThrottleCentered:  true
664 665
            xAxis:                  0
            yAxis:                  0.5
Gus Grubba's avatar
Gus Grubba committed
666 667
        }
    }
668
    //-------------------------------------------------------------------------
Gus Grubba's avatar
Gus Grubba committed
669
    //-- Object Avoidance
Gus Grubba's avatar
Gus Grubba committed
670
    Item {
Gus Grubba's avatar
Gus Grubba committed
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
        visible:                activeVehicle && activeVehicle.objectAvoidance.available && activeVehicle.objectAvoidance.enabled
        anchors.centerIn:       parent
        width:                  parent.width  * 0.5
        height:                 parent.height * 0.5
        Repeater {
            model:              activeVehicle && activeVehicle.objectAvoidance.gridSize > 0 ? activeVehicle.objectAvoidance.gridSize : []
            Rectangle {
                width:          ScreenTools.defaultFontPixelWidth
                height:         width
                radius:         width * 0.5
                color:          distance < 0.25 ? "red" : "orange"
                x:              (parent.width  * activeVehicle.objectAvoidance.grid(modelData).x) + (parent.width  * 0.5)
                y:              (parent.height * activeVehicle.objectAvoidance.grid(modelData).y) + (parent.height * 0.5)
                property real distance: activeVehicle.objectAvoidance.distance(modelData)
            }
        }
    }
    //-------------------------------------------------------------------------
689 690
    //-- Connection Lost While Armed
    Popup {
691
        id:                     connectionLostArmed
692
        width:                  mainWindow.width  * 0.666
693
        height:                 connectionLostArmedCol.height * 1.5
694 695 696 697 698 699 700 701
        modal:                  true
        focus:                  true
        parent:                 Overlay.overlay
        x:                      Math.round((mainWindow.width  - width)  * 0.5)
        y:                      Math.round((mainWindow.height - height) * 0.5)
        closePolicy:            Popup.CloseOnEscape | Popup.CloseOnPressOutside
        background: Rectangle {
            anchors.fill:       parent
702 703
            color:              qgcPal.alertBackground
            border.color:       qgcPal.alertBorder
704 705
            radius:             ScreenTools.defaultFontPixelWidth
        }
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
        Column {
            id:                 connectionLostArmedCol
            spacing:            ScreenTools.defaultFontPixelHeight * 3
            anchors.margins:    ScreenTools.defaultFontPixelHeight
            anchors.centerIn:   parent
            QGCLabel {
                text:           qsTr("Communication Lost")
                font.family:    ScreenTools.demiboldFontFamily
                font.pointSize: ScreenTools.largeFontPointSize
                color:          qgcPal.alertText
                anchors.horizontalCenter: parent.horizontalCenter
            }
            QGCLabel {
                text:           qsTr("Warning: Connection to vehicle lost.")
                color:          qgcPal.alertText
                font.family:    ScreenTools.demiboldFontFamily
                font.pointSize: ScreenTools.mediumFontPointSize
                anchors.horizontalCenter: parent.horizontalCenter
724
            }
725 726 727 728 729 730 731 732 733 734 735
            QGCLabel {
                text:           qsTr("The vehicle will automatically cancel the flight and return to land. Ensure a clear line of sight between transmitter and vehicle. Ensure the takeoff location is clear.")
                width:          connectionLostArmed.width * 0.75
                wrapMode:       Text.WordWrap
                color:          qgcPal.alertText
                font.family:    ScreenTools.demiboldFontFamily
                font.pointSize: ScreenTools.mediumFontPointSize
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
    }
736
}