PowerComponent.qml 23.9 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11
import QtQuick          2.3
import QtQuick.Controls 1.2
12
import QtQuick.Dialogs  1.2
13
import QtQuick.Layouts  1.2
dogmaphobic's avatar
dogmaphobic committed
14

15 16 17 18 19
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controllers   1.0
dogmaphobic's avatar
dogmaphobic committed
20

21 22 23
SetupPage {
    id:             powerPage
    pageComponent:  pageComponent
24

25
    Component {
26 27
        id: pageComponent

Don Gagne's avatar
Don Gagne committed
28 29 30 31
        Item {
            width:  Math.max(availableWidth, innerColumn.width)
            height: innerColumn.height

32 33 34 35 36 37 38 39 40 41 42 43 44
            property int textEditWidth:    ScreenTools.defaultFontPixelWidth * 8

            property Fact battNumCells:         controller.getParameterFact(-1, "BAT_N_CELLS")
            property Fact battHighVolt:         controller.getParameterFact(-1, "BAT_V_CHARGED")
            property Fact battLowVolt:          controller.getParameterFact(-1, "BAT_V_EMPTY")
            property Fact battVoltLoadDrop:     controller.getParameterFact(-1, "BAT_V_LOAD_DROP")
            property Fact battVoltageDivider:   controller.getParameterFact(-1, "BAT_V_DIV")
            property Fact battAmpsPerVolt:      controller.getParameterFact(-1, "BAT_A_PER_V")
            property Fact uavcanEnable:         controller.getParameterFact(-1, "UAVCAN_ENABLE", false)

            readonly property string highlightPrefix:   "<font color=\"" + qgcPal.warningText + "\">"
            readonly property string highlightSuffix:   "</font>"

Don Gagne's avatar
Don Gagne committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
            ColumnLayout {
                id:                         innerColumn
                anchors.horizontalCenter:   parent.horizontalCenter
                spacing:                    ScreenTools.defaultFontPixelHeight

                function getBatteryImage()
                {
                    switch(battNumCells.value) {
                    case 1:  return "/qmlimages/PowerComponentBattery_01cell.svg";
                    case 2:  return "/qmlimages/PowerComponentBattery_02cell.svg"
                    case 3:  return "/qmlimages/PowerComponentBattery_03cell.svg"
                    case 4:  return "/qmlimages/PowerComponentBattery_04cell.svg"
                    case 5:  return "/qmlimages/PowerComponentBattery_05cell.svg"
                    case 6:  return "/qmlimages/PowerComponentBattery_06cell.svg"
                    default: return "/qmlimages/PowerComponentBattery_01cell.svg";
                    }
61
                }
62

Don Gagne's avatar
Don Gagne committed
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
                function drawArrowhead(ctx, x, y, radians)
                {
                    ctx.save();
                    ctx.beginPath();
                    ctx.translate(x,y);
                    ctx.rotate(radians);
                    ctx.moveTo(0,0);
                    ctx.lineTo(5,10);
                    ctx.lineTo(-5,10);
                    ctx.closePath();
                    ctx.restore();
                    ctx.fill();
                }

                function drawLineWithArrow(ctx, x1, y1, x2, y2)
                {
                    ctx.beginPath();
                    ctx.moveTo(x1, y1);
                    ctx.lineTo(x2, y2);
                    ctx.stroke();
                    var rd = Math.atan((y2 - y1) / (x2 - x1));
                    rd += ((x2 > x1) ? 90 : -90) * Math.PI/180;
                    drawArrowhead(ctx, x2, y2, rd);
                }

                PowerComponentController {
                    id:         controller
                    factPanel:  powerPage.viewPanel

                    onOldFirmware:          showMessage(qsTr("ESC Calibration"), qsTr("QGroundControl cannot perform ESC Calibration with this version of firmware. You will need to upgrade to a newer firmware."), StandardButton.Ok)
                    onNewerFirmware:        showMessage(qsTr("ESC Calibration"), qsTr("QGroundControl cannot perform ESC Calibration with this version of firmware. You will need to upgrade QGroundControl."), StandardButton.Ok)
                    onBatteryConnected:     showMessage(qsTr("ESC Calibration"), qsTr("Performing calibration. This will take a few seconds.."), 0)
                    onCalibrationFailed:    showMessage(qsTr("ESC Calibration failed"), errorMessage, StandardButton.Ok)
                    onCalibrationSuccess:   showMessage(qsTr("ESC Calibration"), qsTr("Calibration complete. You can disconnect your battery now if you like."), StandardButton.Ok)
                    onConnectBattery:       showMessage(qsTr("ESC Calibration"), highlightPrefix + qsTr("WARNING: Props must be removed from vehicle prior to performing ESC calibration.") + highlightSuffix + qsTr(" Connect the battery now and calibration will begin."), 0)
                    onDisconnectBattery:    showMessage(qsTr("ESC Calibration failed"), qsTr("You must disconnect the battery prior to performing ESC Calibration. Disconnect your battery and try again."), StandardButton.Ok)
                }

                Component {
                    id: calcVoltageDividerDlgComponent

                    QGCViewDialog {
                        id: calcVoltageDividerDlg
106

Don Gagne's avatar
Don Gagne committed
107 108 109 110 111 112 113 114 115
                        QGCFlickable {
                            anchors.fill:   parent
                            contentHeight:  column.height
                            contentWidth:   column.width

                            Column {
                                id:         column
                                width:      calcVoltageDividerDlg.width
                                spacing:    ScreenTools.defaultFontPixelHeight
116

117
                                QGCLabel {
Don Gagne's avatar
Don Gagne committed
118 119 120
                                    width:      parent.width
                                    wrapMode:   Text.WordWrap
                                    text:       "Measure battery voltage using an external voltmeter and enter the value below. Click Calculate to set the new voltage multiplier."
121
                                }
122

Don Gagne's avatar
Don Gagne committed
123 124 125 126
                                Grid {
                                    columns: 2
                                    spacing: ScreenTools.defaultFontPixelHeight / 2
                                    verticalItemAlignment: Grid.AlignVCenter
127

Don Gagne's avatar
Don Gagne committed
128 129 130 131
                                    QGCLabel {
                                        text: "Measured voltage:"
                                    }
                                    QGCTextField { id: measuredVoltage }
132

Don Gagne's avatar
Don Gagne committed
133 134
                                    QGCLabel { text: "Vehicle voltage:" }
                                    QGCLabel { text: controller.vehicle.battery.voltage.valueString }
135

Don Gagne's avatar
Don Gagne committed
136 137
                                    QGCLabel { text: "Voltage divider:" }
                                    FactLabel { fact: battVoltageDivider }
138
                                }
139

Don Gagne's avatar
Don Gagne committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                                QGCButton {
                                    text: "Calculate"

                                    onClicked:  {
                                        var measuredVoltageValue = parseFloat(measuredVoltage.text)
                                        if (measuredVoltageValue == 0 || isNaN(measuredVoltageValue)) {
                                            return
                                        }
                                        var newVoltageDivider = (measuredVoltageValue * battVoltageDivider.value) / controller.vehicle.battery.voltage.value
                                        if (newVoltageDivider > 0) {
                                            battVoltageDivider.value = newVoltageDivider
                                        }
                                    }
                                }
                            } // Column
                        } // QGCFlickable
                    } // QGCViewDialog
                } // Component - calcVoltageDividerDlgComponent
158

Don Gagne's avatar
Don Gagne committed
159 160
                Component {
                    id: calcAmpsPerVoltDlgComponent
161

Don Gagne's avatar
Don Gagne committed
162 163
                    QGCViewDialog {
                        id: calcAmpsPerVoltDlg
164

Don Gagne's avatar
Don Gagne committed
165 166 167 168
                        QGCFlickable {
                            anchors.fill:   parent
                            contentHeight:  column.height
                            contentWidth:   column.width
169

Don Gagne's avatar
Don Gagne committed
170 171 172 173
                            Column {
                                id:         column
                                width:      calcAmpsPerVoltDlg.width
                                spacing:    ScreenTools.defaultFontPixelHeight
174

175
                                QGCLabel {
Don Gagne's avatar
Don Gagne committed
176 177 178
                                    width:      parent.width
                                    wrapMode:   Text.WordWrap
                                    text:       "Measure current draw using an external current meter and enter the value below. Click Calculate to set the new amps per volt value."
179
                                }
180

Don Gagne's avatar
Don Gagne committed
181 182 183 184
                                Grid {
                                    columns: 2
                                    spacing: ScreenTools.defaultFontPixelHeight / 2
                                    verticalItemAlignment: Grid.AlignVCenter
185

Don Gagne's avatar
Don Gagne committed
186 187 188 189
                                    QGCLabel {
                                        text: "Measured current:"
                                    }
                                    QGCTextField { id: measuredCurrent }
190

Don Gagne's avatar
Don Gagne committed
191 192
                                    QGCLabel { text: "Vehicle current:" }
                                    QGCLabel { text: controller.vehicle.battery.current.valueString }
193

Don Gagne's avatar
Don Gagne committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                                    QGCLabel { text: "Amps per volt:" }
                                    FactLabel { fact: battAmpsPerVolt }
                                }

                                QGCButton {
                                    text: "Calculate"

                                    onClicked:  {
                                        var measuredCurrentValue = parseFloat(measuredCurrent.text)
                                        if (measuredCurrentValue == 0) {
                                            return
                                        }
                                        var newAmpsPerVolt = (measuredCurrentValue * battAmpsPerVolt.value) / controller.vehicle.battery.current.value
                                        if (newAmpsPerVolt != 0) {
                                            battAmpsPerVolt.value = newAmpsPerVolt
                                        }
210 211
                                    }
                                }
Don Gagne's avatar
Don Gagne committed
212 213 214 215
                            } // Column
                        } // QGCFlickable
                    } // QGCViewDialog
                } // Component - calcAmpsPerVoltDlgComponent
216

Don Gagne's avatar
Don Gagne committed
217 218 219
                QGCGroupBox {
                    id:     batteryGroup
                    title:  qsTr("Battery")
220

Don Gagne's avatar
Don Gagne committed
221 222 223 224
                    GridLayout {
                        id:             batteryGrid
                        columns:        5
                        columnSpacing:  ScreenTools.defaultFontPixelWidth
225

Don Gagne's avatar
Don Gagne committed
226 227 228
                        QGCLabel {
                            text:               qsTr("Number of Cells (in Series)")
                        }
229

Don Gagne's avatar
Don Gagne committed
230 231 232 233 234 235
                        FactTextField {
                            id:         cellsField
                            width:      textEditWidth
                            fact:       battNumCells
                            showUnits:  true
                        }
236

Don Gagne's avatar
Don Gagne committed
237 238 239 240 241 242 243 244 245 246 247 248
                        QGCColoredImage {
                            id:                     batteryImage
                            Layout.rowSpan:         3
                            width:                  height * 0.75
                            height:                 100
                            sourceSize.height:      height
                            fillMode:               Image.PreserveAspectFit
                            smooth:                 true
                            color:                  qgcPal.text
                            cache:                  false
                            source:                 getBatteryImage();
                        }
249

Don Gagne's avatar
Don Gagne committed
250
                        Item { width: 1; height: 1; Layout.columnSpan: 2 }
251

Don Gagne's avatar
Don Gagne committed
252 253 254 255
                        QGCLabel {
                            id:                 battHighLabel
                            text:               qsTr("Full Voltage (per cell)")
                        }
256

Don Gagne's avatar
Don Gagne committed
257 258 259 260 261 262
                        FactTextField {
                            id:         battHighField
                            width:      textEditWidth
                            fact:       battHighVolt
                            showUnits:  true
                        }
263

Don Gagne's avatar
Don Gagne committed
264 265 266
                        QGCLabel {
                            text:   qsTr("Battery Max:")
                        }
267

Don Gagne's avatar
Don Gagne committed
268 269 270
                        QGCLabel {
                            text:   (battNumCells.value * battHighVolt.value).toFixed(1) + ' V'
                        }
271

Don Gagne's avatar
Don Gagne committed
272 273 274 275
                        QGCLabel {
                            id:                 battLowLabel
                            text:               qsTr("Empty Voltage (per cell)")
                        }
276

Don Gagne's avatar
Don Gagne committed
277 278 279 280 281 282
                        FactTextField {
                            id:         battLowField
                            width:      textEditWidth
                            fact:       battLowVolt
                            showUnits:  true
                        }
283

Don Gagne's avatar
Don Gagne committed
284 285 286
                        QGCLabel {
                            text:   qsTr("Battery Min:")
                        }
287

Don Gagne's avatar
Don Gagne committed
288 289 290
                        QGCLabel {
                            text:   (battNumCells.value * battLowVolt.value).toFixed(1) + ' V'
                        }
291

Don Gagne's avatar
Don Gagne committed
292 293 294
                        QGCLabel {
                            text:               qsTr("Voltage divider")
                        }
295

Don Gagne's avatar
Don Gagne committed
296 297 298 299
                        FactTextField {
                            id:                 voltMultField
                            fact:               battVoltageDivider
                        }
Don Gagne's avatar
Don Gagne committed
300

Don Gagne's avatar
Don Gagne committed
301 302 303 304 305
                        QGCButton {
                            id:                 voltMultCalculateButton
                            text:               "Calculate"
                            onClicked:          showDialog(calcVoltageDividerDlgComponent, qsTr("Calculate Voltage Divider"), powerPage.showDialogDefaultWidth, StandardButton.Close)
                        }
Don Gagne's avatar
Don Gagne committed
306

Don Gagne's avatar
Don Gagne committed
307
                        Item { width: 1; height: 1; Layout.columnSpan: 2 }
Don Gagne's avatar
Don Gagne committed
308

Don Gagne's avatar
Don Gagne committed
309 310 311 312 313 314 315 316 317
                        QGCLabel {
                            id:                 voltMultHelp
                            Layout.columnSpan:  batteryGrid.columns
                            Layout.fillWidth:   true
                            font.pointSize:     ScreenTools.smallFontPointSize
                            wrapMode:           Text.WordWrap
                            text:               "If the battery voltage reported by the vehicle is largely different than the voltage read externally using a voltmeter you can adjust the voltage multiplier value to correct this. " +
                                                "Click the Calculate button for help with calculating a new value."
                        }
Don Gagne's avatar
Don Gagne committed
318

Don Gagne's avatar
Don Gagne committed
319 320 321 322
                        QGCLabel {
                            id:                 ampPerVoltLabel
                            text:               qsTr("Amps per volt")
                        }
323

Don Gagne's avatar
Don Gagne committed
324 325 326 327
                        FactTextField {
                            id:                 ampPerVoltField
                            fact:               battAmpsPerVolt
                        }
328

Don Gagne's avatar
Don Gagne committed
329 330 331 332 333
                        QGCButton {
                            id:                 ampPerVoltCalculateButton
                            text:               "Calculate"
                            onClicked:          showDialog(calcAmpsPerVoltDlgComponent, qsTr("Calculate Amps per Volt"), powerPage.showDialogDefaultWidth, StandardButton.Close)
                        }
334

Don Gagne's avatar
Don Gagne committed
335
                        Item { width: 1; height: 1; Layout.columnSpan: 2 }
Don Gagne's avatar
Don Gagne committed
336

Don Gagne's avatar
Don Gagne committed
337 338 339 340 341 342 343 344 345 346 347
                        QGCLabel {
                            id:                 ampPerVoltHelp
                            Layout.columnSpan:  batteryGrid.columns
                            Layout.fillWidth:   true
                            font.pointSize:     ScreenTools.smallFontPointSize
                            wrapMode:           Text.WordWrap
                            text:               "If the current draw reported by the vehicle is largely different than the current read externally using a current meter you can adjust the amps per volt value to correct this. " +
                                                "Click the Calculate button for help with calculating a new value."
                        }
                    } // Grid
                } // QGCGroupBox - Battery settings
348

Don Gagne's avatar
Don Gagne committed
349 350 351 352
                QGCGroupBox {
                    anchors.left:   batteryGroup.left
                    anchors.right:  batteryGroup.right
                    title:          qsTr("ESC PWM Minimum and Maximum Calibration")
dogmaphobic's avatar
dogmaphobic committed
353

Don Gagne's avatar
Don Gagne committed
354 355 356 357
                    ColumnLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        spacing:        ScreenTools.defaultFontPixelWidth
358

Don Gagne's avatar
Don Gagne committed
359 360 361 362 363 364 365 366 367 368
                        QGCLabel {
                            color:              qgcPal.warningText
                            wrapMode:           Text.WordWrap
                            text:               qsTr("WARNING: Propellers must be removed from vehicle prior to performing ESC calibration.")
                            Layout.fillWidth:   true
                        }

                        QGCLabel {
                            text: qsTr("You must use USB connection for this operation.")
                        }
369

Don Gagne's avatar
Don Gagne committed
370 371 372 373 374
                        QGCButton {
                            text:       qsTr("Calibrate")
                            width:      ScreenTools.defaultFontPixelWidth * 20
                            onClicked:  controller.calibrateEsc()
                        }
375
                    }
376
                }
377

Don Gagne's avatar
Don Gagne committed
378 379 380 381 382
                QGCCheckBox {
                    id:         showUAVCAN
                    text:       qsTr("Show UAVCAN Settings")
                    checked:    uavcanEnable.rawValue != 0
                }
383

Don Gagne's avatar
Don Gagne committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
                QGCGroupBox {
                    anchors.left:   batteryGroup.left
                    anchors.right:  batteryGroup.right
                    title:          qsTr("UAVCAN Bus Configuration")
                    visible:        showUAVCAN.checked

                    Row {
                        id:         uavCanConfigRow
                        spacing:    ScreenTools.defaultFontPixelWidth

                        FactComboBox {
                            id:                 uavcanEnabledCheckBox
                            width:              ScreenTools.defaultFontPixelWidth * 20
                            fact:               uavcanEnable
                            indexModel:         false
399 400
                        }

Don Gagne's avatar
Don Gagne committed
401 402 403
                        QGCLabel {
                            anchors.verticalCenter: parent.verticalCenter
                            text:                   qsTr("Change required restart")
404
                        }
405
                    }
Don Gagne's avatar
Don Gagne committed
406
                }
407

Don Gagne's avatar
Don Gagne committed
408 409 410 411 412
                QGCGroupBox {
                    anchors.left:   batteryGroup.left
                    anchors.right:  batteryGroup.right
                    title:          qsTr("UAVCAN Motor Index and Direction Assignment")
                    visible:        showUAVCAN.checked
413

Don Gagne's avatar
Don Gagne committed
414 415 416 417
                    ColumnLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        spacing:        ScreenTools.defaultFontPixelWidth
418

419
                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
420 421 422 423
                            wrapMode:           Text.WordWrap
                            color:              qgcPal.warningText
                            text:               qsTr("WARNING: Propellers must be removed from vehicle prior to performing UAVCAN ESC configuration.")
                            Layout.fillWidth:   true
424 425
                        }

426
                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
                            wrapMode:           Text.WordWrap
                            text:               qsTr("ESC parameters will only be accessible in the editor after assignment.")
                            Layout.fillWidth:   true
                        }

                        QGCLabel {
                            wrapMode:           Text.WordWrap
                            text:               qsTr("Start the process, then turn each motor into its turn direction, in the order of their motor indices.")
                            Layout.fillWidth:   true
                        }

                        QGCButton {
                            text:       qsTr("Start Assignment")
                            width:      ScreenTools.defaultFontPixelWidth * 20
                            onClicked:  controller.busConfigureActuators()
                        }

                        QGCButton {
                            text:       qsTr("Stop Assignment")
                            width:      ScreenTools.defaultFontPixelWidth * 20
                            onClicked:  controller.stopBusConfigureActuators()
448 449
                        }
                    }
450
                }
