PX4TuningComponentCopter.qml 23.1 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

DonLakeFlyer's avatar
DonLakeFlyer committed
10 11 12 13
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtCharts         2.2
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
14

DonLakeFlyer's avatar
DonLakeFlyer committed
15 16 17 18 19
import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.ScreenTools   1.0
Don Gagne's avatar
Don Gagne committed
20

21 22 23
SetupPage {
    id:             tuningPage
    pageComponent:  pageComponent
Don Gagne's avatar
Don Gagne committed
24

25 26
    Component {
        id: pageComponent
27

DonLakeFlyer's avatar
DonLakeFlyer committed
28 29 30 31
        Column {
            width: availableWidth

            Component.onCompleted: {
32
                showAdvanced = !ScreenTools.isMobile
DonLakeFlyer's avatar
DonLakeFlyer committed
33 34
            }

35 36 37 38 39
            FactPanelController {
                id:         controller
                factPanel:  tuningPage.viewPanel
            }

DonLakeFlyer's avatar
DonLakeFlyer committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
            // Standard tuning page
            FactSliderPanel {
                width:          availableWidth
                qgcViewPanel:   tuningPage.viewPanel
                visible:        !advanced

                sliderModel: ListModel {
                    ListElement {
                        title:          qsTr("Hover Throttle")
                        description:    qsTr("Adjust throttle so hover is at mid-throttle. Slide to the left if hover is lower than throttle center. Slide to the right if hover is higher than throttle center.")
                        param:          "MPC_THR_HOVER"
                        min:            20
                        max:            80
                        step:           1
                    }
55

DonLakeFlyer's avatar
DonLakeFlyer committed
56 57 58 59 60 61 62 63
                    ListElement {
                        title:          qsTr("Manual minimum throttle")
                        description:    qsTr("Slide to the left to start the motors with less idle power. Slide to the right if descending in manual flight becomes unstable.")
                        param:          "MPC_MANTHR_MIN"
                        min:            0
                        max:            15
                        step:           1
                    }
64
                    /*
DonLakeFlyer's avatar
DonLakeFlyer committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  These seem to have disappeared from PX4 firmware!
                    ListElement {
                        title:          qsTr("Roll sensitivity")
                        description:    qsTr("Slide to the left to make roll control faster and more accurate. Slide to the right if roll oscillates or is too twitchy.")
                        param:          "MC_ROLL_TC"
                        min:            0.15
                        max:            0.25
                        step:           0.01
                    }

                    ListElement {
                        title:          qsTr("Pitch sensitivity")
                        description:    qsTr("Slide to the left to make pitch control faster and more accurate. Slide to the right if pitch oscillates or is too twitchy.")
                        param:          "MC_PITCH_TC"
                        min:            0.15
                        max:            0.25
                        step:           0.01
                    }
*/
84 85
                }
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
86

87
            Loader {
DonLakeFlyer's avatar
DonLakeFlyer committed
88 89
                anchors.left:       parent.left
                anchors.right:      parent.right
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
                sourceComponent:    advanced ? advancePageComponent : undefined
            }

            Component {
                id: advancePageComponent

                // Advanced page
                RowLayout {
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    layoutDirection:    Qt.RightToLeft

                    property real   _chartHeight:       ScreenTools.defaultFontPixelHeight * 20
                    property real   _margins:           ScreenTools.defaultFontPixelHeight / 2
                    property string _currentTuneType:   _tuneList[0]
                    property real   _roll:              _activeVehicle.roll.value
                    property real   _rollSetpoint:      _activeVehicle.setpoint.roll.value
                    property real   _rollRate:          _activeVehicle.rollRate.value
                    property real   _rollRateSetpoint:  _activeVehicle.setpoint.rollRate.value
                    property real   _pitch:             _activeVehicle.pitch.value
                    property real   _pitchSetpoint:     _activeVehicle.setpoint.pitch.value
                    property real   _pitchRate:         _activeVehicle.pitchRate.value
                    property real   _pitchRateSetpoint: _activeVehicle.setpoint.pitchRate.value
                    property real   _yaw:               _activeVehicle.heading.value
                    property real   _yawSetpoint:       _activeVehicle.setpoint.yaw.value
                    property real   _yawRate:           _activeVehicle.yawRate.value
                    property real   _yawRateSetpoint:   _activeVehicle.setpoint.yawRate.value
                    property var    _valueXAxis:        valueXAxis
                    property var    _valueRateXAxis:    valueRateXAxis
                    property var    _valueYAxis:        valueYAxis
                    property var    _valueRateYAxis:    valueRateYAxis
                    property int    _msecs:             0
                    property var    _savedTuningParamValues:    [ ]

                    // The following are set when getValues is called
                    property real   _value
                    property real   _valueSetpoint
                    property real   _valueRate
                    property real   _valueRateSetpoint

                    readonly property int _tickSeparation:      5
DonLakeFlyer's avatar
DonLakeFlyer committed
131
                    readonly property int _maxTickSections:     10
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
                    readonly property int _tuneListRollIndex:   0
                    readonly property int _tuneListPitchIndex:  1
                    readonly property int _tuneListYawIndex:    2
                    readonly property var _tuneList:            [ qsTr("Roll"), qsTr("Pitch"), qsTr("Yaw") ]
                    readonly property var _params:              [
                        [ controller.getParameterFact(-1, "MC_ROLL_P"),
                         controller.getParameterFact(-1, "MC_ROLLRATE_P"),
                         controller.getParameterFact(-1, "MC_ROLLRATE_I"),
                         controller.getParameterFact(-1, "MC_ROLLRATE_D"),
                         controller.getParameterFact(-1, "MC_ROLLRATE_FF") ],
                        [ controller.getParameterFact(-1, "MC_PITCH_P"),
                         controller.getParameterFact(-1, "MC_PITCHRATE_P"),
                         controller.getParameterFact(-1, "MC_PITCHRATE_I"),
                         controller.getParameterFact(-1, "MC_PITCHRATE_D"),
                         controller.getParameterFact(-1, "MC_PITCHRATE_FF") ],
                        [ controller.getParameterFact(-1, "MC_YAW_P"),
                         controller.getParameterFact(-1, "MC_YAWRATE_P"),
                         controller.getParameterFact(-1, "MC_YAWRATE_I"),
                         controller.getParameterFact(-1, "MC_YAWRATE_D"),
                         controller.getParameterFact(-1, "MC_YAW_FF"),
                         controller.getParameterFact(-1, "MC_YAWRATE_FF") ] ]

                    function adjustYAxisMin(yAxis, newValue) {
                        var newMin = Math.min(yAxis.min, newValue)
                        if (newMin % 5 != 0) {
                            newMin -= 5
                            newMin = Math.floor(newMin / _tickSeparation) * _tickSeparation
                        }
                        yAxis.min = newMin
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
162

163 164 165 166 167 168 169 170
                    function adjustYAxisMax(yAxis, newValue) {
                        var newMax = Math.max(yAxis.max, newValue)
                        if (newMax % 5 != 0) {
                            newMax += 5
                            newMax = Math.floor(newMax / _tickSeparation) * _tickSeparation
                        }
                        yAxis.max = newMax
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
                    function getValues() {
                        if (_currentTuneType === _tuneList[_tuneListRollIndex]) {
                            _value = _roll
                            _valueSetpoint = _rollSetpoint
                            _valueRate = _rollRate
                            _valueRateSetpoint = _rollRateSetpoint
                        } else if (_currentTuneType === _tuneList[_tuneListPitchIndex]) {
                            _value = _pitch
                            _valueSetpoint = _pitchSetpoint
                            _valueRate = _pitchRate
                            _valueRateSetpoint = _pitchRateSetpoint
                        } else if (_currentTuneType === _tuneList[_tuneListYawIndex]) {
                            _value = _yaw
                            _valueSetpoint = _yawSetpoint
                            _valueRate = _yawRate
                            _valueRateSetpoint = _yawRateSetpoint
                        }
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
190

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                    function resetGraphs() {
                        valueSeries.removePoints(0, valueSeries.count)
                        valueSetpointSeries.removePoints(0, valueSetpointSeries.count)
                        valueRateSeries.removePoints(0, valueRateSeries.count)
                        valueRateSetpointSeries.removePoints(0, valueRateSetpointSeries.count)
                        _valueXAxis.min = 0
                        _valueXAxis.max = 0
                        _valueRateXAxis.min = 0
                        _valueRateXAxis.max = 0
                        _valueYAxis.min = 0
                        _valueYAxis.max = 10
                        _valueRateYAxis.min = 0
                        _valueRateYAxis.max = 10
                        _msecs = 0
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
206

207 208 209 210 211 212 213 214 215
                    function currentTuneTypeIndex() {
                        if (_currentTuneType === _tuneList[_tuneListRollIndex]) {
                            return _tuneListRollIndex
                        } else if (_currentTuneType === _tuneList[_tuneListPitchIndex]) {
                            return _tuneListPitchIndex
                        } else if (_currentTuneType === _tuneList[_tuneListYawIndex]) {
                            return _tuneListYawIndex
                        }
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
216

217 218 219 220 221 222 223 224
                    // Save the current set of tuning values so we can reset to them
                    function saveTuningParamValues() {
                        var tuneTypeIndex = currentTuneTypeIndex()

                        _savedTuningParamValues = [ ]
                        var currentTuneParams = _params[tuneTypeIndex]
                        for (var i=0; i<currentTuneParams.length; i++) {
                            _savedTuningParamValues.push(currentTuneParams[i].valueString)
DonLakeFlyer's avatar
DonLakeFlyer committed
225
                        }
226
                        savedRepeater.model = _savedTuningParamValues
DonLakeFlyer's avatar
DonLakeFlyer committed
227 228
                    }

229 230
                    function resetToSavedTuningParamValues() {
                        var tuneTypeIndex = currentTuneTypeIndex()
DonLakeFlyer's avatar
DonLakeFlyer committed
231

232 233 234 235
                        for (var i=0; i<_savedTuningParamValues.length; i++) {
                            _params[tuneTypeIndex][i].value = _savedTuningParamValues[i]
                        }
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
236

237 238 239
                    Component.onCompleted: {
                        saveTuningParamValues()
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
240

241 242 243 244
                    on_CurrentTuneTypeChanged: {
                        saveTuningParamValues()
                        resetGraphs()
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
245

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
                    ExclusiveGroup {
                        id: tuneTypeRadios
                    }

                    ValueAxis {
                        id:             valueXAxis
                        min:            0
                        max:            0
                        labelFormat:    "%d"
                        titleText:      "sec"
                    }

                    ValueAxis {
                        id:             valueRateXAxis
                        min:            0
                        max:            0
                        labelFormat:    "%d"
                        titleText:      "sec"
                    }

                    ValueAxis {
                        id:         valueYAxis
                        min:        0
                        max:        10
                        titleText:  "deg"
DonLakeFlyer's avatar
DonLakeFlyer committed
271
                        tickCount:  Math.min(((max - min) / _tickSeparation), _maxTickSections) + 1
272 273 274 275 276 277 278
                    }

                    ValueAxis {
                        id:         valueRateYAxis
                        min:        0
                        max:        10
                        titleText:  "deg/s"
DonLakeFlyer's avatar
DonLakeFlyer committed
279
                        tickCount:  Math.min(((max - min) / _tickSeparation), _maxTickSections) + 1
280 281 282 283
                    }

                    Timer {
                        id:         dataTimer
DonLakeFlyer's avatar
DonLakeFlyer committed
284
                        interval:   10
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
                        running:    false
                        repeat:     true

                        onTriggered: {
                            var seconds = _msecs / 1000
                            _valueXAxis.max = seconds
                            _valueRateXAxis.max = seconds

                            getValues()

                            valueSeries.append(seconds, _value)
                            adjustYAxisMin(_valueYAxis, _value)
                            adjustYAxisMax(_valueYAxis, _value)

                            valueSetpointSeries.append(seconds, _valueSetpoint)
                            adjustYAxisMin(_valueYAxis, _valueSetpoint)
                            adjustYAxisMax(_valueYAxis, _valueSetpoint)

                            valueRateSeries.append(seconds, _valueRate)
                            adjustYAxisMin(_valueRateYAxis, _valueRate)
                            adjustYAxisMax(_valueRateYAxis, _valueRate)

                            valueRateSetpointSeries.append(seconds, _valueRateSetpoint)
                            adjustYAxisMin(_valueRateYAxis, _valueRateSetpoint)
                            adjustYAxisMax(_valueRateYAxis, _valueRateSetpoint)

                            _msecs += interval
DonLakeFlyer's avatar
DonLakeFlyer committed
312 313
                            /*
                              Testing with just start/stop for now. No time limit.
314 315 316 317 318 319 320 321
                            if (valueSeries.count > _maxPointCount) {
                                valueSeries.remove(0)
                                valueSetpointSeries.remove(0)
                                valueRateSeries.remove(0)
                                valueRateSetpointSeries.remove(0)
                                valueXAxis.min = valueSeries.at(0).x
                                valueRateXAxis.min = valueSeries.at(0).x
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
322
                            */
DonLakeFlyer's avatar
DonLakeFlyer committed
323 324
                        }

325 326 327
                        property var _activeVehicle:    QGroundControl.multiVehicleManager.activeVehicle
                        property int _maxPointCount:    10000 / interval
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
328

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
                    Column {
                        spacing:            _margins
                        Layout.alignment:   Qt.AlignTop

                        QGCLabel { text: qsTr("Tuning Axis:") }

                        RowLayout {
                            spacing: _margins

                            Repeater {
                                model: _tuneList
                                QGCRadioButton {
                                    text:           modelData
                                    checked:        _currentTuneType === modelData
                                    exclusiveGroup: tuneTypeRadios

                                    onClicked: _currentTuneType = modelData
DonLakeFlyer's avatar
DonLakeFlyer committed
346 347 348 349
                                }
                            }
                        }

350 351 352
                        Item { width: 1; height: 1 }

                        QGCLabel { text: qsTr("Tuning Values:") }
DonLakeFlyer's avatar
DonLakeFlyer committed
353

354 355 356 357 358 359 360 361 362 363 364 365
                        GridLayout {
                            rows:           factList.length
                            flow:           GridLayout.TopToBottom
                            rowSpacing:     _margins
                            columnSpacing:  _margins

                            property var factList: _params[_tuneList.indexOf(_currentTuneType)]

                            Repeater {
                                model: parent.factList

                                QGCLabel { text: modelData.name }
DonLakeFlyer's avatar
DonLakeFlyer committed
366 367
                            }

368 369
                            Repeater {
                                model: parent.factList
DonLakeFlyer's avatar
DonLakeFlyer committed
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
                                QGCButton {
                                    text: "-"
                                    onClicked: {
                                        var value = modelData.value
                                        modelData.value -= value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value
                                    }
                                }
                            }

                            Repeater {
                                model: parent.factList

                                FactTextField {
                                    Layout.fillWidth:   true
                                    fact:               modelData
                                    showUnits:          false
                                }
                            }

                            Repeater {
                                model: parent.factList

                                QGCButton {
                                    text: "+"
                                    onClicked: {
                                        var value = modelData.value
                                        modelData.value += value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value
                                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
399 400 401 402
                                }
                            }
                        }

403 404 405 406 407 408 409 410 411 412 413 414
                        RowLayout {
                            QGCLabel { text: qsTr("Increment/Decrement %") }

                            QGCComboBox {
                                id:     adjustPercentCombo
                                model:  ListModel {
                                    id: adjustPercentModel
                                    ListElement { text: "5"; value: 0.05 }
                                    ListElement { text: "10"; value: 0.10 }
                                    ListElement { text: "15"; value: 0.15 }
                                    ListElement { text: "20"; value: 0.20 }
                                }
DonLakeFlyer's avatar
DonLakeFlyer committed
415 416
                            }
                        }
417
                        Item { width: 1; height: 1 }
DonLakeFlyer's avatar
DonLakeFlyer committed
418

419
                        QGCLabel { text: qsTr("Saved Tuning Values:") }
DonLakeFlyer's avatar
DonLakeFlyer committed
420

421 422 423 424 425
                        GridLayout {
                            rows:           savedRepeater.model.length
                            flow:           GridLayout.TopToBottom
                            rowSpacing:     _margins
                            columnSpacing:  _margins
DonLakeFlyer's avatar
DonLakeFlyer committed
426

427 428
                            Repeater {
                                model: _params[_tuneList.indexOf(_currentTuneType)]
DonLakeFlyer's avatar
DonLakeFlyer committed
429

430 431
                                QGCLabel { text: modelData.name }
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
432

433 434
                            Repeater {
                                id: savedRepeater
DonLakeFlyer's avatar
DonLakeFlyer committed
435

436 437
                                QGCLabel { text: modelData }
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
438 439
                        }

440 441
                        RowLayout {
                            spacing: _margins
DonLakeFlyer's avatar
DonLakeFlyer committed
442

443 444 445 446
                            QGCButton {
                                text:       qsTr("Save Values")
                                onClicked:  saveTuningParamValues()
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
447

448 449 450 451
                            QGCButton {
                                text:       qsTr("Reset To Saved Values")
                                onClicked:  resetToSavedTuningParamValues()
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
452 453
                        }

454
                        Item { width: 1; height: 1 }
DonLakeFlyer's avatar
DonLakeFlyer committed
455

456
                        QGCLabel { text: qsTr("Chart:") }
DonLakeFlyer's avatar
DonLakeFlyer committed
457

458 459
                        RowLayout {
                            spacing: _margins
DonLakeFlyer's avatar
DonLakeFlyer committed
460

461 462 463 464
                            QGCButton {
                                text:       qsTr("Clear")
                                onClicked:  resetGraphs()
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
465

466 467 468 469
                            QGCButton {
                                text:       dataTimer.running ? qsTr("Stop") : qsTr("Start")
                                onClicked:  dataTimer.running = !dataTimer.running
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
470 471 472
                        }
                    }

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
                    Column {
                        Layout.fillWidth: true

                        ChartView {
                            anchors.left:       parent.left
                            anchors.right:      parent.right
                            height:             availableHeight / 2
                            title:              _currentTuneType
                            antialiasing:       true
                            legend.alignment:   Qt.AlignRight

                            LineSeries {
                                id:         valueSeries
                                name:       "Response"
                                axisY:      valueYAxis
                                axisX:      valueXAxis
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
490

491 492 493 494 495 496
                            LineSeries {
                                id:         valueSetpointSeries
                                name:       "Command"
                                axisY:      valueYAxis
                                axisX:      valueXAxis
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
497 498
                        }

499 500 501 502 503 504 505 506 507 508 509 510 511 512
                        ChartView {
                            anchors.left:       parent.left
                            anchors.right:      parent.right
                            height:             availableHeight / 2
                            title:              _currentTuneType + qsTr(" Rate")
                            antialiasing:       true
                            legend.alignment:   Qt.AlignRight

                            LineSeries {
                                id:         valueRateSeries
                                name:       "Response"
                                axisY:      valueRateYAxis
                                axisX:      valueRateXAxis
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
513

514 515 516 517 518 519
                            LineSeries {
                                id:         valueRateSetpointSeries
                                name:       "Command"
                                axisY:      valueRateYAxis
                                axisX:      valueRateXAxis
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
520 521
                        }
                    }
522 523
                } // RowLayout - Advanced Page
            } // Component - Advanced Page
DonLakeFlyer's avatar
DonLakeFlyer committed
524 525
        } // Column
    } // Component - pageComponent
526
} // SetupPage