Don Gagne's avatar
Don Gagne committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506

                QGCCheckBox {
                    id:     showAdvanced
                    text:   qsTr("Show Advanced Settings")
                }

                QGCGroupBox {
                    anchors.left:   batteryGroup.left
                    anchors.right:  batteryGroup.right
                    title:          qsTr("Advanced Power Settings")
                    visible:        showAdvanced.checked

                    ColumnLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        spacing:        ScreenTools.defaultFontPixelWidth

                        Row {
                            spacing: ScreenTools.defaultFontPixelWidth

                            QGCLabel {
                                text:               qsTr("Voltage Drop on Full Load (per cell)")
                                anchors.baseline:   battDropField.baseline
                            }

                            FactTextField {
                                id:         battDropField
                                width:      textEditWidth
                                fact:       battVoltLoadDrop
                                showUnits:  true
                            }
                        }

                        QGCLabel {
                            wrapMode:           Text.WordWrap
                            text:               qsTr("Batteries show less voltage at high throttle. Enter the difference in Volts between idle throttle and full ") +
                                                qsTr("throttle, divided by the number of battery cells. Leave at the default if unsure. ") +
                                                highlightPrefix + qsTr("If this value is set too high, the battery might be deep discharged and damaged.") + highlightSuffix
                            Layout.fillWidth:   true
                        }

                        Row {
                            spacing: ScreenTools.defaultFontPixelWidth

                            QGCLabel {
                                text: qsTr("Compensated Minimum Voltage:")
                            }

                            QGCLabel {
                                text: ((battNumCells.value * battLowVolt.value) - (battNumCells.value * battVoltLoadDrop.value)).toFixed(1) + qsTr(" V")
                            }
                        }
                    } // Column
                } // QGCGroupBox - Advanced power settings
            } // Column
        } // Item
507 508
    } // Component
} // SetupPage